default_callable_traits.hpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. Copyright Barrett Adair 2016-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_DETAIL_DEFAULT_BOOST_CLBL_TRTS_HPP
  7. #define BOOST_CLBL_TRTS_DETAIL_DEFAULT_BOOST_CLBL_TRTS_HPP
  8. namespace boost { namespace callable_traits { namespace detail {
  9. template<typename T = void>
  10. struct default_callable_traits {
  11. // value is used by all traits classes to participate
  12. // in the <callable_traits/detail/traits.hpp> disjunction.
  13. static constexpr bool value = false;
  14. // used facilitate the disjunction in
  15. // <callable_traits/detail/traits.hpp>
  16. using traits = default_callable_traits;
  17. using error_t = error_type<T>;
  18. // represents the type under consideration
  19. using type = error_t;
  20. // std::true_type for callables with C-style variadics
  21. using has_varargs = std::false_type;
  22. using return_type = error_t;
  23. // arg_types is a std::tuple of argument types for
  24. // callables that are not overloaded/templated function objects.
  25. // arg_types IS defined in terms of INVOKE, which means
  26. // a PMF's arg_types tuple will use a reference to its
  27. // parent class as the first argument, with qualifiers added to
  28. // match the PMF's own qualifiers.
  29. using arg_types = error_t;
  30. // arg_types without the decltype(*this) parameter for member functions
  31. using non_invoke_arg_types = error_t;
  32. // An "approximation" of a callable type, in the form
  33. // of a plain function type. Defined in terms of INVOKE.
  34. // An identity alias for qualified/unqualified plain function
  35. // types.
  36. using function_type = error_t;
  37. // Used to smoothen the edges between PMFs and function objects
  38. using function_object_signature = error_t;
  39. // An identity alias for qualified/unqualified plain function
  40. // types. Equivalent to remove_member_pointer for PMFs. Same
  41. // as function_type for other callable types.
  42. using qualified_function_type = error_t;
  43. // Removes C-style variadics from a signature, if present.
  44. // Aliases error_t for function objects and PMDs.
  45. using remove_varargs = error_t;
  46. // Adds C-style variadics to a signature. Aliases
  47. // error_t for function objects and PMDs.
  48. using add_varargs = error_t;
  49. // std::true_type when the signature includes noexcept, when
  50. // the feature is available
  51. using is_noexcept = std::false_type;
  52. // adds noexcept to a signature if the feature is available
  53. using add_noexcept = error_t;
  54. // removes noexcept from a signature if present
  55. using remove_noexcept = error_t;
  56. // std::true_type when the signature includes transaction_safe, when
  57. // the feature is available
  58. using is_transaction_safe = std::false_type;
  59. // adds transaction_safe to a signature if the feature is available
  60. using add_transaction_safe = error_t;
  61. // removes transaction_safe from a signature if present
  62. using remove_transaction_safe = error_t;
  63. // The class of a PMD or PMF. error_t for other types
  64. using class_type = error_t;
  65. // The qualified reference type of class_type. error_t
  66. // for non-member-pointers.
  67. using invoke_type = error_t;
  68. // Removes reference qualifiers from a signature.
  69. using remove_reference = error_t;
  70. // Adds an lvalue qualifier to a signature, in arbitrary
  71. // accordance with C++11 reference collapsing rules.
  72. using add_member_lvalue_reference = error_t;
  73. // Adds an rvalue qualifier to a signature, in arbitrary
  74. // accordance with C++11 reference collapsing rules.
  75. using add_member_rvalue_reference = error_t;
  76. // Adds a const qualifier to a signature.
  77. using add_member_const = error_t;
  78. // Adds a volatile qualifier to a signature.
  79. using add_member_volatile = error_t;
  80. // Adds both const and volatile qualifiers to a signature.
  81. using add_member_cv = error_t;
  82. // Removes a const qualifier from a signature, if present.
  83. using remove_member_const = error_t;
  84. // Removes a volatile qualifier from a signature, if present.
  85. using remove_member_volatile = error_t;
  86. // Removes both const and volatile qualifiers from a
  87. // signature, if any.
  88. using remove_member_cv = error_t;
  89. // Removes the member pointer from PMDs and PMFs. An identity
  90. // alias for other callable types.
  91. using remove_member_pointer = error_t;
  92. // Changes the parent class type for PMDs and PMFs. Turns
  93. // function pointers, function references, and
  94. // qualified/unqualified function types into PMFs. Turns
  95. // everything else into member data pointers.
  96. template<typename C,
  97. typename U = T,
  98. typename K = typename std::remove_reference<U>::type,
  99. typename L = typename std::conditional<
  100. std::is_same<void, K>::value, error_t, K>::type,
  101. typename Class = typename std::conditional<
  102. std::is_class<C>::value, C, error_t>::type>
  103. using apply_member_pointer = typename std::conditional<
  104. std::is_same<L, error_t>::value || std::is_same<Class, error_t>::value,
  105. error_t, L Class::*>::type;
  106. // Changes the return type of PMFs, function pointers, function
  107. // references, and qualified/unqualified function types. Changes
  108. // the data type of PMDs. error_t for function objects.
  109. template<typename>
  110. using apply_return = error_t;
  111. // Expands the argument types into a template
  112. template<template<class...> class Container>
  113. using expand_args = error_t;
  114. template<template<class...> class Container, typename... RightArgs>
  115. using expand_args_left = error_t;
  116. template<template<class...> class Container, typename... LeftArgs>
  117. using expand_args_right = error_t;
  118. using clear_args = error_t;
  119. template<typename... NewArgs>
  120. using push_front = error_t;
  121. template<typename... NewArgs>
  122. using push_back = error_t;
  123. template<std::size_t ElementCount>
  124. using pop_front = error_t;
  125. template<std::size_t ElementCount>
  126. using pop_back = error_t;
  127. template<std::size_t Index, typename... NewArgs>
  128. using insert_args = error_t;
  129. template<std::size_t Index, std::size_t Count>
  130. using remove_args = error_t;
  131. template<std::size_t Index, typename... NewArgs>
  132. using replace_args = error_t;
  133. static constexpr qualifier_flags cv_flags = cv_of<T>::value;
  134. static constexpr qualifier_flags ref_flags = ref_of<T>::value;
  135. static constexpr qualifier_flags q_flags = cv_flags | ref_flags;
  136. using has_member_qualifiers = std::integral_constant<bool, q_flags != default_>;
  137. using is_const_member = std::integral_constant<bool, 0 < (cv_flags & const_)>;
  138. using is_volatile_member = std::integral_constant<bool, 0 < (cv_flags & volatile_)>;
  139. using is_cv_member = std::integral_constant<bool, cv_flags == (const_ | volatile_)>;
  140. #ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS
  141. using is_reference_member = std::false_type;
  142. using is_lvalue_reference_member = std::false_type;
  143. using is_rvalue_reference_member = std::false_type;
  144. #else
  145. using is_reference_member = std::integral_constant<bool, 0 < ref_flags>;
  146. using is_lvalue_reference_member = std::integral_constant<bool, ref_flags == lref_>;
  147. using is_rvalue_reference_member = std::integral_constant<bool, ref_flags == rref_>;
  148. #endif //#ifdef BOOST_CLBL_TRTS_DISABLE_REFERENCE_QUALIFIERS
  149. };
  150. }}} // namespace boost::callable_traits::detail
  151. #endif // BOOST_CLBL_TRTS_DETAIL_DEFAULT_BOOST_CLBL_TRTS_HPP