BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_isfundamental.h
Go to the documentation of this file.
1/// @file bslmf_isfundamental.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_isfundamental.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_ISFUNDAMENTAL
9#define INCLUDED_BSLMF_ISFUNDAMENTAL
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_isfundamental bslmf_isfundamental
15/// @brief Provide a compile-time check for determining fundamental types.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_isfundamental
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_isfundamental-purpose"> Purpose</a>
25/// * <a href="#bslmf_isfundamental-classes"> Classes </a>
26/// * <a href="#bslmf_isfundamental-description"> Description </a>
27/// * <a href="#bslmf_isfundamental-usage"> Usage </a>
28/// * <a href="#bslmf_isfundamental-example-1-verify-fundamental-types"> Example 1: Verify Fundamental Types </a>
29///
30/// # Purpose {#bslmf_isfundamental-purpose}
31/// Provide a compile-time check for determining fundamental types.
32///
33/// # Classes {#bslmf_isfundamental-classes}
34///
35/// - bsl::is_fundamental: standard meta-function for detecting fundamental types
36/// - bsl::is_fundamental_v: the result value of `bsl::is_fundamental`
37/// - bslmf::IsFundamental: meta-function for detecting fundamental types
38///
39/// @see bslmf_isenum, bslmf_ispointer
40///
41/// # Description {#bslmf_isfundamental-description}
42/// This component defines two meta-functions,
43/// `bsl::is_fundamental` and `BloombergLP::bslmf::IsFundamental` and a template
44/// variable `bsl::is_fundamental_v`, that represents the result value of the
45/// `bsl::is_fundamental` meta-function. All these meta-functions may be used
46/// to query whether a type is a fundamental type.
47///
48/// `bsl::is_fundamental` meets the requirements of the `is_fundamental`
49/// template defined in the C++11 standard [meta.unary.comp], while
50/// `bslmf::Fundamental` was devised before `is_fundamental` was standardized.
51///
52/// The two meta-functions are functionally equivalent except on reference of
53/// fundamental types. Lvalue-references to fundamental types are determined as
54/// fundamental types by `bslmf::IsFundamental`, but not by
55/// `bsl::is_fundamental`. Rvalue-references, on compilers that support them,
56/// are not deemed to be fundamental by either trait. In expected use, the
57/// result for `bsl::is_fundamental` is indicated by the class member `value`,
58/// while the result for `bslmf::Fundamental` is indicated by the class member
59/// `value`.
60///
61/// Note that `bsl::is_fundamental` should be preferred over
62/// `bslmf::Fundamental`, and in general, should be used by new components.
63///
64/// Also note that the template variable `is_fundamental_v` is defined in the
65/// C++17 standard as an inline variable. If the current compiler supports the
66/// inline variable C++17 compiler feature, `bsl::is_fundamental_v` is defined
67/// as an `inline constexpr bool` variable. Otherwise, if the compiler supports
68/// the variable templates C++14 compiler feature, `bsl::is_fundamental_v` is
69/// defined as a non-inline `constexpr bool` variable. See
70/// `BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES` and
71/// `BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES` macros in
72/// bsls_compilerfeatures component for details.
73///
74/// The C++ fundamental types are described in the C++ standard
75/// [basic.fundamental], and consist of the following distinct types, and
76/// cv-qualified variations of these types:
77/// @code
78/// bool
79/// char
80/// signed char
81/// unsigned char
82/// wchar_t
83/// char16_t
84/// char32_t
85/// short int (also referred to as "short")
86/// unsigned short int (also referred to as "unsigned short")
87/// int
88/// unsigned int
89/// long int (also referred to as "long")
90/// unsigned long int (also referred to as "unsigned long")
91/// long long int (also referred to as "long long")
92/// unsigned long long int (also referred to as "unsigned long long")
93/// float
94/// double
95/// long double
96/// void
97/// nullptr_t
98/// @endcode
99///
100/// ## Usage {#bslmf_isfundamental-usage}
101///
102///
103/// In this section we show intended use of this component.
104///
105/// ### Example 1: Verify Fundamental Types {#bslmf_isfundamental-example-1-verify-fundamental-types}
106///
107///
108/// Suppose that we want to assert whether a set of types are fundamental types.
109///
110/// Now, we instantiate the `bsl::is_fundamental` template for several
111/// non-fundamental and fundamental types, and assert the `value` static data
112/// member of each instantiation:
113/// @code
114/// assert(true == bsl::is_fundamental<int>::value);
115/// assert(false == bsl::is_fundamental<int&>::value);
116/// assert(true == bsl::is_fundamental<long long >::value);
117/// assert(false == bsl::is_fundamental<long long *>::value);
118/// @endcode
119/// Note that if the current compiler supports the variable templates C++14
120/// feature then we can re-write the snippet of code above using the
121/// `bsl::is_fundamental_v` variable as follows:
122/// @code
123/// #ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
124/// assert(true == bsl::is_fundamental_v<int>);
125/// assert(false == bsl::is_fundamental_v<int&>);
126/// assert(true == bsl::is_fundamental_v<long long >);
127/// assert(false == bsl::is_fundamental_v<long long *>);
128/// #endif
129/// @endcode
130/// @}
131/** @} */
132/** @} */
133
134/** @addtogroup bsl
135 * @{
136 */
137/** @addtogroup bslmf
138 * @{
139 */
140/** @addtogroup bslmf_isfundamental
141 * @{
142 */
143
144#include <bslscm_version.h>
145
147#include <bslmf_isarithmetic.h>
148#include <bslmf_isvoid.h>
149#include <bslmf_removecv.h>
150
152#include <bsls_keyword.h>
153#include <bsls_nullptr.h>
154
155
156namespace bslmf {
157
158 // ========================
159 // struct IsFundamental_Imp
160 // ========================
161
162/// This `struct` template implements a meta-function to determine whether
163/// the (template parameter) `t_TYPE` is a (non-cv-qualified) fundamental
164/// type. This generic default template derives from `bsl::false_type`.
165/// Template specializations for fundamental types are provided (below) that
166/// derive from `bsl::true_type`.
167template <class t_TYPE>
170
171/// This partial specialization of `IsFundamental_Imp` derives from
172/// `bsl::true_type` for when the (template parameter) `t_TYPE` is `bool`.
173template <> struct IsFundamental_Imp<bool> : bsl::true_type {
174};
175
176/// This partial specialization of `IsFundamental_Imp` derives from
177/// `bsl::true_type` for when the (template parameter) `t_TYPE` is `char`.
178template <> struct IsFundamental_Imp<char> : bsl::true_type {
179};
180
181/// This partial specialization of `IsFundamental_Imp` derives from
182/// `bsl::true_type` for when the (template parameter) `t_TYPE` is
183/// `signed char`.
184template <> struct IsFundamental_Imp<signed char> : bsl::true_type {
185};
186
187/// This partial specialization of `IsFundamental_Imp` derives from
188/// `bsl::true_type` for when the (template parameter) `t_TYPE` is
189/// `unsigned char`.
190template <> struct IsFundamental_Imp<unsigned char> : bsl::true_type {
191};
192
193#if defined BSLS_COMPILERFEATURES_SUPPORT_UTF8_CHAR_TYPE
194/// This partial specialization of `IsFundamental_Imp` derives from
195/// `bsl::true_type` for when the (template parameter) `TYPE` is `char8_t`.
196template <> struct IsFundamental_Imp<char8_t> : bsl::true_type {
197};
198#endif
199
200/// This partial specialization of `IsFundamental_Imp` derives from
201/// `bsl::true_type` for when the (template parameter) `t_TYPE` is
202/// `wchar_t`.
203template <> struct IsFundamental_Imp<wchar_t> : bsl::true_type {
204};
205
206/// This partial specialization of `IsFundamental_Imp` derives from
207/// `bsl::true_type` for when the (template parameter) `t_TYPE` is `short`.
208template <> struct IsFundamental_Imp<short> : bsl::true_type {
209};
210
211/// This partial specialization of `IsFundamental_Imp` derives from
212/// `bsl::true_type` for when the (template parameter) `t_TYPE` is
213/// `unsigned short`.
214template <> struct IsFundamental_Imp<unsigned short> : bsl::true_type {
215};
216
217/// This partial specialization of `IsFundamental_Imp` derives from
218/// `bsl::true_type` for when the (template parameter) `t_TYPE` is `int`.
219template <> struct IsFundamental_Imp<int> : bsl::true_type {
220};
221
222/// This partial specialization of `IsFundamental_Imp` derives from
223/// `bsl::true_type` for when the (template parameter) `t_TYPE` is
224/// `unsigned int`.
225template <> struct IsFundamental_Imp<unsigned int> : bsl::true_type {
226};
227
228/// This partial specialization of `IsFundamental_Imp` derives from
229/// `bsl::true_type` for when the (template parameter) `t_TYPE` is `long`.
230template <> struct IsFundamental_Imp<long> : bsl::true_type {
231};
232
233/// This partial specialization of `IsFundamental_Imp` derives from
234/// `bsl::true_type` for when the (template parameter) `t_TYPE` is
235/// `unsigned long`.
236template <> struct IsFundamental_Imp<unsigned long> : bsl::true_type {
237};
238
239/// This partial specialization of `IsFundamental_Imp` derives from
240/// `bsl::true_type` for when the (template parameter) `t_TYPE` is
241/// `long long`.
242template <> struct IsFundamental_Imp<long long> : bsl::true_type {
243};
244
245/// This partial specialization of `IsFundamental_Imp` derives from
246/// `bsl::true_type` for when the (template parameter) `t_TYPE` is
247/// `unsigned long long`
248template <> struct IsFundamental_Imp<unsigned long long> : bsl::true_type {
249};
250
251/// This partial specialization of `IsFundamental_Imp` derives from
252/// `bsl::true_type` for when the (template parameter) `t_TYPE` is `float`.
253template <> struct IsFundamental_Imp<float> : bsl::true_type {
254};
255
256/// This partial specialization of `IsFundamental_Imp` derives from
257/// `bsl::true_type` for when the (template parameter) `t_TYPE` is `double`.
258template <>
260};
261
262/// This partial specialization of `IsFundamental_Imp` derives from
263/// `bsl::true_type` for when the (template parameter) `t_TYPE` is
264/// `long double`.
265template <> struct IsFundamental_Imp<long double> : bsl::true_type {
266};
267
268/// This partial specialization of `IsFundamental_Imp` derives from
269/// `bsl::true_type` for when the (template parameter) `t_TYPE` is `void`.
270template <> struct IsFundamental_Imp<void> : bsl::true_type {
271};
272
273#if defined(BSLS_COMPILERFEATURES_SUPPORT_NULLPTR)
274/// This partial specialization of `IsFundamental_Imp` derives from
275/// `bsl::true_type` for when the (template parameter) `t_TYPE` is `void`.
276template <> struct IsFundamental_Imp<bsl::nullptr_t> : bsl::true_type {
277};
278#endif
279
280#if defined(BSLS_COMPILERFEATURES_SUPPORT_UNICODE_CHAR_TYPES)
281/// This partial specialization of `IsFundamental_Imp` derives from
282/// `bsl::true_type` for when the (template parameter) `t_TYPE` is `void`.
283template <> struct IsFundamental_Imp<char16_t> : bsl::true_type {
284};
285
286/// This partial specialization of `IsFundamental_Imp` derives from
287/// `bsl::true_type` for when the (template parameter) `t_TYPE` is `void`.
288template <> struct IsFundamental_Imp<char32_t> : bsl::true_type {
289};
290#endif
291
292
293 // ====================
294 // struct IsFundamental
295 // ====================
296
297/// This `struct` template implements a meta-function for checking if a type
298/// is fundamental, or a reference to a fundamental type. The static
299/// constant `value` member will be 1 if `t_TYPE` is fundamental and 0
300/// otherwise.
301template <class t_TYPE>
303: IsFundamental_Imp<typename bsl::remove_cv<t_TYPE>::type>::type {
304};
305
306/// This specialization of `IsFundamental` causes lvalue-references to be
307/// treated as their underlying (non-reference) types.
308template <class t_TYPE>
312
313} // close package namespace
314
315
316namespace bsl {
317
318 // =====================
319 // struct is_fundamental
320 // =====================
321
322/// This `struct` template implements a meta-function for checking if a type
323/// is fundamental as defined in the C++11 standard [basic.fundamental].
324/// Note that this is subtly differemt from `bslmf::IsFundamental`, which
325/// also returns `true_type` for references to fundamental types.
326template <class t_TYPE>
328: integral_constant<bool,
329 is_arithmetic<t_TYPE>::value || is_void<t_TYPE>::value> {
330};
331
332#ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
333/// This template variable represents the result value of the
334/// `bsl::is_fundamental` meta-function.
335template <class t_TYPE>
336BSLS_KEYWORD_INLINE_VARIABLE constexpr bool is_fundamental_v =
338#endif
339
340#if defined(BSLS_COMPILERFEATURES_SUPPORT_NULLPTR)
341/// Explicit specialization to confirm that the type of `nullptr` is
342/// fundamental.
343template <>
345};
346
347/// Explicit specialization to confirm that the type of `const nullptr` is
348/// fundamental.
349template <>
350struct is_fundamental<const bsl::nullptr_t> : bsl::true_type {
351};
352
353/// Explicit specialization to confirm that the type of `volatile nullptr`
354/// is fundamental.
355template <>
356struct is_fundamental<volatile bsl::nullptr_t> : bsl::true_type {
357};
358
359/// Explicit specialization to confirm that the type of
360/// `const volatile nullptr` is fundamental.
361template <>
362struct is_fundamental<const volatile bsl::nullptr_t> : bsl::true_type {
363};
364
365#endif
366
367} // close namespace bsl
368
369#ifndef BDE_OPENSOURCE_PUBLICATION // BACKWARD_COMPATIBILITY
370// ============================================================================
371// BACKWARD COMPATIBILITY
372// ============================================================================
373
374#ifdef bslmf_IsFundamental
375#undef bslmf_IsFundamental
376#endif
377/// This alias is defined for backward compatibility.
378#define bslmf_IsFundamental bslmf::IsFundamental
379#endif // BDE_OPENSOURCE_PUBLICATION -- BACKWARD_COMPATIBILITY
380
381#endif
382
383// ----------------------------------------------------------------------------
384// Copyright 2013 Bloomberg Finance L.P.
385//
386// Licensed under the Apache License, Version 2.0 (the "License");
387// you may not use this file except in compliance with the License.
388// You may obtain a copy of the License at
389//
390// http://www.apache.org/licenses/LICENSE-2.0
391//
392// Unless required by applicable law or agreed to in writing, software
393// distributed under the License is distributed on an "AS IS" BASIS,
394// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
395// See the License for the specific language governing permissions and
396// limitations under the License.
397// ----------------------------- END-OF-FILE ----------------------------------
398
399/** @} */
400/** @} */
401/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_INLINE_VARIABLE
Definition bsls_keyword.h:623
Definition bdlb_printmethods.h:283
BloombergLP::bsls::Nullptr_Impl::Type nullptr_t
Definition bsls_nullptr.h:281
Definition bdlbb_blob.h:576
Definition bslmf_integralconstant.h:244
Definition bslmf_isfundamental.h:329
Definition bslmf_isfundamental.h:168
Definition bslmf_isfundamental.h:303