forward_declarations.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef BOOST_CLBL_TRTS_DETAIL_FORWARD_DECLARATIONS
  2. #define BOOST_CLBL_TRTS_DETAIL_FORWARD_DECLARATIONS
  3. #include <boost/callable_traits/detail/config.hpp>
  4. #include <boost/callable_traits/detail/default_callable_traits.hpp>
  5. namespace boost { namespace callable_traits { namespace detail {
  6. template<typename T>
  7. struct function;
  8. template<typename T>
  9. struct has_normal_call_operator
  10. {
  11. template<typename N, N Value>
  12. struct check { check(std::nullptr_t) {} };
  13. template<typename U>
  14. static std::int8_t test(
  15. check<decltype(&U::operator()), &U::operator()>);
  16. template<typename>
  17. static std::int16_t test(...);
  18. static constexpr bool value =
  19. sizeof(test<T>(nullptr)) == sizeof(std::int8_t);
  20. };
  21. struct callable_dummy {
  22. void operator()() {}
  23. };
  24. template<typename T>
  25. using default_to_function_object = typename std::conditional<
  26. has_normal_call_operator<T>::value,
  27. T, callable_dummy>::type;
  28. template<typename T>
  29. struct pmf;
  30. template<typename T>
  31. struct pmd;
  32. template<typename F, typename T = typename std::remove_reference<F>::type>
  33. using function_object_base = typename std::conditional<
  34. has_normal_call_operator<T>::value,
  35. pmf<decltype(&default_to_function_object<T>::operator())>,
  36. default_callable_traits<T>>::type;
  37. template<typename T, typename Base = function_object_base<T>>
  38. struct function_object;
  39. }}} // namespace boost::callable_traits::detail
  40. #endif // #ifndef BOOST_CLBL_TRTS_DETAIL_FORWARD_DECLARATIONS