callable_traits.qbk 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  1. [article CallableTraits
  2. [quickbook 1.6]
  3. [id callable_traits]
  4. [copyright 2016-2018 Barrett Adair]
  5. [authors [Adair, Barrett]]
  6. [license
  7. Distributed under the Boost Software License, Version 1.0.
  8. (See accompanying file LICENSE.md or copy at
  9. [@http://www.boost.org/LICENSE_1_0.txt http://www.boost.org/LICENSE_1_0.txt])
  10. ]
  11. [source-mode c++]
  12. [last-revision $Date$]
  13. [lang en]
  14. ]
  15. [/ developer: you should enable word wrap before you read further]
  16. [template libname[][^Boost.CallableTraits]]
  17. [template lib_namespace[][^callable_traits]]
  18. [template namespace_scoped[][^boost::callable_traits::]]
  19. [template header_include_prefix[]callable_traits/]
  20. [template invoke[][@http://en.cppreference.com/w/cpp/utility/functional/invoke [^['INVOKE]]]]
  21. [template hana[][@https://boostorg.github.io/hana/ [^Boost.Hana]]]
  22. [template feedback[][link callable_traits.contact feedback]]
  23. [template unsure[][link callable_traits.contact ?]]
  24. [template link_contact_the_author[][link callable_traits.contact contact me]]
  25. [template repo[][@https://github.com/boostorg/callable_traits GitHub]]
  26. [template abominable_paper[][@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0172r0.html "abominable" function types]]
  27. [template link_compatibility[][link callable_traits.compatibility Compatibility]]
  28. [template link_compatibility_issues[][link callable_traits.compatibility.compatibility_issues Compatibility Issues]]
  29. [template function_types_link[][@http://www.boost.org/doc/libs/1_61_0/libs/function_types/doc/html/index.html [^Boost.FunctionTypes]]]
  30. [template function_types[][^Boost.FunctionTypes]]
  31. [section:introduction Overview]
  32. [libname] is a C++11 header-only library for the inspection, synthesis, and decomposition of callable types. [libname] aims to be the "complete type manipulation facility for function types" mentioned in the final paragraph of C++17 proposal [@http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2015/p0172r0.html p0172], and removes the need for template specializations for different function signatures. C++17 `noexcept` and the Transactional Memory TS are also supported if available.
  33. [import ../example/intro.cpp]
  34. [intro]
  35. [section:motivation Motivation]
  36. [:[*['["Don't try to write helper code to detect PMFs/PMDs and dispatch on them -- it is an [_absolute nightmare]. PMF types are the worst types by far in the core language.]]]
  37. -- Stephan T. Lavavej, CppCon 2015, [@https://www.youtube.com/watch?v=zt7ThwVfap0&t=11m40s "functional: What's New, And Proper Usage"]
  38. ]
  39. Consider for a moment the code below, which defines all 48 template specializations necessary to specialize for every valid function type in pure C++17:
  40. [import ./hideous_template.snippet.cpp]
  41. [hideous_template]
  42. Things get even more complicated with member function pointers, function pointers, function references, function objects, and `transaction_safe`.
  43. Granted, use cases for such obscure specializations are vitually nonexistent in run-of-the-mill application codebases. Even in library code, these are exceedingly rare. However, there are a handful of metaprogramming scenarios that can only be solved with this kind of template "spam". Writing, testing, and maintaining such code is tedious and costly.
  44. [libname] offers a final and decisive library-level solution to this problem, and removes the need for these specializations entirely (platform-specific calling conventions notwithstanding).
  45. [endsect][/section:motivation]
  46. [section:boost_function_types Regarding [^Boost.FunctionTypes]]
  47. The features in [libname] largely overlap with [function_types_link]. Here are some reasons why you might prefer [libname]:
  48. # [function_types] is tightly coupled to [@http://www.boost.org/doc/libs/1_64_0/libs/mpl/doc/index.html [^Boost.MPL]] sequences, while [libname] has no dependencies other than the standard library.
  49. # [libname] targets C++11 and later:
  50. # [libname] treats function objects/lambdas as first-class citizens.
  51. # [libname] supports lvalue/rvalue reference member qualifiers.
  52. # [libname] supports `noexcept` and `transaction_safe`.
  53. # [function_types] does not attempt to factor all callable types into a unified, [invoke]-aware interface.
  54. # [function_types] relies heavily on "tag" types, while [libname] follows the style of <type_traits> instead. Supporting C++11 and later in [function_types] would have required significant proliferation of these tags.
  55. For example, here is how to remove member `const` from a member function pointer type in the [function_types] library:
  56. #include <type_traits>
  57. #include <boost/function_types/components.hpp>
  58. #include <boost/function_types/member_function_pointer.hpp>
  59. struct foo {
  60. void bar() const {}
  61. };
  62. using const_removed = typename boost::function_types::member_function_pointer<
  63. typename boost::function_types::components<decltype(&foo::bar)>::types,
  64. boost::function_types::non_const>::type;
  65. static_assert(std::is_same<const_removed, void(foo::*)()>::value, "");
  66. int main(){}
  67. [libname] makes this easier:
  68. [import ../example/function_types_remove_const_comparison.cpp]
  69. [function_types_remove_const_comparison]
  70. The [function_types] library includes an excellent [@http://www.boost.org/doc/libs/1_64_0/libs/function_types/example/interface_example.cpp example] for generating type-erased interfaces (implementation [@http://www.boost.org/doc/libs/1_64_0/libs/function_types/example/interface.hpp here]). This example was [@https://github.com/badair/eraserface/blob/master/include/eraserface/eraserface.hpp re-implemented] using [libname] to yield a [@https://github.com/badair/eraserface/blob/master/example/basic_example.cpp slightly more intuitive interface].
  71. [function_types] is a fine library, but its interface left room for improvement.
  72. [endsect][/section:boost_function_types]
  73. [section:compatibility Compatibility]
  74. [template link_travis_ci[][@https://travis-ci.org/boostorg/callable_traits/builds Travis]]
  75. [template link_appveyor_ci[][@https://ci.appveyor.com/project/boostorg/callable-traits Appveyor]]
  76. [libname] supports on GCC 4.7.4+, Clang 3.5.2+, XCode 6.4+, and Visual Studio 2015+. Continuous integration is managed on [link_appveyor_ci] for Visual Studio, and on [link_travis_ci] for everything else. The Intel C++ Compiler is not officially supported yet, although the 2017 version for Linux does pass a handful of test cases.
  77. [template yes[][role green \u2713]]
  78. [template c11[][role green c++11]]
  79. [template c14[][role green c++14]]
  80. [template c17[][role green c++17]]
  81. [template gnutm[][role gold c++17] (requires -fgnu-tm)]
  82. [template noabom[][role gold c++11] (no abominables)]
  83. [template no[][role red static_assert fails on instantiation]]
  84. [template falsy[][role gold c++11] (always false)]
  85. [template noop[][role gold c++11] (no effect)]
  86. [template unk[]unknown]
  87. [table GCC Support
  88. [[feature] [GCC 8.2.0] [GCC 7.3.0] [GCC 6.3.0] [GCC 5.4.0] [GCC 4.9.2] [GCC 4.8.2] [GCC 4.7.4]]
  89. [[[link callable_traits.reference.ref_add_member_const [^add_member_const]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[noabom]] [[noabom]] ]
  90. [[[link callable_traits.reference.ref_add_member_cv [^add_member_cv]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[noabom]] [[noabom]] ]
  91. [[[link callable_traits.reference.ref_add_member_lvalue_reference [^add_member_lvalue_reference]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[no]] [[no]] ]
  92. [[[link callable_traits.reference.ref_add_member_rvalue_reference [^add_member_rvalue_reference]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[no]] [[no]] ]
  93. [[[link callable_traits.reference.ref_add_member_volatile [^add_member_volatile]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[noabom]] [[noabom]] ]
  94. [[[link callable_traits.reference.ref_add_noexcept [^add_noexcept]]] [[c17]] [[c17]] [[c17]] [[no]] [[no]] [[no]] [[no]] ]
  95. [[[link callable_traits.reference.ref_add_transaction_safe [^add_transaction_safe]]] [[gnutm]] [[gnutm]] [[gnutm]] [[no]] [[no]] [[no]] [[no]] ]
  96. [[[link callable_traits.reference.ref_add_varargs [^add_varargs]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  97. [[[link callable_traits.reference.ref_apply_member_pointer [^apply_member_pointer]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  98. [[[link callable_traits.reference.ref_apply_return [^apply_return]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  99. [[[link callable_traits.reference.ref_args [^args]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  100. [[[link callable_traits.reference.ref_class_of [^class_of]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  101. [[[link callable_traits.reference.ref_function_type [^function_type]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  102. [[[link callable_traits.reference.ref_has_member_qualifiers [^has_member_qualifiers]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[noabom]] [[noabom]] ]
  103. [[[link callable_traits.reference.ref_has_varargs [^has_varargs]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  104. [[[link callable_traits.reference.ref_has_void_return [^has_void_return]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  105. [[[link callable_traits.reference.ref_is_const_member [^is_const_member]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[noabom]] [[noabom]] ]
  106. [[[link callable_traits.reference.ref_is_cv_member [^is_cv_member]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[noabom]] [[noabom]] ]
  107. [[[link callable_traits.reference.ref_is_invocable [^is_invocable]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[unk]] [[unk]] ]
  108. [[[link callable_traits.reference.ref_is_lvalue_reference_member [^is_lvalue_reference_member]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[falsy]] [[falsy]] ]
  109. [[[link callable_traits.reference.ref_is_noexcept [^is_noexcept]]] [[c17]] [[c17]] [[c17]] [[falsy]] [[falsy]] [[falsy]] [[falsy]] ]
  110. [[[link callable_traits.reference.ref_is_reference_member [^is_reference_member]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[falsy]] [[falsy]] ]
  111. [[[link callable_traits.reference.ref_is_rvalue_reference_member [^is_rvalue_reference_member]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[falsy]] [[falsy]] ]
  112. [[[link callable_traits.reference.ref_is_transaction_safe [^is_transaction_safe]]] [[gnutm]] [[gnutm]] [[gnutm]] [[falsy]] [[falsy]] [[falsy]] [[falsy]] ]
  113. [[[link callable_traits.reference.ref_is_volatile_member [^is_volatile_member]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[noabom]] [[noabom]] ]
  114. [[[link callable_traits.reference.ref_qualified_class_of [^qualified_class_of]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  115. [[[link callable_traits.reference.ref_remove_member_const [^remove_member_const]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[noabom]] [[noabom]] ]
  116. [[[link callable_traits.reference.ref_remove_member_cv [^remove_member_cv]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[noabom]] [[noabom]] ]
  117. [[[link callable_traits.reference.ref_remove_member_reference [^remove_member_reference]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[noop]] [[noop]] ]
  118. [[[link callable_traits.reference.ref_remove_member_volatile [^remove_member_volatile]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[noabom]] [[noabom]] ]
  119. [[[link callable_traits.reference.ref_remove_noexcept [^remove_noexcept]]] [[c17]] [[c17]] [[c17]] [[noop]] [[noop]] [[noop]] [[noop]] ]
  120. [[[link callable_traits.reference.ref_remove_transaction_safe [^remove_transaction_safe]]] [[gnutm]] [[gnutm]] [[gnutm]] [[noop]] [[noop]] [[noop]] [[noop]] ]
  121. [[[link callable_traits.reference.ref_remove_varargs [^remove_varargs]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  122. [[[link callable_traits.reference.ref_return_type [^return_type]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  123. ]
  124. [table LLVM/Clang Support
  125. [[feature] [Clang 7.0.1] [Clang 6.0.0] [Clang 5.0.1] [Clang 4.0.0] [Clang 3.8.0] [Clang 3.7.1] [Clang 3.6.2] [Clang 3.5.2]]
  126. [[[link callable_traits.reference.ref_add_member_const [^add_member_const]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  127. [[[link callable_traits.reference.ref_add_member_cv [^add_member_cv]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  128. [[[link callable_traits.reference.ref_add_member_lvalue_reference [^add_member_lvalue_reference]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  129. [[[link callable_traits.reference.ref_add_member_rvalue_reference [^add_member_rvalue_reference]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  130. [[[link callable_traits.reference.ref_add_member_volatile [^add_member_volatile]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  131. [[[link callable_traits.reference.ref_add_noexcept [^add_noexcept]]] [[c11]] [[c17]] [[c17]] [[c17]] [[no]] [[no]] [[no]] [[no]] ]
  132. [[[link callable_traits.reference.ref_add_transaction_safe [^add_transaction_safe]]] [[unk]] [[unk]] [[unk]] [[unk]] [[no]] [[no]] [[no]] [[no]] ]
  133. [[[link callable_traits.reference.ref_add_varargs [^add_varargs]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  134. [[[link callable_traits.reference.ref_apply_member_pointer [^apply_member_pointer]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  135. [[[link callable_traits.reference.ref_apply_return [^apply_return]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  136. [[[link callable_traits.reference.ref_args [^args]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  137. [[[link callable_traits.reference.ref_class_of [^class_of]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  138. [[[link callable_traits.reference.ref_function_type [^function_type]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  139. [[[link callable_traits.reference.ref_has_member_qualifiers [^has_member_qualifiers]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  140. [[[link callable_traits.reference.ref_has_varargs [^has_varargs]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  141. [[[link callable_traits.reference.ref_has_void_return [^has_void_return]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  142. [[[link callable_traits.reference.ref_is_const_member [^is_const_member]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  143. [[[link callable_traits.reference.ref_is_cv_member [^is_cv_member]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  144. [[[link callable_traits.reference.ref_is_invocable [^is_invocable]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  145. [[[link callable_traits.reference.ref_is_lvalue_reference_member [^is_lvalue_reference_member]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  146. [[[link callable_traits.reference.ref_is_noexcept [^is_noexcept]]] [[c17]] [[c17]] [[c17]] [[c17]] [[falsy]] [[falsy]] [[falsy]] [[falsy]] ]
  147. [[[link callable_traits.reference.ref_is_reference_member [^is_reference_member]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  148. [[[link callable_traits.reference.ref_is_rvalue_reference_member [^is_rvalue_reference_member]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  149. [[[link callable_traits.reference.ref_is_transaction_safe [^is_transaction_safe]]] [[unk]] [[unk]] [[unk]] [[unk]] [[falsy]] [[falsy]] [[falsy]] [[falsy]] ]
  150. [[[link callable_traits.reference.ref_is_volatile_member [^is_volatile_member]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  151. [[[link callable_traits.reference.ref_qualified_class_of [^qualified_class_of]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  152. [[[link callable_traits.reference.ref_remove_member_const [^remove_member_const]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  153. [[[link callable_traits.reference.ref_remove_member_cv [^remove_member_cv]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  154. [[[link callable_traits.reference.ref_remove_member_reference [^remove_member_reference]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  155. [[[link callable_traits.reference.ref_remove_member_volatile [^remove_member_volatile]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  156. [[[link callable_traits.reference.ref_remove_noexcept [^remove_noexcept]]] [[c17]] [[c17]] [[c17]] [[c17]] [[noop]] [[noop]] [[noop]] [[noop]] ]
  157. [[[link callable_traits.reference.ref_remove_transaction_safe [^remove_transaction_safe]]] [[unk]] [[unk]] [[unk]] [[unk]] [[noop]] [[noop]] [[noop]] [[noop]] ]
  158. [[[link callable_traits.reference.ref_remove_varargs [^remove_varargs]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  159. [[[link callable_traits.reference.ref_return_type [^return_type]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  160. ]
  161. [table XCode/AppleClang Support
  162. [[feature] [XCode 8] [XCode 7.3] [XCode 7.2] [XCode 7.1] [XCode 6.4]]
  163. [[[link callable_traits.reference.ref_add_member_const [^add_member_const]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  164. [[[link callable_traits.reference.ref_add_member_cv [^add_member_cv]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  165. [[[link callable_traits.reference.ref_add_member_lvalue_reference [^add_member_lvalue_reference]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  166. [[[link callable_traits.reference.ref_add_member_rvalue_reference [^add_member_rvalue_reference]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  167. [[[link callable_traits.reference.ref_add_member_volatile [^add_member_volatile]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  168. [[[link callable_traits.reference.ref_add_noexcept [^add_noexcept]]] [[unk]] [[no]] [[no]] [[no]] [[no]] ]
  169. [[[link callable_traits.reference.ref_add_transaction_safe [^add_transaction_safe]]] [[unk]] [[no]] [[no]] [[no]] [[no]] ]
  170. [[[link callable_traits.reference.ref_add_varargs [^add_varargs]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  171. [[[link callable_traits.reference.ref_apply_member_pointer [^apply_member_pointer]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  172. [[[link callable_traits.reference.ref_apply_return [^apply_return]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  173. [[[link callable_traits.reference.ref_args [^args]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  174. [[[link callable_traits.reference.ref_class_of [^class_of]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  175. [[[link callable_traits.reference.ref_function_type [^function_type]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  176. [[[link callable_traits.reference.ref_has_member_qualifiers [^has_member_qualifiers]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  177. [[[link callable_traits.reference.ref_has_varargs [^has_varargs]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  178. [[[link callable_traits.reference.ref_has_void_return [^has_void_return]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  179. [[[link callable_traits.reference.ref_is_const_member [^is_const_member]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  180. [[[link callable_traits.reference.ref_is_cv_member [^is_cv_member]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  181. [[[link callable_traits.reference.ref_is_invocable [^is_invocable]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  182. [[[link callable_traits.reference.ref_is_lvalue_reference_member [^is_lvalue_reference_member]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  183. [[[link callable_traits.reference.ref_is_noexcept [^is_noexcept]]] [[unk]] [[falsy]] [[falsy]] [[falsy]] [[falsy]] ]
  184. [[[link callable_traits.reference.ref_is_reference_member [^is_reference_member]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  185. [[[link callable_traits.reference.ref_is_rvalue_reference_member [^is_rvalue_reference_member]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  186. [[[link callable_traits.reference.ref_is_transaction_safe [^is_transaction_safe]]] [[unk]] [[falsy]] [[falsy]] [[falsy]] [[falsy]] ]
  187. [[[link callable_traits.reference.ref_is_volatile_member [^is_volatile_member]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  188. [[[link callable_traits.reference.ref_qualified_class_of [^qualified_class_of]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  189. [[[link callable_traits.reference.ref_remove_member_const [^remove_member_const]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  190. [[[link callable_traits.reference.ref_remove_member_cv [^remove_member_cv]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  191. [[[link callable_traits.reference.ref_remove_member_reference [^remove_member_reference]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  192. [[[link callable_traits.reference.ref_remove_member_volatile [^remove_member_volatile]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  193. [[[link callable_traits.reference.ref_remove_noexcept [^remove_noexcept]]] [[unk]] [[noop]] [[noop]] [[noop]] [[noop]] ]
  194. [[[link callable_traits.reference.ref_remove_transaction_safe [^remove_transaction_safe]]] [[unk]] [[noop]] [[noop]] [[noop]] [[noop]] ]
  195. [[[link callable_traits.reference.ref_remove_varargs [^remove_varargs]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  196. [[[link callable_traits.reference.ref_return_type [^return_type]]] [[c11]] [[c11]] [[c11]] [[c11]] [[c11]] ]
  197. ]
  198. [table Visual Studio Support
  199. [[feature] [MSVC with Visual Studio 2017] [MSVC with Visual Studio 2015 (latest update)]]
  200. [[[link callable_traits.reference.ref_add_member_const [^add_member_const]]] [[c11]] [[c11]] ]
  201. [[[link callable_traits.reference.ref_add_member_cv [^add_member_cv]]] [[c11]] [[c11]] ]
  202. [[[link callable_traits.reference.ref_add_member_lvalue_reference [^add_member_lvalue_reference]]] [[c11]] [[c11]] ]
  203. [[[link callable_traits.reference.ref_add_member_rvalue_reference [^add_member_rvalue_reference]]] [[c11]] [[c11]] ]
  204. [[[link callable_traits.reference.ref_add_member_volatile [^add_member_volatile]]] [[c11]] [[c11]] ]
  205. [[[link callable_traits.reference.ref_add_noexcept [^add_noexcept]]] [[no]] [[no]] ]
  206. [[[link callable_traits.reference.ref_add_transaction_safe [^add_transaction_safe]]] [[no]] [[no]] ]
  207. [[[link callable_traits.reference.ref_add_varargs [^add_varargs]]] [[c11] (define BOOST_DISABLE_WIN32 to disable __cdecl on PMF varargs)] [[c11] (define BOOST_DISABLE_WIN32 to disable __cdecl on PMF varargs)] ]
  208. [[[link callable_traits.reference.ref_apply_member_pointer [^apply_member_pointer]]] [[c11]] [[c11]] ]
  209. [[[link callable_traits.reference.ref_apply_return [^apply_return]]] [[c11]] [[c11]] ]
  210. [[[link callable_traits.reference.ref_args [^args]]] [[c11]] [[c11]] ]
  211. [[[link callable_traits.reference.ref_class_of [^class_of]]] [[c11]] [[c11]] ]
  212. [[[link callable_traits.reference.ref_function_type [^function_type]]] [[c11]] [[c11]] ]
  213. [[[link callable_traits.reference.ref_has_member_qualifiers [^has_member_qualifiers]]] [[c11]] [[c11]] ]
  214. [[[link callable_traits.reference.ref_has_varargs [^has_varargs]]] [[c11] (define BOOST_DISABLE_WIN32 to disable __cdecl on PMF varargs)] [[c11] (define BOOST_DISABLE_WIN32 to disable __cdecl on PMF varargs)] ]
  215. [[[link callable_traits.reference.ref_has_void_return [^has_void_return]]] [[c11]] [[c11]] ]
  216. [[[link callable_traits.reference.ref_is_const_member [^is_const_member]]] [[c11]] [[c11]] ]
  217. [[[link callable_traits.reference.ref_is_cv_member [^is_cv_member]]] [[c11]] [[c11]] ]
  218. [[[link callable_traits.reference.ref_is_invocable [^is_invocable]]] [[c11]] [[role gold c++11] (always false for functions that are simultaneously ref and cv-qualified due to compiler bug)] ]
  219. [[[link callable_traits.reference.ref_is_lvalue_reference_member [^is_lvalue_reference_member]]] [[c11]] [[c11]] ]
  220. [[[link callable_traits.reference.ref_is_noexcept [^is_noexcept]]] [[falsy]] [[falsy]] ]
  221. [[[link callable_traits.reference.ref_is_reference_member [^is_reference_member]]] [[c11]] [[c11]] ]
  222. [[[link callable_traits.reference.ref_is_rvalue_reference_member [^is_rvalue_reference_member]]] [[c11]] [[c11]] ]
  223. [[[link callable_traits.reference.ref_is_transaction_safe [^is_transaction_safe]]] [[falsy]] [[falsy]] ]
  224. [[[link callable_traits.reference.ref_is_volatile_member [^is_volatile_member]]] [[c11]] [[c11]] ]
  225. [[[link callable_traits.reference.ref_qualified_class_of [^qualified_class_of]]] [[c11]][[c11]] ]
  226. [[[link callable_traits.reference.ref_remove_member_const [^remove_member_const]]] [[c11]] [[c11]] ]
  227. [[[link callable_traits.reference.ref_remove_member_cv [^remove_member_cv]]] [[c11]] [[c11]] ]
  228. [[[link callable_traits.reference.ref_remove_member_reference [^remove_member_reference]]] [[c11]] [[c11]] ]
  229. [[[link callable_traits.reference.ref_remove_member_volatile [^remove_member_volatile]]] [[c11]] [[c11]] ]
  230. [[[link callable_traits.reference.ref_remove_noexcept [^remove_noexcept]]] [[noop]] [[noop]] ]
  231. [[[link callable_traits.reference.ref_remove_transaction_safe [^remove_transaction_safe]]] [[noop]] [[noop]] ]
  232. [[[link callable_traits.reference.ref_remove_varargs [^remove_varargs]]] [[c11] (define BOOST_DISABLE_WIN32 to disable __cdecl on PMF varargs)] [[c11] (define BOOST_DISABLE_WIN32 to disable __cdecl on PMF varargs)] ]
  233. [[[link callable_traits.reference.ref_return_type [^return_type]]] [[c11]] [[c11]] ]
  234. ]
  235. [endsect][/section:compatibility]
  236. [endsect][/section:introduction]
  237. [section:reference Reference Documentation]
  238. This reference will be most beneficial to readers familiar with the following C++ topics:
  239. * [@http://en.cppreference.com/w/cpp/language/partial_specialization template specializations]
  240. * [@http://en.cppreference.com/w/cpp/language/sfinae SFINAE]
  241. * [invoke] rules
  242. * function types
  243. * [@http://en.cppreference.com/w/cpp/language/pointer#Pointers_to_functions function pointers]
  244. * [@http://stackoverflow.com/questions/480248/function-references function references]
  245. * [@http://en.cppreference.com/w/cpp/language/pointer#Pointers_to_member_functions pointers to member functions] (a.k.a. PMFs)
  246. * [@http://en.cppreference.com/w/cpp/language/pointer#Pointers_to_data_members pointers to data members] (a.k.a. PMDs)
  247. * [@http://en.cppreference.com/w/cpp/language/operators#Function_call_operator the function call operator, [^operator()]]
  248. * [@https://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers universal references] and [@http://stackoverflow.com/questions/13725747/concise-explanation-of-reference-collapsing-rules-requested-1-a-a-2 reference collapsing rules]
  249. * [@http://en.cppreference.com/w/cpp/language/member_functions#const-.2C_volatile-.2C_and_ref-qualified_member_functions cv-qualified and ref-qualified member functions]
  250. * [abominable_paper]
  251. * [@http://en.cppreference.com/w/c/language/variadic C-style variadics], a.k.a. varargs
  252. [import ../../../boost/callable_traits/add_member_const.hpp]
  253. [add_member_const_hpp]
  254. [import ../../../boost/callable_traits/add_member_cv.hpp]
  255. [add_member_cv_hpp]
  256. [import ../../../boost/callable_traits/add_member_lvalue_reference.hpp]
  257. [add_member_lvalue_reference_hpp]
  258. [import ../../../boost/callable_traits/add_member_rvalue_reference.hpp]
  259. [add_member_rvalue_reference_hpp]
  260. [import ../../../boost/callable_traits/add_member_volatile.hpp]
  261. [add_member_volatile_hpp]
  262. [import ../../../boost/callable_traits/add_noexcept.hpp]
  263. [add_noexcept_hpp]
  264. [import ../../../boost/callable_traits/add_transaction_safe.hpp]
  265. [add_transaction_safe_hpp]
  266. [import ../../../boost/callable_traits/add_varargs.hpp]
  267. [add_varargs_hpp]
  268. [import ../../../boost/callable_traits/apply_member_pointer.hpp]
  269. [apply_member_pointer_hpp]
  270. [import ../../../boost/callable_traits/apply_return.hpp]
  271. [apply_return_hpp]
  272. [import ../../../boost/callable_traits/args.hpp]
  273. [args_hpp]
  274. [import ../../../boost/callable_traits/class_of.hpp]
  275. [class_of_hpp]
  276. [import ../../../boost/callable_traits/function_type.hpp]
  277. [function_type_hpp]
  278. [import ../../../boost/callable_traits/has_member_qualifiers.hpp]
  279. [has_member_qualifiers_hpp]
  280. [import ../../../boost/callable_traits/has_varargs.hpp]
  281. [has_varargs_hpp]
  282. [import ../../../boost/callable_traits/has_void_return.hpp]
  283. [has_void_return_hpp]
  284. [import ../../../boost/callable_traits/is_const_member.hpp]
  285. [is_const_member_hpp]
  286. [import ../../../boost/callable_traits/is_cv_member.hpp]
  287. [is_cv_member_hpp]
  288. [import ../../../boost/callable_traits/is_invocable.hpp]
  289. [is_invocable_hpp]
  290. [import ../../../boost/callable_traits/is_lvalue_reference_member.hpp]
  291. [is_lvalue_reference_member_hpp]
  292. [import ../../../boost/callable_traits/is_reference_member.hpp]
  293. [is_reference_member_hpp]
  294. [import ../../../boost/callable_traits/is_rvalue_reference_member.hpp]
  295. [is_rvalue_reference_member_hpp]
  296. [import ../../../boost/callable_traits/is_noexcept.hpp]
  297. [is_noexcept_hpp]
  298. [import ../../../boost/callable_traits/is_transaction_safe.hpp]
  299. [is_transaction_safe_hpp]
  300. [import ../../../boost/callable_traits/is_volatile_member.hpp]
  301. [is_volatile_member_hpp]
  302. [import ../../../boost/callable_traits/qualified_class_of.hpp]
  303. [qualified_class_of_hpp]
  304. [import ../../../boost/callable_traits/remove_member_const.hpp]
  305. [remove_member_const_hpp]
  306. [import ../../../boost/callable_traits/remove_member_cv.hpp]
  307. [remove_member_cv_hpp]
  308. [import ../../../boost/callable_traits/remove_member_reference.hpp]
  309. [remove_member_reference_hpp]
  310. [import ../../../boost/callable_traits/remove_member_volatile.hpp]
  311. [remove_member_volatile_hpp]
  312. [import ../../../boost/callable_traits/remove_noexcept.hpp]
  313. [remove_noexcept_hpp]
  314. [import ../../../boost/callable_traits/remove_transaction_safe.hpp]
  315. [remove_transaction_safe_hpp]
  316. [import ../../../boost/callable_traits/remove_varargs.hpp]
  317. [remove_varargs_hpp]
  318. [import ../../../boost/callable_traits/return_type.hpp]
  319. [return_type_hpp]
  320. [endsect][/section:reference]
  321. [/*********************************************************************]
  322. [/***************************** F A Q *********************************]
  323. [/*********************************************************************]
  324. [section:faq FAQ]
  325. [heading:reasons Why should I use [libname]?]
  326. If you are not writing generic code, you should not use [libname].
  327. If you ['are] writing generic code, take a moment to skim your header files, and see if you can find code that looks like this:
  328. template<class Return, class First, class Second>
  329. class foo<Return(First, Second)> {
  330. // ^^^^^^^^^^^^^^^^^^^^^
  331. };
  332. Or maybe something like this:
  333. template<class Return, class ...Args>
  334. class foo<Return(*)(Args...)> {
  335. // ^^^^^^^^^^^^^^^^^^
  336. };
  337. Or, if you are *really* unlucky, something like this:
  338. template<class Return, class T, class ...Args>
  339. class foo<Return(T::*)(Args..., ...) const volatile & noexcept> {
  340. // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  341. };
  342. With [libname], you can get rid of all of these template specializations (unless you deal with platform-specific calling conventions, for now). Even if you are only specializing a simple function type like `Return(Args...)`, [libname] might be useful to you. You may find that [libname] can help make your code more readable, more maintainable, more generic, and less error-prone.
  343. [libname] is well-tested on many platforms. [libname] correctly handles many corner cases that are often overlooked. The need for a proper library solution grows as more features are added to C++.
  344. [heading Boost is a massive dependency. Do I really need it?]
  345. Nope! [libname] doesn't have any dependencies, so all you need are the [libname] headers.
  346. [heading Why use reference collapsing rules when adding member function ref-qualifiers?]
  347. Although arbitrary, the reference collapsing rules are well-defined and already known to many template metaprogrammers. Anything else would be a burden to memorize. This also parallels the metafunctions provided in `<type_traits>`.
  348. [heading Many features in this library cause a "substitution failure" when the template constraints are violated. Does this mean that I can violate the constraints in a SFINAE context, as long as there is another legal substitute?]
  349. Yes. The SFINAE-ability of violated constraints has been tested extensively on supported compilers. Achieving this required some messy code in the public header files.
  350. [heading What about calling conventions?]
  351. I originally implemented features for these. However, these features necessitated many, many more platform-specific test cases. The code is still designed to accommodate such features, so I would consider adding them in the future if there is sufficient interest.
  352. [endsect]
  353. [section:building Building the test suite]
  354. This section contains the instructions for building and running the test cases and documentatation examples that are packaged with [libname].
  355. [note Some test cases that use language features that do not work on some supported compilers. These conflicts are "resolved" by replacing `int main(){}` with the actual test via conditional compilation.]
  356. [heading Dependencies]
  357. Even though the [libname] headers do not rely on external dependencies, you'll need to install [@https://cmake.org/ CMake] version 3.5 or higher to run the full test suite. The build instructions assume that both CMake and Git are available from your environment PATH. Boost.Build is also supported.
  358. [heading Linux/OSX - clone and run test suite]
  359. Open a shell and enter the following commands:
  360. ```
  361. git clone http://github.com/boostorg/callable_traits
  362. cd callable_traits
  363. mkdir build
  364. cd build
  365. cmake .. -DCMAKE_CXX_COMPILER=/path/to/compiler
  366. make check
  367. ```
  368. [heading Windows - clone and run test suite]
  369. [note Cygwin and MSYS users should refer to the Linux section (you know who you are).]
  370. Fire up `cmd.exe` and enter the following commands:
  371. ```
  372. git clone http://github.com/boostorg/callable_traits
  373. cd callable_traits
  374. mkdir build
  375. cd build
  376. cmake ..
  377. path\to\msbuild.exe check.vcxproj /t:build /p:Configuration=Debug /p:Platform=Win32 /v:n /nologo
  378. ```
  379. To build with Clang/C2 instead of MSVC, append `-TLLVM-vs2014` (or similar supported flag) to the CMake arguments. This will only work if you have Clang/C2 installed.
  380. [endsect][/section:building]
  381. [/*********************************************************************]
  382. [/************************* C O N T A C T *****************************]
  383. [/*********************************************************************]
  384. [section:contact Contact]
  385. [libname] is authored and maintained by Barrett Adair.
  386. Comments, feedback, bug reports, and questions are appreciated, which can be submitted in the following ways:
  387. * Open a new issue [@https://github.com/boostorg/callable_traits/issues/new] on GitHub
  388. * Send an email to barrettellisadair
  389. * ...at gmail.com
  390. [endsect][/section:contact]
  391. [section:acknowledgements Acknowledgements]
  392. Credit to Tobias Schwinger for authoring the influential [function_types_link].
  393. Thanks to the following people for their reviews and feedback:
  394. * Bruno Dutra
  395. * Edward Diener
  396. * Emil Dotchevski
  397. * Gavin Lambert
  398. * Jason Rice
  399. * John Fletcher
  400. * Klemens Morgenstern
  401. * Niall Douglas
  402. * Paul Fultz II
  403. * Peter Dimov
  404. * Tim Song
  405. * Zach Laine
  406. Special thanks to...
  407. * Louis Dionne, for the significant time and effort spent as the Boost review manager, and for introducing me to the exciting world of Boost development.
  408. * The Harding University Computer Science Department, for the all of the challenging instruction, inspiration, and mentorship (especially to Dr. Dana Steil, for teaching me the joy of C++)
  409. * My family, for the support and encouragement during the development of this library, and for so much more.
  410. [endsect][/section:acknowledgements]