BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_ispointer.h
Go to the documentation of this file.
1/// @file bslmf_ispointer.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_ispointer.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_ISPOINTER
9#define INCLUDED_BSLMF_ISPOINTER
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_ispointer bslmf_ispointer
15/// @brief Provide a compile-time check for pointer types.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_ispointer
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_ispointer-purpose"> Purpose</a>
25/// * <a href="#bslmf_ispointer-classes"> Classes </a>
26/// * <a href="#bslmf_ispointer-description"> Description </a>
27/// * <a href="#bslmf_ispointer-usage"> Usage </a>
28/// * <a href="#bslmf_ispointer-example-1-verify-pointer-types"> Example 1: Verify Pointer Types </a>
29///
30/// # Purpose {#bslmf_ispointer-purpose}
31/// Provide a compile-time check for pointer types.
32///
33/// # Classes {#bslmf_ispointer-classes}
34///
35/// - bsl::is_pointer: standard meta-function for determining pointer types
36/// - bsl::is_pointer_v: the result value of the `bsl::is_pointer` meta-function
37/// - bsl::IsPointer: meta-function for determining pointer types
38///
39/// @see bslmf_integralconstant
40///
41/// # Description {#bslmf_ispointer-description}
42/// This component defines two meta-functions, `bsl::is_pointer`
43/// and `BloombergLP::bslmf::IsPointer` and a template variable
44/// `bsl::is_pointer_v`, that represents the result value of the
45/// `bsl::is_pointer` meta-function. All these meta-functions may be used to
46/// query whether or not a type is a pointer type.
47///
48/// `bsl::is_pointer` meets the requirements of the `is_pointer` template
49/// defined in the C++11 standard [meta.unary.cat], while `bslmf::IsPointer` was
50/// devised before `is_pointer` was standardized.
51///
52/// The two meta-functions are functionally equivalent. The major difference
53/// between them is that the result for `bsl::is_pointer` is indicated by the
54/// class member `value`, while the result for `bslmf::IsPointer` is indicated
55/// by the class member `value`.
56///
57/// Note that `bsl::is_pointer` should be preferred over `bslmf::IsPointer`, and
58/// in general, should be used by new components.
59///
60/// Also note that the template variable `is_pointer_v` is defined in the C++17
61/// standard as an inline variable. If the current compiler supports the inline
62/// variable C++17 compiler feature, `bsl::is_pointer_v` is defined as an
63/// `inline constexpr bool` variable. Otherwise, if the compiler supports the
64/// variable templates C++14 compiler feature, `bsl::is_pointer_v` is
65/// defined as a non-inline `constexpr bool` variable. See
66/// `BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES` and
67/// `BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES` macros in
68/// bsls_compilerfeatures component for details.
69///
70/// ## Usage {#bslmf_ispointer-usage}
71///
72///
73/// In this section we show intended use of this component.
74///
75/// ### Example 1: Verify Pointer Types {#bslmf_ispointer-example-1-verify-pointer-types}
76///
77///
78/// Suppose that we want to assert whether a particular type is a pointer type.
79///
80/// First, we create two `typedef`s -- a pointer type and a non-pointer type:
81/// @code
82/// typedef int MyType;
83/// typedef int *MyPtrType;
84/// @endcode
85/// Now, we instantiate the `bsl::is_pointer` template for each of the
86/// `typedef`s and assert the `value` static data member of each instantiation:
87/// @code
88/// assert(false == bsl::is_pointer<MyType>::value);
89/// assert(true == bsl::is_pointer<MyPtrType>::value);
90/// @endcode
91/// Note that if the current compiler supports the variable templates C++14
92/// feature then we can re-write the snippet of code above using the
93/// `bsl::is_pointer_v` variable as follows:
94/// @code
95/// #ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
96/// assert(false == bsl::is_pointer_v<MyType>);
97/// assert(true == bsl::is_pointer_v<MyPtrType>);
98/// #endif
99/// @endcode
100/// @}
101/** @} */
102/** @} */
103
104/** @addtogroup bsl
105 * @{
106 */
107/** @addtogroup bslmf
108 * @{
109 */
110/** @addtogroup bslmf_ispointer
111 * @{
112 */
113
114#include <bslscm_version.h>
115
117
119#include <bsls_keyword.h>
120#include <bsls_platform.h>
121
122#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
123#include <bslmf_removecv.h>
124#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
125
126namespace bsl {
127
128 // =================
129 // struct is_pointer
130 // =================
131
132/// This `struct` template implements the `is_pointer` meta-function defined
133/// in the C++11 standard [meta.unary.cat] to determine if the (template
134/// parameter) `t_TYPE` is a pointer. This `struct` derives from
135/// `bsl::true_type` if the `t_TYPE` is a pointer type (but not a
136/// pointer-to-non-static-member type), and `bsl::false_type` otherwise.
137template <class t_TYPE>
140
141/// This partial specialization of `is_pointer` derives from
142/// `bsl::true_type` for when the (template parameter) `t_TYPE` is a
143/// (cv-unqalified) pointer type.
144template <class t_TYPE>
145struct is_pointer<t_TYPE *> : bsl::true_type {
146};
147
148#if defined(BSLS_PLATFORM_CMP_MSVC) && BSLS_PLATFORM_CMP_VERSION < 1900
149// Older Microsoft compilers do not recognize cv-qualifiers on function pointer
150// types as matching a 't_TYPE *const' partial specialization, but can
151// correctly strip the cv-qualifier if we take a second template instantiation
152// on a more general 't_TYPE const' parameter.
153
154template <class t_TYPE>
155struct is_pointer<t_TYPE const> : is_pointer<t_TYPE>::type {
156 // This partial specialization of 'is_pointer' derives from
157 // 'bsl::true_type' for when the (template parameter) 't_TYPE' is a 'const'
158 // qualified pointer type.
159};
160
161template <class t_TYPE>
162struct is_pointer<t_TYPE volatile> : is_pointer<t_TYPE>::type {
163 // This partial specialization of 'is_pointer' derives from
164 // 'bsl::true_type' for when the (template parameter) 't_TYPE' is a
165 // 'volatile' qualified pointer type.
166};
167
168template <class t_TYPE>
169struct is_pointer<t_TYPE const volatile> : is_pointer<t_TYPE>::type {
170 // This partial specialization of 'is_pointer' derives from
171 // 'bsl::true_type' for when the (template parameter) 't_TYPE' is a 'const
172 // volatile' qualified pointer type.
173};
174#else
175// Preferred implementation avoids a second dispatch for arbitrary cv-qualified
176// types.
177
178/// This partial specialization of `is_pointer` derives from
179/// `bsl::true_type` for when the (template parameter) `t_TYPE` is a `const`
180/// qualified pointer type.
181template <class t_TYPE>
182struct is_pointer<t_TYPE *const> : bsl::true_type {
183};
184
185/// This partial specialization of `is_pointer` derives from
186/// `bsl::true_type` for when the (template parameter) `t_TYPE` is a
187/// `volatile` qualified pointer type.
188template <class t_TYPE>
189struct is_pointer<t_TYPE *volatile> : bsl::true_type {
190};
191
192/// This partial specialization of `is_pointer` derives from
193/// `bsl::true_type` for when the (template parameter) `t_TYPE` is a 'const
194/// volatile' qualified pointer type.
195template <class t_TYPE>
196struct is_pointer<t_TYPE *const volatile> : bsl::true_type {
197};
198#endif
199
200#ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
201/// This template variable represents the result value of the
202/// `bsl::is_pointer` meta-function.
203template <class t_TYPE>
204BSLS_KEYWORD_INLINE_VARIABLE constexpr bool is_pointer_v =
206#endif
207
208} // close namespace bsl
209
210
211namespace bslmf {
212
213 // ================
214 // struct IsPointer
215 // ================
216
217/// This `struct` template implements a meta-function to determine if the
218/// (template parameter) `t_TYPE` is a pointer type. This `struct` derives
219/// from `bsl::true_type` if the `t_TYPE` is a pointer type (but not a
220/// pointer to non-static member), and `bsl::false_type` otherwise.
221///
222/// Note that this `struct` is functionally equivalent to `bsl::is_pointer`,
223/// and the use of `bsl::is_pointer` should be preferred.
224template <class t_TYPE>
225struct IsPointer : bsl::is_pointer<t_TYPE>::type {
226};
227
228} // close package namespace
229
230
231#ifndef BDE_OPENSOURCE_PUBLICATION // BACKWARD_COMPATIBILITY
232// ============================================================================
233// BACKWARD-COMPATIBILITY
234// ============================================================================
235
236#ifdef bslmf_IsPointer
237#undef bslmf_IsPointer
238#endif
239
240/// This alias is defined for backward-compatibility.
241#define bslmf_IsPointer bslmf::IsPointer
242#endif // BDE_OPENSOURCE_PUBLICATION -- BACKWARD_COMPATIBILITY
243
244#endif
245
246// ----------------------------------------------------------------------------
247// Copyright 2013 Bloomberg Finance L.P.
248//
249// Licensed under the Apache License, Version 2.0 (the "License");
250// you may not use this file except in compliance with the License.
251// You may obtain a copy of the License at
252//
253// http://www.apache.org/licenses/LICENSE-2.0
254//
255// Unless required by applicable law or agreed to in writing, software
256// distributed under the License is distributed on an "AS IS" BASIS,
257// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
258// See the License for the specific language governing permissions and
259// limitations under the License.
260// ----------------------------- END-OF-FILE ----------------------------------
261
262/** @} */
263/** @} */
264/** @} */
#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_ispointer.h:138
Definition bslmf_ispointer.h:225