move_or_copy_assign_ref.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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_assign_ref.hpp
  10. *
  11. * This header contains definition of \c move_or_copy_assign_ref type trait.
  12. */
  13. #ifndef BOOST_SCOPE_DETAIL_MOVE_OR_COPY_ASSIGN_REF_HPP_INCLUDED_
  14. #define BOOST_SCOPE_DETAIL_MOVE_OR_COPY_ASSIGN_REF_HPP_INCLUDED_
  15. #include <type_traits>
  16. #include <boost/scope/detail/config.hpp>
  17. #include <boost/scope/detail/header.hpp>
  18. #ifdef BOOST_HAS_PRAGMA_ONCE
  19. #pragma once
  20. #endif
  21. namespace boost {
  22. namespace scope {
  23. namespace detail {
  24. //! The type trait produces an rvalue reference to \a From if \a To has a non-throwing assignment from a \a From rvalue and an lvalue reference otherwise.
  25. template< typename From, typename To = From >
  26. struct move_or_copy_assign_ref
  27. {
  28. using type = typename std::conditional<
  29. std::is_nothrow_assignable< To, From >::value,
  30. From&&,
  31. From const&
  32. >::type;
  33. };
  34. template< typename From, typename To >
  35. struct move_or_copy_assign_ref< From&, To >
  36. {
  37. using type = From&;
  38. };
  39. } // namespace detail
  40. } // namespace scope
  41. } // namespace boost
  42. #include <boost/scope/detail/footer.hpp>
  43. #endif // BOOST_SCOPE_DETAIL_MOVE_OR_COPY_ASSIGN_REF_HPP_INCLUDED_