BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bslmf_ismemberobjectpointer.h
Go to the documentation of this file.
1/// @file bslmf_ismemberobjectpointer.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_ismemberobjectpointer.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_ISMEMBEROBJECTPOINTER
9#define INCLUDED_BSLMF_ISMEMBEROBJECTPOINTER
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_ismemberobjectpointer bslmf_ismemberobjectpointer
15/// @brief Provide a compile-time check for member object pointer types.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_ismemberobjectpointer
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_ismemberobjectpointer-purpose"> Purpose</a>
25/// * <a href="#bslmf_ismemberobjectpointer-classes"> Classes </a>
26/// * <a href="#bslmf_ismemberobjectpointer-description"> Description </a>
27/// * <a href="#bslmf_ismemberobjectpointer-usage"> Usage </a>
28/// * <a href="#bslmf_ismemberobjectpointer-example-1-verify-member-object-pointer-types"> Example 1: Verify Member Object Pointer Types </a>
29///
30/// # Purpose {#bslmf_ismemberobjectpointer-purpose}
31/// Provide a compile-time check for member object pointer types.
32///
33/// # Classes {#bslmf_ismemberobjectpointer-classes}
34///
35/// - bsl::is_member_object_pointer: standard meta-function
36/// - bsl::is_member_object_pointer_v: the result value of the meta-function
37///
38/// @see bslmf_integralconstant, bslmf_ismemberfunctionpointer
39///
40/// # Description {#bslmf_ismemberobjectpointer-description}
41/// This component defines a meta-function,
42/// `bsl::is_member_object_pointer` and a template variable
43/// `bsl::is_member_object_pointer_v`, that represents the result value of the
44/// `bsl::is_member_object_pointer` meta-function, that may be used to query
45/// whether a type is a pointer to non-static member object type.
46///
47/// `bsl::is_member_object_pointer` meets the requirements of the
48/// `is_member_object_pointer` template defined in the C++11 standard
49/// [meta.unary.cat].
50///
51/// Note that the template variable `is_member_object_pointer_v` is defined in
52/// the C++17 standard as an inline variable. If the current compiler supports
53/// the inline variable C++17 compiler feature,
54/// `bsl::is_member_object_pointer_v` is defined as an `inline constexpr bool`
55/// variable. Otherwise, if the compiler supports the variable templates C++14
56/// compiler feature, `bsl::is_member_object_pointer_v` is defined as a
57/// non-inline `constexpr bool` variable. See
58/// `BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES` and
59/// `BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES` macros in
60/// bsls_compilerfeatures component for details.
61///
62/// ## Usage {#bslmf_ismemberobjectpointer-usage}
63///
64///
65/// In this section we show intended use of this component.
66///
67/// ### Example 1: Verify Member Object Pointer Types {#bslmf_ismemberobjectpointer-example-1-verify-member-object-pointer-types}
68///
69///
70/// Suppose that we want to assert whether a set of types are pointers to member
71/// object types.
72///
73/// First, we create a user-defined type `MyStruct`:
74/// @code
75/// struct MyStruct
76/// {
77/// };
78/// @endcode
79/// Now, we create a `typedef` for a member object pointer type:
80/// @code
81/// typedef int MyStruct::* DataMemPtr;
82/// @endcode
83/// Finally, we instantiate the `bsl::is_member_object_pointer` template for a
84/// non-member data type and the `MyStructDataPtr` type, and assert the `value`
85/// static data member of each instantiation:
86/// @code
87/// assert(false == bsl::is_member_object_pointer<int*>::value);
88/// assert(true == bsl::is_member_object_pointer<DataMemPtr>::value);
89/// @endcode
90/// Note that if the current compiler supports the variable templates C++14
91/// feature then we can re-write the snippet of code above using the
92/// `bsl::is_member_object_pointer_v` variable as follows:
93/// @code
94/// #ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
95/// assert(false == bsl::is_member_object_pointer_v<int*>);
96/// assert(true == bsl::is_member_object_pointer_v<DataMemPtr>);
97/// #endif
98/// @endcode
99/// @}
100/** @} */
101/** @} */
102
103/** @addtogroup bsl
104 * @{
105 */
106/** @addtogroup bslmf
107 * @{
108 */
109/** @addtogroup bslmf_ismemberobjectpointer
110 * @{
111 */
112
113#include <bslscm_version.h>
114
116#include <bslmf_isconst.h>
117#include <bslmf_isfunction.h>
118
120#include <bsls_keyword.h>
121#include <bsls_platform.h>
122
123#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
125#endif // BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
126
127#if !defined(BSLS_PLATFORM_CMP_IBM)
128namespace bsl {
129
130 // ===============================
131 // struct is_member_object_pointer
132 // ===============================
133
134/// This `struct` template implements the `is_member_object_pointer`
135/// meta-function defined in the C++11 standard [meta.unary.cat] to
136/// determine if the (template parameter) `t_TYPE` is a pointer to
137/// non-static data member type. This `struct` derives from
138/// `bsl::true_type` if the `t_TYPE` is a pointer to non-static data member
139/// type, and from `bsl::false_type` otherwise.
140template <class t_TYPE>
143
144#ifdef BSLS_PLATFORM_CMP_MSVC
145# pragma warning(push)
146# pragma warning(disable: 4180) // cv-qualifier has no effect on function type
147#endif
148
149/// Partial specialization relies on the principle that only object types
150/// can be `const`-qualified. Reference-types and function-types do not
151/// retain the `const` qualifier when added in this manner, and there are
152/// no `void` class members.
153template <class t_TYPE, class t_CLASS>
154struct is_member_object_pointer<t_TYPE t_CLASS::*>
155: is_const<const t_TYPE>::type {
156};
157
158#ifdef BSLS_PLATFORM_CMP_MSVC
159# pragma warning(pop)
160#endif
161
162/// Partial specialization relies on the principle that only object types
163/// can be `const`-qualified. Reference-types and function-types do not
164/// retain the `const` qualifier when added in this manner, and there are
165/// no `void` class members.
166template <class t_TYPE, class t_CLASS>
167struct is_member_object_pointer<t_TYPE t_CLASS::*const>
168: is_const<const t_TYPE>::type {
169};
170
171/// Partial specialization relies on the principle that only object types
172/// can be `const`-qualified. Reference-types and function-types do not
173/// retain the `const` qualifier when added in this manner, and there are
174/// no `void` class members.
175template <class t_TYPE, class t_CLASS>
176struct is_member_object_pointer<t_TYPE t_CLASS::*volatile>
177: is_const<const t_TYPE>::type {
178};
179
180/// Partial specialization relies on the principle that only object types
181/// can be `const`-qualified. Reference-types and function-types do not
182/// retain the `const` qualifier when added in this manner, and there are
183/// no `void` class members.
184template <class t_TYPE, class t_CLASS>
185struct is_member_object_pointer<t_TYPE t_CLASS::*const volatile>
186: is_const<const t_TYPE>::type {
187};
188
189} // close namespace bsl
190#else
191// The IBM xlC compiler produces parses an error when trying to add 'const' to
192// a function type, so leans on the original BDE implementation of this trait.
193// Note that this implementation fails on all other compilers for member
194// functions with a C-style elipsis, erroneously reporting such functions as
195// data members. However, xlC appears to have sufficient compenstating bugs
196// that this implementation gives the correct result in such cases too.
197
198
199namespace bslmf {
200
201 // ================================
202 // struct IsPointerToMemberData_Imp
203 // ================================
204
205template <class t_TYPE>
206struct IsPointerToMemberData_Imp : bsl::false_type {
207 // This 'struct' template provides a meta-function to determine whether the
208 // (template parameter) 't_TYPE' is a pointer to non-static data member
209 // type. This generic default template derives from 'bsl::false_type'. A
210 // template specialization is provided (below) that derives from
211 // 'bsl::true_type'.
212};
213
214template <class t_TYPE, class t_CLASS>
215struct IsPointerToMemberData_Imp<t_TYPE t_CLASS::*>
216: bsl::integral_constant<bool, !bsl::is_function<t_TYPE>::value> {
217 // This partial specialization of 'IsPointerToMemberData_Imp' derives from
218 // 'bsl::true_type' for when the (template parameter) 't_TYPE' is a pointer
219 // to non-static data member type.
220};
221
222} // close package namespace
223
224
225namespace bsl {
226
227 // ===============================
228 // struct is_member_object_pointer
229 // ===============================
230
231template <class t_TYPE>
232struct is_member_object_pointer
233: BloombergLP::bslmf::IsPointerToMemberData_Imp<t_TYPE>::type {
234 // This 'struct' template implements the 'is_member_object_pointer'
235 // meta-function defined in the C++11 standard [meta.unary.cat] to
236 // determine if the (template parameter) 't_TYPE' is a pointer to
237 // non-static data member type. This 'struct' derives from
238 // 'bsl::true_type' if the 't_TYPE' is a pointer to non-static data member
239 // type, and from 'bsl::false_type' otherwise.
240};
241
242template <class t_TYPE>
243struct is_member_object_pointer<const t_TYPE>
244: BloombergLP::bslmf::IsPointerToMemberData_Imp<t_TYPE>::type {
245 // Partial specialization to handle 'const'-qualified pointer-to-member
246 // objects.
247};
248
249template <class t_TYPE>
250struct is_member_object_pointer<volatile t_TYPE>
251: BloombergLP::bslmf::IsPointerToMemberData_Imp<t_TYPE>::type {
252 // Partial specialization to handle 'volatile'-qualified pointer-to-member
253 // objects.
254};
255
256template <class t_TYPE>
257struct is_member_object_pointer<const volatile t_TYPE>
258: BloombergLP::bslmf::IsPointerToMemberData_Imp<t_TYPE>::type {
259 // Partial specialization to handle 'const volatile'-qualified
260 // pointer-to-member objects.
261};
262
263} // close namespace bsl
264#endif
265
266#ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
267namespace bsl {
268
269/// This template variable represents the result value of the
270/// `bsl::is_member_object_pointer` meta-function.
271template <class t_TYPE>
272BSLS_KEYWORD_INLINE_VARIABLE constexpr bool is_member_object_pointer_v =
274} // close namespace bsl
275#endif
276
277#endif
278
279// ----------------------------------------------------------------------------
280// Copyright 2013-2018 Bloomberg Finance L.P.
281//
282// Licensed under the Apache License, Version 2.0 (the "License");
283// you may not use this file except in compliance with the License.
284// You may obtain a copy of the License at
285//
286// http://www.apache.org/licenses/LICENSE-2.0
287//
288// Unless required by applicable law or agreed to in writing, software
289// distributed under the License is distributed on an "AS IS" BASIS,
290// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
291// See the License for the specific language governing permissions and
292// limitations under the License.
293// ----------------------------- END-OF-FILE ----------------------------------
294
295/** @} */
296/** @} */
297/** @} */
static const t_TYPE 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 bdlbb_blob.h:576
Definition bslmf_integralconstant.h:244
Definition bslmf_isconst.h:144
Definition bslmf_ismemberobjectpointer.h:141