BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslmf_isvolatile.h
Go to the documentation of this file.
1/// @file bslmf_isvolatile.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_isvolatile.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_ISVOLATILE
9#define INCLUDED_BSLMF_ISVOLATILE
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_isvolatile bslmf_isvolatile
15/// @brief Provide a compile-time check for `volatile`-qualified types.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_isvolatile
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_isvolatile-purpose"> Purpose</a>
25/// * <a href="#bslmf_isvolatile-classes"> Classes </a>
26/// * <a href="#bslmf_isvolatile-description"> Description </a>
27/// * <a href="#bslmf_isvolatile-usage"> Usage </a>
28/// * <a href="#bslmf_isvolatile-example-1-verify-volatile-types"> Example 1: Verify volatile Types </a>
29///
30/// # Purpose {#bslmf_isvolatile-purpose}
31/// Provide a compile-time check for `volatile`-qualified types.
32///
33/// # Classes {#bslmf_isvolatile-classes}
34///
35/// - bsl::is_volatile: meta-function for determining `volatile`-qualified types
36/// - bsl::is_volatile_v: the result value of `bsl::is_volatile`
37///
38/// @see bslmf_integralconstant
39///
40/// # Description {#bslmf_isvolatile-description}
41/// This component defines a meta-function, `bsl::is_volatile` and
42/// a template variable `bsl::is_volatile_v`, that represents the result value
43/// of the meta-function, that may be used to query whether a type is
44/// `volatile`-qualified as defined in the C++11 standard
45/// [basic.type.qualifier].
46///
47/// `bsl::is_volatile` meets the requirements of the `is_volatile` template
48/// defined in the C++11 standard [meta.unary.prop].
49///
50/// Note that the template variable `is_volatile_v` is defined in the C++17
51/// standard as an inline variable. If the current compiler supports the inline
52/// variable C++17 compiler feature, `bsl::is_volatile_v` is defined as an
53/// `inline constexpr bool` variable. Otherwise, if the compiler supports the
54/// variable templates C++14 compiler feature, `bsl::is_volatile_v` is defined
55/// as a non-inline `constexpr bool` variable. See
56/// `BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES` and
57/// `BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES` macros in
58/// bsls_compilerfeatures component for details.
59///
60/// ## Usage {#bslmf_isvolatile-usage}
61///
62///
63/// In this section we show intended use of this component.
64///
65/// ### Example 1: Verify volatile Types {#bslmf_isvolatile-example-1-verify-volatile-types}
66///
67///
68/// Suppose that we want to assert whether a particular type is
69/// `volatile`-qualified.
70///
71/// First, we create two `typedef`s -- a `volatile`-qualified type and an
72/// unqualified type:
73/// @code
74/// typedef int MyType;
75/// typedef volatile int MyVolatileType;
76/// @endcode
77/// Now, we instantiate the `bsl::is_volatile` template for each of the
78/// `typedef`s and assert the `value` static data member of each instantiation:
79/// @code
80/// assert(false == bsl::is_volatile<MyType>::value);
81/// assert(true == bsl::is_volatile<MyVolatileType>::value);
82/// @endcode
83/// Note that if the current compiler supports the variable templates C++14
84/// feature, then we can re-write the snippet of code above as follows:
85/// @code
86/// #ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
87/// assert(false == bsl::is_volatile_v<MyType>);
88/// assert(true == bsl::is_volatile_v<MyVolatileType>);
89/// #endif
90/// @endcode
91/// @}
92/** @} */
93/** @} */
94
95/** @addtogroup bsl
96 * @{
97 */
98/** @addtogroup bslmf
99 * @{
100 */
101/** @addtogroup bslmf_isvolatile
102 * @{
103 */
104
105#include <bslscm_version.h>
106
108#include <bslmf_issame.h>
109
110#include <bsls_platform.h>
112#include <bsls_keyword.h>
113
114#include <stddef.h>
115
116
117#if (defined(BSLS_PLATFORM_CMP_MSVC) && BSLS_PLATFORM_CMP_VERSION < 1910) \
118 || defined(BSLS_PLATFORM_CMP_IBM)
119// The Microsoft compiler does not recognize array-types as cv-qualified (when
120// the element type is cv-qualified) when performing matching for partial
121// template specialization, but does get the correct result when performing
122// overload resolution for functions (taking arrays by reference). Given the
123// function dispatch behavior being correct, we choose to work around this
124// compiler bug, rather than try to report compiler behavior, as the compiler
125// itself is inconsistent depending on how the trait might be used. This also
126// corresponds to how Microsft itself implements the trait in VC2010 and later.
127# define BSLMF_ISVOLATILE_COMPILER_DOES_NOT_DETECT_CV_QUALIFIED_ARRAY_ELEMENT 1
128#endif
129
130namespace bsl {
131
132 // ==================
133 // struct is_volatile
134 // ==================
135
136/// This `struct` template implements the `is_volatile` meta-function
137/// defined in the C++11 standard [meta.unary.cat] to determine if the
138/// (template parameter) `t_TYPE` is `volatile`-qualified. This `struct`
139/// derives from `bsl::true_type` if the `t_TYPE` is `volatile`-qualified, and `bsl::false_type` otherwise.
140///
141/// \note Note that this generic default
142/// template derives from `bsl::false_type`. A template specialization is
143/// provided (below) that derives from `bsl::true_type`.
144template <class t_TYPE>
146};
147
148 // ===================================
149 // struct is_volatile<t_TYPE volatile>
150 // ===================================
151
152#if defined(BSLS_PLATFORM_CMP_SUN) && BSLS_PLATFORM_CMP_VERSION < 0x5130
153template <class t_TYPE>
154struct is_volatile<volatile t_TYPE>
155: integral_constant<bool, !is_same<t_TYPE, volatile t_TYPE>::value> {
156 // This partial specialization of 'is_volatile', for when the (template
157 // parameter) 't_TYPE' is 'volatile'-qualified, derives from
158 // 'bsl::true_type'. Note that the Solaris CC compiler misdiagnoses
159 // cv-qualified "abominable" function types as being cv-qualified
160 // themselves. The correct result is obtained by delegating the result to
161 // a call through 'is_same'.
162};
163#else
164/// This partial specialization of `is_volatile`, for when the (template
165/// parameter) `t_TYPE` is `volatile`-qualified, derives from
166/// `bsl::true_type`.
167template <class t_TYPE>
168struct is_volatile<volatile t_TYPE> : true_type {
169};
170#endif
171
172
173#ifdef BSLMF_ISVOLATILE_COMPILER_DOES_NOT_DETECT_CV_QUALIFIED_ARRAY_ELEMENT
174// The Microsoft compiler does not recognize array-types as cv-qualified when
175// the element type is cv-qualified when performing matching for partial
176// template specialization, but does get the correct result when performing
177// overload resolution for functions (taking arrays by reference). Given the
178// function dispatch behavior being correct, we choose to work around this
179// compiler bug, rather than try to report compiler behavior, as the compiler
180// itself is inconsistent depeoning on how the trait might be used. This also
181// corresponds to how Microsft itself implements the trait in VC2010 and later.
182
183template <class t_TYPE>
184struct is_volatile<volatile t_TYPE[]> : true_type {
185 // This partial specialization of 'is_volatile', for when the (template
186 // parameter) 't_TYPE' is 'volatile'-qualified, derives from
187 // 'bsl::true_type'. Note that this single specialization is sufficient to
188 // work around the MSVC issue, even for multidimensional arrays.
189};
190
191template <class t_TYPE, size_t t_LENGTH>
192struct is_volatile<volatile t_TYPE[t_LENGTH]> : true_type {
193 // This partial specialization of 'is_volatile', for when the (template
194 // parameter) 't_TYPE' is 'volatile'-qualified, derives from
195 // 'bsl::true_type'. Note that this single specialization is sufficient to
196 // work around the MSVC issue, even for multidimensional arrays.
197};
198#endif
199
200#ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
201/// This template variable represents the result value of the
202/// `bsl::is_volatile` meta-function.
203template <class t_TYPE>
204BSLS_KEYWORD_INLINE_VARIABLE constexpr bool is_volatile_v =
206#endif
207
208} // close namespace bsl
209
210#endif
211
212// ----------------------------------------------------------------------------
213// Copyright 2017 Bloomberg Finance L.P.
214//
215// Licensed under the Apache License, Version 2.0 (the "License");
216// you may not use this file except in compliance with the License.
217// You may obtain a copy of the License at
218//
219// http://www.apache.org/licenses/LICENSE-2.0
220//
221// Unless required by applicable law or agreed to in writing, software
222// distributed under the License is distributed on an "AS IS" BASIS,
223// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
224// See the License for the specific language governing permissions and
225// limitations under the License.
226// ----------------------------- END-OF-FILE ----------------------------------
227
228/** @} */
229/** @} */
230/** @} */
static const t_TYPE value
Definition bslmf_integralconstant.h:267
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_INLINE_VARIABLE
Definition bsls_keyword.h:665
Definition bdlat_valuetypefunctions.h:939
integral_constant< bool, true > true_type
Definition bslmf_integralconstant.h:296
Definition bslmf_integralconstant.h:261
Definition bslmf_isvolatile.h:145