reference_content.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. # include "boost/type_traits/integral_constant.hpp"
  16. # include "boost/type_traits/has_nothrow_copy.hpp"
  17. namespace boost {
  18. namespace detail {
  19. struct void_type {};
  20. ///////////////////////////////////////////////////////////////////////////////
  21. // (detail) class template reference_content
  22. //
  23. // Non-Assignable wrapper for references.
  24. //
  25. template <typename RefT>
  26. class reference_content
  27. {
  28. private: // representation
  29. RefT content_;
  30. public: // structors
  31. ~reference_content()
  32. {
  33. }
  34. reference_content(RefT r)
  35. : content_( r )
  36. {
  37. }
  38. reference_content(const reference_content& operand)
  39. : content_( operand.content_ )
  40. {
  41. }
  42. private: // non-Assignable
  43. reference_content& operator=(const reference_content&);
  44. public: // queries
  45. RefT get() const
  46. {
  47. return content_;
  48. }
  49. };
  50. ///////////////////////////////////////////////////////////////////////////////
  51. // (detail) metafunction make_reference_content
  52. //
  53. // Wraps with reference_content if specified type is reference.
  54. //
  55. template <typename T = void_type> struct make_reference_content;
  56. template <typename T>
  57. struct make_reference_content
  58. {
  59. typedef T type;
  60. };
  61. template <typename T>
  62. struct make_reference_content< T& >
  63. {
  64. typedef reference_content<T&> type;
  65. };
  66. template <>
  67. struct make_reference_content< void_type >
  68. {
  69. template <typename T>
  70. struct apply
  71. : make_reference_content<T>
  72. {
  73. };
  74. typedef void_type type;
  75. };
  76. } // namespace detail
  77. ///////////////////////////////////////////////////////////////////////////////
  78. // reference_content<T&> type traits specializations
  79. //
  80. template <typename T>
  81. struct has_nothrow_copy<
  82. ::boost::detail::reference_content< T& >
  83. >
  84. : boost::true_type
  85. {
  86. };
  87. } // namespace boost
  88. #endif // BOOST_DETAIL_REFERENCE_CONTENT_HPP