function_types.qbk 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. [library Boost.FunctionTypes
  2. [quickbook 1.3]
  3. [version 2.5]
  4. [authors [Schwinger, Tobias]]
  5. [copyright 2004-2007 Tobias Schwinger]
  6. [license
  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])
  10. ]
  11. [purpose Meta-programming support library]
  12. [category template]
  13. [category generic]
  14. [last-revision $Date$]
  15. ]
  16. [def __unspecified__ /unspecified/]
  17. [def __mpl__ [@../../../mpl/index.html MPL]]
  18. [def __mpl_integral_constant__ __mpl__ - [@../../../mpl/doc/refmanual/integral-constant.html Integral Constant]]
  19. [def __mpl_fwd_seq__ __mpl__ - [@../../../mpl/doc/refmanual/forward-sequence.html Forward Sequence]]
  20. [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]]
  21. [def __mpl_lambda_expression__ __mpl__ - [@../../../mpl/doc/refmanual/lambda-expression.html Lambda Expression]]
  22. [def __is_function [link boost_functiontypes.reference.classification.is_function is_function]]
  23. [def __is_function_pointer [link boost_functiontypes.reference.classification.is_function_pointer is_function_pointer]]
  24. [def __is_function_reference [link boost_functiontypes.reference.classification.is_function_reference is_function_reference]]
  25. [def __is_member_function_pointer [link boost_functiontypes.reference.classification.is_member_function_pointer is_member_function_pointer]]
  26. [def __is_callable_builtin [link boost_functiontypes.reference.classification.is_callable_builtin is_callable_builtin]]
  27. [def __is_nonmember_callable_builtin [link boost_functiontypes.reference.classification.is_nonmember_callable_builtin is_nonmember_callable_builtin]]
  28. [def __components [link boost_functiontypes.reference.decomposition.components components]]
  29. [def __parameter_types [link boost_functiontypes.reference.decomposition.parameter_types parameter_types]]
  30. [def __function_arity [link boost_functiontypes.reference.decomposition.function_arity function_arity]]
  31. [def __result_type [link boost_functiontypes.reference.decomposition.result_type result_type]]
  32. [def __function_type [link boost_functiontypes.reference.synthesis.function_type function_type]]
  33. [def __function_pointer [link boost_functiontypes.reference.synthesis.function_pointer function_pointer]]
  34. [def __function_reference [link boost_functiontypes.reference.synthesis.function_reference function_reference]
  35. [def __member_function_pointer [link boost_functiontypes.reference.synthesis.member_function_pointer member_function_pointer]]
  36. [def __null_tag [link boost_functiontypes.reference.tag_types.null_tag null_tag]]
  37. [/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]
  38. [section:introduction Introduction]
  39. Boost.FunctionTypes provides functionality to classify, decompose and synthesize
  40. function, function pointer, function reference and pointer to member types.
  41. We collectively refer to these types as /callable builtin/ types.
  42. In particular, the library can be used to:
  43. * test whether a type is a specific callable, builtin type,
  44. * extract all component properties from callable, builtin types, and
  45. * create callable, builtin types from specified properties.
  46. The library is designed to work well with other Boost libraries and uses
  47. well-accepted concepts introduced by Boost and TR1.
  48. Templates that encapsulate boolean or numeric properties define a static member
  49. constant called [^value].
  50. __is_function_pointer< bool(*)(int) >::value // == true
  51. __function_arity< bool(*)(int) >::value // == 1
  52. Templates that encapsulate properties that are single types contain a type
  53. member called [^type].
  54. __function_type< mpl::vector<bool,int> >::type // is bool(int)
  55. __result_type< bool(&)(int) >::type // is bool
  56. Templates that encapsulate properties that are type lists model an
  57. MPL-compatible type sequence.
  58. __parameter_types< bool(int) > // models an MPL sequence
  59. [endsect]
  60. [section:use_cases Use Cases]
  61. Generic libraries that accept callable arguments are common in C++.
  62. Accepting a callable argument of builin type often involves a lot of repetitive
  63. code because the accepting function is overloaded for different function
  64. arities. Further, member functions may have [^const]/[^volatile]-qualifiers,
  65. a function may take a variable number of (additional, POD-typed) arguments (such
  66. as [^printf]) and several C++ implementations encode a calling convention with
  67. each function's type to allow calls across language or (sub-)system boundaries.
  68. template<typename R>
  69. void accept_function(R(* func)());
  70. template<typename R>
  71. void accept_function(R(& func)());
  72. template<typename R, typename C>
  73. void accept_function(R(C::* func)());
  74. template<typename R, typename C>
  75. void accept_function(R(C::* func)() const);
  76. template<typename R, typename C>
  77. void accept_function(R(C::* func)() volatile);
  78. template<typename R, typename C>
  79. void accept_function(R(C::* func)() const volatile);
  80. template<typename R>
  81. void accept_function(R(* func)(...));
  82. template<typename R>
  83. void accept_function(R(& func)(...));
  84. template<typename R, typename C>
  85. void accept_function(R(C::* func)(...));
  86. template<typename R, typename C>
  87. void accept_function(R(C::* func)(...) const);
  88. template<typename R, typename C>
  89. void accept_function(R(C::* func)(...) volatile);
  90. template<typename R, typename C>
  91. void accept_function(R(C::* func)(...) const volatile);
  92. // ...
  93. // needs to be repeated for every additional function parameter
  94. // times the number of possible calling conventions
  95. The "overloading approach" obviously does not scale well: There might be several
  96. functions that accept callable arguments in one library and client code might
  97. end up using several libraries that use this pattern.
  98. On the developer side, library developers spend their time solving the same
  99. problem, working around the same portability issues, and apply similar
  100. optimizations to keep the compilation time down.
  101. Using Boost.FunctionTypes it is possible to write a single function template
  102. instead:
  103. template<typename F>
  104. void accept_function(F f)
  105. {
  106. // ... use Boost.FunctionTypes to analyse F
  107. }
  108. The combination with a tuples library that provides an invoker component, such
  109. as [@../../../fusion/index.html Boost.Fusion], allows to build flexible callback
  110. facilities that are entirely free of repetitive code as shown by the
  111. [@../../../function_types/example/interpreter.hpp interpreter example].
  112. When taking the address of an overloaded function or function template, the
  113. type of the function must be known from the context the expression is used
  114. in. The code below shows three examples for choosing the [^float(float)]
  115. overload of [^std::abs].
  116. float (*ptr_absf)(float) = & std::abs;
  117. void foo(float(*func)(float));
  118. void bar()
  119. {
  120. foo(& std::abs);
  121. }
  122. std::transform(b, e, o, static_cast<float(*)(float)>(& std::abs));
  123. The library's type synthesis capabilities can be used to automate overload
  124. selection and instantiation of function templates. Given an overloaded function
  125. template
  126. template<typename R, typename T0>
  127. R overloaded(T0);
  128. template<typename R, typename T0, typename T1>
  129. R overloaded(T0,T1);
  130. template<typename R. typename T0, typename T1, typename T2>
  131. R overloaded(T0,T1,T2);
  132. we can pick any of the three overloads and instantiate the template with
  133. template arguments from a type sequence in a single expression:
  134. static_cast<__function_pointer<Seq>::type>(& overloaded)
  135. This technique can be occasionally more flexible than template argument
  136. deduction from a function call because the exact types from the sequence
  137. are used to specialize the template (including possibly cv-qualified
  138. reference types and the result type). It is applied twice in the
  139. [@../../../function_types/example/interface.hpp interface example].
  140. Another interersting property of callable, builtin types is that they can be
  141. valid types for non-type template parameters. This way, a function can be
  142. pinpointed at compile time, allowing the compiler to eliminate the call by
  143. inlining.
  144. The [@../../../function_types/example/fast_mem_fn.hpp fast_mem_fn example]
  145. exploits this characteristic and implements a potentially inlining version of
  146. [@../../../bind/mem_fn.html boost::mem_fn]
  147. limited to member functions that are known at compile time.
  148. [endsect]
  149. [/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]
  150. [section:about_tag_types About Tag Types]
  151. Boost.FunctionTypes uses tag types to encode properties that are not types
  152. per se, such as calling convention or whether a function is variadic or cv-
  153. qualified.
  154. These tags can be used to determine whether one property of a type has a
  155. particular value.
  156. is_function<int(...), variadic>::value // == true
  157. is_function<int() , variadic>::value // == false
  158. A compound property tag describes a combination of possible values of different
  159. properties.
  160. The type [^components<F>], where [^F] is a callable builtin type, is a compound
  161. property tag that describes [^F].
  162. The [^tag] class template can be used to combine property tags.
  163. tag<non_const,default_cc> // combination of two properties
  164. When several values for the same property are specified in [^tag]'s argument
  165. list, only the rightmost one is used; others are ignored.
  166. tag<components<F>, default_cc> // overrides F's calling convention property
  167. When compound property tag is specified to analyse a type, all of its component
  168. properties must match.
  169. is_member_function_pointer< F, tag<const_qualified,default_cc> >::value
  170. // true for
  171. // F = void(a_class::*)() const
  172. // false for
  173. // F = void(a_class::*)()
  174. // F = void(__fastcall a_class::*)() const
  175. Default values are selected for properties not specified by the tag in the
  176. context of type synthesis.
  177. // given S = mpl::vector<int,a_class const &>
  178. member_function_pointer<S>::type // is int (a_class::*)() const
  179. // note: the cv-qualification is picked based on the class type,
  180. // a nonvariadic signature and the default calling convention
  181. // are used
  182. member_function_pointer<S,non_const>::type // is int (a_class::*)()
  183. // no const qualification, as explicitly specified by the tag type
  184. [endsect]
  185. [/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]
  186. [section:reference Reference]
  187. [section:classification Class templates for type classification]
  188. [section:is_function is_function]
  189. template<typename T, typename Tag = __null_tag>
  190. struct is_function;
  191. [*Header]
  192. #include <boost/function_types/is_function.hpp>
  193. [variablelist
  194. [[[^T]][Type to analyze]]
  195. [[[^Tag]][Further properties required for a positive result]]
  196. [[[^is_function<T,Tag>]][Predicate value as __mpl_integral_constant__]]
  197. [[[^is_function<T,Tag>::value]][Constant boolean value]]
  198. ]
  199. Determines whether a given type is a function, possibly with
  200. additional properties as specified by a property tag.
  201. [endsect]
  202. [section:is_function_pointer is_function_pointer]
  203. template<typename T, typename Tag = __null_tag>
  204. struct is_function_pointer;
  205. [*Header]
  206. #include <boost/function_types/is_function_pointer.hpp>
  207. [variablelist
  208. [[[^T]][Type to analyze]]
  209. [[[^Tag]][Further properties required for a positive result]]
  210. [[[^is_function_pointer<T,Tag>]][Predicate value __mpl_integral_constant__]]
  211. [[[^is_function_pointer<T,Tag>::value]][Constant boolean value]]
  212. ]
  213. Determines whether a given type is a function pointer, possibly with
  214. additional properties as specified by a property tag.
  215. [endsect]
  216. [section:is_function_reference is_function_reference]
  217. template<typename T, typename Tag = __null_tag>
  218. struct is_function_reference;
  219. [*Header]
  220. #include <boost/function_types/is_function_reference.hpp>
  221. [variablelist
  222. [[[^T]][Type to analyze]]
  223. [[[^Tag]][Further properties required for a positive result]]
  224. [[[^is_function_reference<T,Tag>]][Predicate value __mpl_integral_constant__]]
  225. [[[^is_function_reference<T,Tag>::value]][Constant boolean value]]
  226. ]
  227. Determines whether a given type is a function reference, possibly with
  228. additional properties as specified by a property tag.
  229. [endsect]
  230. [section:is_member_pointer is_member_pointer]
  231. template<typename T, typename Tag = __null_tag>
  232. struct is_member_pointer;
  233. [*Header]
  234. #include <boost/function_types/is_member_pointer.hpp>
  235. [variablelist
  236. [[[^T]][Type to analyze]]
  237. [[[^Tag]][Further properties required for a positive result]]
  238. [[[^is_member_pointer<T,Tag>]][Predicate value __mpl_integral_constant__]]
  239. [[[^is_member_pointer<T,Tag>::value]][Constant boolean value]]
  240. ]
  241. Determines whether a given type is a pointer to member (object or function)
  242. type, possibly with additional properties as specified by a property tag.
  243. [endsect]
  244. [section:is_member_object_pointer is_member_object_pointer]
  245. template<typename T>
  246. struct is_member_object_pointer;
  247. [*Header]
  248. #include <boost/function_types/is_member_object_pointer.hpp>
  249. [variablelist
  250. [[[^T]][Type to analyze]]
  251. [[[^is_member_object_pointer<T>]][Predicate value __mpl_integral_constant__]]
  252. [[[^is_member_object_pointer<T>::value]][Constant boolean value]]
  253. ]
  254. Determines whether a given type is a pointer to member object type.
  255. [endsect]
  256. [section:is_member_function_pointer is_member_function_pointer]
  257. template<typename T, typename Tag = __null_tag>
  258. struct is_member_function_pointer;
  259. [*Header]
  260. #include <boost/function_types/is_member_function_pointer.hpp>
  261. [variablelist
  262. [[[^T]][Type to analyze]]
  263. [[[^Tag]][Further properties required for a positive result]]
  264. [[[^is_member_function_pointer<T,Tag>]][Predicate value __mpl_integral_constant__]]
  265. [[[^is_member_function_pointer<T,Tag>::value]][Constant boolean value]]
  266. ]
  267. Determines whether a given type is a member function pointer, possibly with
  268. additional properties as specified by a property tag.
  269. [endsect]
  270. [section:is_callable_builtin is_callable_builtin]
  271. template<typename T, typename Tag = __null_tag>
  272. struct is_callable_builtin;
  273. [*Header]
  274. #include <boost/function_types/is_callable_builtin.hpp>
  275. [variablelist
  276. [[[^T]][Type to analyze]]
  277. [[[^Tag]][Further properties required for a positive result]]
  278. [[[^is_callable_builtin<T,Tag>]][Predicate value as __mpl_integral_constant__]]
  279. [[[^is_callable_builtin<T,Tag>::value]][Constant boolean value]]
  280. ]
  281. Determines whether a given type is a callable builtin, possibly with
  282. additional properties as specified by a property tag.
  283. [endsect]
  284. [section:is_nonmember_callable_builtin is_nonmember_callable_builtin]
  285. template<typename T, typename Tag = __null_tag>
  286. struct is_nonmember_callable_builtin;
  287. [*Header]
  288. #include <boost/function_types/is_nonmember_callable_builtin.hpp>
  289. [variablelist
  290. [[[^T]][Type to analyze]]
  291. [[[^Tag]][Further properties required for a positive result]]
  292. [[[^is_nonmember_callable_builtin<T,Tag>]][Predicate value as __mpl_integral_constant__]]
  293. [[[^is_nonmember_callable_builtin<T,Tag>::value]][Constant boolean value]]
  294. ]
  295. Determines whether a given type is a callable builtin that is not a
  296. member function pointer, possibly with
  297. additional properties as specified by a property tag.
  298. [endsect]
  299. [endsect] [/ Class templates for type classification ]
  300. [/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]
  301. [section:decomposition Class templates for type decomposition]
  302. [section:result_type result_type]
  303. template<typename F>
  304. struct result_type;
  305. [*Header]
  306. #include <boost/function_types/result_type.hpp>
  307. [variablelist
  308. [[[^F]][Type to analyze]]
  309. [[[^result_type<F>::type]][Result type of [^F]]]
  310. ]
  311. Extracts the result type of a callable, builtin type.
  312. If [^F] is no callable, builtin type, any attempt to access the
  313. [^type] member results in a compile error.
  314. [endsect]
  315. [section:parameter_types parameter_types]
  316. template<typename F, class ClassTransform = add_reference<_> >
  317. struct parameter_types;
  318. [*Header]
  319. #include <boost/function_types/parameter_types.hpp>
  320. [variablelist
  321. [[[^F]][Type to analyze]]
  322. [[[^ClassTransform]]
  323. [__mpl_lambda_expression__ to transform the
  324. class type if [^F] is a member function pointer]]
  325. [[[^parameter_types<F,ClassTransform>]]
  326. [__mpl_fb_ext_ra_seq__ of parameter types]]
  327. ]
  328. Extracts the parameter types of a callable, builtin type.
  329. If [^F] is no callable, builtin type, any attempt to access the
  330. sequence results in a compile error.
  331. [endsect]
  332. [section:function_arity function_arity]
  333. template<typename F>
  334. struct function_arity;
  335. [*Header]
  336. #include <boost/function_types/function_arity.hpp>
  337. [variablelist
  338. [[[^F]][Callable builtin type]]
  339. [[[^function_arity<F>]][Function arity as __mpl_integral_constant__]]
  340. [[[^function_arity<F>::value]][Constant value of the function arity]]
  341. ]
  342. Extracts the function arity, that is the number of parameters.
  343. The hidden [^this] of member function pointers counts, in other words
  344. the arity value is always greater than or equal to one if [^F] is a
  345. member function pointer.
  346. If [^F] is no callable, builtin type, any attempt to access the
  347. value results in a compile error.
  348. [endsect]
  349. [section:components components]
  350. template<typename T, class ClassTransform = add_reference<_> >
  351. struct components;
  352. [*Header]
  353. #include <boost/function_types/components.hpp>
  354. [variablelist
  355. [[[^T]][Type to analyze]]
  356. [[[^ClassTransform]]
  357. [__mpl_lambda_expression__ to transform the
  358. class type if [^T] is a member function pointer]]
  359. [[[^components<T,ClassTransform>]]
  360. [__mpl_fb_ext_ra_seq__ of all
  361. component types and property tag]]
  362. [[[^components<T,ClassTransform>::types]]
  363. [Decorated MPL Sequence, exposed for optimization]]
  364. ]
  365. Extracts all properties of a callable builtin type, that is the result type,
  366. followed by the parameter types (including the type of [^this] for member
  367. function pointers).
  368. If [^T] is no callable builtin type, the component types are an empty
  369. sequence and the Tag's meaning is equivalent to the [^__null_tag].
  370. [endsect]
  371. [endsect] [/ Class templates for type decomposition]
  372. [/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]
  373. [section:synthesis Class templates for type synthesis]
  374. [section:function_type function_type]
  375. template<typename Types, typename Tag = __null_tag>
  376. struct function_type;
  377. [*Header]
  378. #include <boost/function_types/function_type.hpp>
  379. [variablelist
  380. [[[^Types]][Component types in form of an __mpl_fwd_seq__ or another callable, builtin type]]
  381. [[[^Tag]][Further properties]]
  382. [[[^function_type<Types,Tag>::type]][Synthesized type]]
  383. ]
  384. Synthesizes a function type from given properties.
  385. If the template parameters do not describe a valid type, any attempt
  386. to access the [^type] member will result in a compile error.
  387. [endsect]
  388. [section:function_pointer function_pointer]
  389. template<typename Types, typename Tag = __null_tag>
  390. struct function_pointer;
  391. [*Header]
  392. #include <boost/function_types/function_pointer.hpp>
  393. [variablelist
  394. [[[^Types]][Component types in form of an __mpl_fwd_seq__ or another callable, builtin type]]
  395. [[[^Tag]][Further properties]]
  396. [[[^function_pointer<Types,Tag>::type]][Synthesized type]]
  397. ]
  398. Synthesizes a function pointer type from given properties.
  399. If the template parameters do not describe a valid type, any attempt
  400. to access the [^type] member will result in a compile error.
  401. [endsect]
  402. [section:function_reference function_reference]
  403. template<typename Types, typename Tag = __null_tag>
  404. struct function_reference;
  405. [*Header]
  406. #include <boost/function_types/function_reference.hpp>
  407. [variablelist
  408. [[[^Types]][Component types in form of an __mpl_fwd_seq__ or another callable, builtin type]]
  409. [[[^Tag]][Further properties]]
  410. [[[^function_reference<Types,Tag>::type]][Synthesized type]]
  411. ]
  412. Synthesizes a function reference type from given properties.
  413. If the template parameters do not describe a valid type, any attempt
  414. to access the [^type] member will result in a compile error.
  415. [endsect]
  416. [section:member_function_pointer member_function_pointer]
  417. template<typename Types, typename Tag = __null_tag>
  418. struct member_function_pointer;
  419. [*Header]
  420. #include <boost/function_types/member_function_pointer.hpp>
  421. [variablelist
  422. [[[^Types]][Component types in form of an __mpl_fwd_seq__ or another callable, builtin type]]
  423. [[[^Tag]][Further properties]]
  424. [[[^member_function_pointer<Types,Tag>::type]][Synthesized type]]
  425. ]
  426. Synthesizes a member function pointer type from given properties.
  427. An optional reference or possibly cv-qualified pointer is removed from
  428. the second type in the sequence to determine the the class type.
  429. The cv-qualification of the resulting type applies to the member
  430. function, unless otherwise explicitly specified by the property tag.
  431. If the template parameters do not describe a valid type, any attempt
  432. to access the [^type] member will result in a compile error.
  433. [endsect]
  434. [endsect] [/ Class templates for type synthesis ]
  435. [/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]
  436. [section:tag_types Tag Types]
  437. [section:variadic variadic]
  438. typedef __unspecified__ variadic;
  439. [*Header]
  440. #include <boost/function_types/property_tags.hpp>
  441. States that a function type takes a variable number of arguments through
  442. an ellipsis parameter (such as [^printf]).
  443. [endsect]
  444. [section:non_variadic non_variadic]
  445. typedef __unspecified__ non_variadic;
  446. [*Header]
  447. #include <boost/function_types/property_tags.hpp>
  448. States that a function type does not have an ellipsis parameter.
  449. [endsect]
  450. [section:default_cc default_cc]
  451. typedef __unspecified__ default_cc;
  452. [*Header]
  453. #include <boost/function_types/property_tags.hpp>
  454. States that a function type encodes the default calling convention.
  455. [endsect]
  456. [section:const_qualified const_qualified]
  457. typedef __unspecified__ const_qualified;
  458. [*Header]
  459. #include <boost/function_types/property_tags.hpp>
  460. States that a function type is const qualified.
  461. [endsect]
  462. [section:non_const non_const]
  463. typedef __unspecified__ non_const;
  464. [*Header]
  465. #include <boost/function_types/property_tags.hpp>
  466. States that a function type is not const qualified.
  467. [endsect]
  468. [section:volatile_qualified volatile_qualified]
  469. typedef __unspecified__ volatile_qualified;
  470. [*Header]
  471. #include <boost/function_types/property_tags.hpp>
  472. States that a function type is volatile qualified.
  473. [endsect]
  474. [section:non_volatile non_volatile]
  475. typedef __unspecified__ non_volatile;
  476. [*Header]
  477. #include <boost/function_types/property_tags.hpp>
  478. States that a function type is not volatile qualified.
  479. [endsect]
  480. [section:non_cv non_cv]
  481. typedef __unspecified__ non_cv;
  482. [*Header]
  483. #include <boost/function_types/property_tags.hpp>
  484. States that a function type is neither const nor volatile qualified.
  485. Equivalent to `__tag<__non_const,__non_volatile>`, but involves
  486. fewer template instantiations when evaluated.
  487. [endsect]
  488. [section:const_non_volatile const_non_volatile]
  489. typedef __unspecified__ const_non_volatile;
  490. [*Header]
  491. #include <boost/function_types/property_tags.hpp>
  492. States that a function type is const but not volatile qualified.
  493. Equivalent to `__tag<__const_qualified,__non_volatile>`, but involves
  494. fewer template instantiations when evaluated.
  495. [endsect]
  496. [section:volatile_non_const volatile_non_const]
  497. typedef __unspecified__ volatile_non_const;
  498. [*Header]
  499. #include <boost/function_types/property_tags.hpp>
  500. States that a function type is volatile but not const qualified.
  501. Equivalent to `__tag<__volatile_qualified,__non_const>`, but involves
  502. fewer template instantiations when evaluated.
  503. [endsect]
  504. [section:cv_qualfied cv_qualfied]
  505. typedef __unspecified__ cv_qualified;
  506. [*Header]
  507. #include <boost/function_types/property_tags.hpp>
  508. States that a function type is both const and volatile qualified.
  509. Equivalent to `__tag<__const_qualified,__volatile_qualified>`, but involves
  510. fewer template instantiations when evaluated.
  511. [endsect]
  512. [section:null_tag null_tag]
  513. typedef __unspecified__ null_tag;
  514. [*Header]
  515. #include <boost/function_types/property_tags.hpp>
  516. States nothing.
  517. [endsect]
  518. [section:tag tag]
  519. template<class Tag1, class Tag2,
  520. class Tag3 = null_tag, class Tag4 = null_tag>
  521. struct tag;
  522. [*Header]
  523. #include <boost/function_types/property_tags.hpp>
  524. [variablelist
  525. [[[^Tag['N]]][Property tag]]
  526. [[[^tag<Tag1,Tag2...>]][Compound property tag]]
  527. ]
  528. Combination of up to four property tags. If the arguments describe different
  529. values for the same property the value of the rightmost argument is used.
  530. [endsect]
  531. [endsect] [/ Tag Types]
  532. [/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]
  533. [section:macros Macros]
  534. [section:BOOST_FT_MAX_ARITY BOOST_FT_MAX_ARITY]
  535. Expands to a numeric value that describes the maximum function arity
  536. supported by the library.
  537. Defaults to 20 if not explicitly defined by the user before inclusion
  538. of the first library header.
  539. [endsect]
  540. [*The following macros do not need to be defined, unless to configure
  541. the library to work with a compiler and/or calling convention not covered by
  542. the auto-detection mechanism in [^boost/function_types/config/compiler.hpp].]
  543. [section:BOOST_FT_CC_NAMES BOOST_FT_CC_NAMES]
  544. Expands to a [@../../../preprocessor/doc/data/sequences.html sequence] of
  545. ternary [@../../../preprocessor/doc/data/tuples.html tuples] (these data
  546. types are defined in the [@../../../preprocessor/doc/index.html
  547. documentation of the Boost Preprocessor library]).
  548. Each sequence element describes one calling convention specifier.
  549. The first element in each tuple is the macro suffix for
  550. [link boost_functiontypes.reference.macros.BOOST_FT_CC [^BOOST_FT\_CC\_*]],
  551. the second element is the name of the tag that describes the calling
  552. convention and the third is the name of the specifier.
  553. The specifier is allowed to be an empty string, so the third tuple element
  554. is either [@../../../preprocessor/doc/ref/empty.html [^BOOST_PP_EMPTY]] or
  555. [@../../../preprocessor/doc/ref/identity.html [^BOOST_PP_IDENTITY]][^(['name])].
  556. Define this macro to extend the set of possible names for custom calling
  557. conventions. The macro expands to nothing by default.
  558. The following names are predefined by the library and must not occur in the
  559. definition of [^BOOST_FT_CC_NAMES]:
  560. #define BOOST_FT_BUILTIN_CC_NAMES \
  561. (( IMPLICIT , implicit_cc , BOOST_PP_EMPTY ))\
  562. (( CDECL , cdecl_cc , BOOST_PP_IDENTITY(__cdecl ) ))\
  563. (( STDCALL , stdcall_cc , BOOST_PP_IDENTITY(__stdcall ) ))\
  564. (( PASCAL , pascal_cc , BOOST_PP_IDENTITY(pascal ) ))\
  565. (( FASTCALL , fastcall_cc , BOOST_PP_IDENTITY(__fastcall) ))\
  566. (( CLRCALL , clrcall_cc , BOOST_PP_IDENTITY(__clrcall ) ))\
  567. (( THISCALL , thiscall_cc , BOOST_PP_IDENTITY(__thiscall) ))\
  568. (( IMPLICIT_THISCALL , thiscall_cc , BOOST_PP_EMPTY ))
  569. // Don't get confused by the last line, here (thiscall can't be specified
  570. // explicitly prior to MSVC 8).
  571. [endsect]
  572. [section:BOOST_FT_CC BOOST_FT\_CC\_*]
  573. Enables a specific calling convention. * denotes the macro suffix, as
  574. defined by
  575. [link boost_functiontypes.reference.macros.BOOST_FT_CC_NAMES [^BOOST_FT_CC_NAMES]]
  576. or
  577. [link boost_functiontypes.reference.macros.BOOST_FT_CC_NAMES [^BOOST_FT_BUILTIN_CC_NAMES]].
  578. The macro expands to a list of restrictions, separated by the [^|] character.
  579. Possible items are:
  580. * callable_builtin
  581. * member
  582. * non_member
  583. * variadic
  584. * non_variadic
  585. If no such macro is defined for a particular calling convention, it is disabled.
  586. Example:
  587. #define BOOST_FT_CC_STDCALL non_variadic|callable_builtin
  588. // enables stdcall calling convention for all non-variadic,
  589. // callable, builtin types
  590. [endsect]
  591. [section:BOOST_FT_COMMON_X86_CCs BOOST_FT_COMMON_X86_CCs]
  592. Defining this macro causes the following macros to be defined, if not defined
  593. already:
  594. #define BOOST_FT_CC_CDECL BOOST_FT_COMMON_X86_CCs
  595. #define BOOST_FT_CC_STDCALL non_variadic|BOOST_FT_COMMON_X86_CCs
  596. #define BOOST_FT_CC_FASTCALL non_variadic|BOOST_FT_COMMON_X86_CCs
  597. [endsect]
  598. [section:BOOST_FT_SYNTAX BOOST_FT_SYNTAX]
  599. This macro allows to change the syntax of callable builtin types.
  600. It is useful to handle the compiler specific placement of the calling
  601. convention specifier.
  602. The default definition is as follows:
  603. #define BOOST_FT_SYNTAX(result,lparen,cc_spec,type_mod,name,rparen) \
  604. result() lparen() cc_spec() type_mod() name() rparen()
  605. [endsect]
  606. [section:BOOST_FT_NULLARY_PARAM BOOST_FT_NULLARY_PARAM]
  607. Set to [^void] for compilers that insist on a [^void] parameter for
  608. nullary function types, empty by default.
  609. [endsect]
  610. [section:BOOST_FT_NO_CV_FUNC_SUPPORT BOOST_FT_NO_CV_FUNC_SUPPORT]
  611. Disables support for cv-qualified function types.
  612. Cv-qualified function types are illegal by the current standard
  613. version, but there is a pending defect report on that issue.
  614. It defaults to [^1] until the standard changes, setting this macro
  615. to [^0] may not work.
  616. [endsect]
  617. [*The following macros are useful for testing when changing the source code of
  618. the library.]
  619. [section:BOOST_FT_PREPROCESSING_MODE BOOST_FT_PREPROCESSING_MODE]
  620. Makes the compiler preprocess as much as possible of the library code
  621. (rather than loading already-preprocessed header files) if defined.
  622. [endsect]
  623. [section:BOOST_FT_CC_PREPROCESSING BOOST_FT_CC_PREPROCESSING]
  624. Makes the compiler preprocess the loop over possible names for custom
  625. calling conventions (rather than loading an already-preprocessed header
  626. file) if defined.
  627. This macro is defined automatically if
  628. [link boost_functiontypes.reference.macros.BOOST_FT_CC_NAMES [^BOOST_FT_CC_NAMES]]
  629. has been defined.
  630. [endsect]
  631. [endsect]
  632. [endsect]
  633. [/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]
  634. [section:rationale Rationale]
  635. [heading Error handling rationale]
  636. The library does not define the required members of class templates in
  637. case of an error. This technique causes the compiler to stop displaying
  638. diagnostics in client code, at the point where the error actually is,
  639. instead of tracing template instantiations into the implementation of
  640. the library.
  641. The library's components have limited error conditions, so problematic
  642. input can be spotted easily.
  643. [heading Why MPL Sequences?]
  644. MPL provides algorithms on Sequences, so transformations (such as turning
  645. by-value parameter types into const references for optimized forwarding
  646. or computing a signature to specialize
  647. [@../../../function/index.html [^boost::function]] after applying
  648. [@../../../bind/index.html [^boost::bind]]) can be expressed more
  649. easily. The MPL Sequence concept is compatible with several other Boost
  650. libraries (most importantly [@../../../fusion/index.html Fusion]),
  651. so another reason is interoperability.
  652. [heading Pointer to member object types]
  653. Despite their syntax, pointer to member object types can be seen as
  654. dereferencing functionals.
  655. [heading The ClassTransform template parameter]
  656. [^This]-pointer, [^this]-reference or just the object (or maybe even a
  657. smart pointer to the object) plus adjustments of cv-qualification - all
  658. these cases have their place, somewhere and there is no single best answer.
  659. Special treatment of the class type within the sequence can significantly
  660. complicate client code. A custom [^ClassTransform] argument allows the
  661. client to adjust the class type before the sequence is formed and then
  662. treat all parameters uniformly.
  663. [heading Why tag types?]
  664. Let's consider the alternatives.
  665. The first one is just using more templates so every property has to be
  666. asked for explicitly. This approach results in more complicated client
  667. code if more than one propery has to be checked and in a exponentially
  668. larger library interface.
  669. The second alternative is having the client pass in bit patterns via
  670. non-type template parameters. The logic has to be performed by the
  671. client and there are much more error conditions. Further, class templates
  672. with non-type template parameters do not work within MPL lambda
  673. expressions and can cause problems with older compilers.
  674. [heading Is it safe to have the synthesis templates take a callable
  675. builtin type or an MPL sequence as the first template argument?]
  676. Yes, but it isn't immediately obvious as the set of possible MPL sequences
  677. isn't inherently disjoint from the set of callable builtin types.
  678. However, any attempt to make a builtin type work as an MPL sequence is
  679. a bad idea, because builtin types are accessible before the headers that
  680. make the type a sequence have been included, which can easily violate the
  681. ODR.
  682. [heading Why does the hidden [^this] parameter count for the
  683. function arity of member functions?]
  684. It was found preferable that the following condition holds:
  685. mpl::size< __parameter_types<T> >::value == __function_arity<T>::value
  686. [heading Why ignore top-level cv-qualifiers on pointers?]
  687. A cv-qualified pointer is still a pointer. It usually doesn't matter and
  688. even if it does, it's a job for
  689. [@../../../type_traits/index.html Boost.TypeTraits].
  690. [endsect]
  691. [section:acknowledgements Acknowledgements]
  692. Thanks go to the following people for supporting the development of this
  693. library in one or the other way:
  694. * David Abrahams
  695. * Tom Brinkman
  696. * Aleksey Gurtovoy
  697. * Jody Hagins
  698. * Hartmut Kaiser
  699. * Andy Little
  700. * John Maddock
  701. * Paul Mensonides
  702. * Alexander Nasonov
  703. * Richard Smith
  704. * Rob Stewart
  705. * Jonathan Turkanis
  706. * Pavel Vozenilek
  707. * Steven Watanabe
  708. * K. Noel Belcourt
  709. [endsect]