BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_isintegral.h
Go to the documentation of this file.
1/// @file bslmf_isintegral.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_isintegral.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_ISINTEGRAL
9#define INCLUDED_BSLMF_ISINTEGRAL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_isintegral bslmf_isintegral
15/// @brief Provide a compile-time check for integral types.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_isintegral
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_isintegral-purpose"> Purpose</a>
25/// * <a href="#bslmf_isintegral-classes"> Classes </a>
26/// * <a href="#bslmf_isintegral-description"> Description </a>
27/// * <a href="#bslmf_isintegral-usage"> Usage </a>
28/// * <a href="#bslmf_isintegral-example-1-verify-integral-types"> Example 1: Verify Integral Types </a>
29///
30/// # Purpose {#bslmf_isintegral-purpose}
31/// Provide a compile-time check for integral types.
32///
33/// # Classes {#bslmf_isintegral-classes}
34///
35/// - bsl::is_integral: standard meta-function for determining integral types
36/// - bsl::is_integral_v: the result value of `bsl::is_integral`
37///
38/// @see bslmf_integralconstant
39///
40/// # Description {#bslmf_isintegral-description}
41/// This component defines a meta-function, `bsl::is_integral` and
42/// a template variable `bsl::is_integral_v`, that represents the result value
43/// of the `bsl::is_integral` meta-function, that may be used to query whether a
44/// type is an integral type as defined in section 3.9.1.7 of the C++11 standard
45/// [basic.fundamental] (excluding those types that were introduced in C++11).
46///
47/// `bsl::is_integral` meets the requirements of the `is_integral` template
48/// defined in the C++11 standard [meta.unary.cat] except that it may not
49/// correctly evaluate types introduced in C++11.
50///
51/// Note that the template variable `is_integral_v` is defined in the C++17
52/// standard as an inline variable. If the current compiler supports the inline
53/// variable C++17 compiler feature, `bsl::is_integral_v` is defined as an
54/// `inline constexpr bool` variable. Otherwise, if the compiler supports the
55/// variable templates C++14 compiler feature, `bsl::is_integral_v` is defined
56/// as a non-inline `constexpr bool` variable. See
57/// `BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES` and
58/// `BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES` macros in
59/// bsls_compilerfeatures component for details.
60///
61/// ## Usage {#bslmf_isintegral-usage}
62///
63///
64/// In this section we show intended use of this component.
65///
66/// ### Example 1: Verify Integral Types {#bslmf_isintegral-example-1-verify-integral-types}
67///
68///
69/// Suppose that we want to assert whether a particular type is an integral
70/// type.
71///
72/// First, we create two `typedef`s -- an integral type and a non-integral type:
73/// @code
74/// typedef void MyType;
75/// typedef int MyIntegralType;
76/// @endcode
77/// Now, we instantiate the `bsl::is_integral` 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_integral<MyType>::value);
81/// assert(true == bsl::is_integral<MyIntegralType>::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 using the
85/// `bsl::is_integral_v` variable as follows:
86/// @code
87/// #ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
88/// assert(false == bsl::is_integral_v<MyType>);
89/// assert(true == bsl::is_integral_v<MyIntegralType>);
90/// #endif
91/// @endcode
92/// @}
93/** @} */
94/** @} */
95
96/** @addtogroup bsl
97 * @{
98 */
99/** @addtogroup bslmf
100 * @{
101 */
102/** @addtogroup bslmf_isintegral
103 * @{
104 */
105
106#include <bslscm_version.h>
107
109
111#include <bsls_keyword.h>
112#include <bsls_libraryfeatures.h>
113
114#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
115#include <bslmf_removecv.h>
116#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
117
118#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
119#include <type_traits> // 'std::is_integral', 'std::is_integral_v'
120#endif
121namespace bsl {
122 // ==================
123 // struct is_integral
124 // ==================
125
126#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
127template <class t_TYPE>
129 std::is_integral<t_TYPE>::value>
130{};
131
132#else
133
134/// This `struct` template implements the `is_integral` meta-function
135/// defined in the C++11 standard [meta.unary.cat] to determine if the
136/// (template parameter) `t_TYPE` is an integral type. This `struct`
137/// derives from `bsl::true_type` if the `t_TYPE` is an integral type, and
138/// `bsl::false_type` otherwise.
139template <class t_TYPE>
141};
142
143/// This partial specialization of `is_integral`, for when the (template
144/// parameter) `t_TYPE` is `const`-qualified delegates to the
145/// non-cv-qualified primary template.
146template <class t_TYPE>
147struct is_integral<const t_TYPE> : is_integral<t_TYPE>::type {
148};
149
150/// This partial specialization of `is_integral`, for when the (template
151/// parameter) `t_TYPE` is `volatile`-qualified delegates to the
152/// non-cv-qualified primary template.
153template <class t_TYPE>
154struct is_integral<volatile t_TYPE> : is_integral<t_TYPE>::type {
155};
156
157/// This partial specialization of `is_integral`, for when the (template
158/// parameter) `t_TYPE` is `const volatile`-qualified delegates to the
159/// non-cv-qualified primary template.
160template <class t_TYPE>
161struct is_integral<const volatile t_TYPE> : is_integral<t_TYPE>::type {
162};
163
164/// This explicit specialization of `is_integral`, for when the (template
165/// parameter) `t_TYPE` is `bool`, derives from `bsl::true_type`.
166template <>
167struct is_integral<bool> : bsl::true_type {
168};
169
170/// This explicit specialization of `is_integral`, for when the (template
171/// parameter) `t_TYPE` is `char`, derives from `bsl::true_type`.
172template <>
173struct is_integral<char> : bsl::true_type {
174};
175
176/// This explicit specialization of `is_integral`, for when the (template
177/// parameter) `t_TYPE` is `wchar_t`, derives from `bsl::true_type`.
178template <>
179struct is_integral<wchar_t> : bsl::true_type {
180};
181
182#if defined(BSLS_COMPILERFEATURES_SUPPORT_UTF8_CHAR_TYPE)
183template <>
184struct is_integral<char8_t> : bsl::true_type {
185 // This explicit specialization of 'is_integral', for when the (template
186 // parameter) 'TYPE' is 'wchar_t', derives from 'bsl::true_type'.
187};
188#endif // BSLS_COMPILERFEATURES_SUPPORT_UTF8_CHAR_TYPE
189
190#if defined BSLS_COMPILERFEATURES_SUPPORT_UNICODE_CHAR_TYPES
191template <>
192struct is_integral<char16_t> : bsl::true_type {
193 // This explicit specialization of 'is_integral', for when the (template
194 // parameter) 't_TYPE' is 'wchar_t', derives from 'bsl::true_type'.
195};
196
197template <>
198struct is_integral<char32_t> : bsl::true_type {
199 // This explicit specialization of 'is_integral', for when the (template
200 // parameter) 't_TYPE' is 'wchar_t', derives from 'bsl::true_type'.
201};
202#endif // BSLS_COMPILERFEATURES_SUPPORT_UNICODE_CHAR_TYPES
203
204/// This explicit specialization of `is_integral`, for when the (template
205/// parameter) `t_TYPE` is `signed char`, derives from `bsl::true_type`.
206template <>
207struct is_integral<signed char> : bsl::true_type {
208};
209
210/// This explicit specialization of `is_integral`, for when the (template
211/// parameter) `t_TYPE` is `unsigned char`, derives from `bsl::true_type`.
212template <>
213struct is_integral<unsigned char> : bsl::true_type {
214};
215
216/// This explicit specialization of `is_integral`, for when the (template
217/// parameter) `t_TYPE` is `short`, derives from `bsl::true_type`.
218template <>
219struct is_integral<short int> : bsl::true_type {
220};
221
222/// This explicit specialization of `is_integral`, for when the (template
223/// parameter) `t_TYPE` is `unsigned short`, derives from `bsl::true_type`.
224template <>
225struct is_integral<unsigned short int> : bsl::true_type {
226};
227
228/// This explicit specialization of `is_integral`, for when the (template
229/// parameter) `t_TYPE` is `int`, derives from `bsl::true_type`.
230template <>
231struct is_integral<int> : bsl::true_type {
232};
233
234/// This explicit specialization of `is_integral`, for when the (template
235/// parameter) `t_TYPE` is `unsigned int`, derives from `bsl::true_type`.
236template <>
237struct is_integral<unsigned int> : bsl::true_type {
238};
239
240/// This explicit specialization of `is_integral`, for when the (template
241/// parameter) `t_TYPE` is `long int`, derives from `bsl::true_type`.
242template <>
243struct is_integral<long int> : bsl::true_type {
244};
245
246/// This explicit specialization of `is_integral`, for when the (template
247/// parameter) `t_TYPE` is `unsigned long int`, derives from
248/// `bsl::true_type`.
249template <>
250struct is_integral<unsigned long int> : bsl::true_type {
251};
252
253/// This explicit specialization of `is_integral`, for when the (template
254/// parameter) `t_TYPE` is `long long int`, derives from `bsl::true_type`.
255template <>
256struct is_integral<long long int> : bsl::true_type {
257};
258
259/// This explicit specialization of `is_integral`, for when the (template
260/// parameter) `t_TYPE` is `unsigned long long int`, derives from
261/// `bsl::true_type`.
262template <>
263struct is_integral<unsigned long long int> : bsl::true_type {
264};
265#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
266
267#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
268using std::is_integral_v;
269#else
270#ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
271template <class t_TYPE>
272BSLS_KEYWORD_INLINE_VARIABLE constexpr bool is_integral_v =
274 // This template variable represents the result value of the
275 // 'bsl::is_integral' meta-function.
276#endif
277#endif // BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
278
279} // close namespace bsl
280
281#endif
282
283// ----------------------------------------------------------------------------
284// Copyright 2013 Bloomberg Finance L.P.
285//
286// Licensed under the Apache License, Version 2.0 (the "License");
287// you may not use this file except in compliance with the License.
288// You may obtain a copy of the License at
289//
290// http://www.apache.org/licenses/LICENSE-2.0
291//
292// Unless required by applicable law or agreed to in writing, software
293// distributed under the License is distributed on an "AS IS" BASIS,
294// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
295// See the License for the specific language governing permissions and
296// limitations under the License.
297// ----------------------------- END-OF-FILE ----------------------------------
298
299/** @} */
300/** @} */
301/** @} */
static const bool value
Definition bslmf_integralconstant.h:258
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_INLINE_VARIABLE
Definition bsls_keyword.h:623
Definition bdlb_printmethods.h:283
Definition bslmf_integralconstant.h:244
Definition bslmf_isintegral.h:130