BDE 4.14.0 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
147/// (cv-unqualified) pointer-to-member type. Note that additional partial
148/// specializations are required to handle the cv-qualified cases.
149template <class t_TARGET_TYPE, class t_HOST_TYPE>
150struct is_member_pointer<t_TARGET_TYPE t_HOST_TYPE::*> : true_type {
151};
152
153/// This partial specialization provides the `true_type` result for a
154/// `const`-qualified pointer-to-member type.
155template <class t_TARGET_TYPE, class t_HOST_TYPE>
156struct is_member_pointer<t_TARGET_TYPE t_HOST_TYPE::*const> : true_type {
157};
158
159/// This partial specialization provides the `true_type` result for a
160/// `volatile`-qualified pointer-to-member type.
161template <class t_TARGET_TYPE, class t_HOST_TYPE>
162struct is_member_pointer<t_TARGET_TYPE t_HOST_TYPE::*volatile> : true_type {
163};
164
165/// This partial specialization provides the `true_type` result for a
166/// `const volatile`-qualified pointer-to-member type.
167template <class t_TARGET_TYPE, class t_HOST_TYPE>
168struct is_member_pointer<t_TARGET_TYPE t_HOST_TYPE::*const volatile>
169: true_type {
170};
171
172#ifdef BSLS_COMPILERFEATURES_SUPPORT_VARIABLE_TEMPLATES
173/// This template variable represents the result value of the
174/// `bsl::is_member_pointer` meta-function.
175template <class t_TYPE>
176BSLS_KEYWORD_INLINE_VARIABLE constexpr bool is_member_pointer_v =
178#endif
179
180#if defined(BSLS_PLATFORM_CMP_MSVC) \
181 && BSLS_PLATFORM_CMP_VERSION < 1910 \
182 &&!((BSLS_PLATFORM_CMP_VERSION == 1900) && defined(BSLS_PLATFORM_CPU_64_BIT))
183// MSVC 2013 (and earlier) has two bugs that affect this component. First,
184// it does not match partial specializations for cv-qualified pointer-to-member
185// types, requiring a general stripping of cv-qualifiers for all types to get
186// the right result. Secondly, pointer-to-cv-qualified-member-function fails
187// to match the partial specialization at all, so fall back on trying to match
188// a member function with exactly the right signature using variadic templates,
189// which apparently does work. Note that this bug also appears to affect the
190// MSVC 2015 compiler, but only for 32-bit builds.
191
192template <class t_TYPE>
193struct is_member_pointer<const t_TYPE> : is_member_pointer<t_TYPE>::type {
194 // The 'const'-qualified (template parameter) 't_TYPE' is a member pointer
195 // if the corresponding unqualified 't_TYPE' is a member pointer.
196};
197
198template <class t_TYPE>
199struct is_member_pointer<volatile t_TYPE> : is_member_pointer<t_TYPE>::type {
200 // The 'volatile'-qualified (template parameter) 't_TYPE' is a member
201 // pointer if the corresponding unqualified 't_TYPE' is a member pointer.
202};
203
204template <class t_TYPE>
205struct is_member_pointer<const volatile t_TYPE>
206: is_member_pointer<t_TYPE>::type {
207 // The 'const volatile'-qualified (template parameter) 't_TYPE' is a member
208 // pointer if the corresponding unqualified 't_TYPE' is a member pointer.
209};
210
211template <class RESULT, class HOST, class... ARGS>
212struct is_member_pointer<RESULT (HOST::*)(ARGS...)> : true_type {
213 // This partial specialization for non-cv-qualified pointer-to-member types
214 // derives from 'true_type' if the specified (template parameter) 'type' is
215 // a function type.
216};
217
218template <class RESULT, class HOST, class... ARGS>
219struct is_member_pointer<RESULT (HOST::*)(ARGS...) const> : true_type {
220 // This partial specialization for non-cv-qualified pointer-to-member types
221 // derives from 'true_type' if the specified (template parameter) 'type' is
222 // a function type.
223};
224
225template <class RESULT, class HOST, class... ARGS>
226struct is_member_pointer<RESULT (HOST::*)(ARGS...) volatile> : true_type {
227 // This partial specialization for non-cv-qualified pointer-to-member types
228 // derives from 'true_type' if the specified (template parameter) 'type' is
229 // a function type.
230};
231
232template <class RESULT, class HOST, class... ARGS>
233struct is_member_pointer<RESULT (HOST::*)(ARGS...) const volatile>
234 : true_type {
235 // This partial specialization for non-cv-qualified pointer-to-member types
236 // derives from 'true_type' if the specified (template parameter) 'type' is
237 // a function type.
238};
239
240template <class RESULT, class HOST, class... ARGS>
241struct is_member_pointer<RESULT (HOST::*)(ARGS...,...)> : true_type {
242 // This partial specialization for non-cv-qualified pointer-to-member types
243 // derives from 'true_type' if the specified (template parameter) 'type' is
244 // a function type.
245};
246
247template <class RESULT, class HOST, class... ARGS>
248struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) const> : true_type {
249 // This partial specialization for non-cv-qualified pointer-to-member types
250 // derives from 'true_type' if the specified (template parameter) 'type' is
251 // a function type.
252};
253
254template <class RESULT, class HOST, class... ARGS>
255struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) volatile> : true_type {
256 // This partial specialization for non-cv-qualified pointer-to-member types
257 // derives from 'true_type' if the specified (template parameter) 'type' is
258 // a function type.
259};
260
261template <class RESULT, class HOST, class... ARGS>
262struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) const volatile>
263 : true_type {
264 // This partial specialization for non-cv-qualified pointer-to-member types
265 // derives from 'true_type' if the specified (template parameter) 'type' is
266 // a function type.
267};
268
269#if defined(BSLS_COMPILERFEATURES_SUPPORT_REF_QUALIFIERS)
270// Only MSVC 2015 32-bit builds get here
271template <class RESULT, class HOST, class... ARGS>
272struct is_member_pointer<RESULT (HOST::*)(ARGS...) &>
273 : true_type {
274 // This partial specialization for non-cv-qualified pointer-to-member types
275 // derives from 'true_type' if the specified (template parameter) 'type' is
276 // a function type.
277};
278
279template <class RESULT, class HOST, class... ARGS>
280struct is_member_pointer<RESULT (HOST::*)(ARGS...) const &>
281 : true_type {
282 // This partial specialization for non-cv-qualified pointer-to-member types
283 // derives from 'true_type' if the specified (template parameter) 'type' is
284 // a function type.
285};
286
287template <class RESULT, class HOST, class... ARGS>
288struct is_member_pointer<RESULT (HOST::*)(ARGS...) volatile &>
289 : true_type {
290 // This partial specialization for non-cv-qualified pointer-to-member types
291 // derives from 'true_type' if the specified (template parameter) 'type' is
292 // a function type.
293};
294
295template <class RESULT, class HOST, class... ARGS>
296struct is_member_pointer<RESULT (HOST::*)(ARGS...) const volatile &>
297 : true_type {
298 // This partial specialization for non-cv-qualified pointer-to-member types
299 // derives from 'true_type' if the specified (template parameter) 'type' is
300 // a function type.
301};
302
303template <class RESULT, class HOST, class... ARGS>
304struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) &>
305 : true_type {
306 // This partial specialization for non-cv-qualified pointer-to-member types
307 // derives from 'true_type' if the specified (template parameter) 'type' is
308 // a function type.
309};
310
311template <class RESULT, class HOST, class... ARGS>
312struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) const &>
313 : true_type {
314 // This partial specialization for non-cv-qualified pointer-to-member types
315 // derives from 'true_type' if the specified (template parameter) 'type' is
316 // a function type.
317};
318
319template <class RESULT, class HOST, class... ARGS>
320struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) volatile &>
321 : true_type {
322 // This partial specialization for non-cv-qualified pointer-to-member types
323 // derives from 'true_type' if the specified (template parameter) 'type' is
324 // a function type.
325};
326
327template <class RESULT, class HOST, class... ARGS>
328struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) const volatile &>
329 : true_type {
330 // This partial specialization for non-cv-qualified pointer-to-member types
331 // derives from 'true_type' if the specified (template parameter) 'type' is
332 // a function type.
333};
334
335template <class RESULT, class HOST, class... ARGS>
336struct is_member_pointer<RESULT (HOST::*)(ARGS...) &&>
337 : true_type {
338 // This partial specialization for non-cv-qualified pointer-to-member types
339 // derives from 'true_type' if the specified (template parameter) 'type' is
340 // a function type.
341};
342
343template <class RESULT, class HOST, class... ARGS>
344struct is_member_pointer<RESULT (HOST::*)(ARGS...) const &&>
345 : true_type {
346 // This partial specialization for non-cv-qualified pointer-to-member types
347 // derives from 'true_type' if the specified (template parameter) 'type' is
348 // a function type.
349};
350
351template <class RESULT, class HOST, class... ARGS>
352struct is_member_pointer<RESULT (HOST::*)(ARGS...) volatile &&>
353 : true_type {
354 // This partial specialization for non-cv-qualified pointer-to-member types
355 // derives from 'true_type' if the specified (template parameter) 'type' is
356 // a function type.
357};
358
359template <class RESULT, class HOST, class... ARGS>
360struct is_member_pointer<RESULT (HOST::*)(ARGS...) const volatile &&>
361 : true_type {
362 // This partial specialization for non-cv-qualified pointer-to-member types
363 // derives from 'true_type' if the specified (template parameter) 'type' is
364 // a function type.
365};
366
367template <class RESULT, class HOST, class... ARGS>
368struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) &&>
369 : true_type {
370 // This partial specialization for non-cv-qualified pointer-to-member types
371 // derives from 'true_type' if the specified (template parameter) 'type' is
372 // a function type.
373};
374
375template <class RESULT, class HOST, class... ARGS>
376struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) const &&>
377 : true_type {
378 // This partial specialization for non-cv-qualified pointer-to-member types
379 // derives from 'true_type' if the specified (template parameter) 'type' is
380 // a function type.
381};
382
383template <class RESULT, class HOST, class... ARGS>
384struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) volatile &&>
385 : true_type {
386 // This partial specialization for non-cv-qualified pointer-to-member types
387 // derives from 'true_type' if the specified (template parameter) 'type' is
388 // a function type.
389};
390
391template <class RESULT, class HOST, class... ARGS>
392struct is_member_pointer<RESULT (HOST::*)(ARGS...,...) const volatile &&>
393 : true_type {
394 // This partial specialization for non-cv-qualified pointer-to-member types
395 // derives from 'true_type' if the specified (template parameter) 'type' is
396 // a function type.
397};
398#endif // Reference-qualifier support for MSVC 2015
399
400#endif // MSVC workarounds
401
402} // close namespace bsl
403
404#endif
405
406// ----------------------------------------------------------------------------
407// Copyright 2013 Bloomberg Finance L.P.
408//
409// Licensed under the Apache License, Version 2.0 (the "License");
410// you may not use this file except in compliance with the License.
411// You may obtain a copy of the License at
412//
413// http://www.apache.org/licenses/LICENSE-2.0
414//
415// Unless required by applicable law or agreed to in writing, software
416// distributed under the License is distributed on an "AS IS" BASIS,
417// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
418// See the License for the specific language governing permissions and
419// limitations under the License.
420// ----------------------------- END-OF-FILE ----------------------------------
421
422/** @} */
423/** @} */
424/** @} */
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_INLINE_VARIABLE
Definition bsls_keyword.h:623
Definition bdlb_printmethods.h:283
integral_constant< bool, true > true_type
Definition bslmf_integralconstant.h:303
Definition bslmf_integralconstant.h:244
Definition bslmf_ismemberpointer.h:143