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