Dukales

copy qualifiers

Jun 20th, 2015
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.39 KB | None | 0 0
  1.  
  2. template< typename from, typename to >
  3. struct copy_cv_reference
  4. {
  5.  
  6.     using type = to;
  7.  
  8. };
  9.  
  10. template< typename from, typename to >
  11. struct copy_cv_reference< from const, to >
  12.         : copy_cv_reference< from, to const >
  13. {
  14.  
  15. };
  16.  
  17. template< typename from, typename to >
  18. struct copy_cv_reference< volatile from, to >
  19.         : copy_cv_reference< from, volatile to >
  20. {
  21.  
  22. };
  23.  
  24. template< typename from, typename to >
  25. struct copy_cv_reference< from const, to & >
  26.         : copy_cv_reference< from, to const & >
  27. {
  28.  
  29. };
  30.  
  31. template< typename from, typename to >
  32. struct copy_cv_reference< volatile from, to & >
  33.         : copy_cv_reference< from, volatile to & >
  34. {
  35.  
  36. };
  37.  
  38. template< typename from, typename to >
  39. struct copy_cv_reference< from const, to && >
  40.         : copy_cv_reference< from, to const && >
  41. {
  42.  
  43. };
  44.  
  45. template< typename from, typename to >
  46. struct copy_cv_reference< volatile from, to && >
  47.         : copy_cv_reference< from, volatile to && >
  48. {
  49.  
  50. };
  51.  
  52. template< typename from, typename to >
  53. struct copy_cv_reference< from &, to >
  54.         : copy_cv_reference< from, to & >
  55. {
  56.  
  57. };
  58.  
  59. template< typename from, typename to >
  60. struct copy_cv_reference< from &&, to >
  61.         : copy_cv_reference< from, to && >
  62. {
  63.  
  64. };
  65.  
  66. namespace test
  67. {
  68.  
  69. struct A {};
  70. struct B {};
  71. static_assert((std::is_same< copy_cv_reference< volatile const A &, B >::type, volatile const B & >{}), "");
  72. static_assert((std::is_same< copy_cv_reference< const A &, B >::type, const B & >{}), "");
  73. static_assert((std::is_same< copy_cv_reference< volatile A &, B >::type, volatile B & >{}), "");
  74. static_assert((std::is_same< copy_cv_reference< A &, B >::type, B & >{}), "");
  75. static_assert((std::is_same< copy_cv_reference< volatile const A &, B >::type, volatile const B & >{}), "");
  76. static_assert((std::is_same< copy_cv_reference< const A &&, B >::type, const B && >{}), "");
  77. static_assert((std::is_same< copy_cv_reference< volatile A &&, B >::type, volatile B && >{}), "");
  78. static_assert((std::is_same< copy_cv_reference< A &&, B >::type, B && >{}), "");
  79. static_assert((std::is_same< copy_cv_reference< volatile const A, B >::type, volatile const B >{}), "");
  80. static_assert((std::is_same< copy_cv_reference< const A, B >::type, const B >{}), "");
  81. static_assert((std::is_same< copy_cv_reference< volatile A, B >::type, volatile B >{}), "");
  82. static_assert((std::is_same< copy_cv_reference< A, B >::type, B >{}), "");
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment