BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_isclass.h
Go to the documentation of this file.
1/// @file bslmf_isclass.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_isclass.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_ISCLASS
9#define INCLUDED_BSLMF_ISCLASS
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_isclass bslmf_isclass
15/// @brief Provide a compile-time check for determining class types.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_isclass
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_isclass-purpose"> Purpose</a>
25/// * <a href="#bslmf_isclass-classes"> Classes </a>
26/// * <a href="#bslmf_isclass-description"> Description </a>
27/// * <a href="#bslmf_isclass-usage"> Usage </a>
28/// * <a href="#bslmf_isclass-example-1-verify-class-types"> Example 1: Verify Class Types </a>
29///
30/// # Purpose {#bslmf_isclass-purpose}
31/// Provide a compile-time check for determining class types.
32///
33/// # Classes {#bslmf_isclass-classes}
34///
35/// - bsl::is_class: standard meta-function for determining class types
36/// - bsl::is_class_v: the result value of the `bsl::is_class` meta-function
37/// - bslmf::IsClass: meta-function for determining class types
38///
39/// # Description {#bslmf_isclass-description}
40/// This component defines two meta-functions, `bsl::is_class` and
41/// `BloombergLP::bslmf::IsClass` and a template variable `bsl::is_class_v`,
42/// that represents the result value of the `bsl::is_class` meta-function. All
43/// these meta-functions may be used to query whether a type is a `class`,
44/// `struct`, or `union`, optionally qualified with `const` or `volatile`.
45///
46/// `bsl::is_class` meets the requirements of the `is_class` template defined in
47/// the C++11 standard [meta.unary.cat], while `bslmf::IsClass` was devised
48/// before `is_class` was standardized.
49///
50/// The two meta-functions are functionally equivalent. The major difference
51/// between them is that the result for `bsl::is_class` is indicated by the
52/// class member `value`, while the result for `bslmf::IsClass` is indicated by
53/// the class member `value`.
54///
55/// Note that `bsl::is_class` should be preferred over `bslmf::IsClass`, and in
56/// general, should be used by new components.
57///
58/// Also note that the template variable `is_class_v` is defined in the C++17
59/// standard as an inline variable. If the current compiler supports the inline
60/// variable C++17 compiler feature, `bsl::is_class_v` is defined as an
61/// `inline constexpr bool` variable. Otherwise, if the compiler supports the
62/// variable templates C++14 compiler feature, `bsl::is_class_v` is defined as a
63/// non-inline `constexpr bool` variable. See
64/// `BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES` and
65/// `BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES` macros in
66/// bsls_compilerfeatures component for details.
67///
68/// ## Usage {#bslmf_isclass-usage}
69///
70///
71/// In this section we show intended use of this component.
72///
73/// ### Example 1: Verify Class Types {#bslmf_isclass-example-1-verify-class-types}
74///
75///
76/// Suppose that we want to assert whether a set of types are class types.
77///
78/// First, we create a class type `MyClass`:
79/// @code
80/// class MyClass
81/// {
82/// };
83/// @endcode
84/// Now, we instantiate the `bsl::is_class` template for both a non-class type
85/// and the defined type `MyClass`, and assert the `value` static data member of
86/// each instantiation:
87/// @code
88/// assert(false == bsl::is_class<int>::value);
89/// assert(true == bsl::is_class<MyClass>::value);
90/// @endcode
91/// Note that if the current compiler supports the variable the templates C++14
92/// feature then we can re-write the snippet of code above using the
93/// `bsl::is_class_v` variable as follows:
94/// @code
95/// #ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
96/// assert(false == bsl::is_class_v<int>);
97/// assert(true == bsl::is_class_v<MyClass>);
98/// #endif
99/// @endcode
100/// @}
101/** @} */
102/** @} */
103
104/** @addtogroup bsl
105 * @{
106 */
107/** @addtogroup bslmf
108 * @{
109 */
110/** @addtogroup bslmf_isclass
111 * @{
112 */
113
114#include <bslscm_version.h>
115
117#include <bslmf_voidtype.h>
118
120#include <bsls_keyword.h>
121
122#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
123#include <bslmf_removecv.h>
124#include <cstdlib>
125#endif
126
127
128namespace bslmf {
129
130 // ==================
131 // struct IsClass_Imp
132 // ==================
133
134/// This `struct` template provides a meta-function to determine whether the
135/// (template parameter) `t_TYPE` is a class type.
136template <class t_TYPE, class = void>
139
140/// This `struct` template provides a meta-function to determine whether the
141/// (template parameter) `t_TYPE` is a class type.
142template <class t_TYPE>
143struct IsClass_Imp<t_TYPE, BSLMF_VOIDTYPE(int t_TYPE::*)> : bsl::true_type {
144};
145
146} // close package namespace
147
148
149namespace bsl {
150
151 // ===============
152 // struct is_class
153 // ===============
154
155/// This `struct` template implements the `is_class` meta-function defined
156/// in the C++11 standard [meta.unary.cat] to determine if the (template
157/// parameter) `t_TYPE` is a class. Note that for implementations without
158/// native library support, this component will mis-diagnose `union` types
159/// as classes. This would be correct according to the core language
160/// definition of a class type, but is an error according to the standard
161/// library definition of this type trait.
162template <class t_TYPE>
163struct is_class : BloombergLP::bslmf::IsClass_Imp<t_TYPE>::type {
164};
165
166#ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
167/// This template variable represents the result value of the
168/// `bsl::is_class` meta-function.
169template <class t_TYPE>
170BSLS_KEYWORD_INLINE_VARIABLE constexpr bool is_class_v =
172#endif
173
174} // close namespace bsl
175
176
177namespace bslmf {
178 // ==============
179 // struct IsClass
180 // ==============
181
182/// This meta-function derives from `bsl::true_type` if the (template
183/// parameter) `t_TYPE` is a class type, or a reference to a class type, and
184/// from `bsl::false_type` otherwise.
185///
186/// Note that although this `struct` is functionally identical to
187/// `bsl::is_class`, the use of `bsl::is_class` should be preferred.
188template <class t_TYPE>
189struct IsClass : bsl::is_class<t_TYPE>::type {
190};
191
192} // close package namespace
193
194
195#ifndef BDE_OPENSOURCE_PUBLICATION // BACKWARD_COMPATIBILITY
196// ============================================================================
197// BACKWARD COMPATIBILITY
198// ============================================================================
199
200#ifdef bslmf_IsClass
201#undef bslmf_IsClass
202#endif
203/// This alias is defined for backward compatibility.
204#define bslmf_IsClass bslmf::IsClass
205#endif // BDE_OPENSOURCE_PUBLICATION -- BACKWARD_COMPATIBILITY
206
207#endif
208
209// ----------------------------------------------------------------------------
210// Copyright 2019 Bloomberg Finance L.P.
211//
212// Licensed under the Apache License, Version 2.0 (the "License");
213// you may not use this file except in compliance with the License.
214// You may obtain a copy of the License at
215//
216// http://www.apache.org/licenses/LICENSE-2.0
217//
218// Unless required by applicable law or agreed to in writing, software
219// distributed under the License is distributed on an "AS IS" BASIS,
220// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
221// See the License for the specific language governing permissions and
222// limitations under the License.
223// ----------------------------- END-OF-FILE ----------------------------------
224
225/** @} */
226/** @} */
227/** @} */
#define BSLMF_VOIDTYPE(ARG)
Definition bslmf_voidtype.h:335
#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 bdlbb_blob.h:576
Definition bslmf_integralconstant.h:244
Definition bslmf_isclass.h:163
Definition bslmf_isclass.h:137
Definition bslmf_isclass.h:189