| 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 |  | 
|---|
| 13 | #ifndef BOOST_DETAIL_REFERENCE_CONTENT_HPP | 
|---|
| 14 | #define BOOST_DETAIL_REFERENCE_CONTENT_HPP | 
|---|
| 15 |  | 
|---|
| 16 | #include "boost/config.hpp" | 
|---|
| 17 |  | 
|---|
| 18 | #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) | 
|---|
| 19 | #   include "boost/mpl/bool.hpp" | 
|---|
| 20 | #   include "boost/type_traits/has_nothrow_copy.hpp" | 
|---|
| 21 | #else | 
|---|
| 22 | #   include "boost/mpl/if.hpp" | 
|---|
| 23 | #   include "boost/type_traits/is_reference.hpp" | 
|---|
| 24 | #endif | 
|---|
| 25 |  | 
|---|
| 26 | #include "boost/mpl/void.hpp" | 
|---|
| 27 |  | 
|---|
| 28 | namespace boost { | 
|---|
| 29 |  | 
|---|
| 30 | namespace detail { | 
|---|
| 31 |  | 
|---|
| 32 | /////////////////////////////////////////////////////////////////////////////// | 
|---|
| 33 | // (detail) class template reference_content | 
|---|
| 34 | // | 
|---|
| 35 | // Non-Assignable wrapper for references. | 
|---|
| 36 | // | 
|---|
| 37 | template <typename RefT> | 
|---|
| 38 | class reference_content | 
|---|
| 39 | { | 
|---|
| 40 | private: // representation | 
|---|
| 41 |  | 
|---|
| 42 |     RefT content_; | 
|---|
| 43 |  | 
|---|
| 44 | public: // structors | 
|---|
| 45 |  | 
|---|
| 46 |     ~reference_content() | 
|---|
| 47 |     { | 
|---|
| 48 |     } | 
|---|
| 49 |  | 
|---|
| 50 |     reference_content(RefT r) | 
|---|
| 51 |         : content_( r ) | 
|---|
| 52 |     { | 
|---|
| 53 |     } | 
|---|
| 54 |  | 
|---|
| 55 |     reference_content(const reference_content& operand) | 
|---|
| 56 |         : content_( operand.content_ ) | 
|---|
| 57 |     { | 
|---|
| 58 |     } | 
|---|
| 59 |  | 
|---|
| 60 | private: // non-Assignable | 
|---|
| 61 |  | 
|---|
| 62 |     reference_content& operator=(const reference_content&); | 
|---|
| 63 |  | 
|---|
| 64 | public: // queries | 
|---|
| 65 |  | 
|---|
| 66 |     RefT get() const | 
|---|
| 67 |     { | 
|---|
| 68 |         return content_; | 
|---|
| 69 |     } | 
|---|
| 70 |  | 
|---|
| 71 | }; | 
|---|
| 72 |  | 
|---|
| 73 | /////////////////////////////////////////////////////////////////////////////// | 
|---|
| 74 | // (detail) metafunction make_reference_content | 
|---|
| 75 | // | 
|---|
| 76 | // Wraps with reference_content if specified type is reference. | 
|---|
| 77 | // | 
|---|
| 78 |  | 
|---|
| 79 | template <typename T = mpl::void_> struct make_reference_content; | 
|---|
| 80 |  | 
|---|
| 81 | #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) | 
|---|
| 82 |  | 
|---|
| 83 | template <typename T> | 
|---|
| 84 | struct make_reference_content | 
|---|
| 85 | { | 
|---|
| 86 |     typedef T type; | 
|---|
| 87 | }; | 
|---|
| 88 |  | 
|---|
| 89 | template <typename T> | 
|---|
| 90 | struct make_reference_content< T& > | 
|---|
| 91 | { | 
|---|
| 92 |     typedef reference_content<T&> type; | 
|---|
| 93 | }; | 
|---|
| 94 |  | 
|---|
| 95 | #else // defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) | 
|---|
| 96 |  | 
|---|
| 97 | template <typename T> | 
|---|
| 98 | struct make_reference_content | 
|---|
| 99 |     : mpl::if_< | 
|---|
| 100 |           is_reference<T> | 
|---|
| 101 |         , reference_content<T> | 
|---|
| 102 |         , T | 
|---|
| 103 |         > | 
|---|
| 104 | { | 
|---|
| 105 | }; | 
|---|
| 106 |  | 
|---|
| 107 | #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround | 
|---|
| 108 |  | 
|---|
| 109 | template <> | 
|---|
| 110 | struct make_reference_content< mpl::void_ > | 
|---|
| 111 | { | 
|---|
| 112 |     template <typename T> | 
|---|
| 113 |     struct apply | 
|---|
| 114 |         : make_reference_content<T> | 
|---|
| 115 |     { | 
|---|
| 116 |     }; | 
|---|
| 117 |  | 
|---|
| 118 |     typedef mpl::void_ type; | 
|---|
| 119 | }; | 
|---|
| 120 |  | 
|---|
| 121 | } // namespace detail | 
|---|
| 122 |  | 
|---|
| 123 | /////////////////////////////////////////////////////////////////////////////// | 
|---|
| 124 | // reference_content<T&> type traits specializations | 
|---|
| 125 | // | 
|---|
| 126 |  | 
|---|
| 127 | #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) | 
|---|
| 128 |  | 
|---|
| 129 | template <typename T> | 
|---|
| 130 | struct has_nothrow_copy< | 
|---|
| 131 |       ::boost::detail::reference_content< T& > | 
|---|
| 132 |     > | 
|---|
| 133 |     : mpl::true_ | 
|---|
| 134 | { | 
|---|
| 135 | }; | 
|---|
| 136 |  | 
|---|
| 137 | #endif // !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) | 
|---|
| 138 |  | 
|---|
| 139 | } // namespace boost | 
|---|
| 140 |  | 
|---|
| 141 | #endif // BOOST_DETAIL_REFERENCE_CONTENT_HPP | 
|---|