callable_base.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*=============================================================================
  2. Copyright (c) 2015 Paul Fultz II
  3. callable_base.h
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #ifndef BOOST_HOF_GUARD_CALLABLE_BASE_H
  8. #define BOOST_HOF_GUARD_CALLABLE_BASE_H
  9. #include <boost/hof/detail/delegate.hpp>
  10. #include <boost/hof/detail/result_of.hpp>
  11. #include <boost/hof/apply.hpp>
  12. #ifndef BOOST_HOF_CALLABLE_BASE_USE_TEMPLATE_ALIAS
  13. #if (defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7)
  14. #define BOOST_HOF_CALLABLE_BASE_USE_TEMPLATE_ALIAS 0
  15. #else
  16. #define BOOST_HOF_CALLABLE_BASE_USE_TEMPLATE_ALIAS 1
  17. #endif
  18. #endif
  19. namespace boost { namespace hof { namespace detail {
  20. template<class F>
  21. struct non_class_function
  22. {
  23. F f;
  24. BOOST_HOF_DELEGATE_CONSTRUCTOR(non_class_function, F, f)
  25. template<class... Ts>
  26. constexpr BOOST_HOF_SFINAE_RESULT(apply_f, id_<F>, id_<Ts>...)
  27. operator()(Ts&&... xs) const BOOST_HOF_SFINAE_RETURNS
  28. (
  29. boost::hof::apply(f, BOOST_HOF_FORWARD(Ts)(xs)...)
  30. );
  31. };
  32. template<class F>
  33. struct callable_base_type
  34. : std::conditional<(BOOST_HOF_IS_CLASS(F) && !BOOST_HOF_IS_FINAL(F) && !BOOST_HOF_IS_POLYMORPHIC(F)), F, non_class_function<F>>
  35. {};
  36. #if BOOST_HOF_CALLABLE_BASE_USE_TEMPLATE_ALIAS
  37. template<class F>
  38. using callable_base = typename callable_base_type<F>::type;
  39. #else
  40. template<class F>
  41. struct callable_base
  42. : callable_base_type<F>::type
  43. {
  44. typedef typename callable_base_type<F>::type base;
  45. BOOST_HOF_INHERIT_CONSTRUCTOR(callable_base, base)
  46. };
  47. template<class F>
  48. struct callable_base_type<callable_base<F>>
  49. : callable_base_type<F>
  50. {};
  51. #endif
  52. }}} // namespace boost::hof
  53. #endif