My Project
Functions
move_if_noexcept.hpp File Reference
#include "conditional.hpp"
#include "is_copy_constructible.hpp"
#include "is_nothrow_move_constructible.hpp"
#include "move.hpp"

Go to the source code of this file.

Functions

template<typename T >
constexpr conditional_t< !is_nothrow_move_constructible< T >::value &&is_copy_constructible< T >::value, T const &, T && > bsl::move_if_noexcept (T &val) noexcept
 move_if_noexcept obtains an rvalue reference to its argument if its move constructor does not throw exceptions or if there is no copy constructor (move-only type), otherwise obtains an lvalue reference to its argument. It is typically used to combine move semantics with strong exception guarantee. More...
 

Detailed Description

Function Documentation

◆ move_if_noexcept()

template<typename T >
constexpr conditional_t< !is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value, T const &, T &&> bsl::move_if_noexcept ( T &  val)
noexcept

move_if_noexcept obtains an rvalue reference to its argument if its move constructor does not throw exceptions or if there is no copy constructor (move-only type), otherwise obtains an lvalue reference to its argument. It is typically used to combine move semantics with strong exception guarantee.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_move_if_noexcept_overview() noexcept
{
bool val1{true};
bool const &&val2{bsl::move_if_noexcept(val1)};
if (val2) {
bsl::print() << "success\n";
}
}
}
Template Parameters
Tthe type that defines the value being moved
Parameters
valthe value being moved
Returns
std::move(val) or val, depending on exception guarantees.