BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslmf_ismemberpointer.h
Go to the documentation of this file.
1/// @file bslmf_ismemberpointer.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_ismemberpointer.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_ISMEMBERPOINTER
9#define INCLUDED_BSLMF_ISMEMBERPOINTER
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_ismemberpointer bslmf_ismemberpointer
15/// @brief Provide a compile-time check for non-static member pointer types.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_ismemberpointer
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_ismemberpointer-purpose"> Purpose</a>
25/// * <a href="#bslmf_ismemberpointer-classes"> Classes </a>
26/// * <a href="#bslmf_ismemberpointer-description"> Description </a>
27/// * <a href="#bslmf_ismemberpointer-usage"> Usage </a>
28/// * <a href="#bslmf_ismemberpointer-example-1-verify-member-pointer-types"> Example 1: Verify Member Pointer Types </a>
29///
30/// # Purpose {#bslmf_ismemberpointer-purpose}
31/// Provide a compile-time check for non-static member pointer types.
32///
33/// # Classes {#bslmf_ismemberpointer-classes}
34///
35/// - bsl::is_member_pointer: standard meta-function for member pointer types
36/// - bsl::is_member_pointer_v: the result value of the standard meta-function
37///
38/// @see bslmf_ismemberfunctionpointer, bslmf_ismemberobjectpointer
39///
40/// # Description {#bslmf_ismemberpointer-description}
41/// This component defines a meta-function,
42/// `bsl::is_member_pointer` and a template variable `bsl::is_member_pointer_v`,
43/// that represents the result value of the `bsl::is_member_pointer`
44/// meta-function, that may be used to query whether a type is a pointer to
45/// non-static member type.
46///
47/// `bsl::is_member_pointer` meets the requirements of the `is_member_pointer`
48/// template defined in the C++11 standard [meta.unary.comp].
49///
50/// Note that the template variable `is_member_pointer_v` is defined in the
51/// C++17 standard as an inline variable. If the current compiler supports the
52/// inline variable C++17 compiler feature, `bsl::is_member_pointer_v` is
53/// defined as an `inline constexpr bool` variable. Otherwise, if the compiler
54/// supports the variable templates C++14 compiler feature,
55/// `bsl::is_member_pointer_v` is defined as a non-inline `constexpr bool`
56/// variable. See `BSLS_COMPILERFEATURES_SUPPORT_INLINE_VARIABLES` and
57/// `BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES` macros in
58/// bsls_compilerfeatures component for details.
59///
60/// ## Usage {#bslmf_ismemberpointer-usage}
61///
62///
63/// In this section we show intended use of this component.
64///
65/// ### Example 1: Verify Member Pointer Types {#bslmf_ismemberpointer-example-1-verify-member-pointer-types}
66///
67///
68/// Suppose that we want to assert whether a set of types are member pointer
69/// types.
70///
71/// First, we create a user-defined type `MyStruct`:
72/// @code
73/// struct MyStruct
74/// {
75/// };
76/// @endcode
77/// Now, we create three `typedef`s -- a member object pointer type, a member
78/// function pointer type and a general function pointer type:
79/// @code
80/// typedef int MyStruct::* DataMemPtr;
81/// typedef int (MyStruct::*MyStructMethodPtr) ();
82/// typedef int (*MyFunctionPtr) ();
83/// @endcode
84/// Finally, we instantiate the `bsl::is_member_pointer` template for various
85/// types and assert the `value` static data member of each instantiation:
86/// @code
87/// assert(false == bsl::is_member_pointer<int*>::value);
88/// assert(false == bsl::is_member_pointer<MyFunctionPtr>::value);
89/// assert(true == bsl::is_member_pointer<DataMemPtr>::value);
90/// assert(true == bsl::is_member_pointer<MyStructMethodPtr>::value);
91/// @endcode
92/// Note that if the current compiler supports the variable templates C++14
93/// feature then we can re-write the snippet of code above using the
94/// `bsl::is_member_pointer_v` variable as follows:
95/// @code
96/// #ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
97/// assert(false == bsl::is_member_pointer_v<int*>);
98/// assert(false == bsl::is_member_pointer_v<MyFunctionPtr>);
99/// assert(true == bsl::is_member_pointer_v<DataMemPtr>);
100/// assert(true == bsl::is_member_pointer_v<MyStructMethodPtr>);
101/// #endif
102/// @endcode
103/// @}
104/** @} */
105/** @} */
106
107/** @addtogroup bsl
108 * @{
109 */
110/** @addtogroup bslmf
111 * @{
112 */
113/** @addtogroup bslmf_ismemberpointer
114 * @{
115 */
116
117#include <bslscm_version.h>
118
120
122#include <bsls_keyword.h>
123#include <bsls_platform.h>
124
125#ifndef BDE_DONT_ALLOW_TRANSITIVE_INCLUDES
128#endif
129
130namespace bsl {
131
132 // ========================
133 // struct is_member_pointer
134 // ========================
135
136/// This `struct` template implements the `is_member_pointer` meta-function
137/// defined in the C++11 standard [meta.unary.comp] to determine if the
138/// (template parameter) `t_TYPE` is a member pointer type. This `struct`
139/// derives from `bsl::true_type` if the `t_TYPE` is a member pointer type,
140/// and from `bsl::false_type` otherwise. Additional specializations are
141/// provided below to give the correct answer in all cases.
142template <class t_TYPE>
145
146/// This partial specialization provides the `true_type` result for a (cv-unqualified) pointer-to-member type.
147///
148/// \note Note that additional partial
149/// specializations are required to handle the cv-qualified cases.
150template <class t_TARGET_TYPE, class t_HOST_TYPE>
151struct is_member_pointer<t_TARGET_TYPE t_HOST_TYPE::*> : true_type {
152};
153
154/// This partial specialization provides the `true_type` result for a
155/// `const`-qualified pointer-to-member type.
156template <class t_TARGET_TYPE, class t_HOST_TYPE>
157struct is_member_pointer<t_TARGET_TYPE t_HOST_TYPE::*const> : true_type {
158};
159
160/// This partial specialization provides the `true_type` result for a
161/// `volatile`-qualified pointer-to-member type.
162template <class t_TARGET_TYPE, class t_HOST_TYPE>
163struct is_member_pointer<t_TARGET_TYPE t_HOST_TYPE::*volatile> : true_type {
164};
165
166/// This partial specialization provides the `true_type` result for a
167/// `const volatile`-qualified pointer-to-member type.
168template <class t_TARGET_TYPE, class t_HOST_TYPE>
169struct is_member_pointer<t_TARGET_TYPE t_HOST_TYPE::*const volatile>
170: true_type {
171};
172
173#ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
174/// This template variable represents the result value of the
175/// `bsl::is_member_pointer` meta-function.
176template <class t_TYPE>
177BSLS_KEYWORD_INLINE_VARIABLE constexpr bool is_member_pointer_v =
179#endif
180
181#if defined(BSLS_PLATFORM_CMP_MSVC) \
182 && BSLS_PLATFORM_CMP_VERSION < 1910 \
183 &&!((BSLS_PLATFORM_CMP_VERSION == 1900) && defined(BSLS_PLATFORM_CPU_64_BIT))
184// MSVC 2013 (and earlier) has two bugs that affect this component. First,
185// it does not match partial specializations for cv-qualified pointer-to-member
186// types, requiring a general stripping of cv-qualifiers for all types to get
187// the right result. Secondly, pointer-to-cv-qualified-member-function fails
188// to match the partial specialization at all, so fall back on trying to match
189// a member function with exactly the right signature using variadic templates,
190// which apparently does work. Note that this bug also appears to affect the
191// MSVC 2015 compiler, but only for 32-bit builds.
192
193template <class t_TYPE>
194struct is_member_pointer<const t_TYPE> : is_member_pointer<t_TYPE>::type {
195 // The 'const'-qualified (template parameter) 't_TYPE' is a member pointer
196 // if the corresponding unqualified 't_TYPE' is a member pointer.
197};
198
199template <class t_TYPE>
200struct is_member_pointer<volatile t_TYPE> : is_member_pointer<t_TYPE>::type {
201 // The 'volatile'-qualified (template parameter) 't_TYPE' is a member
202 // pointer if the corresponding unqualified 't_TYPE' is a member pointer.
203};
204
205template <class t_TYPE>
206struct is_member_pointer<const volatile t_TYPE>
207: is_member_pointer<t_TYPE>::type {
208 // The 'const volatile'-qualified (template parameter) 't_TYPE' is a member
209 // pointer if the corresponding unqualified 't_TYPE' is a member pointer.
210};
211
212template <class RESULT, class HOST, class... ARGS>
213struct is_member_pointer<RESULT (HOST::*)(ARGS...)> : true_type {
214 // This partial specialization for non-cv-qualified pointer-to-member types
215 // derives from 'true_type' if the specified (template parameter) 'type' is
216 // a function type.
217};
218
219template <class RESULT, class HOST, class... ARGS>
220struct is_member_pointer<RESULT (HOST::*)(ARGS...) const> : true_type {
221 // This partial specialization for non-cv-qualified pointer-to-member types
222 // derives from 'true_type' if the specified (template parameter) 'type' is
223 // a function type.
224};
225
226template <class RESULT, class HOST, class... ARGS>
227struct is_member_pointer<RESULT (HOST::*)(ARGS...) volatile> : true_type {
228 // This partial specialization for non-cv-qualified pointer-to-member types
229 // derives from 'true_type' if the specified (template parameter) 'type' is
230 // a function type.
231};
232
233template <class RESULT, class HOST, class... ARGS>
234struct is_member_pointer<RESULT (HOST::*)(ARGS...) const volatile>
235 : true_type {
236 // This partial specialization for non-cv-qualified pointer-to-member types
237 // derives from 'true_type' if the specified (template parameter) 'type' is
238 // a function type.
239};
240
241template <class RESULT, class HOST, class... ARGS>
242struct is_member_pointer<RESULT (HOST::*)(ARGS...,...)> : true_type {
243 // This partial specialization for non-cv-qualified pointer-to-member types
244 // derives from 'true_type' if the specified (template parameter) 'type' is
245 // a function type.
246};
247
248template <class RESULT, class HOST, class... ARGS>
249struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) const> : true_type {
250 // This partial specialization for non-cv-qualified pointer-to-member types
251 // derives from 'true_type' if the specified (template parameter) 'type' is
252 // a function type.
253};
254
255template <class RESULT, class HOST, class... ARGS>
256struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) volatile> : true_type {
257 // This partial specialization for non-cv-qualified pointer-to-member types
258 // derives from 'true_type' if the specified (template parameter) 'type' is
259 // a function type.
260};
261
262template <class RESULT, class HOST, class... ARGS>
263struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) const volatile>
264 : true_type {
265 // This partial specialization for non-cv-qualified pointer-to-member types
266 // derives from 'true_type' if the specified (template parameter) 'type' is
267 // a function type.
268};
269
270#if defined(BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS)
271// Only MSVC 2015 32-bit builds get here
272template <class RESULT, class HOST, class... ARGS>
273struct is_member_pointer<RESULT (HOST::*)(ARGS...) &>
274 : true_type {
275 // This partial specialization for non-cv-qualified pointer-to-member types
276 // derives from 'true_type' if the specified (template parameter) 'type' is
277 // a function type.
278};
279
280template <class RESULT, class HOST, class... ARGS>
281struct is_member_pointer<RESULT (HOST::*)(ARGS...) const &>
282 : true_type {
283 // This partial specialization for non-cv-qualified pointer-to-member types
284 // derives from 'true_type' if the specified (template parameter) 'type' is
285 // a function type.
286};
287
288template <class RESULT, class HOST, class... ARGS>
289struct is_member_pointer<RESULT (HOST::*)(ARGS...) volatile &>
290 : true_type {
291 // This partial specialization for non-cv-qualified pointer-to-member types
292 // derives from 'true_type' if the specified (template parameter) 'type' is
293 // a function type.
294};
295
296template <class RESULT, class HOST, class... ARGS>
297struct is_member_pointer<RESULT (HOST::*)(ARGS...) const volatile &>
298 : true_type {
299 // This partial specialization for non-cv-qualified pointer-to-member types
300 // derives from 'true_type' if the specified (template parameter) 'type' is
301 // a function type.
302};
303
304template <class RESULT, class HOST, class... ARGS>
305struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) &>
306 : true_type {
307 // This partial specialization for non-cv-qualified pointer-to-member types
308 // derives from 'true_type' if the specified (template parameter) 'type' is
309 // a function type.
310};
311
312template <class RESULT, class HOST, class... ARGS>
313struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) const &>
314 : true_type {
315 // This partial specialization for non-cv-qualified pointer-to-member types
316 // derives from 'true_type' if the specified (template parameter) 'type' is
317 // a function type.
318};
319
320template <class RESULT, class HOST, class... ARGS>
321struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) volatile &>
322 : true_type {
323 // This partial specialization for non-cv-qualified pointer-to-member types
324 // derives from 'true_type' if the specified (template parameter) 'type' is
325 // a function type.
326};
327
328template <class RESULT, class HOST, class... ARGS>
329struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) const volatile &>
330 : true_type {
331 // This partial specialization for non-cv-qualified pointer-to-member types
332 // derives from 'true_type' if the specified (template parameter) 'type' is
333 // a function type.
334};
335
336template <class RESULT, class HOST, class... ARGS>
337struct is_member_pointer<RESULT (HOST::*)(ARGS...) &&>
338 : true_type {
339 // This partial specialization for non-cv-qualified pointer-to-member types
340 // derives from 'true_type' if the specified (template parameter) 'type' is
341 // a function type.
342};
343
344template <class RESULT, class HOST, class... ARGS>
345struct is_member_pointer<RESULT (HOST::*)(ARGS...) const &&>
346 : true_type {
347 // This partial specialization for non-cv-qualified pointer-to-member types
348 // derives from 'true_type' if the specified (template parameter) 'type' is
349 // a function type.
350};
351
352template <class RESULT, class HOST, class... ARGS>
353struct is_member_pointer<RESULT (HOST::*)(ARGS...) volatile &&>
354 : true_type {
355 // This partial specialization for non-cv-qualified pointer-to-member types
356 // derives from 'true_type' if the specified (template parameter) 'type' is
357 // a function type.
358};
359
360template <class RESULT, class HOST, class... ARGS>
361struct is_member_pointer<RESULT (HOST::*)(ARGS...) const volatile &&>
362 : true_type {
363 // This partial specialization for non-cv-qualified pointer-to-member types
364 // derives from 'true_type' if the specified (template parameter) 'type' is
365 // a function type.
366};
367
368template <class RESULT, class HOST, class... ARGS>
369struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) &&>
370 : true_type {
371 // This partial specialization for non-cv-qualified pointer-to-member types
372 // derives from 'true_type' if the specified (template parameter) 'type' is
373 // a function type.
374};
375
376template <class RESULT, class HOST, class... ARGS>
377struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) const &&>
378 : true_type {
379 // This partial specialization for non-cv-qualified pointer-to-member types
380 // derives from 'true_type' if the specified (template parameter) 'type' is
381 // a function type.
382};
383
384template <class RESULT, class HOST, class... ARGS>
385struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) volatile &&>
386 : true_type {
387 // This partial specialization for non-cv-qualified pointer-to-member types
388 // derives from 'true_type' if the specified (template parameter) 'type' is
389 // a function type.
390};
391
392template <class RESULT, class HOST, class... ARGS>
393struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) const volatile &&>
394 : true_type {
395 // This partial specialization for non-cv-qualified pointer-to-member types
396 // derives from 'true_type' if the specified (template parameter) 'type' is
397 // a function type.
398};
399#endif // Reference-qualifier support for MSVC 2015
400
401#endif // MSVC workarounds
402
403} // close namespace bsl
404
405#endif
406
407// ----------------------------------------------------------------------------
408// Copyright 2013 Bloomberg Finance L.P.
409//
410// Licensed under the Apache License, Version 2.0 (the "License");
411// you may not use this file except in compliance with the License.
412// You may obtain a copy of the License at
413//
414// http://www.apache.org/licenses/LICENSE-2.0
415//
416// Unless required by applicable law or agreed to in writing, software
417// distributed under the License is distributed on an "AS IS" BASIS,
418// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
419// See the License for the specific language governing permissions and
420// limitations under the License.
421// ----------------------------- END-OF-FILE ----------------------------------
422
423/** @} */
424/** @} */
425/** @} */
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
#define BSLS_KEYWORD_INLINE_VARIABLE
Definition bsls_keyword.h:665
Definition bdlat_valuetypefunctions.h:939
integral_constant< bool, true > true_type
Definition bslmf_integralconstant.h:296
Definition bslmf_integralconstant.h:261
Definition bslmf_ismemberpointer.h:143