Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template< std::size_t cvref_id, typename type > struct add_cvref;
- template< typename to > struct add_cvref< 0, to > { using type = to ; };
- template< typename to > struct add_cvref< 1, to > { using type = to const ; };
- template< typename to > struct add_cvref< 2, to > { using type = to & ; };
- template< typename to > struct add_cvref< 3, to > { using type = to const & ; };
- template< typename to > struct add_cvref< 4, to > { using type = to &&; };
- template< typename to > struct add_cvref< 5, to > { using type = to const &&; };
- template< typename to > struct add_cvref< 6, to > { using type = volatile to ; };
- template< typename to > struct add_cvref< 7, to > { using type = volatile to const ; };
- template< typename to > struct add_cvref< 8, to > { using type = volatile to & ; };
- template< typename to > struct add_cvref< 9, to > { using type = volatile to const & ; };
- template< typename to > struct add_cvref< 10, to > { using type = volatile to &&; };
- template< typename to > struct add_cvref< 11, to > { using type = volatile to const &&; };
- template< std::size_t cvref_id, typename to >
- using add_cvref_t = typename add_cvref< cvref_id, to >::type;
- template< typename type > constexpr std::size_t cvref_id = 0;
- template< typename type > constexpr std::size_t cvref_id< type const > = 1;
- template< typename type > constexpr std::size_t cvref_id< type & > = 2;
- template< typename type > constexpr std::size_t cvref_id< type const & > = 3;
- template< typename type > constexpr std::size_t cvref_id< type && > = 4;
- template< typename type > constexpr std::size_t cvref_id< type const && > = 5;
- template< typename type > constexpr std::size_t cvref_id< volatile type > = 6;
- template< typename type > constexpr std::size_t cvref_id< volatile type const > = 7;
- template< typename type > constexpr std::size_t cvref_id< volatile type & > = 8;
- template< typename type > constexpr std::size_t cvref_id< volatile type const & > = 9;
- template< typename type > constexpr std::size_t cvref_id< volatile type && > = 10;
- template< typename type > constexpr std::size_t cvref_id< volatile type const && > = 11;
- template< typename from, typename to >
- using copy_cv_reference_t = add_cvref_t< cvref_id< from >, to >;
- namespace test
- {
- struct A {};
- struct B {};
- static_assert(std::is_same< copy_cv_reference_t< A , B >, B >{});
- static_assert(std::is_same< copy_cv_reference_t< A const , B >, B const >{});
- static_assert(std::is_same< copy_cv_reference_t< volatile A , B >, volatile B >{});
- static_assert(std::is_same< copy_cv_reference_t< volatile A const , B >, volatile B const >{});
- static_assert(std::is_same< copy_cv_reference_t< A &, B >, B & >{});
- static_assert(std::is_same< copy_cv_reference_t< A const &, B >, B const & >{});
- static_assert(std::is_same< copy_cv_reference_t< volatile A &, B >, volatile B & >{});
- static_assert(std::is_same< copy_cv_reference_t< volatile A const &, B >, volatile B const & >{});
- static_assert(std::is_same< copy_cv_reference_t< A &&, B >, B && >{});
- static_assert(std::is_same< copy_cv_reference_t< A const &&, B >, B const && >{});
- static_assert(std::is_same< copy_cv_reference_t< volatile A &&, B >, volatile B && >{});
- static_assert(std::is_same< copy_cv_reference_t< volatile A const &&, B >, volatile B const && >{});
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement