BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_removevolatile.h
Go to the documentation of this file.
1/// @file bslmf_removevolatile.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_removevolatile.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_REMOVEVOLATILE
9#define INCLUDED_BSLMF_REMOVEVOLATILE
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_removevolatile bslmf_removevolatile
15/// @brief Provide a meta-function for removing `volatile`-qualifier.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_removevolatile
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_removevolatile-purpose"> Purpose</a>
25/// * <a href="#bslmf_removevolatile-classes"> Classes </a>
26/// * <a href="#bslmf_removevolatile-description"> Description </a>
27/// * <a href="#bslmf_removevolatile-usage"> Usage </a>
28/// * <a href="#bslmf_removevolatile-example-1-removing-the-volatile-qualifier-of-a-type"> Example 1: Removing the volatile-Qualifier of a Type </a>
29///
30/// # Purpose {#bslmf_removevolatile-purpose}
31/// Provide a meta-function for removing `volatile`-qualifier.
32///
33/// # Classes {#bslmf_removevolatile-classes}
34///
35/// - bsl::remove_volatile: meta-function for removing `volatile`-qualifier
36/// - bsl::remove_volatile_t: alias to the return type of the meta-function
37///
38/// @see bslmf_addvolatile
39///
40/// # Description {#bslmf_removevolatile-description}
41/// This component defines a meta-function, `bsl::remove_volatile`
42/// and declares an `bsl::remove_volatile_t` alias to the return type of the
43/// `bsl::remove_volatile`, that may be used to remove any top-level
44/// `volatile`-qualifier from a type.
45///
46/// `bsl::remove_volatile` and `bsl::remove_volatile_t` meet the requirements of
47/// the @ref remove_volatile template defined in the C++11 standard
48/// [meta.trans.cv].
49///
50/// ## Usage {#bslmf_removevolatile-usage}
51///
52///
53/// In this section we show intended use of this component.
54///
55/// ### Example 1: Removing the volatile-Qualifier of a Type {#bslmf_removevolatile-example-1-removing-the-volatile-qualifier-of-a-type}
56///
57///
58/// Suppose that we want to remove any `volatile`-qualifier from a particular
59/// type.
60///
61/// First, we create two `typedef`s -- a `volatile`-qualified type
62/// (`MyVolatileType`) and the same type without the `volatile`-qualifier
63/// (`MyType`):
64/// @code
65/// typedef int MyType;
66/// typedef volatile int MyVolatileType;
67/// @endcode
68/// Now, we remove the `volatile`-qualifier from `MyVolatileType` using
69/// `bsl::remove_volatile` and verify that the resulting type is the same as
70/// `MyType`:
71/// @code
72/// assert(true == (bsl::is_same<bsl::remove_volatile<MyVolatileType>::type,
73/// MyType>::value));
74/// @endcode
75/// Finally, if the current compiler supports alias templates C++11 feature, we
76/// remove a `volatile`-qualifier from `MyVolatileType` using
77///`bsl::remove_volatile_t` and verify that the resulting type is the same as
78/// `MyType`:
79/// @code
80/// #ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
81/// assert(true ==
82/// (bsl::is_same<bsl::remove_volatile_t<MyVolatileType>, MyType>::value));
83/// #endif
84/// @endcode
85/// Note, that the `bsl::remove_volatile_t` avoids the `::type` suffix and
86/// `typename` prefix when we want to use the result of the `bsl::remove_const`
87/// meta-function in templates.
88/// @}
89/** @} */
90/** @} */
91
92/** @addtogroup bsl
93 * @{
94 */
95/** @addtogroup bslmf
96 * @{
97 */
98/** @addtogroup bslmf_removevolatile
99 * @{
100 */
101
102#include <bslscm_version.h>
103
105#include <bsls_platform.h>
106
107#include <stddef.h>
108
109// Several compiler tool-chains have problems removing the 'volatile'
110// qualifiers from arrays.
111
112#if defined(BSLS_PLATFORM_CMP_IBM)
113
114# define BSLS_REMOVEVOLATILE_WORKAROUND_VOLATILE_MULTIDIMENSIONAL_ARRAY 1
115 // The IBM xlC compiler has an odd issue trying to remove 'volatile'
116 // qualifiers from multidimensional arrays. This workaround was last
117 // verified as required for the xlC 12.1 compiler - more recent compilers
118 // still need testing.
119
120#elif (defined(BSLS_PLATFORM_CMP_SUN) && BSLS_PLATFORM_CMP_VERSION < 0x5130) \
121 || (defined(BSLS_PLATFORM_CMP_MSVC) \
122 && BSLS_PLATFORM_CMP_VERSION <= 1900 \
123 && _MSC_FULL_VER < 190023918)
124
125# define BSLS_REMOVEVOLATILE_WORKAROUND_VOLATILE_ARRAY 1
126 // The Microsoft compiler does not recognize array-types as cv-qualified
127 // when the element type is cv-qualified when performing matching for
128 // partial template specialization, but does get the correct result when
129 // performing overload resolution for functions (taking arrays by
130 // reference). Given the function dispatch behavior being correct, we
131 // choose to work around this compiler bug, rather than try to report
132 // compiler behavior, as the compiler itself is inconsistent depending on
133 // how the trait might be used. This also corresponds to how Microsoft
134 // itself implements the trait in VC2010 and later. Note that Microsoft
135 // fixed this bug in Update 2 for MSVC2015, which requires checking the
136 // '_MSC_FULL_VER' macro; the workaround below would be ambiguous when
137 // trying to remove 'volatile' from an array of 'volatile' elements with a
138 // conforming compiler.
139
140#endif
141
142namespace bsl {
143
144 // ======================
145 // struct remove_volatile
146 // ======================
147
148/// This `struct` template implements the @ref remove_volatile meta-function
149/// defined in the C++11 standard [meta.trans.cv], providing an alias,
150/// `type`, that returns the result. `type` has the same type as the
151/// (template parameter) `t_TYPE` except that any top-level
152/// `volatile`-qualifier has been removed. Note that this generic default
153/// template provides a `type` that is an alias to `t_TYPE` for when
154/// `t_TYPE` is not `volatile`-qualified. A template specialization is
155/// provided (below) that removes the `volatile`-qualifier for when `t_TYPE`
156/// is `volatile`-qualified.
157template <class t_TYPE>
159
160 // PUBLIC TYPES
161
162 /// This `typedef` is an alias to the (template parameter) `t_TYPE`.
163 typedef t_TYPE type;
164};
165
166 // =======================================
167 // struct remove_volatile<t_TYPE volatile>
168 // =======================================
169
170/// This partial specialization of `bsl::remove_volatile`, for when the
171/// (template parameter) `t_TYPE` is `volatile`-qualified, provides a
172/// `typedef`, `type`, that has the `volatile`-qualifier removed.
173template <class t_TYPE>
174struct remove_volatile<t_TYPE volatile> {
175
176 // PUBLIC TYPES
177
178 /// This `typedef` is an alias to the same type as the (template
179 /// parameter) `t_TYPE` except with the `volatile`-qualifier removed.
180 typedef t_TYPE type;
181};
182
183#if defined(BSLS_REMOVEVOLATILE_WORKAROUND_VOLATILE_MULTIDIMENSIONAL_ARRAY)
184template <class t_TYPE, size_t t_N>
185struct remove_volatile<t_TYPE[t_N]> {
186 // This partial specialization of 'bsl::remove_volatile', for when the
187 // (template parameter) 't_TYPE' is an array type. On IBM compilers, it is
188 // necessary to separately @ref remove_volatile on the element type, and then
189 // reconstruct the array dimensions.
190
191 // PUBLIC TYPES
192 typedef typename remove_volatile<t_TYPE>::type type[t_N];
193 // This 'typedef' is an alias to the same type as the (template
194 // parameter) 't_TYPE[t_N]' except with the 'volatile'-qualifier
195 // removed.
196};
197
198template <class t_TYPE, size_t t_N>
199struct remove_volatile<volatile t_TYPE[t_N]> {
200 // This partial specialization of 'bsl::remove_volatile', for when the
201 // (template parameter) 't_TYPE' is an array type. On IBM compilers, it is
202 // necessary to separately @ref remove_volatile on the element type, and then
203 // reconstruct the array dimensions.
204
205 // PUBLIC TYPES
206 typedef typename remove_volatile<volatile t_TYPE>::type type[t_N];
207 // This 'typedef' is an alias to the same type as the (template
208 // parameter) 't_TYPE[t_N]' except with the 'volatile'-qualifier
209 // removed.
210};
211
212template <class t_TYPE>
213struct remove_volatile<t_TYPE[]> {
214 // This partial specialization of 'bsl::remove_volatile', for when the
215 // (template parameter) 't_TYPE' is an array type. On IBM compilers, it is
216 // necessary to separately @ref remove_volatile on the element type, and then
217 // reconstruct the array dimensions.
218
219 // PUBLIC TYPES
220 typedef typename remove_volatile<t_TYPE>::type type[];
221 // This 'typedef' is an alias to the same type as the (template
222 // parameter) 't_TYPE[]' except with the 'volatile'-qualifier removed.
223};
224
225template <class t_TYPE>
226struct remove_volatile<volatile t_TYPE[]> {
227 // This partial specialization of 'bsl::remove_volatile', for when the
228 // (template parameter) 't_TYPE' is an array type. On IBM compilers, it is
229 // necessary to separately @ref remove_volatile on the element type, and then
230 // reconstruct the array dimensions.
231
232 // PUBLIC TYPES
234 // This 'typedef' is an alias to the same type as the (template
235 // parameter) 't_TYPE[]' except with the 'volatile'-qualifier removed.
236};
237#elif defined(BSLS_REMOVEVOLATILE_WORKAROUND_VOLATILE_ARRAY)
238template <class t_TYPE>
239struct remove_volatile<t_TYPE[]> {
240 // This partial specialization of 'bsl::remove_volatile', for when the
241 // (template parameter) 't_TYPE' is an array type. On Microsoft compilers,
242 // it is necessary to separately @ref remove_volatile on the element type, and
243 // then reconstruct the array dimensions.
244
245 // PUBLIC TYPES
246 typedef typename remove_volatile<t_TYPE>::type type[];
247 // This 'typedef' is an alias to the same type as the (template
248 // parameter) 't_TYPE[]' except with the 'volatile'-qualifier removed.
249};
250
251template <class t_TYPE, size_t t_LENGTH>
252struct remove_volatile<t_TYPE[t_LENGTH]> {
253 // This partial specialization of 'bsl::remove_volatile', for when the
254 // (template parameter) 't_TYPE' is an array type. On Microsoft compilers,
255 // it is necessary to separately @ref remove_volatile on the element type, and
256 // then reconstruct the array dimensions.
257
258 // PUBLIC TYPES
259 typedef typename remove_volatile<t_TYPE>::type type[t_LENGTH];
260 // This 'typedef' is an alias to the same type as the (template
261 // parameter) 't_TYPE[t_N]' except with the 'volatile'-qualifier
262 // removed.
263};
264#endif
265
266#ifdef BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
267
268// ALIASES
269
270/// `remove_volatile_t` is an alias to the return type of the
271/// `bsl::remove_volatile` meta-function. Note, that the
272/// `remove_volatile_t` avoids the `::type` suffix and `typename` prefix
273/// when we want to use the result of the meta-function in templates.
274template <class t_TYPE>
275using remove_volatile_t = typename remove_volatile<t_TYPE>::type;
276#endif // BSLS_COMPILERFEATURES_SUPPORT_ALIAS_TEMPLATES
277
278} // close namespace bsl
279
280#endif
281
282// ----------------------------------------------------------------------------
283// Copyright 2013 Bloomberg Finance L.P.
284//
285// Licensed under the Apache License, Version 2.0 (the "License");
286// you may not use this file except in compliance with the License.
287// You may obtain a copy of the License at
288//
289// http://www.apache.org/licenses/LICENSE-2.0
290//
291// Unless required by applicable law or agreed to in writing, software
292// distributed under the License is distributed on an "AS IS" BASIS,
293// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
294// See the License for the specific language governing permissions and
295// limitations under the License.
296// ----------------------------- END-OF-FILE ----------------------------------
297
298/** @} */
299/** @} */
300/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlb_printmethods.h:283
t_TYPE type
Definition bslmf_removevolatile.h:180
Definition bslmf_removevolatile.h:158
t_TYPE type
This typedef is an alias to the (template parameter) t_TYPE.
Definition bslmf_removevolatile.h:163