BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_addlvaluereference.h
Go to the documentation of this file.
1/// @file bslmf_addlvaluereference.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_addlvaluereference.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_ADDLVALUEREFERENCE
9#define INCLUDED_BSLMF_ADDLVALUEREFERENCE
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_addlvaluereference bslmf_addlvaluereference
15/// @brief Provide a compile-time type transformation to lvalue reference.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_addlvaluereference
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_addlvaluereference-purpose"> Purpose</a>
25/// * <a href="#bslmf_addlvaluereference-classes"> Classes </a>
26/// * <a href="#bslmf_addlvaluereference-description"> Description </a>
27/// * <a href="#bslmf_addlvaluereference-usage"> Usage </a>
28/// * <a href="#bslmf_addlvaluereference-example-1-transforming-types-to-lvalue-reference-types"> Example 1: Transforming Types to Lvalue Reference Types </a>
29///
30/// # Purpose {#bslmf_addlvaluereference-purpose}
31/// Provide a compile-time type transformation to lvalue reference.
32///
33/// # Classes {#bslmf_addlvaluereference-classes}
34///
35/// - bsl::add_lvalue_reference: standard meta-function for type transformation
36/// - bsl::add_lvalue_reference_t: alias to the return type of the meta-function
37///
38/// @see bslmf_addrvaluereference, bslmf_removereference
39///
40/// # Description {#bslmf_addlvaluereference-description}
41/// This component defines a meta-function,
42/// `bsl::add_lvalue_reference`, that may be used to transform a type to its
43/// lvalue reference type. An lvalue, as defined in C++11 standard
44/// [basic.lval], is an expression that designates a function or an object.
45///
46/// `bsl::add_lvalue_reference` and `bsl::add_lvalue_reference_t` meet the
47/// requirements of the `add_lvalue_reference` template defined in the C++11
48/// standard [meta.trans.ref].
49///
50/// ## Usage {#bslmf_addlvaluereference-usage}
51///
52///
53/// In this section we show intended use of this component.
54///
55/// ### Example 1: Transforming Types to Lvalue Reference Types {#bslmf_addlvaluereference-example-1-transforming-types-to-lvalue-reference-types}
56///
57///
58/// Suppose that we want to transform a set of types to their lvalue reference
59/// types.
60///
61/// Now, we instantiate the `bsl::add_lvalue_reference` template for each of
62/// these types, and use the `bsl::is_same` meta-function to assert the `type`
63/// static data member of each instantiation:
64/// @code
65/// assert(true ==
66/// (bsl::is_same<bsl::add_lvalue_reference<int>::type, int&>::value));
67/// assert(false ==
68/// (bsl::is_same<bsl::add_lvalue_reference<int>::type, int >::value));
69/// assert(true ==
70/// (bsl::is_same<bsl::add_lvalue_reference<int&>::type, int&>::value));
71/// #if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
72/// assert(true ==
73/// (bsl::is_same<bsl::add_lvalue_reference<int&&>::type, int&>::value));
74/// #endif
75/// @endcode
76/// Finally, if the current compiler supports alias templates C++11 feature, we
77/// instantiate the `bsl::add_lvalue_reference_t` template for the same set of
78/// types, and use the `bsl::is_same` meta-function to assert the resultant type
79/// of each instantiation:
80/// @code
81/// #ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
82/// assert(true ==
83/// (bsl::is_same<bsl::add_lvalue_reference_t<int>, int& >::value));
84/// assert(false ==
85/// (bsl::is_same<bsl::add_lvalue_reference_t<int>, int >::value));
86/// assert(true ==
87/// (bsl::is_same<bsl::add_lvalue_reference_t<int&>, int& >::value));
88/// #if defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
89/// assert(true ==
90/// (bsl::is_same<bsl::add_lvalue_reference_t<int&&>, int&&>::value));
91/// #endif
92/// #endif
93/// @endcode
94/// Note, that the rvalue reference used above is a feature introduced in the
95/// C++11 standard and may not be supported by all compilers.
96///
97/// Also note that the `bsl::add_lvalue_reference_t` avoids the `::type` suffix
98/// and `typename` prefix when we want to use the result of
99/// `bsl::add_lvalue_reference` meta-function in templates.
100/// @}
101/** @} */
102/** @} */
103
104/** @addtogroup bsl
105 * @{
106 */
107/** @addtogroup bslmf
108 * @{
109 */
110/** @addtogroup bslmf_addlvaluereference
111 * @{
112 */
113
114#include <bslscm_version.h>
115
117
118namespace bsl {
119 // ===========================
120 // struct add_lvalue_reference
121 // ===========================
122
123/// This `struct` template implements a meta-function to transform the
124/// (template parameter) `t_TYPE` to its lvalue reference type.
125template <class t_TYPE>
127
128 /// This `typedef` defines the return type of this meta function.
129 typedef t_TYPE& type;
130};
131
132#if !defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
133
134/// This partial specialization of `add_lvalue_reference` defines a return
135/// type when it is instantiated with an lvalue reference type.
136template <class t_TYPE>
137struct add_lvalue_reference<t_TYPE&> {
138
139 /// This `typedef` defines the return type of this meta function.
140 typedef t_TYPE& type;
141};
142
143#endif
144
145/// This partial specialization of `add_lvalue_reference` defines the return
146/// type when it is instantiated with `void` type.
147template <>
149
150 /// This `typedef` defines the return type of this meta function.
151 typedef void type;
152};
153
154/// This partial specialization of `add_lvalue_reference` defines the return
155/// type when it is instantiated with `void const` type.
156template <>
157struct add_lvalue_reference<void const> {
158
159 /// This `typedef` defines the return type of this meta function.
160 typedef void const type;
161};
162
163/// This partial specialization of `add_lvalue_reference` defines the return
164/// type when it is instantiated with `void volatile` type.
165template <>
166struct add_lvalue_reference<void volatile> {
167
168 /// This `typedef` defines the return type of this meta function.
169 typedef void volatile type;
170};
171
172/// This partial specialization of `add_lvalue_reference` defines the return
173/// type when it is instantiated with `void const volatile` type.
174template <>
175struct add_lvalue_reference<void const volatile> {
176
177 /// This `typedef` defines the return type of this meta function.
178 typedef void const volatile type;
179};
180
181#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
182
183// ALIASES
184
185/// `add_lvalue_reference_t` is an alias to the return type of
186/// `add_lvalue_reference` meta-function. Note, that the `add_const_t`
187/// avoids the `::type` suffix and `typename` prefix when we want to use the
188/// result of the meta-function in templates.
189template <class t_TYPE>
190using add_lvalue_reference_t = typename add_lvalue_reference<t_TYPE>::type;
191
192#endif // BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
193
194} // close namespace bsl
195
196#endif
197
198// ----------------------------------------------------------------------------
199// Copyright 2013 Bloomberg Finance L.P.
200//
201// Licensed under the Apache License, Version 2.0 (the "License");
202// you may not use this file except in compliance with the License.
203// You may obtain a copy of the License at
204//
205// http://www.apache.org/licenses/LICENSE-2.0
206//
207// Unless required by applicable law or agreed to in writing, software
208// distributed under the License is distributed on an "AS IS" BASIS,
209// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
210// See the License for the specific language governing permissions and
211// limitations under the License.
212// ----------------------------- END-OF-FILE ----------------------------------
213
214/** @} */
215/** @} */
216/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlb_printmethods.h:283
t_TYPE & type
This typedef defines the return type of this meta function.
Definition bslmf_addlvaluereference.h:140
void type
This typedef defines the return type of this meta function.
Definition bslmf_addlvaluereference.h:151
void const type
This typedef defines the return type of this meta function.
Definition bslmf_addlvaluereference.h:160
void const volatile type
This typedef defines the return type of this meta function.
Definition bslmf_addlvaluereference.h:178
void volatile type
This typedef defines the return type of this meta function.
Definition bslmf_addlvaluereference.h:169
Definition bslmf_addlvaluereference.h:126
t_TYPE & type
This typedef defines the return type of this meta function.
Definition bslmf_addlvaluereference.h:129