BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_isfloatingpoint.h
Go to the documentation of this file.
1/// @file bslmf_isfloatingpoint.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_isfloatingpoint.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_ISFLOATINGPOINT
9#define INCLUDED_BSLMF_ISFLOATINGPOINT
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_isfloatingpoint bslmf_isfloatingpoint
15/// @brief Provide a compile-time check for floating-point types.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_isfloatingpoint
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_isfloatingpoint-purpose"> Purpose</a>
25/// * <a href="#bslmf_isfloatingpoint-classes"> Classes </a>
26/// * <a href="#bslmf_isfloatingpoint-description"> Description </a>
27/// * <a href="#bslmf_isfloatingpoint-usage"> Usage </a>
28/// * <a href="#bslmf_isfloatingpoint-example-1-verify-floating-point-types"> Example 1: Verify Floating-Point Types </a>
29///
30/// # Purpose {#bslmf_isfloatingpoint-purpose}
31/// Provide a compile-time check for floating-point types.
32///
33/// # Classes {#bslmf_isfloatingpoint-classes}
34///
35/// - bsl::is_floating_point: meta-function for determining floating-point types
36/// - bsl::is_floating_point_v: the result value of `bsl::is_floating_point`
37///
38/// @see bslmf_integralconstant
39///
40/// # Description {#bslmf_isfloatingpoint-description}
41/// This component defines a meta-function,
42/// `bsl::is_floating_point` and a template variable `bsl::is_floating_point_v`,
43/// that represents the result value of the `bsl::is_floating_point`
44/// meta-function, that may be used to query whether a type is a (possibly
45/// cv-qualified) floating-point type as defined in section 3.9.1.8 of the C++11
46/// standard [basic.fundamental].
47///
48/// `bsl::is_floating_point` meets the requirements of the `is_floating_point`
49/// template defined in the C++11 standard [meta.unary.cat].
50///
51/// Note that the template variable `is_floating_point_v` is defined in the
52/// C++17 standard as an inline variable. If the current compiler supports the
53/// inline variable C++17 compiler feature, `bsl::is_floating_point_v` is
54/// defined as an `inline constexpr bool` variable. Otherwise, if the compiler
55/// supports the variable templates C++14 compiler feature,
56/// `bsl::is_floating_point_v` is defined as a non-inline `constexpr bool`
57/// variable. See `BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES` and
58/// `BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES` macros in
59/// bsls_compilerfeatures component for details.
60///
61/// ## Usage {#bslmf_isfloatingpoint-usage}
62///
63///
64/// In this section we show intended use of this component.
65///
66/// ### Example 1: Verify Floating-Point Types {#bslmf_isfloatingpoint-example-1-verify-floating-point-types}
67///
68///
69/// Suppose that we want to assert whether a particular type is a floating-point
70/// type.
71///
72/// First, we create two `typedef`s -- a floating-point type and a
73/// non-floating-point type:
74/// @code
75/// typedef void MyType;
76/// typedef float MyFloatingPointType;
77/// @endcode
78/// Now, we instantiate the `bsl::is_floating_point` template for each of the
79/// `typedef`s and assert the `value` static data member of each instantiation:
80/// @code
81/// assert(false == bsl::is_floating_point<MyType>::value);
82/// assert(true == bsl::is_floating_point<MyFloatingPointType>::value);
83/// @endcode
84/// Note that if the current compiler supports the variable templates C++14
85/// feature, then we can re-write the snippet of code above using the
86/// 'bsl::is_floating_point_v<T> as follows:
87/// @code
88/// #ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
89/// assert(false == bsl::is_floating_point_v<MyType>);
90/// assert(true == bsl::is_floating_point_v<MyFloatingPointType>);
91/// #endif
92/// @endcode
93/// @}
94/** @} */
95/** @} */
96
97/** @addtogroup bsl
98 * @{
99 */
100/** @addtogroup bslmf
101 * @{
102 */
103/** @addtogroup bslmf_isfloatingpoint
104 * @{
105 */
106
107#include <bslscm_version.h>
108
110
112#include <bsls_keyword.h>
113#include <bsls_libraryfeatures.h>
114
115#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
116#include <bslmf_removecv.h>
117#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
118
119#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
120#include <type_traits> // 'std::is_floating_point' and
121 // 'std::is_floating_point_v' (C++17)
122#endif
123
124 // ========================
125 // struct is_floating_point
126 // ========================
127
128namespace bsl {
129#ifdef BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
130template <class t_TYPE>
132 bool,
133 std::is_floating_point<t_TYPE>::value>
134{};
135
136#else
137
138/// This `struct` template implements the `is_floating_point` meta-function
139/// defined in the C++11 standard [meta.unary.cat] to determine if the
140/// (template parameter) `t_TYPE` is a floating-point type. This `struct`
141/// derives from `bsl::true_type` if the `t_TYPE` is a floating-point type,
142/// and `bsl::false_type` otherwise.
143template <class t_TYPE>
145};
146
147/// This explicit specialization of `is_floating_point`, for when the
148/// (template parameter) `t_TYPE` is `float`, derives from `bsl::true_type`.
149template <>
150struct is_floating_point<float> : bsl::true_type {
151};
152
153/// This explicit specialization of `is_floating_point`, for when the
154/// (template parameter) `t_TYPE` is `double`, derives from
155/// `bsl::true_type`.
156template <>
157struct is_floating_point<double> : bsl::true_type {
158};
159
160/// This explicit specialization of `is_floating_point`, for when the
161/// (template parameter) `t_TYPE` is `long double`, derives from
162/// `bsl::true_type`.
163template <>
164struct is_floating_point<long double> : bsl::true_type {
165};
166
167/// This partial specialization of `is_floating_point`, for when the
168/// (template parameter) `t_TYPE` is `const`-qualified delegates to the
169/// non-cv-qualified primary template.
170template <class t_TYPE>
171struct is_floating_point<const t_TYPE> : is_floating_point<t_TYPE>::type {
172};
173
174/// This partial specialization of `is_floating_point`, for when the
175/// (template parameter) `t_TYPE` is `volatile`-qualified delegates to the
176/// non-cv-qualified primary template.
177template <class t_TYPE>
178struct is_floating_point<volatile t_TYPE> : is_floating_point<t_TYPE>::type {
179};
180
181/// This partial specialization of `is_floating_point`, for when the
182/// (template parameter) `t_TYPE` is `const volatile`-qualified delegates to
183/// the non-cv-qualified primary template.
184template <class t_TYPE>
185struct is_floating_point<const volatile t_TYPE>
186: is_floating_point<t_TYPE>::type {
187};
188#endif // BSLS_LIBRARYFEATURES_HAS_CPP11_BASELINE_LIBRARY
189
190#ifdef BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
191using std::is_floating_point_v;
192#else
193#ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
194template <class t_TYPE>
195BSLS_KEYWORD_INLINE_VARIABLE constexpr bool is_floating_point_v =
197 // This template variable represents the result value of the
198 // 'bsl::is_floating_point' meta-function.
199#endif
200#endif // BSLS_LIBRARYFEATURES_HAS_CPP17_BASELINE_LIBRARY
201} // close namespace bsl
202
203#endif
204
205// ----------------------------------------------------------------------------
206// Copyright 2013 Bloomberg Finance L.P.
207//
208// Licensed under the Apache License, Version 2.0 (the "License");
209// you may not use this file except in compliance with the License.
210// You may obtain a copy of the License at
211//
212// http://www.apache.org/licenses/LICENSE-2.0
213//
214// Unless required by applicable law or agreed to in writing, software
215// distributed under the License is distributed on an "AS IS" BASIS,
216// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
217// See the License for the specific language governing permissions and
218// limitations under the License.
219// ----------------------------- END-OF-FILE ----------------------------------
220
221/** @} */
222/** @} */
223/** @} */
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_isfloatingpoint.h:134