BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_addvolatile.h
Go to the documentation of this file.
1/// @file bslmf_addvolatile.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_addvolatile.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_ADDVOLATILE
9#define INCLUDED_BSLMF_ADDVOLATILE
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_addvolatile bslmf_addvolatile
15/// @brief Provide a meta-function for adding a `volatile`-qualifier.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_addvolatile
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_addvolatile-purpose"> Purpose</a>
25/// * <a href="#bslmf_addvolatile-classes"> Classes </a>
26/// * <a href="#bslmf_addvolatile-description"> Description </a>
27/// * <a href="#bslmf_addvolatile-usage"> Usage </a>
28/// * <a href="#bslmf_addvolatile-example-1-adding-a-volatile-qualifier-to-a-type"> Example 1: Adding a volatile-Qualifier to a Type </a>
29///
30/// # Purpose {#bslmf_addvolatile-purpose}
31/// Provide a meta-function for adding a `volatile`-qualifier.
32///
33/// # Classes {#bslmf_addvolatile-classes}
34///
35/// - bsl::add_volatile: meta-function for adding top-level `volatile`-qualifier
36/// - bsl::add_volatile_t: alias to the return type of the `bsl::add_volatile`
37///
38/// @see bslmf_removevolatile
39///
40/// # Description {#bslmf_addvolatile-description}
41/// This component defines a meta-function, `bsl::add_volatile`
42/// and declares an `bsl::add_volatile_t` alias to the return type of the
43/// `bsl::add_volatile`, that may be used to add a top-level
44/// `volatile`-qualifier to a type if it is not a reference type, nor a function
45/// type, nor already `volatile`-qualified at the top-level.
46///
47/// `bsl::add_volatile` and `bsl::add_volatile_t` meet the requirements of the
48/// @ref add_volatile template defined in the C++11 standard [meta.trans.cv].
49///
50/// ## Usage {#bslmf_addvolatile-usage}
51///
52///
53/// In this section we show intended use of this component.
54///
55/// ### Example 1: Adding a volatile-Qualifier to a Type {#bslmf_addvolatile-example-1-adding-a-volatile-qualifier-to-a-type}
56///
57///
58/// Suppose that we want to add a `volatile`-qualifier to a particular type.
59///
60/// First, we create two `typedef`s -- a `volatile`-qualified type
61/// (`MyVolatileType`) and the same type without the `volatile`-qualifier
62/// (`MyType`):
63/// @code
64/// typedef int MyType;
65/// typedef volatile int MyVolatileType;
66/// @endcode
67/// Now, we add a `volatile`-qualifier to `MyType` using `bsl::add_volatile` and
68/// verify that the resulting type is the same as `MyVolatileType`:
69/// @code
70/// assert(true ==
71/// (bsl::is_same<bsl::add_volatile<MyType>::type, MyVolatileType>::value));
72/// @endcode
73/// Finally, if the current compiler supports alias templates C++11 feature, we
74/// add a `volatile`-qualifier to `MyType` using `bsl::add_volatile_t` and
75/// verify that the resulting type is the same as `MyVolatileType`:
76/// @code
77/// #ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
78/// assert(true ==
79/// (bsl::is_same<bsl::add_volatile_t<MyType>, MyVolatileType>::value));
80/// #endif
81/// @endcode
82/// Note, that the `bsl::add_volatile_t` avoids the `::type` suffix and
83/// `typename` prefix when we want to use the result of the `bsl::add_volatile`
84/// meta-function in templates.
85/// @}
86/** @} */
87/** @} */
88
89/** @addtogroup bsl
90 * @{
91 */
92/** @addtogroup bslmf
93 * @{
94 */
95/** @addtogroup bslmf_addvolatile
96 * @{
97 */
98
99#include <bslscm_version.h>
100
101#include <bslmf_isfunction.h>
102#include <bslmf_isreference.h>
103#include <bslmf_isvolatile.h>
104
106
107
108
109namespace bslmf {
110
111 // ======================
112 // struct AddVolatile_Imp
113 // ======================
114
115/// This `struct` template provides an alias, `Type`, that adds a
116/// `volatile`-qualifier to the (template parameter) `t_TYPE` if the
117/// (template parameter) `t_ADD_VOLATILE_FLAG` is `true`. This generic
118/// default template adds the `volatile`-qualifier to `t_TYPE`. A template
119/// specialization (below) leaves `t_TYPE` as-is in its `Type` alias.
120template <class t_TYPE, bool t_ADD_VOLATILE_FLAG>
122
123 // PUBLIC TYPES
124
125 /// This `typedef` is an alias to a type that is the same as the
126 /// (template parameter) `t_TYPE` except that a top-level
127 /// `volatile`-qualifier has been added.
128 typedef t_TYPE volatile Type;
129};
130
131 // =====================================
132 // struct AddVolatile_Imp<t_TYPE, false>
133 // =====================================
134
135/// This partial specialization of `AddVolatile_Imp`, for when the (template
136/// parameter) `t_ADD_VOLATILE_FLAG` is `false`, provides an alias `Type`
137/// that has the same type as the (template parameter) `t_TYPE`.
138template <class t_TYPE>
139struct AddVolatile_Imp<t_TYPE, false> {
140
141 // PUBLIC TYPES
142
143 /// This `typedef` is an alias to the (template parameter) `t_TYPE`.
144 typedef t_TYPE Type;
145};
146
147} // close package namespace
148
149
150namespace bsl {
151
152 // ===================
153 // struct add_volatile
154 // ===================
155
156/// This `struct` template implements the @ref add_volatile meta-function
157/// defined in the C++11 standard [meta.trans.cv], providing an alias,
158/// `type`, that returns the result. If the (template parameter) `t_TYPE`
159/// is not a reference type, nor a function type, nor already
160/// `volatile`-qualified at the top-level, then `type` is an alias to
161/// `t_TYPE` with a top-level `volatile`-qualifier added; otherwise, `type`
162/// is an alias to `t_TYPE`.
163template <class t_TYPE>
165
166 /// This `typedef` is an alias to the (template parameter) `t_TYPE` with
167 /// a top-level `volatile`-qualifier added if `t_TYPE` is not a
168 /// reference type, nor a function type, nor already
169 /// `volatile`-qualified at the top-level; otherwise, `type` is an alias
170 /// to `t_TYPE`.
171 typedef typename BloombergLP::bslmf::AddVolatile_Imp<
172 t_TYPE,
175};
176
177#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
178
179// ALIASES
180
181/// `add_volatile_t` is an alias to the return type of the
182/// `bsl::add_volatile` meta-function. Note, that the `bsl::add_volatile_t`
183/// avoids the `::type` suffix and `typename` prefix when we want to use the
184/// result of the meta-function in templates.
185template <class t_TYPE>
186using add_volatile_t = typename add_volatile<t_TYPE>::type;
187#endif // BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
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
Definition bdlbb_blob.h:576
Definition bslmf_addvolatile.h:164
BloombergLP::bslmf::AddVolatile_Imp< t_TYPE,!is_reference< t_TYPE >::value &&!is_function< t_TYPE >::value &&!is_volatile< t_TYPE >::value >::Type type
Definition bslmf_addvolatile.h:174
Definition bslmf_isfunction.h:232
Definition bslmf_isreference.h:137
Definition bslmf_isvolatile.h:144
t_TYPE Type
This typedef is an alias to the (template parameter) t_TYPE.
Definition bslmf_addvolatile.h:144
Definition bslmf_addvolatile.h:121
t_TYPE volatile Type
Definition bslmf_addvolatile.h:128