reference_content.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //-----------------------------------------------------------------------------
  2. // boost detail/reference_content.hpp header file
  3. // See http://www.boost.org for updates, documentation, and revision history.
  4. //-----------------------------------------------------------------------------
  5. //
  6. // Copyright (c) 2003
  7. // Eric Friedman
  8. //
  9. // Distributed under the Boost Software License, Version 1.0. (See
  10. // accompanying file LICENSE_1_0.txt or copy at
  11. // http://www.boost.org/LICENSE_1_0.txt)
  12. #ifndef BOOST_DETAIL_REFERENCE_CONTENT_HPP
  13. #define BOOST_DETAIL_REFERENCE_CONTENT_HPP
  14. #include "boost/config.hpp"
  15. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  16. # include "boost/mpl/bool.hpp"
  17. # include "boost/type_traits/has_nothrow_copy.hpp"
  18. #else
  19. # include "boost/mpl/if.hpp"
  20. # include "boost/type_traits/is_reference.hpp"
  21. #endif
  22. #include "boost/mpl/void.hpp"
  23. namespace boost {
  24. namespace detail {
  25. ///////////////////////////////////////////////////////////////////////////////
  26. // (detail) class template reference_content
  27. //
  28. // Non-Assignable wrapper for references.
  29. //
  30. template <typename RefT>
  31. class reference_content
  32. {
  33. private: // representation
  34. RefT content_;
  35. public: // structors
  36. ~reference_content()
  37. {
  38. }
  39. reference_content(RefT r)
  40. : content_( r )
  41. {
  42. }
  43. reference_content(const reference_content& operand)
  44. : content_( operand.content_ )
  45. {
  46. }
  47. private: // non-Assignable
  48. reference_content& operator=(const reference_content&);
  49. public: // queries
  50. RefT get() const
  51. {
  52. return content_;
  53. }
  54. };
  55. ///////////////////////////////////////////////////////////////////////////////
  56. // (detail) metafunction make_reference_content
  57. //
  58. // Wraps with reference_content if specified type is reference.
  59. //
  60. template <typename T = mpl::void_> struct make_reference_content;
  61. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  62. template <typename T>
  63. struct make_reference_content
  64. {
  65. typedef T type;
  66. };
  67. template <typename T>
  68. struct make_reference_content< T& >
  69. {
  70. typedef reference_content<T&> type;
  71. };
  72. #else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  73. template <typename T>
  74. struct make_reference_content
  75. : mpl::if_<
  76. is_reference<T>
  77. , reference_content<T>
  78. , T
  79. >
  80. {
  81. };
  82. #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround
  83. template <>
  84. struct make_reference_content< mpl::void_ >
  85. {
  86. template <typename T>
  87. struct apply
  88. : make_reference_content<T>
  89. {
  90. };
  91. typedef mpl::void_ type;
  92. };
  93. } // namespace detail
  94. ///////////////////////////////////////////////////////////////////////////////
  95. // reference_content<T&> type traits specializations
  96. //
  97. #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  98. template <typename T>
  99. struct has_nothrow_copy<
  100. ::boost::detail::reference_content< T& >
  101. >
  102. : mpl::true_
  103. {
  104. };
  105. #endif // !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
  106. } // namespace boost
  107. #endif // BOOST_DETAIL_REFERENCE_CONTENT_HPP