BDE 4.39.x 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 @ref 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.
125///
126/// See @ref bslmf_addlvaluereference
127template <class t_TYPE>
129
130 /// This `typedef` defines the return type of this meta function.
131 typedef t_TYPE& type;
132};
133
134#if !defined(BSLS_COMPILERFEATURES_SUPPORT_RVALUE_REFERENCES)
135
136/// This partial specialization of @ref add_lvalue_reference defines a return
137/// type when it is instantiated with an lvalue reference type.
138template <class t_TYPE>
139struct add_lvalue_reference<t_TYPE&> {
140
141 /// This `typedef` defines the return type of this meta function.
142 typedef t_TYPE& type;
143};
144
145#endif
146
147/// This partial specialization of @ref add_lvalue_reference defines the return
148/// type when it is instantiated with `void` type.
149template <>
151
152 /// This `typedef` defines the return type of this meta function.
153 typedef void type;
154};
155
156/// This partial specialization of @ref add_lvalue_reference defines the return
157/// type when it is instantiated with `void const` type.
158template <>
159struct add_lvalue_reference<void const> {
160
161 /// This `typedef` defines the return type of this meta function.
162 typedef void const type;
163};
164
165/// This partial specialization of @ref add_lvalue_reference defines the return
166/// type when it is instantiated with `void volatile` type.
167template <>
168struct add_lvalue_reference<void volatile> {
169
170 /// This `typedef` defines the return type of this meta function.
171 typedef void volatile type;
172};
173
174/// This partial specialization of @ref add_lvalue_reference defines the return
175/// type when it is instantiated with `void const volatile` type.
176template <>
177struct add_lvalue_reference<void const volatile> {
178
179 /// This `typedef` defines the return type of this meta function.
180 typedef void const volatile type;
181};
182
183#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
184
185// ALIASES
186
187/// @ref add_lvalue_reference_t is an alias to the return type of
188/// @ref add_lvalue_reference meta-function. Note, that the @ref add_const_t
189/// avoids the `::type` suffix and `typename` prefix when we want to use the
190/// result of the meta-function in templates.
191template <class t_TYPE>
192using add_lvalue_reference_t = typename add_lvalue_reference<t_TYPE>::type;
193
194#endif // BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
195
196} // close namespace bsl
197
198#endif
199
200// ----------------------------------------------------------------------------
201// Copyright 2013 Bloomberg Finance L.P.
202//
203// Licensed under the Apache License, Version 2.0 (the "License");
204// you may not use this file except in compliance with the License.
205// You may obtain a copy of the License at
206//
207// http://www.apache.org/licenses/LICENSE-2.0
208//
209// Unless required by applicable law or agreed to in writing, software
210// distributed under the License is distributed on an "AS IS" BASIS,
211// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
212// See the License for the specific language governing permissions and
213// limitations under the License.
214// ----------------------------- END-OF-FILE ----------------------------------
215
216/** @} */
217/** @} */
218/** @} */
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlat_valuetypefunctions.h:939
t_TYPE & type
This typedef defines the return type of this meta function.
Definition bslmf_addlvaluereference.h:142
void type
This typedef defines the return type of this meta function.
Definition bslmf_addlvaluereference.h:153
void const type
This typedef defines the return type of this meta function.
Definition bslmf_addlvaluereference.h:162
void const volatile type
This typedef defines the return type of this meta function.
Definition bslmf_addlvaluereference.h:180
void volatile type
This typedef defines the return type of this meta function.
Definition bslmf_addlvaluereference.h:171
Definition bslmf_addlvaluereference.h:128
t_TYPE & type
This typedef defines the return type of this meta function.
Definition bslmf_addlvaluereference.h:131