Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 13 | #ifndef NDNBOOST_DETAIL_REFERENCE_CONTENT_HPP |
| 14 | #define NDNBOOST_DETAIL_REFERENCE_CONTENT_HPP |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 15 | |
| 16 | #include "ndnboost/config.hpp" |
| 17 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 18 | #if !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 19 | # include "ndnboost/mpl/bool.hpp" |
| 20 | # include "ndnboost/type_traits/has_nothrow_copy.hpp" |
| 21 | #else |
| 22 | # include "ndnboost/mpl/if.hpp" |
| 23 | # include "ndnboost/type_traits/is_reference.hpp" |
| 24 | #endif |
| 25 | |
| 26 | #include "ndnboost/mpl/void.hpp" |
| 27 | |
| 28 | namespace ndnboost { |
| 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 81 | #if !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 95 | #else // defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 107 | #endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 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 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 127 | #if !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 128 | |
| 129 | template <typename T> |
| 130 | struct has_nothrow_copy< |
| 131 | ::ndnboost::detail::reference_content< T& > |
| 132 | > |
| 133 | : mpl::true_ |
| 134 | { |
| 135 | }; |
| 136 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 137 | #endif // !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) |
Jeff Thompson | ef2d5a4 | 2013-08-22 19:09:24 -0700 | [diff] [blame] | 138 | |
| 139 | } // namespace ndnboost |
| 140 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 141 | #endif // NDNBOOST_DETAIL_REFERENCE_CONTENT_HPP |