BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_removereference.h
Go to the documentation of this file.
1/// @file bslmf_removereference.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_removereference.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_REMOVEREFERENCE
9#define INCLUDED_BSLMF_REMOVEREFERENCE
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_removereference bslmf_removereference
15/// @brief Provide a meta-function for stripping reference-ness from types.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_removereference
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_removereference-purpose"> Purpose</a>
25/// * <a href="#bslmf_removereference-classes"> Classes </a>
26/// * <a href="#bslmf_removereference-description"> Description </a>
27/// * <a href="#bslmf_removereference-usage"> Usage </a>
28/// * <a href="#bslmf_removereference-example-1-remove-reference-ness-of-types"> Example 1: Remove Reference-ness of Types </a>
29///
30/// # Purpose {#bslmf_removereference-purpose}
31/// Provide a meta-function for stripping reference-ness from types.
32///
33/// # Classes {#bslmf_removereference-classes}
34///
35/// - bsl::remove_reference: standard meta-function for stripping reference-ness
36/// - bsl::remove_reference_t: alias to the return type of the meta-function
37/// - bslmf::RemoveReference: meta-function for stripping reference-ness
38///
39/// @see bslmf_addreference
40///
41/// # Description {#bslmf_removereference-description}
42/// This component defines two meta-functions,
43/// `bsl::remove_reference` and `BloombergLP::bslmf::RemoveReference`, both of
44/// which may be used to strip reference-ness (including both lvalue and rvalue
45/// reference-ness, if the latter is supported by the compiler) from a type.
46///
47/// `bsl::remove_reference` meets the requirements of the @ref remove_reference
48/// template defined in the C++11 standard [meta.trans.ref], while
49/// `bslmf::RemoveReference` was devised before @ref remove_reference was
50/// standardized.
51///
52/// The two meta-functions are functionally equivalent. The major difference
53/// between them is that the result for `bsl::remove_reference` is indicated by
54/// the class member `type`, while the result for `bslmf::RemoveReference` is
55/// indicated by the class member `Type`.
56///
57/// Note that `bsl::remove_reference` should be preferred over
58/// `bslmf::RemoveReference`, and in general, should be used by new components.
59///
60/// ## Usage {#bslmf_removereference-usage}
61///
62///
63/// In this section we show intended use of this component.
64///
65/// ### Example 1: Remove Reference-ness of Types {#bslmf_removereference-example-1-remove-reference-ness-of-types}
66///
67///
68/// Suppose that we want to remove the reference-ness of a set of types.
69///
70/// Now, remove the reference-ness of a set of types using
71/// `bsl::remove_reference` and verify that the returned type has any
72/// reference-ness removed:
73/// @code
74/// assert(true ==
75/// (bsl::is_same<bsl::remove_reference<int& >::type, int >::value));
76/// assert(false ==
77/// (bsl::is_same<bsl::remove_reference<int& >::type, int&>::value));
78/// assert(true ==
79/// (bsl::is_same<bsl::remove_reference<int >::type, int >::value));
80/// #if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
81/// assert(true ==
82/// (bsl::is_same<bsl::remove_reference<int&&>::type, int >::value));
83/// #endif
84/// @endcode
85/// Finally, if the current compiler supports alias templates C++11 feature, we
86/// remove reference-ness from a set of types using `bsl::remove_reference_t`
87/// and verify that the resulting type has any reference-ness removed:
88/// @code
89/// #ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
90/// assert(true ==
91/// (bsl::is_same<bsl::remove_reference_t<int& >, int >::value));
92/// assert(false ==
93/// (bsl::is_same<bsl::remove_reference_t<int& >, int&>::value));
94/// assert(true ==
95/// (bsl::is_same<bsl::remove_reference_t<int >, int >::value));
96/// #if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
97/// assert(true ==
98/// (bsl::is_same<bsl::remove_reference_t<int&&>, int >::value));
99/// #endif
100/// #endif
101/// @endcode
102/// Note that rvalue reference is a feature introduced in the C++11 standard and
103/// may not be supported by all compilers.
104///
105/// Also note, that the `bsl::remove_reference_t` avoids the `::type` suffix and
106/// `typename` prefix when we want to use the result of the
107/// `bsl::remove_reference` meta-function in templates.
108/// @}
109/** @} */
110/** @} */
111
112/** @addtogroup bsl
113 * @{
114 */
115/** @addtogroup bslmf
116 * @{
117 */
118/** @addtogroup bslmf_removereference
119 * @{
120 */
121
122#include <bslscm_version.h>
123
125#include <bsls_libraryfeatures.h>
126
127#if BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
128#include <type_traits> // 'std::remove_reference', 'std_remove_reference_t'
129#endif
130
131 // =======================
132 // struct remove_reference
133 // =======================
134
135namespace bsl {
136
137#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
138using std::remove_reference;
139#else
140
141/// This `struct` template implements the @ref remove_reference meta-function
142/// defined in the C++11 standard [meta.trans.ref], providing an alias,
143/// `type`, that returns the result. `type` has the same type as the
144/// (template parameter) `t_TYPE` except with reference-ness removed. Note
145/// that this generic default template provides a `type` that is an alias to
146/// `t_TYPE` for when `t_TYPE` is not a reference. A template
147/// specialization is provided (below) that removes reference-ness for when
148/// `t_TYPE` is a reference.
149template <class t_TYPE>
150struct remove_reference {
151
152 /// This `typedef` is an alias to the (template parameter) `t_TYPE`.
153 typedef t_TYPE type;
154};
155
156/// This partial specialization of `bsl::remove_reference`, for when the
157/// (template parameter) `t_TYPE` is an rvalue reference, provides a
158/// `typedef`, `type`, that has reference-ness of `t_TYPE` removed.
159template <class t_TYPE>
160struct remove_reference<t_TYPE&> {
161
162 /// This `typedef` is an alias to the same type as the (template
163 /// parameter) `t_TYPE` except with the reference-ness removed.
164 typedef t_TYPE type;
165};
166
167#if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
168
169template <class t_TYPE>
170struct remove_reference<t_TYPE&&> {
171 // This partial specialization of 'bsl::remove_reference', for when the
172 // (template parameter) 't_TYPE' is a reference, provides a 'typedef',
173 // 'type', that has reference-ness of 't_TYPE' removed.
174
175 typedef t_TYPE type;
176 // This 'typedef' is an alias to the same type as the (template
177 // parameter) 't_TYPE' except with the reference-ness removed.
178};
179
180#endif
181#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
182
183#ifdef BSLS_LIBRARYFEATURES_HAS_CPP14_BASELINE_LIBRARY
184using std::remove_reference_t;
185#else
186#if defined(BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES)
187// ALIASES
188template <class t_TYPE>
189using remove_reference_t = typename remove_reference<t_TYPE>::type;
190 // 'remove_reference_t' is an alias to the return type of the
191 // 'bsl::remove_reference' meta-function. Note, that the
192 // 'remove_reference_t' avoids the '::type' suffix and 'typename' prefix
193 // when we want to use the result of the meta-function in templates.
194#endif // BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
195
196#endif // BSLS_LIBRARYFEATURES_HAS_CPP14_BASELINE_LIBRARY
197
198} // close namespace bsl
199
200
201namespace bslmf {
202
203 // ======================
204 // struct RemoveReference
205 // ======================
206
207/// This `struct` template implements a meta-function to remove the
208/// reference-ness from the (template parameter) `t_TYPE`. Note that
209/// although this `struct` is functionally equivalent to
210/// `bsl::remove_reference`, the use of `bsl::remove_reference` should be
211/// preferred.
212template <class t_TYPE>
214
215 /// This `typedef` is an alias to the same type as the (template
216 /// parameter) `t_TYPE` except with any reference-ness removed.
217 typedef typename bsl::remove_reference<t_TYPE>::type Type;
218};
219
220} // close package namespace
221
222
223#ifndef BDE_OPENSOURCE_PUBLICATION // BACKWARD_COMPATIBILITY
224// ============================================================================
225// BACKWARD COMPATIBILITY
226// ============================================================================
227
228#ifdef bslmf_RemoveReference
229#undef bslmf_RemoveReference
230#endif
231/// This alias is defined for backward compatibility.
232#define bslmf_RemoveReference bslmf::RemoveReference
233#endif // BDE_OPENSOURCE_PUBLICATION -- BACKWARD_COMPATIBILITY
234
235#endif
236
237// ----------------------------------------------------------------------------
238// Copyright 2013 Bloomberg Finance L.P.
239//
240// Licensed under the Apache License, Version 2.0 (the "License");
241// you may not use this file except in compliance with the License.
242// You may obtain a copy of the License at
243//
244// http://www.apache.org/licenses/LICENSE-2.0
245//
246// Unless required by applicable law or agreed to in writing, software
247// distributed under the License is distributed on an "AS IS" BASIS,
248// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
249// See the License for the specific language governing permissions and
250// limitations under the License.
251// ----------------------------- END-OF-FILE ----------------------------------
252
253/** @} */
254/** @} */
255/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlb_printmethods.h:283
Definition bdlbb_blob.h:576
Definition bslmf_removereference.h:213
bsl::remove_reference< t_TYPE >::type Type
Definition bslmf_removereference.h:217