BDE 4.14.0 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// Include version that can be compiled with C++03
110// Generated on Thu Oct 21 10:11:37 2021
111// Command line: sim_cpp11_features.pl bslmf_functionpointertraits.h
112# define COMPILING_BSLMF_FUNCTIONPOINTERTRAITS_H
114# undef COMPILING_BSLMF_FUNCTIONPOINTERTRAITS_H
115#else
116
117
118namespace bslmf {
119
120/// C++ function pointer linkage tag.
123
124/// C function pointer linkage tag.
127
128 // ===========================
129 // class FunctionPointerTraits
130 // ===========================
131
132/// This class gives information about the specified `t_PROTOTYPE`. The
133/// general definition gives no information, but specializations for
134/// function pointers types define nested types `ResultType`,
135/// `ArgumentList`, and `Linkage`.
136template <class t_PROTOTYPE>
138
140};
141
142 // =======================
143 // class IsFunctionPointer
144 // =======================
145
146/// This template determines if the specified `t_PROTOTYPE` is a free (i.e.,
147/// non-member) function pointer. `value` is defined as 1 if the specified
148/// `t_PROTOTYPE` is a function pointer type, and a zero value otherwise.
149template <class t_PROTOTYPE>
152 bool,
153 FunctionPointerTraits<t_PROTOTYPE>::IS_FUNCTION_POINTER> {
154};
155
156// ---- Anything below this line is implementation specific. Do not use. ----
157
158#if defined(BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT_TYPES) && \
159 !defined(BSLS_COMPILERFEATURES_SUPPORT_VARIADIC_TEMPLATES)
160 // All of our compilers which identify 'noexcept' as part of the type
161 // system (a C++17 piece of functionality) similarly also support variadic
162 // templates, so we refrain from having the dead code to support this case.
163# error Feature not supported for compilers without variadic templates
164#endif
165
166 // ---------------------------
167 // class FunctionPointerTraits
168 // ---------------------------
169
170#if !BSLS_COMPILERFEATURES_SIMULATE_CPP11_FEATURES // $var-args=14
171
172// This pragma is not supported by older versions of Apple Clang
173// {DRQS 169716845<GO>}
174#if defined(BSLS_PLATFORM_CMP_CLANG) && (!defined(BSLS_PLATFORM_OS_DARWIN) \
175 || BSLS_PLATFORM_CMP_VER_MAJOR > 130000)
176#pragma clang diagnostic push
177#pragma clang diagnostic ignored "-Wdeprecated-volatile"
178#endif
179
180/// Specialization for function pointers that return `t_BSLMF_RETURN` and
181/// accept a fixed number of arguments
182template <class t_BSLMF_RETURN, class... t_ARGS>
183struct FunctionPointerTraits<t_BSLMF_RETURN (*)(t_ARGS...)> {
184
185 enum {
186 IS_FUNCTION_POINTER = 1,
187 IS_NOEXCEPT = 0
188 };
189 enum { e_IS_VARARG = 0 };
190 typedef t_BSLMF_RETURN ResultType;
191 typedef typename TypeList<t_ARGS...>::Type ArgumentList;
192 typedef t_BSLMF_RETURN FuncType(t_ARGS...);
194};
195
196/// Specialization for function pointers that return `t_BSLMF_RETURN` and
197/// accept variable (C-style varargs) number of arguments
198template <class t_BSLMF_RETURN, class... t_ARGS>
199struct FunctionPointerTraits<t_BSLMF_RETURN (*)(t_ARGS...,...)> {
200
201 enum {
202 IS_FUNCTION_POINTER = 1,
203 IS_NOEXCEPT = 0
204 };
205 enum { e_IS_VARARG = 1 };
206 typedef t_BSLMF_RETURN ResultType;
207 typedef typename TypeList<t_ARGS...>::Type ArgumentList;
208 typedef t_BSLMF_RETURN FuncType(t_ARGS...,...);
210};
211
212#if defined(BSLS_PLATFORM_CMP_CLANG)
213#pragma clang diagnostic pop
214#endif
215
216#endif
217
218#if defined(BSLS_PLATFORM_CMP_MSVC)
219// Microsoft Visual C++ has a problem matching 'T * const' pointers to the
220// appropriate partial specialization, whereas it will match a 'T const'
221// specialization. We could use the Microsoft fix on all platforms, but why
222// instantiate more traits than necessary when testing pointer traits of
223// cv-qualified types that are not function pointers?
224
225template <class t_PROTOTYPE>
226struct FunctionPointerTraits<t_PROTOTYPE const>
227: FunctionPointerTraits<t_PROTOTYPE> {
228 // This class gives information about the specified 't_PROTOTYPE'. The
229 // general definition gives no information, but specializations for
230 // function pointers types define nested types 'ResultType',
231 // 'ArgumentList', and 'Linkage'.
232};
233
234template <class t_PROTOTYPE>
235struct FunctionPointerTraits<t_PROTOTYPE volatile>
236: FunctionPointerTraits<t_PROTOTYPE> {
237 // This class gives information about the specified 't_PROTOTYPE'. The
238 // general definition gives no information, but specializations for
239 // function pointers types define nested types 'ResultType',
240 // 'ArgumentList', and 'Linkage'.
241};
242
243template <class t_PROTOTYPE>
244struct FunctionPointerTraits<t_PROTOTYPE const volatile>
245: FunctionPointerTraits<t_PROTOTYPE> {
246 // This class gives information about the specified 't_PROTOTYPE'. The
247 // general definition gives no information, but specializations for
248 // function pointers types define nested types 'ResultType',
249 // 'ArgumentList', and 'Linkage'.
250};
251#else
252/// This class gives information about the specified `t_PROTOTYPE`. The
253/// general definition gives no information, but specializations for
254/// function pointers types define nested types `ResultType`,
255/// `ArgumentList`, and `Linkage`.
256template <class t_PROTOTYPE>
257struct FunctionPointerTraits<t_PROTOTYPE *const>
259};
260
261/// This class gives information about the specified `t_PROTOTYPE`. The
262/// general definition gives no information, but specializations for
263/// function pointers types define nested types `ResultType`,
264/// `ArgumentList`, and `Linkage`.
265template <class t_PROTOTYPE>
266struct FunctionPointerTraits<t_PROTOTYPE *volatile>
268};
269
270/// This class gives information about the specified `t_PROTOTYPE`. The
271/// general definition gives no information, but specializations for
272/// function pointers types define nested types `ResultType`,
273/// `ArgumentList`, and `Linkage`.
274template <class t_PROTOTYPE>
275struct FunctionPointerTraits<t_PROTOTYPE *const volatile>
277};
278// }}} END GENERATED CODE
279#endif
280
281#ifdef BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT_TYPES
282
283#if defined(BSLS_PLATFORM_CMP_CLANG)
284#pragma clang diagnostic push
285#pragma clang diagnostic ignored "-Wdeprecated-volatile"
286#endif
287
288/// Specialization for `noexcept` function pointers that return
289/// `t_BSLMF_RETURN` and accept a fixed number of arguments
290template <class t_BSLMF_RETURN, class... t_ARGS>
291struct FunctionPointerTraits<t_BSLMF_RETURN (*)(t_ARGS...) noexcept> {
292
293 enum {
294 IS_FUNCTION_POINTER = 1,
295 IS_NOEXCEPT = 1
296 };
297 enum { e_IS_VARARG = 0 };
298 typedef t_BSLMF_RETURN ResultType;
299 typedef typename TypeList<t_ARGS...>::Type ArgumentList;
300 typedef t_BSLMF_RETURN FuncType(t_ARGS...) noexcept;
301 typedef FunctionPointerCPlusPlusLinkage Linkage;
302};
303
304/// Specialization for `noexcept` function pointers that return
305/// `t_BSLMF_RETURN` and accept variable (C-style varargs) number of
306/// arguments
307template <class t_BSLMF_RETURN, class... t_ARGS>
308struct FunctionPointerTraits<t_BSLMF_RETURN (*)(t_ARGS...,...) noexcept> {
309
310 enum {
311 IS_FUNCTION_POINTER = 1,
312 IS_NOEXCEPT = 1
313 };
314 enum { e_IS_VARARG = 1 };
315 typedef t_BSLMF_RETURN ResultType;
316 typedef typename TypeList<t_ARGS...>::Type ArgumentList;
317 typedef t_BSLMF_RETURN FuncType(t_ARGS...,...) noexcept;
318 typedef FunctionPointerCPlusPlusLinkage Linkage;
319};
320
321#if defined(BSLS_PLATFORM_CMP_CLANG)
322#pragma clang diagnostic pop
323#endif
324
325#endif // BSLS_COMPILERFEATURES_SUPPORT_NOEXCEPT_TYPES
326
327} // close package namespace
328
329#ifndef BDE_OPENSOURCE_PUBLICATION // BACKWARD_COMPATIBILITY
330// ============================================================================
331// BACKWARD COMPATIBILITY
332// ============================================================================
333
334/// This alias is defined for backward compatibility.
337
338/// This alias is defined for backward compatibility.
340
341#ifdef bslmf_FunctionPointerTraits
342#undef bslmf_FunctionPointerTraits
343#endif
344/// This alias is defined for backward compatibility.
345#define bslmf_FunctionPointerTraits bslmf::FunctionPointerTraits
346
347#ifdef bslmf_IsFunctionPointer
348#undef bslmf_IsFunctionPointer
349#endif
350/// This alias is defined for backward compatibility.
351#define bslmf_IsFunctionPointer bslmf::IsFunctionPointer
352#endif // BDE_OPENSOURCE_PUBLICATION -- BACKWARD_COMPATIBILITY
353
354
355
356#endif // End C++11 code
357
358#endif
359
360// ----------------------------------------------------------------------------
361// Copyright 2013 Bloomberg Finance L.P.
362//
363// Licensed under the Apache License, Version 2.0 (the "License");
364// you may not use this file except in compliance with the License.
365// You may obtain a copy of the License at
366//
367// http://www.apache.org/licenses/LICENSE-2.0
368//
369// Unless required by applicable law or agreed to in writing, software
370// distributed under the License is distributed on an "AS IS" BASIS,
371// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
372// See the License for the specific language governing permissions and
373// limitations under the License.
374// ----------------------------- END-OF-FILE ----------------------------------
375
376/** @} */
377/** @} */
378/** @} */
bslmf::FunctionPointerCLinkage bslmf_FunctionPointerCLinkage
This alias is defined for backward compatibility.
Definition bslmf_functionpointertraits.h:339
bslmf::FunctionPointerCPlusPlusLinkage bslmf_FunctionPointerCPlusPlusLinkage
This alias is defined for backward compatibility.
Definition bslmf_functionpointertraits.h:336
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
Definition bdlbb_blob.h:576
Definition bslmf_integralconstant.h:244
C function pointer linkage tag.
Definition bslmf_functionpointertraits.h:125
C++ function pointer linkage tag.
Definition bslmf_functionpointertraits.h:121
TypeList< t_ARGS... >::Type ArgumentList
Definition bslmf_functionpointertraits.h:207
t_BSLMF_RETURN FuncType(t_ARGS...,...)
Definition bslmf_functionpointertraits.h:208
t_BSLMF_RETURN ResultType
Definition bslmf_functionpointertraits.h:206
FunctionPointerCPlusPlusLinkage Linkage
Definition bslmf_functionpointertraits.h:209
TypeList< t_ARGS... >::Type ArgumentList
Definition bslmf_functionpointertraits.h:191
t_BSLMF_RETURN ResultType
Definition bslmf_functionpointertraits.h:190
t_BSLMF_RETURN FuncType(t_ARGS...)
Definition bslmf_functionpointertraits.h:192
FunctionPointerCPlusPlusLinkage Linkage
Definition bslmf_functionpointertraits.h:193
Definition bslmf_functionpointertraits.h:137
@ IS_FUNCTION_POINTER
Definition bslmf_functionpointertraits.h:139
Definition bslmf_functionpointertraits.h:153
Definition bslmf_typelist.h:1609