tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
move_if_noexcept.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2019 Tobias Hienzsch
3
4#ifndef TETL_UTILITY_MOVE_IF_NOEXCEPT_HPP
5#define TETL_UTILITY_MOVE_IF_NOEXCEPT_HPP
6
7#include <etl/_type_traits/conditional.hpp>
8#include <etl/_type_traits/is_copy_constructible.hpp>
9#include <etl/_type_traits/is_nothrow_move_constructible.hpp>
10#include <etl/_utility/move.hpp>
11
12namespace etl {
13
14/// \brief Conditionally convert a value to an rvalue.
15/// \details Same as etl::move unless the type's move constructor could throw
16/// and the type is copyable, in which case an lvalue-reference is returned
17/// instead.
18template <typename T>
19[[nodiscard]] constexpr auto move_if_noexcept(T& x) noexcept
20 -> etl::conditional_t<!etl::is_nothrow_move_constructible_v<T> and etl::is_copy_constructible_v<T>, T const&, T&&>
21{
22 return etl::move(x);
23}
24
25} // namespace etl
26
27#endif // TETL_UTILITY_MOVE_IF_NOEXCEPT_HPP
Definition adjacent_find.hpp:9
constexpr auto move_if_noexcept(T &x) noexcept -> etl::conditional_t<!etl::is_nothrow_move_constructible_v< T > and etl::is_copy_constructible_v< T >, T const &, T && >
Conditionally convert a value to an rvalue.
Definition move_if_noexcept.hpp:19