args.hpp 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. @Copyright Barrett Adair 2015-2017
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  5. */
  6. #ifndef BOOST_CLBL_TRTS_ARGS_HPP
  7. #define BOOST_CLBL_TRTS_ARGS_HPP
  8. #include <boost/callable_traits/detail/core.hpp>
  9. namespace boost { namespace callable_traits {
  10. //[ args_hpp
  11. /*`[section:ref_args args]
  12. [heading Header]
  13. ``#include <boost/callable_traits/args.hpp>``
  14. [heading Definition]
  15. */
  16. template<typename T, template<class...> class Container = std::tuple>
  17. using args_t = //see below
  18. //<-
  19. detail::try_but_fail_if_invalid<
  20. typename detail::traits<
  21. detail::shallow_decay<T>>::template expand_args<Container>,
  22. cannot_expand_the_parameter_list_of_first_template_argument>;
  23. namespace detail {
  24. template<typename T, template<class...> class Container,
  25. typename = std::false_type>
  26. struct args_impl {};
  27. template<typename T, template<class...> class Container>
  28. struct args_impl <T, Container, typename std::is_same<
  29. args_t<T, Container>, detail::dummy>::type>
  30. {
  31. using type = args_t<T, Container>;
  32. };
  33. }
  34. //->
  35. template<typename T,
  36. template<class...> class Container = std::tuple>
  37. struct args : detail::args_impl<T, Container> {};
  38. //<-
  39. }} // namespace boost::callable_traits
  40. //->
  41. /*`
  42. [heading Constraints]
  43. * `T` must be one of the following:
  44. * function
  45. * function pointer
  46. * function reference
  47. * member function pointer
  48. * member data pointer
  49. * user-defined type with a non-overloaded `operator()`
  50. * type of a non-generic lambda
  51. [heading Behavior]
  52. * When the constraints are violated, a substitution failure occurs.
  53. * When `T` is a function, function pointer, or function reference, the aliased type is `Container` instantiated with the function's parameter types.
  54. * When `T` is a function object, the aliased type is `Container` instantiated with the `T::operator()` parameter types.
  55. * When `T` is a member function pointer, the aliased type is a `Container` instantiation, where the first type argument is a reference to the parent class of `T`, qualified according to the member qualifiers on `T`, such that the first type is equivalent to `boost::callable_traits::qualified_class_of_t<T>`. The subsequent type arguments, if any, are the parameter types of the member function.
  56. * When `T` is a member data pointer, the aliased type is `Container` with a single element, which is a `const` reference to the parent class of `T`.
  57. [heading Input/Output Examples]
  58. [table
  59. [[`T`] [`args_t<T>`]]
  60. [[`void(float, char, int)`] [`std::tuple<float, char, int>`]]
  61. [[`void(*)(float, char, int)`] [`std::tuple<float, char, int`]]
  62. [[`void(&)(float, char, int)`] [`std::tuple<float, char, int`]]
  63. [[`void(float, char, int) const &&`][`std::tuple<float, char, int>`]]
  64. [[`void(*)()`] [`std::tuple<>`]]
  65. [[`void(foo::* const &)(float, char, int)`] [`std::tuple<foo&, float, char, int>`]]
  66. [[`int(foo::*)(int) const`] [`std::tuple<const foo&, int>`]]
  67. [[`void(foo::*)() volatile &&`] [`std::tuple<volatile foo &&>`]]
  68. [[`int foo::*`] [`std::tuple<const foo&>`]]
  69. [[`const int foo::*`] [`std::tuple<const foo&>`]]
  70. [[`int`] [(substitution failure)]]
  71. [[`int (*const)()`] [(substitution failure)]]
  72. ]
  73. [heading Example Program]
  74. [import ../example/args.cpp]
  75. [args]
  76. [endsect]
  77. */
  78. //]
  79. #endif // #ifndef BOOST_CLBL_TRTS_ARGS_HPP