BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bslmf_functionpointertraits.h
Go to the documentation of this file.
1/// @file bslmf_functionpointertraits.h
2///
3/// The content of this file has been pre-processed for Doxygen.
4///
5
6
7// bslmf_functionpointertraits.h -*-C++-*-
8#ifndef INCLUDED_BSLMF_FUNCTIONPOINTERTRAITS
9#define INCLUDED_BSLMF_FUNCTIONPOINTERTRAITS
10
11#include <bsls_ident.h>
12BSLS_IDENT("$Id: $")
13
14/// @defgroup bslmf_functionpointertraits bslmf_functionpointertraits
15/// @brief Provide a meta-function for determining function pointer traits.
16/// @addtogroup bsl
17/// @{
18/// @addtogroup bslmf
19/// @{
20/// @addtogroup bslmf_functionpointertraits
21/// @{
22///
23/// <h1> Outline </h1>
24/// * <a href="#bslmf_functionpointertraits-purpose"> Purpose</a>
25/// * <a href="#bslmf_functionpointertraits-classes"> Classes </a>
26/// * <a href="#bslmf_functionpointertraits-description"> Description </a>
27/// * <a href="#bslmf_functionpointertraits-usage"> Usage </a>
28///
29/// # Purpose {#bslmf_functionpointertraits-purpose}
30/// Provide a meta-function for determining function pointer traits.
31///
32/// # Classes {#bslmf_functionpointertraits-classes}
33///
34/// - bslmf::FunctionPointerTraits: meta-function for detecting function pointer
35/// - traits
36/// - bslmf::IsFunctionPointer: meta-function to determine if a type is a
37/// - function pointer
38///
39/// @see bslmf_memberfunctionpointertraits
40///
41/// # Description {#bslmf_functionpointertraits-description}
42/// This component provides meta-functions for determining whether
43/// a type is a pointer to either a free function or a class method (but not to
44/// a member function, see the component @ref bslmf_memberfunctionpointertraits
45/// component for that), and some information about this function type. The
46/// meta-function `bslmf::IsFunctionPointer` provides an enumerated `value`
47/// which can be either 1 or 0 depending on whether or not the template argument
48/// `t_PROTOTYPE` is a pointer to a free function or class method. In the
49/// affirmative, the class `bslmf::FunctionPointerTraits` also provides
50/// information regarding the function type, such as its argument list type and
51/// its return type.
52///
53/// Note that there is no reference-to-function traits class, since whether
54/// `FUNC` is a reference to function type can be very easily obtained using the
55/// meta-function call `bslmf::IsFunctionPointer<FUNC *>`.
56///
57/// ## Usage {#bslmf_functionpointertraits-usage}
58///
59///
60/// Define the following function types:
61/// @code
62/// typedef int (*IntFunctionIntIntPtr)(int, int);
63/// typedef void (*VoidFunc0)();
64/// @endcode
65/// The following program should compile and run without errors:
66/// @code
67/// int main()
68/// {
69/// assert(0 == bslmf::IsFunctionPointer<int>::value);
70/// assert(0 == bslmf::IsFunctionPointer<void>::value);
71///
72/// assert(1 == bslmf::IsFunctionPointer<IntFunctionIntIntPtr>::value);
73/// typedef bslmf::FunctionPointerTraits<IntFunctionIntIntPtr>::ResultType
74/// ResultType1;
75/// assert(1 == (bsl::is_same<ResultType1, int>::value));
76///
77/// assert(1 == bslmf::IsFunctionPointer<VoidFunc0>::value);
78/// typedef bslmf::FunctionPointerTraits<VoidFunc0>::ResultType
79/// ResultType0;
80/// typedef bslmf::FunctionPointerTraits<VoidFunc0>::ArgumentList
81/// ArgList0;
82/// assert(1 == (bsl::is_same<ResultType0, void>::value));
83/// assert(1 == (bsl::is_same<ArgList0, bslmf::TypeList0>::value));
84/// }
85/// @endcode
86/// @}
87/** @} */
88/** @} */
89
90/** @addtogroup bsl
91 * @{
92 */
93/** @addtogroup bslmf
94 * @{
95 */
96/** @addtogroup bslmf_functionpointertraits
97 * @{
98 */
99
100#include <bslscm_version.h>
101
103#include <bslmf_typelist.h>
104
106#include <bsls_platform.h>
107
108#if BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES
109// clang-format off
110// Include version that can be compiled with C++03
111// Generated on Mon Jan 13 08:31:25 2025
112// Command line: sim_cpp11_features.pl bslmf_functionpointertraits.h
113
114# define COMPILING_BSLMF_FUNCTIONPOINTERTRAITS_H
116# undef COMPILING_BSLMF_FUNCTIONPOINTERTRAITS_H
117
118// clang-format on
119#else
120
121
122namespace bslmf {
123
124/// C++ function pointer linkage tag.
125///
126/// See @ref bslmf_functionpointertraits
129
130/// C function pointer linkage tag.
131///
132/// See @ref bslmf_functionpointertraits
135
136 // ===========================
137 // class FunctionPointerTraits
138 // ===========================
139
140/// This class gives information about the specified `t_PROTOTYPE`. The
141/// general definition gives no information, but specializations for
142/// function pointers types define nested types `ResultType`,
143/// `ArgumentList`, and `Linkage`.
144///
145/// See @ref bslmf_functionpointertraits
146template <class t_PROTOTYPE>
148
150};
151
152 // =======================
153 // class IsFunctionPointer
154 // =======================
155
156/// This template determines if the specified `t_PROTOTYPE` is a free (i.e.,
157/// non-member) function pointer. `value` is defined as 1 if the specified
158/// `t_PROTOTYPE` is a function pointer type, and a zero value otherwise.
159template <class t_PROTOTYPE>
162 bool,
163 FunctionPointerTraits<t_PROTOTYPE>::IS_FUNCTION_POINTER> {
164};
165
166// ---- Anything below this line is implementation specific. Do not use. ----
167
168#if defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT_TYPES) && \
169 !defined(BSLS_COMPILERFEATURES_SUPPORT_VARIADIC_TEMPLATES)
170 // All of our compilers which identify 'noexcept' as part of the type
171 // system (a C++17 piece of functionality) similarly also support variadic
172 // templates, so we refrain from having the dead code to support this case.
173# error Feature not supported for compilers without variadic templates
174#endif
175
176 // ---------------------------
177 // class FunctionPointerTraits
178 // ---------------------------
179
180#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES // $var-args=14
181
182// This pragma is not supported by older versions of Apple Clang
183// {DRQS 169716845<GO>}
184#if defined(BSLS_PLATFORM_CMP_CLANG) && (!defined(BSLS_PLATFORM_OS_DARWIN) \
185 || BSLS_PLATFORM_CMP_VERSION > 130000)
186#pragma clang diagnostic push
187#pragma clang diagnostic ignored "-Wdeprecated-volatile"
188#endif
189
190/// Specialization for function pointers that return `t_BSLMF_RETURN` and
191/// accept a fixed number of arguments
192template <class t_BSLMF_RETURN, class... t_ARGS>
193struct FunctionPointerTraits<t_BSLMF_RETURN (*)(t_ARGS...)> {
194
195 enum {
196 IS_FUNCTION_POINTER = 1,
197 IS_NOEXCEPT = 0
198 };
199 enum { e_IS_VARARG = 0 };
200 typedef t_BSLMF_RETURN ResultType;
201 typedef typename TypeList<t_ARGS...>::Type ArgumentList;
202 typedef t_BSLMF_RETURN FuncType(t_ARGS...);
204};
205
206/// Specialization for function pointers that return `t_BSLMF_RETURN` and
207/// accept variable (C-style varargs) number of arguments
208template <class t_BSLMF_RETURN, class... t_ARGS>
209struct FunctionPointerTraits<t_BSLMF_RETURN (*)(t_ARGS...,...)> {
210
211 enum {
212 IS_FUNCTION_POINTER = 1,
213 IS_NOEXCEPT = 0
214 };
215 enum { e_IS_VARARG = 1 };
216 typedef t_BSLMF_RETURN ResultType;
217 typedef typename TypeList<t_ARGS...>::Type ArgumentList;
218 typedef t_BSLMF_RETURN FuncType(t_ARGS...,...);
220};
221
222#if defined(BSLS_PLATFORM_CMP_CLANG)
223#pragma clang diagnostic pop
224#endif
225
226#endif
227
228#if defined(BSLS_PLATFORM_CMP_MSVC)
229// Microsoft Visual C++ has a problem matching 'T * const' pointers to the
230// appropriate partial specialization, whereas it will match a 'T const'
231// specialization. We could use the Microsoft fix on all platforms, but why
232// instantiate more traits than necessary when testing pointer traits of
233// cv-qualified types that are not function pointers?
234
235template <class t_PROTOTYPE>
236struct FunctionPointerTraits<t_PROTOTYPE const>
237: FunctionPointerTraits<t_PROTOTYPE> {
238 // This class gives information about the specified 't_PROTOTYPE'. The
239 // general definition gives no information, but specializations for
240 // function pointers types define nested types 'ResultType',
241 // 'ArgumentList', and 'Linkage'.
242};
243
244template <class t_PROTOTYPE>
245struct FunctionPointerTraits<t_PROTOTYPE volatile>
246: FunctionPointerTraits<t_PROTOTYPE> {
247 // This class gives information about the specified 't_PROTOTYPE'. The
248 // general definition gives no information, but specializations for
249 // function pointers types define nested types 'ResultType',
250 // 'ArgumentList', and 'Linkage'.
251};
252
253template <class t_PROTOTYPE>
254struct FunctionPointerTraits<t_PROTOTYPE const volatile>
255: FunctionPointerTraits<t_PROTOTYPE> {
256 // This class gives information about the specified 't_PROTOTYPE'. The
257 // general definition gives no information, but specializations for
258 // function pointers types define nested types 'ResultType',
259 // 'ArgumentList', and 'Linkage'.
260};
261#else
262/// This class gives information about the specified `t_PROTOTYPE`. The
263/// general definition gives no information, but specializations for
264/// function pointers types define nested types `ResultType`,
265/// `ArgumentList`, and `Linkage`.
266template <class t_PROTOTYPE>
267struct FunctionPointerTraits<t_PROTOTYPE *const>
269};
270
271/// This class gives information about the specified `t_PROTOTYPE`. The
272/// general definition gives no information, but specializations for
273/// function pointers types define nested types `ResultType`,
274/// `ArgumentList`, and `Linkage`.
275template <class t_PROTOTYPE>
276struct FunctionPointerTraits<t_PROTOTYPE *volatile>
278};
279
280/// This class gives information about the specified `t_PROTOTYPE`. The
281/// general definition gives no information, but specializations for
282/// function pointers types define nested types `ResultType`,
283/// `ArgumentList`, and `Linkage`.
284template <class t_PROTOTYPE>
285struct FunctionPointerTraits<t_PROTOTYPE *const volatile>
287};
288// }}} END GENERATED CODE
289#endif
290
291#ifdef BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT_TYPES
292
293#if defined(BSLS_PLATFORM_CMP_CLANG)
294#pragma clang diagnostic push
295#pragma clang diagnostic ignored "-Wdeprecated-volatile"
296#endif
297
298/// Specialization for `noexcept` function pointers that return
299/// `t_BSLMF_RETURN` and accept a fixed number of arguments
300template <class t_BSLMF_RETURN, class... t_ARGS>
301struct FunctionPointerTraits<t_BSLMF_RETURN (*)(t_ARGS...) noexcept> {
302
303 enum {
304 IS_FUNCTION_POINTER = 1,
305 IS_NOEXCEPT = 1
306 };
307 enum { e_IS_VARARG = 0 };
308 typedef t_BSLMF_RETURN ResultType;
309 typedef typename TypeList<t_ARGS...>::Type ArgumentList;
310 typedef t_BSLMF_RETURN FuncType(t_ARGS...) noexcept;
311 typedef FunctionPointerCPlusPlusLinkage Linkage;
312};
313
314/// Specialization for `noexcept` function pointers that return
315/// `t_BSLMF_RETURN` and accept variable (C-style varargs) number of
316/// arguments
317template <class t_BSLMF_RETURN, class... t_ARGS>
318struct FunctionPointerTraits<t_BSLMF_RETURN (*)(t_ARGS...,...) noexcept> {
319
320 enum {
321 IS_FUNCTION_POINTER = 1,
322 IS_NOEXCEPT = 1
323 };
324 enum { e_IS_VARARG = 1 };
325 typedef t_BSLMF_RETURN ResultType;
326 typedef typename TypeList<t_ARGS...>::Type ArgumentList;
327 typedef t_BSLMF_RETURN FuncType(t_ARGS...,...) noexcept;
328 typedef FunctionPointerCPlusPlusLinkage Linkage;
329};
330
331#if defined(BSLS_PLATFORM_CMP_CLANG)
332#pragma clang diagnostic pop
333#endif
334
335#endif // BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT_TYPES
336
337} // close package namespace
338
339#ifndef BDE_OPENSOURCE_PUBLICATION // BACKWARD_COMPATIBILITY
340// ============================================================================
341// BACKWARD COMPATIBILITY
342// ============================================================================
343
344/// This alias is defined for backward compatibility.
347
348/// This alias is defined for backward compatibility.
350
351#ifdef bslmf_FunctionPointerTraits
352#undef bslmf_FunctionPointerTraits
353#endif
354/// This alias is defined for backward compatibility.
355#define bslmf_FunctionPointerTraits bslmf::FunctionPointerTraits
356
357#ifdef bslmf_IsFunctionPointer
358#undef bslmf_IsFunctionPointer
359#endif
360/// This alias is defined for backward compatibility.
361#define bslmf_IsFunctionPointer bslmf::IsFunctionPointer
362#endif // BDE_OPENSOURCE_PUBLICATION -- BACKWARD_COMPATIBILITY
363
364
365
366#endif // End C++11 code
367
368#endif
369
370// ----------------------------------------------------------------------------
371// Copyright 2013 Bloomberg Finance L.P.
372//
373// Licensed under the Apache License, Version 2.0 (the "License");
374// you may not use this file except in compliance with the License.
375// You may obtain a copy of the License at
376//
377// http://www.apache.org/licenses/LICENSE-2.0
378//
379// Unless required by applicable law or agreed to in writing, software
380// distributed under the License is distributed on an "AS IS" BASIS,
381// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
382// See the License for the specific language governing permissions and
383// limitations under the License.
384// ----------------------------- END-OF-FILE ----------------------------------
385
386/** @} */
387/** @} */
388/** @} */
bslmf::FunctionPointerCLinkage bslmf_FunctionPointerCLinkage
This alias is defined for backward compatibility.
Definition bslmf_functionpointertraits.h:349
bslmf::FunctionPointerCPlusPlusLinkage bslmf_FunctionPointerCPlusPlusLinkage
This alias is defined for backward compatibility.
Definition bslmf_functionpointertraits.h:346
#define BSLS_IDENT(str)
BSLS_IDENT() - insert string into .comment binary segment (if supported)
Definition bsls_ident.h:238
Definition bdlbb_blob.h:579
Definition bslmf_integralconstant.h:261
Definition bslmf_functionpointertraits.h:133
Definition bslmf_functionpointertraits.h:127
TypeList< t_ARGS... >::Type ArgumentList
Definition bslmf_functionpointertraits.h:217
t_BSLMF_RETURN FuncType(t_ARGS...,...)
Definition bslmf_functionpointertraits.h:218
t_BSLMF_RETURN ResultType
Definition bslmf_functionpointertraits.h:216
FunctionPointerCPlusPlusLinkage Linkage
Definition bslmf_functionpointertraits.h:219
TypeList< t_ARGS... >::Type ArgumentList
Definition bslmf_functionpointertraits.h:201
t_BSLMF_RETURN ResultType
Definition bslmf_functionpointertraits.h:200
t_BSLMF_RETURN FuncType(t_ARGS...)
Definition bslmf_functionpointertraits.h:202
FunctionPointerCPlusPlusLinkage Linkage
Definition bslmf_functionpointertraits.h:203
Definition bslmf_functionpointertraits.h:147
@ IS_FUNCTION_POINTER
Definition bslmf_functionpointertraits.h:149
Definition bslmf_functionpointertraits.h:163
Definition bslmf_typelist.h:1612