1 [library Boost.FunctionTypes
4 [authors [Schwinger, Tobias]]
5 [copyright 2004-2007 Tobias Schwinger]
7 Distributed under the Boost Software License, Version 1.0.
8 (See accompanying file LICENSE_1_0.txt or copy at
9 [@http://www.boost.org/LICENSE_1_0.txt])
11 [purpose Meta-programming support library]
14 [last-revision $Date$]
17 [def __unspecified__ /unspecified/]
19 [def __mpl__ [@../../../mpl/index.html MPL]]
20 [def __mpl_integral_constant__ __mpl__ - [@../../../mpl/doc/refmanual/integral-constant.html Integral Constant]]
21 [def __mpl_fwd_seq__ __mpl__ - [@../../../mpl/doc/refmanual/forward-sequence.html Forward Sequence]]
22 [def __mpl_fb_ext_ra_seq__ __mpl__ - [@../../../mpl/doc/refmanual/front-extensible-sequence.html Front] / [@../../../mpl/doc/refmanual/back-extensible-sequence.html Back ][@../../../mpl/doc/refmanual/extensible-sequence.html Extensible ][@../../../mpl/doc/refmanual/random-access-sequence.html Random Access Sequence]]
23 [def __mpl_lambda_expression__ __mpl__ - [@../../../mpl/doc/refmanual/lambda-expression.html Lambda Expression]]
25 [def __is_function [link boost_functiontypes.reference.classification.is_function is_function]]
26 [def __is_function_pointer [link boost_functiontypes.reference.classification.is_function_pointer is_function_pointer]]
27 [def __is_function_reference [link boost_functiontypes.reference.classification.is_function_reference is_function_reference]]
28 [def __is_member_function_pointer [link boost_functiontypes.reference.classification.is_member_function_pointer is_member_function_pointer]]
29 [def __is_callable_builtin [link boost_functiontypes.reference.classification.is_callable_builtin is_callable_builtin]]
30 [def __is_nonmember_callable_builtin [link boost_functiontypes.reference.classification.is_nonmember_callable_builtin is_nonmember_callable_builtin]]
32 [def __components [link boost_functiontypes.reference.decomposition.components components]]
33 [def __parameter_types [link boost_functiontypes.reference.decomposition.parameter_types parameter_types]]
34 [def __function_arity [link boost_functiontypes.reference.decomposition.function_arity function_arity]]
35 [def __result_type [link boost_functiontypes.reference.decomposition.result_type result_type]]
37 [def __function_type [link boost_functiontypes.reference.synthesis.function_type function_type]]
38 [def __function_pointer [link boost_functiontypes.reference.synthesis.function_pointer function_pointer]]
39 [def __function_reference [link boost_functiontypes.reference.synthesis.function_reference function_reference]
40 [def __member_function_pointer [link boost_functiontypes.reference.synthesis.member_function_pointer member_function_pointer]]
42 [def __null_tag [link boost_functiontypes.reference.tag_types.null_tag null_tag]]
44 [/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]
46 [section:introduction Introduction]
48 Boost.FunctionTypes provides functionality to classify, decompose and synthesize
49 function, function pointer, function reference and pointer to member types.
51 We collectively refer to these types as /callable builtin/ types.
53 In particular, the library can be used to:
55 * test whether a type is a specific callable, builtin type,
56 * extract all component properties from callable, builtin types, and
57 * create callable, builtin types from specified properties.
59 The library is designed to work well with other Boost libraries and uses
60 well-accepted concepts introduced by Boost and TR1.
62 Templates that encapsulate boolean or numeric properties define a static member
63 constant called [^value].
65 __is_function_pointer< bool(*)(int) >::value // == true
67 __function_arity< bool(*)(int) >::value // == 1
69 Templates that encapsulate properties that are single types contain a type
70 member called [^type].
72 __function_type< mpl::vector<bool,int> >::type // is bool(int)
74 __result_type< bool(&)(int) >::type // is bool
76 Templates that encapsulate properties that are type lists model an
77 MPL-compatible type sequence.
79 __parameter_types< bool(int) > // models an MPL sequence
83 [section:use_cases Use Cases]
85 Generic libraries that accept callable arguments are common in C++.
86 Accepting a callable argument of builin type often involves a lot of repetitive
87 code because the accepting function is overloaded for different function
88 arities. Further, member functions may have [^const]/[^volatile]-qualifiers,
89 a function may take a variable number of (additional, POD-typed) arguments (such
90 as [^printf]) and several C++ implementations encode a calling convention with
91 each function's type to allow calls across language or (sub-)system boundaries.
94 void accept_function(R(* func)());
97 void accept_function(R(& func)());
99 template<typename R, typename C>
100 void accept_function(R(C::* func)());
102 template<typename R, typename C>
103 void accept_function(R(C::* func)() const);
105 template<typename R, typename C>
106 void accept_function(R(C::* func)() volatile);
108 template<typename R, typename C>
109 void accept_function(R(C::* func)() const volatile);
112 void accept_function(R(* func)(...));
115 void accept_function(R(& func)(...));
117 template<typename R, typename C>
118 void accept_function(R(C::* func)(...));
120 template<typename R, typename C>
121 void accept_function(R(C::* func)(...) const);
123 template<typename R, typename C>
124 void accept_function(R(C::* func)(...) volatile);
126 template<typename R, typename C>
127 void accept_function(R(C::* func)(...) const volatile);
131 // needs to be repeated for every additional function parameter
132 // times the number of possible calling conventions
134 The "overloading approach" obviously does not scale well: There might be several
135 functions that accept callable arguments in one library and client code might
136 end up using several libraries that use this pattern.
137 On the developer side, library developers spend their time solving the same
138 problem, working around the same portability issues, and apply similar
139 optimizations to keep the compilation time down.
141 Using Boost.FunctionTypes it is possible to write a single function template
145 void accept_function(F f)
147 // ... use Boost.FunctionTypes to analyse F
150 The combination with a tuples library that provides an invoker component, such
151 as [@../../../fusion/index.html Boost.Fusion], allows to build flexible callback
152 facilities that are entirely free of repetitive code as shown by the
153 [@../../../function_types/example/interpreter.hpp interpreter example].
155 When taking the address of an overloaded function or function template, the
156 type of the function must be known from the context the expression is used
157 in. The code below shows three examples for choosing the [^float(float)]
158 overload of [^std::abs].
160 float (*ptr_absf)(float) = & std::abs;
163 void foo(float(*func)(float));
171 std::transform(b, e, o, static_cast<float(*)(float)>(& std::abs));
173 The library's type synthesis capabilities can be used to automate overload
174 selection and instantiation of function templates. Given an overloaded function
177 template<typename R, typename T0>
180 template<typename R, typename T0, typename T1>
183 template<typename R. typename T0, typename T1, typename T2>
184 R overloaded(T0,T1,T2);
186 we can pick any of the three overloads and instantiate the template with
187 template arguments from a type sequence in a single expression:
189 static_cast<__function_pointer<Seq>::type>(& overloaded)
191 This technique can be occasionally more flexible than template argument
192 deduction from a function call because the exact types from the sequence
193 are used to specialize the template (including possibly cv-qualified
194 reference types and the result type). It is applied twice in the
195 [@../../../function_types/example/interface.hpp interface example].
197 Another interersting property of callable, builtin types is that they can be
198 valid types for non-type template parameters. This way, a function can be
199 pinpointed at compile time, allowing the compiler to eliminate the call by
201 The [@../../../function_types/example/fast_mem_fn.hpp fast_mem_fn example]
202 exploits this characteristic and implements a potentially inlining version of
203 [@../../../bind/mem_fn.html boost::mem_fn]
204 limited to member functions that are known at compile time.
209 [/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]
210 [section:about_tag_types About Tag Types]
212 Boost.FunctionTypes uses tag types to encode properties that are not types
213 per se, such as calling convention or whether a function is variadic or cv-
216 These tags can be used to determine whether one property of a type has a
219 is_function<int(...), variadic>::value // == true
220 is_function<int() , variadic>::value // == false
222 A compound property tag describes a combination of possible values of different
224 The type [^components<F>], where [^F] is a callable builtin type, is a compound
225 property tag that describes [^F].
226 The [^tag] class template can be used to combine property tags.
228 tag<non_const,default_cc> // combination of two properties
230 When several values for the same property are specified in [^tag]'s argument
231 list, only the rightmost one is used; others are ignored.
233 tag<components<F>, default_cc> // overrides F's calling convention property
235 When compound property tag is specified to analyse a type, all of its component
236 properties must match.
238 is_member_function_pointer< F, tag<const_qualified,default_cc> >::value
240 // F = void(a_class::*)() const
242 // F = void(a_class::*)()
243 // F = void(__fastcall a_class::*)() const
245 Default values are selected for properties not specified by the tag in the
246 context of type synthesis.
248 // given S = mpl::vector<int,a_class const &>
250 member_function_pointer<S>::type // is int (a_class::*)() const
251 // note: the cv-qualification is picked based on the class type,
252 // a nonvariadic signature and the default calling convention
255 member_function_pointer<S,non_const>::type // is int (a_class::*)()
256 // no const qualification, as explicitly specified by the tag type
261 [/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]
263 [section:reference Reference]
266 [section:classification Class templates for type classification]
268 [section:is_function is_function]
270 template<typename T, typename Tag = __null_tag>
275 #include <boost/function_types/is_function.hpp>
278 [[[^T]][Type to analyze]]
279 [[[^Tag]][Further properties required for a positive result]]
280 [[[^is_function<T,Tag>]][Predicate value as __mpl_integral_constant__]]
281 [[[^is_function<T,Tag>::value]][Constant boolean value]]
284 Determines whether a given type is a function, possibly with
285 additional properties as specified by a property tag.
290 [section:is_function_pointer is_function_pointer]
292 template<typename T, typename Tag = __null_tag>
293 struct is_function_pointer;
297 #include <boost/function_types/is_function_pointer.hpp>
300 [[[^T]][Type to analyze]]
301 [[[^Tag]][Further properties required for a positive result]]
302 [[[^is_function_pointer<T,Tag>]][Predicate value __mpl_integral_constant__]]
303 [[[^is_function_pointer<T,Tag>::value]][Constant boolean value]]
306 Determines whether a given type is a function pointer, possibly with
307 additional properties as specified by a property tag.
312 [section:is_function_reference is_function_reference]
314 template<typename T, typename Tag = __null_tag>
315 struct is_function_reference;
319 #include <boost/function_types/is_function_reference.hpp>
322 [[[^T]][Type to analyze]]
323 [[[^Tag]][Further properties required for a positive result]]
324 [[[^is_function_reference<T,Tag>]][Predicate value __mpl_integral_constant__]]
325 [[[^is_function_reference<T,Tag>::value]][Constant boolean value]]
328 Determines whether a given type is a function reference, possibly with
329 additional properties as specified by a property tag.
334 [section:is_member_pointer is_member_pointer]
336 template<typename T, typename Tag = __null_tag>
337 struct is_member_pointer;
341 #include <boost/function_types/is_member_pointer.hpp>
344 [[[^T]][Type to analyze]]
345 [[[^Tag]][Further properties required for a positive result]]
346 [[[^is_member_pointer<T,Tag>]][Predicate value __mpl_integral_constant__]]
347 [[[^is_member_pointer<T,Tag>::value]][Constant boolean value]]
350 Determines whether a given type is a pointer to member (object or function)
351 type, possibly with additional properties as specified by a property tag.
356 [section:is_member_object_pointer is_member_object_pointer]
359 struct is_member_object_pointer;
363 #include <boost/function_types/is_member_object_pointer.hpp>
366 [[[^T]][Type to analyze]]
367 [[[^is_member_object_pointer<T>]][Predicate value __mpl_integral_constant__]]
368 [[[^is_member_object_pointer<T>::value]][Constant boolean value]]
371 Determines whether a given type is a pointer to member object type.
376 [section:is_member_function_pointer is_member_function_pointer]
378 template<typename T, typename Tag = __null_tag>
379 struct is_member_function_pointer;
383 #include <boost/function_types/is_member_function_pointer.hpp>
386 [[[^T]][Type to analyze]]
387 [[[^Tag]][Further properties required for a positive result]]
388 [[[^is_member_function_pointer<T,Tag>]][Predicate value __mpl_integral_constant__]]
389 [[[^is_member_function_pointer<T,Tag>::value]][Constant boolean value]]
392 Determines whether a given type is a member function pointer, possibly with
393 additional properties as specified by a property tag.
398 [section:is_callable_builtin is_callable_builtin]
400 template<typename T, typename Tag = __null_tag>
401 struct is_callable_builtin;
405 #include <boost/function_types/is_callable_builtin.hpp>
408 [[[^T]][Type to analyze]]
409 [[[^Tag]][Further properties required for a positive result]]
410 [[[^is_callable_builtin<T,Tag>]][Predicate value as __mpl_integral_constant__]]
411 [[[^is_callable_builtin<T,Tag>::value]][Constant boolean value]]
414 Determines whether a given type is a callable builtin, possibly with
415 additional properties as specified by a property tag.
421 [section:is_nonmember_callable_builtin is_nonmember_callable_builtin]
423 template<typename T, typename Tag = __null_tag>
424 struct is_nonmember_callable_builtin;
428 #include <boost/function_types/is_nonmember_callable_builtin.hpp>
431 [[[^T]][Type to analyze]]
432 [[[^Tag]][Further properties required for a positive result]]
433 [[[^is_nonmember_callable_builtin<T,Tag>]][Predicate value as __mpl_integral_constant__]]
434 [[[^is_nonmember_callable_builtin<T,Tag>::value]][Constant boolean value]]
437 Determines whether a given type is a callable builtin that is not a
438 member function pointer, possibly with
439 additional properties as specified by a property tag.
444 [endsect] [/ Class templates for type classification ]
446 [/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]
448 [section:decomposition Class templates for type decomposition]
451 [section:result_type result_type]
458 #include <boost/function_types/result_type.hpp>
461 [[[^F]][Type to analyze]]
462 [[[^result_type<F>::type]][Result type of [^F]]]
465 Extracts the result type of a callable, builtin type.
467 If [^F] is no callable, builtin type, any attempt to access the
468 [^type] member results in a compile error.
473 [section:parameter_types parameter_types]
475 template<typename F, class ClassTransform = add_reference<_> >
476 struct parameter_types;
480 #include <boost/function_types/parameter_types.hpp>
483 [[[^F]][Type to analyze]]
485 [__mpl_lambda_expression__ to transform the
486 class type if [^F] is a member function pointer]]
488 [[[^parameter_types<F,ClassTransform>]]
489 [__mpl_fb_ext_ra_seq__ of parameter types]]
492 Extracts the parameter types of a callable, builtin type.
494 If [^F] is no callable, builtin type, any attempt to access the
495 sequence results in a compile error.
500 [section:function_arity function_arity]
503 struct function_arity;
507 #include <boost/function_types/function_arity.hpp>
510 [[[^F]][Callable builtin type]]
511 [[[^function_arity<F>]][Function arity as __mpl_integral_constant__]]
512 [[[^function_arity<F>::value]][Constant value of the function arity]]
515 Extracts the function arity, that is the number of parameters.
516 The hidden [^this] of member function pointers counts, in other words
517 the arity value is always greater than or equal to one if [^F] is a
518 member function pointer.
520 If [^F] is no callable, builtin type, any attempt to access the
521 value results in a compile error.
526 [section:components components]
528 template<typename T, class ClassTransform = add_reference<_> >
533 #include <boost/function_types/components.hpp>
536 [[[^T]][Type to analyze]]
538 [__mpl_lambda_expression__ to transform the
539 class type if [^T] is a member function pointer]]
541 [[[^components<T,ClassTransform>]]
542 [__mpl_fb_ext_ra_seq__ of all
543 component types and property tag]]
544 [[[^components<T,ClassTransform>::types]]
545 [Decorated MPL Sequence, exposed for optimization]]
548 Extracts all properties of a callable builtin type, that is the result type,
549 followed by the parameter types (including the type of [^this] for member
552 If [^T] is no callable builtin type, the component types are an empty
553 sequence and the Tag's meaning is equivalent to the [^__null_tag].
557 [endsect] [/ Class templates for type decomposition]
559 [/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]
561 [section:synthesis Class templates for type synthesis]
564 [section:function_type function_type]
566 template<typename Types, typename Tag = __null_tag>
567 struct function_type;
571 #include <boost/function_types/function_type.hpp>
574 [[[^Types]][Component types in form of an __mpl_fwd_seq__ or another callable, builtin type]]
575 [[[^Tag]][Further properties]]
576 [[[^function_type<Types,Tag>::type]][Synthesized type]]
579 Synthesizes a function type from given properties.
581 If the template parameters do not describe a valid type, any attempt
582 to access the [^type] member will result in a compile error.
587 [section:function_pointer function_pointer]
589 template<typename Types, typename Tag = __null_tag>
590 struct function_pointer;
594 #include <boost/function_types/function_pointer.hpp>
597 [[[^Types]][Component types in form of an __mpl_fwd_seq__ or another callable, builtin type]]
598 [[[^Tag]][Further properties]]
599 [[[^function_pointer<Types,Tag>::type]][Synthesized type]]
602 Synthesizes a function pointer type from given properties.
604 If the template parameters do not describe a valid type, any attempt
605 to access the [^type] member will result in a compile error.
610 [section:function_reference function_reference]
612 template<typename Types, typename Tag = __null_tag>
613 struct function_reference;
617 #include <boost/function_types/function_reference.hpp>
620 [[[^Types]][Component types in form of an __mpl_fwd_seq__ or another callable, builtin type]]
621 [[[^Tag]][Further properties]]
622 [[[^function_reference<Types,Tag>::type]][Synthesized type]]
625 Synthesizes a function reference type from given properties.
627 If the template parameters do not describe a valid type, any attempt
628 to access the [^type] member will result in a compile error.
633 [section:member_function_pointer member_function_pointer]
635 template<typename Types, typename Tag = __null_tag>
636 struct member_function_pointer;
640 #include <boost/function_types/member_function_pointer.hpp>
643 [[[^Types]][Component types in form of an __mpl_fwd_seq__ or another callable, builtin type]]
644 [[[^Tag]][Further properties]]
645 [[[^member_function_pointer<Types,Tag>::type]][Synthesized type]]
648 Synthesizes a member function pointer type from given properties.
650 An optional reference or possibly cv-qualified pointer is removed from
651 the second type in the sequence to determine the the class type.
652 The cv-qualification of the resulting type applies to the member
653 function, unless otherwise explicitly specified by the property tag.
655 If the template parameters do not describe a valid type, any attempt
656 to access the [^type] member will result in a compile error.
661 [endsect] [/ Class templates for type synthesis ]
663 [/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]
665 [section:tag_types Tag Types]
667 [section:variadic variadic]
669 typedef __unspecified__ variadic;
673 #include <boost/function_types/property_tags.hpp>
675 States that a function type takes a variable number of arguments through
676 an ellipsis parameter (such as [^printf]).
680 [section:non_variadic non_variadic]
682 typedef __unspecified__ non_variadic;
686 #include <boost/function_types/property_tags.hpp>
688 States that a function type does not have an ellipsis parameter.
692 [section:default_cc default_cc]
694 typedef __unspecified__ default_cc;
698 #include <boost/function_types/property_tags.hpp>
700 States that a function type encodes the default calling convention.
704 [section:const_qualified const_qualified]
706 typedef __unspecified__ const_qualified;
710 #include <boost/function_types/property_tags.hpp>
712 States that a function type is const qualified.
716 [section:non_const non_const]
718 typedef __unspecified__ non_const;
722 #include <boost/function_types/property_tags.hpp>
724 States that a function type is not const qualified.
728 [section:volatile_qualified volatile_qualified]
730 typedef __unspecified__ volatile_qualified;
734 #include <boost/function_types/property_tags.hpp>
736 States that a function type is volatile qualified.
740 [section:non_volatile non_volatile]
742 typedef __unspecified__ non_volatile;
746 #include <boost/function_types/property_tags.hpp>
748 States that a function type is not volatile qualified.
752 [section:non_cv non_cv]
754 typedef __unspecified__ non_cv;
758 #include <boost/function_types/property_tags.hpp>
760 States that a function type is neither const nor volatile qualified.
761 Equivalent to `__tag<__non_const,__non_volatile>`, but involves
762 fewer template instantiations when evaluated.
766 [section:const_non_volatile const_non_volatile]
768 typedef __unspecified__ const_non_volatile;
772 #include <boost/function_types/property_tags.hpp>
774 States that a function type is const but not volatile qualified.
775 Equivalent to `__tag<__const_qualified,__non_volatile>`, but involves
776 fewer template instantiations when evaluated.
780 [section:volatile_non_const volatile_non_const]
782 typedef __unspecified__ volatile_non_const;
786 #include <boost/function_types/property_tags.hpp>
788 States that a function type is volatile but not const qualified.
789 Equivalent to `__tag<__volatile_qualified,__non_const>`, but involves
790 fewer template instantiations when evaluated.
794 [section:cv_qualfied cv_qualfied]
796 typedef __unspecified__ cv_qualified;
800 #include <boost/function_types/property_tags.hpp>
802 States that a function type is both const and volatile qualified.
803 Equivalent to `__tag<__const_qualified,__volatile_qualified>`, but involves
804 fewer template instantiations when evaluated.
808 [section:null_tag null_tag]
810 typedef __unspecified__ null_tag;
814 #include <boost/function_types/property_tags.hpp>
822 template<class Tag1, class Tag2,
823 class Tag3 = null_tag, class Tag4 = null_tag>
828 #include <boost/function_types/property_tags.hpp>
831 [[[^Tag['N]]][Property tag]]
832 [[[^tag<Tag1,Tag2...>]][Compound property tag]]
835 Combination of up to four property tags. If the arguments describe different
836 values for the same property the value of the rightmost argument is used.
840 [endsect] [/ Tag Types]
842 [/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]
844 [section:macros Macros]
846 [section:BOOST_FT_MAX_ARITY BOOST_FT_MAX_ARITY]
848 Expands to a numeric value that describes the maximum function arity
849 supported by the library.
851 Defaults to 20 if not explicitly defined by the user before inclusion
852 of the first library header.
858 [*The following macros do not need to be defined, unless to configure
859 the library to work with a compiler and/or calling convention not covered by
860 the auto-detection mechanism in [^boost/function_types/config/compiler.hpp].]
863 [section:BOOST_FT_CC_NAMES BOOST_FT_CC_NAMES]
865 Expands to a [@../../../preprocessor/doc/data/sequences.html sequence] of
866 ternary [@../../../preprocessor/doc/data/tuples.html tuples] (these data
867 types are defined in the [@../../../preprocessor/doc/index.html
868 documentation of the Boost Preprocessor library]).
869 Each sequence element describes one calling convention specifier.
870 The first element in each tuple is the macro suffix for
871 [link boost_functiontypes.reference.macros.BOOST_FT_CC [^BOOST_FT\_CC\_*]],
872 the second element is the name of the tag that describes the calling
873 convention and the third is the name of the specifier.
874 The specifier is allowed to be an empty string, so the third tuple element
875 is either [@../../../preprocessor/doc/ref/empty.html [^BOOST_PP_EMPTY]] or
876 [@../../../preprocessor/doc/ref/identity.html [^BOOST_PP_IDENTITY]][^(['name])].
878 Define this macro to extend the set of possible names for custom calling
879 conventions. The macro expands to nothing by default.
881 The following names are predefined by the library and must not occur in the
882 definition of [^BOOST_FT_CC_NAMES]:
884 #define BOOST_FT_BUILTIN_CC_NAMES \
885 (( IMPLICIT , implicit_cc , BOOST_PP_EMPTY ))\
886 (( CDECL , cdecl_cc , BOOST_PP_IDENTITY(__cdecl ) ))\
887 (( STDCALL , stdcall_cc , BOOST_PP_IDENTITY(__stdcall ) ))\
888 (( PASCAL , pascal_cc , BOOST_PP_IDENTITY(pascal ) ))\
889 (( FASTCALL , fastcall_cc , BOOST_PP_IDENTITY(__fastcall) ))\
890 (( CLRCALL , clrcall_cc , BOOST_PP_IDENTITY(__clrcall ) ))\
891 (( THISCALL , thiscall_cc , BOOST_PP_IDENTITY(__thiscall) ))\
892 (( IMPLICIT_THISCALL , thiscall_cc , BOOST_PP_EMPTY ))
893 // Don't get confused by the last line, here (thiscall can't be specified
894 // explicitly prior to MSVC 8).
898 [section:BOOST_FT_CC BOOST_FT\_CC\_*]
900 Enables a specific calling convention. * denotes the macro suffix, as
902 [link boost_functiontypes.reference.macros.BOOST_FT_CC_NAMES [^BOOST_FT_CC_NAMES]]
904 [link boost_functiontypes.reference.macros.BOOST_FT_CC_NAMES [^BOOST_FT_BUILTIN_CC_NAMES]].
906 The macro expands to a list of restrictions, separated by the [^|] character.
915 If no such macro is defined for a particular calling convention, it is disabled.
918 #define BOOST_FT_CC_STDCALL non_variadic|callable_builtin
919 // enables stdcall calling convention for all non-variadic,
920 // callable, builtin types
924 [section:BOOST_FT_COMMON_X86_CCs BOOST_FT_COMMON_X86_CCs]
926 Defining this macro causes the following macros to be defined, if not defined
929 #define BOOST_FT_CC_CDECL BOOST_FT_COMMON_X86_CCs
930 #define BOOST_FT_CC_STDCALL non_variadic|BOOST_FT_COMMON_X86_CCs
931 #define BOOST_FT_CC_FASTCALL non_variadic|BOOST_FT_COMMON_X86_CCs
935 [section:BOOST_FT_SYNTAX BOOST_FT_SYNTAX]
937 This macro allows to change the syntax of callable builtin types.
938 It is useful to handle the compiler specific placement of the calling
939 convention specifier.
941 The default definition is as follows:
943 #define BOOST_FT_SYNTAX(result,lparen,cc_spec,type_mod,name,rparen) \
944 result() lparen() cc_spec() type_mod() name() rparen()
948 [section:BOOST_FT_NULLARY_PARAM BOOST_FT_NULLARY_PARAM]
950 Set to [^void] for compilers that insist on a [^void] parameter for
951 nullary function types, empty by default.
955 [section:BOOST_FT_NO_CV_FUNC_SUPPORT BOOST_FT_NO_CV_FUNC_SUPPORT]
957 Disables support for cv-qualified function types.
958 Cv-qualified function types are illegal by the current standard
959 version, but there is a pending defect report on that issue.
960 It defaults to [^1] until the standard changes, setting this macro
961 to [^0] may not work.
967 [*The following macros are useful for testing when changing the source code of
972 [section:BOOST_FT_PREPROCESSING_MODE BOOST_FT_PREPROCESSING_MODE]
974 Makes the compiler preprocess as much as possible of the library code
975 (rather than loading already-preprocessed header files) if defined.
979 [section:BOOST_FT_CC_PREPROCESSING BOOST_FT_CC_PREPROCESSING]
981 Makes the compiler preprocess the loop over possible names for custom
982 calling conventions (rather than loading an already-preprocessed header
985 This macro is defined automatically if
986 [link boost_functiontypes.reference.macros.BOOST_FT_CC_NAMES [^BOOST_FT_CC_NAMES]]
995 [/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]
997 [section:rationale Rationale]
999 [heading Error handling rationale]
1001 The library does not define the required members of class templates in
1002 case of an error. This technique causes the compiler to stop displaying
1003 diagnostics in client code, at the point where the error actually is,
1004 instead of tracing template instantiations into the implementation of
1007 The library's components have limited error conditions, so problematic
1008 input can be spotted easily.
1011 [heading Why MPL Sequences?]
1013 MPL provides algorithms on Sequences, so transformations (such as turning
1014 by-value parameter types into const references for optimized forwarding
1015 or computing a signature to specialize
1016 [@../../../function/index.html [^boost::function]] after applying
1017 [@../../../bind/index.html [^boost::bind]]) can be expressed more
1018 easily. The MPL Sequence concept is compatible with several other Boost
1019 libraries (most importantly [@../../../fusion/index.html Fusion]),
1020 so another reason is interoperability.
1023 [heading Pointer to member object types]
1025 Despite their syntax, pointer to member object types can be seen as
1026 dereferencing functionals.
1029 [heading The ClassTransform template parameter]
1031 [^This]-pointer, [^this]-reference or just the object (or maybe even a
1032 smart pointer to the object) plus adjustments of cv-qualification - all
1033 these cases have their place, somewhere and there is no single best answer.
1035 Special treatment of the class type within the sequence can significantly
1036 complicate client code. A custom [^ClassTransform] argument allows the
1037 client to adjust the class type before the sequence is formed and then
1038 treat all parameters uniformly.
1041 [heading Why tag types?]
1043 Let's consider the alternatives.
1045 The first one is just using more templates so every property has to be
1046 asked for explicitly. This approach results in more complicated client
1047 code if more than one propery has to be checked and in a exponentially
1048 larger library interface.
1050 The second alternative is having the client pass in bit patterns via
1051 non-type template parameters. The logic has to be performed by the
1052 client and there are much more error conditions. Further, class templates
1053 with non-type template parameters do not work within MPL lambda
1054 expressions and can cause problems with older compilers.
1056 [heading Is it safe to have the synthesis templates take a callable
1057 builtin type or an MPL sequence as the first template argument?]
1059 Yes, but it isn't immediately obvious as the set of possible MPL sequences
1060 isn't inherently disjoint from the set of callable builtin types.
1062 However, any attempt to make a builtin type work as an MPL sequence is
1063 a bad idea, because builtin types are accessible before the headers that
1064 make the type a sequence have been included, which can easily violate the
1067 [heading Why does the hidden [^this] parameter count for the
1068 function arity of member functions?]
1070 It was found preferable that the following condition holds:
1072 mpl::size< __parameter_types<T> >::value == __function_arity<T>::value
1074 [heading Why ignore top-level cv-qualifiers on pointers?]
1076 A cv-qualified pointer is still a pointer. It usually doesn't matter and
1077 even if it does, it's a job for
1078 [@../../../type_traits/index.html Boost.TypeTraits].
1083 [section:acknowledgements Acknowledgements]
1085 Thanks go to the following people for supporting the development of this
1086 library in one or the other way: