BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_isarithmetic.h
Go to the documentation of this file.
1/// @file bslmf_isarithmetic.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_isarithmetic.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_ISARITHMETIC
9#define INCLUDED_BSLMF_ISARITHMETIC
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_isarithmetic bslmf_isarithmetic
15/// @brief Provide a compile-time check for determining arithmetic types.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_isarithmetic
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_isarithmetic-purpose"> Purpose</a>
25/// * <a href="#bslmf_isarithmetic-classes"> Classes </a>
26/// * <a href="#bslmf_isarithmetic-description"> Description </a>
27/// * <a href="#bslmf_isarithmetic-usage"> Usage </a>
28/// * <a href="#bslmf_isarithmetic-example-1-verify-arithmetic-types"> Example 1: Verify Arithmetic Types </a>
29///
30/// # Purpose {#bslmf_isarithmetic-purpose}
31/// Provide a compile-time check for determining arithmetic types.
32///
33/// # Classes {#bslmf_isarithmetic-classes}
34///
35/// - bsl::is_arithmetic: standard meta-function for determining arithmetic types
36/// - bsl::is_arithmetic_v: the result value of `bsl::is_arithmetic`
37///
38/// @see bslmf_integralconstant
39///
40/// # Description {#bslmf_isarithmetic-description}
41/// This component defines a meta-function, `bsl::is_arithmetic`
42/// and a template variable `bsl::is_arithmetic_v` that represents the result
43/// value of the `bsl::is_arithmetic` meta-function, that may be used to query
44/// whether a template parameter type is an arithmetic type.
45///
46/// `bsl::is_arithmetic` meets the requirements of the `is_arithmetic` template
47/// defined in the C++11 standard [meta.unary.comp].
48///
49/// Note that the template variable `is_arithmetic_v` is defined in the C++17
50/// standard as an inline variable. If the current compiler supports the inline
51/// variable C++17 compiler feature, `bsl::is_arithmetic_v` is defined as an
52/// `inline constexpr bool` variable. Otherwise, if the compiler supports
53/// the variable templates C++14 compiler feature, `bsl::is_arithmetic_v` is
54/// defined as a non-inline `constexpr bool` variable. See
55/// `BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES` and
56/// `BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES` macros in
57/// bsls_compilerfeatures component for details.
58///
59/// ## Usage {#bslmf_isarithmetic-usage}
60///
61///
62/// In this section we show intended use of this component.
63///
64/// ### Example 1: Verify Arithmetic Types {#bslmf_isarithmetic-example-1-verify-arithmetic-types}
65///
66///
67/// Suppose that we want to assert whether a set of types are arithmetic types.
68///
69/// Now, we instantiate the `bsl::is_arithmetic` template for these types, and
70/// assert the `value` static data member of each instantiation:
71/// @code
72/// assert(false == bsl::is_arithmetic<int& >::value);
73/// assert(false == bsl::is_arithmetic<int *>::value);
74/// assert(true == bsl::is_arithmetic<int >::value);
75/// @endcode
76/// Note that if the current compiler supports the variable templates C++14
77/// feature then we can re-write the snippet of code above using the
78/// `bsl::is_arithmetic_v` variable as follows:
79/// @code
80/// #ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
81/// assert(false == bsl::is_arithmetic_v<int& >);
82/// assert(false == bsl::is_arithmetic_v<int *>);
83/// assert(true == bsl::is_arithmetic_v<int >);
84/// #endif
85/// @endcode
86/// @}
87/** @} */
88/** @} */
89
90/** @addtogroup bsl
91 * @{
92 */
93/** @addtogroup bslmf
94 * @{
95 */
96/** @addtogroup bslmf_isarithmetic
97 * @{
98 */
99
100#include <bslscm_version.h>
101
104#include <bslmf_isintegral.h>
105
107#include <bsls_keyword.h>
108
109namespace bsl {
110
111 // ====================
112 // struct is_arithmetic
113 // ====================
114
115/// This `struct` template implements the `is_arithmetic` meta-function
116/// defined in the C++11 standard [meta.unary.comp] to determine if the
117/// (template parameter) `t_TYPE` is an arithmetic type. This `struct`
118/// derives from `bsl::true_type` if the `t_TYPE` is an arithmetic type, and
119/// from `bsl::false_type` otherwise.
120template <class t_TYPE>
122: integral_constant<bool,
123 is_integral<t_TYPE>::value ||
124 is_floating_point<t_TYPE>::value> {
125};
126
127#ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
128/// This template variable represents the result value of the
129/// `bsl::is_arithmetic` meta-function.
130template <class t_TYPE>
131BSLS_KEYWORD_INLINE_VARIABLE constexpr bool is_arithmetic_v =
133#endif
134
135} // close namespace bsl
136
137#endif
138
139// ----------------------------------------------------------------------------
140// Copyright 2013 Bloomberg Finance L.P.
141//
142// Licensed under the Apache License, Version 2.0 (the "License");
143// you may not use this file except in compliance with the License.
144// You may obtain a copy of the License at
145//
146// http://www.apache.org/licenses/LICENSE-2.0
147//
148// Unless required by applicable law or agreed to in writing, software
149// distributed under the License is distributed on an "AS IS" BASIS,
150// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
151// See the License for the specific language governing permissions and
152// limitations under the License.
153// ----------------------------- END-OF-FILE ----------------------------------
154
155/** @} */
156/** @} */
157/** @} */
#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_isarithmetic.h:124