parameter_index_helper.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef BOOST_CLBL_TRTS_PARAMETER_INDEX_HELPER_HPP
  2. #define BOOST_CLBL_TRTS_PARAMETER_INDEX_HELPER_HPP
  3. #include <boost/callable_traits/detail/config.hpp>
  4. namespace boost { namespace callable_traits { namespace detail {
  5. template<std::size_t I, typename T, bool IgnoreThisPointer = false,
  6. bool AllowPlus1 = false, std::size_t Count = 0>
  7. struct parameter_index_helper {
  8. using error_t = error_type<T>;
  9. using args_tuple = typename std::conditional<IgnoreThisPointer,
  10. typename detail::traits<T>::non_invoke_arg_types,
  11. typename detail::traits<T>::arg_types>::type;
  12. static constexpr bool has_parameter_list =
  13. !std::is_same<args_tuple, invalid_type>::value
  14. && !std::is_same<args_tuple, reference_error>::value;
  15. using temp_tuple = typename std::conditional<has_parameter_list,
  16. args_tuple, std::tuple<error_t>>::type;
  17. static constexpr std::size_t parameter_list_size =
  18. std::tuple_size<temp_tuple>::value;
  19. static constexpr bool is_out_of_range = has_parameter_list &&
  20. I >= parameter_list_size + static_cast<std::size_t>(AllowPlus1);
  21. static constexpr bool is_count_out_of_range = has_parameter_list &&
  22. I + Count > parameter_list_size + static_cast<std::size_t>(AllowPlus1);
  23. static constexpr std::size_t index =
  24. has_parameter_list && !is_out_of_range ? I : 0;
  25. static constexpr std::size_t count =
  26. has_parameter_list && !is_count_out_of_range ? Count : 0;
  27. using permissive_tuple = typename std::conditional<
  28. has_parameter_list && !is_out_of_range,
  29. args_tuple, std::tuple<error_t>>::type;
  30. using permissive_function = typename std::conditional<
  31. has_parameter_list && !is_out_of_range,
  32. T, error_t(error_t)>::type;
  33. };
  34. }}} // namespace boost::callable_traits::detail
  35. #endif // #ifndef BOOST_CLBL_TRTS_PARAMETER_INDEX_HELPER_HPP