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