blob: 098d4eafdeb77b60b1998e45052c5c543a534b3b [file] [log] [blame]
Jeff Thompsonef2d5a42013-08-22 19:09:24 -07001//-----------------------------------------------------------------------------
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 Thompson3d613fd2013-10-15 15:39:04 -070013#ifndef NDNBOOST_DETAIL_REFERENCE_CONTENT_HPP
14#define NDNBOOST_DETAIL_REFERENCE_CONTENT_HPP
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070015
16#include "ndnboost/config.hpp"
17
Jeff Thompson3d613fd2013-10-15 15:39:04 -070018#if !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070019# 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
28namespace ndnboost {
29
30namespace detail {
31
32///////////////////////////////////////////////////////////////////////////////
33// (detail) class template reference_content
34//
35// Non-Assignable wrapper for references.
36//
37template <typename RefT>
38class reference_content
39{
40private: // representation
41
42 RefT content_;
43
44public: // 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
60private: // non-Assignable
61
62 reference_content& operator=(const reference_content&);
63
64public: // 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
79template <typename T = mpl::void_> struct make_reference_content;
80
Jeff Thompson3d613fd2013-10-15 15:39:04 -070081#if !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070082
83template <typename T>
84struct make_reference_content
85{
86 typedef T type;
87};
88
89template <typename T>
90struct make_reference_content< T& >
91{
92 typedef reference_content<T&> type;
93};
94
Jeff Thompson3d613fd2013-10-15 15:39:04 -070095#else // defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -070096
97template <typename T>
98struct make_reference_content
99 : mpl::if_<
100 is_reference<T>
101 , reference_content<T>
102 , T
103 >
104{
105};
106
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700107#endif // NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION workaround
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700108
109template <>
110struct 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 Thompson3d613fd2013-10-15 15:39:04 -0700127#if !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700128
129template <typename T>
130struct has_nothrow_copy<
131 ::ndnboost::detail::reference_content< T& >
132 >
133 : mpl::true_
134{
135};
136
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700137#endif // !defined(NDNBOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
Jeff Thompsonef2d5a42013-08-22 19:09:24 -0700138
139} // namespace ndnboost
140
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700141#endif // NDNBOOST_DETAIL_REFERENCE_CONTENT_HPP