| 1 | /* |
| 2 | * Distributed under the Boost Software License, Version 1.0. |
| 3 | * (See accompanying file LICENSE_1_0.txt or copy at |
| 4 | * https://www.boost.org/LICENSE_1_0.txt) |
| 5 | * |
| 6 | * Copyright (c) 2022 Andrey Semashev |
| 7 | */ |
| 8 | /*! |
| 9 | * \file scope/detail/move_or_copy_construct_ref.hpp |
| 10 | * |
| 11 | * This header contains definition of \c move_or_copy_construct_ref type trait. |
| 12 | */ |
| 13 | |
| 14 | #ifndef BOOST_SCOPE_DETAIL_MOVE_OR_COPY_CONSTRUCT_REF_HPP_INCLUDED_ |
| 15 | #define BOOST_SCOPE_DETAIL_MOVE_OR_COPY_CONSTRUCT_REF_HPP_INCLUDED_ |
| 16 | |
| 17 | #include <type_traits> |
| 18 | #include <boost/scope/detail/config.hpp> |
| 19 | #include <boost/scope/detail/header.hpp> |
| 20 | |
| 21 | #ifdef BOOST_HAS_PRAGMA_ONCE |
| 22 | #pragma once |
| 23 | #endif |
| 24 | |
| 25 | namespace boost { |
| 26 | namespace scope { |
| 27 | namespace detail { |
| 28 | |
| 29 | //! The type trait produces an rvalue reference to \a From if \a To has a non-throwing constructor from a \a From rvalue and an lvalue reference otherwise. |
| 30 | template< typename From, typename To = From > |
| 31 | struct move_or_copy_construct_ref |
| 32 | { |
| 33 | using type = typename std::conditional< |
| 34 | std::is_nothrow_constructible< To, From >::value, |
| 35 | From&&, |
| 36 | From const& |
| 37 | >::type; |
| 38 | }; |
| 39 | |
| 40 | template< typename From, typename To > |
| 41 | struct move_or_copy_construct_ref< From&, To > |
| 42 | { |
| 43 | using type = From&; |
| 44 | }; |
| 45 | |
| 46 | } // namespace detail |
| 47 | } // namespace scope |
| 48 | } // namespace boost |
| 49 | |
| 50 | #include <boost/scope/detail/footer.hpp> |
| 51 | |
| 52 | #endif // BOOST_SCOPE_DETAIL_MOVE_OR_COPY_CONSTRUCT_REF_HPP_INCLUDED_ |
| 53 | |