123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- #ifndef BOOST_HOF_GUARD_FUNCTION_IMPLICIT_H
- #define BOOST_HOF_GUARD_FUNCTION_IMPLICIT_H
- #include <boost/hof/pack.hpp>
- #include <boost/hof/detail/result_of.hpp>
- namespace boost { namespace hof { namespace detail {
- template<class F, class Pack, class X, class=void>
- struct is_implicit_callable
- : std::false_type
- {};
- #if BOOST_HOF_NO_EXPRESSION_SFINAE
- template<class F, class Pack, class X>
- struct is_implicit_callable<F, Pack, X, typename std::enable_if<
- std::is_convertible<typename result_of<Pack, id_<F>>::type, X>::value
- >::type>
- : std::true_type
- {};
- #else
- template<class F, class Pack, class X>
- struct is_implicit_callable<F, Pack, X, typename std::enable_if<
- std::is_convertible<decltype(std::declval<Pack>()(std::declval<F>())), X>::value
- >::type>
- : std::true_type
- {};
- #endif
- }
- template<template <class...> class F>
- struct implicit
- {
- template<class Pack>
- struct invoker
- {
- Pack p;
- constexpr invoker(Pack pp) BOOST_HOF_NOEXCEPT_CONSTRUCTIBLE(Pack, Pack&&)
- : p(boost::hof::move(pp))
- {}
- template<class X, class=typename std::enable_if<detail::is_implicit_callable<F<X>, Pack, X>::value>::type>
- constexpr operator X() const BOOST_HOF_NOEXCEPT(noexcept(p(F<X>())))
- {
- return p(F<X>());
- }
- #if !(defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7)
- invoker (const invoker&) = delete;
- invoker& operator= (const invoker&) = delete;
- private:
- friend struct implicit;
- invoker (invoker&&) = default;
- #endif
- };
- struct make_invoker
- {
- template<class Pack>
- constexpr invoker<Pack> operator()(Pack p) const BOOST_HOF_NOEXCEPT(noexcept(invoker<Pack>(boost::hof::move(p))))
- {
- return invoker<Pack>(boost::hof::move(p));
- }
- };
- template<class... Ts>
- constexpr auto operator()(Ts&&... xs) const
- BOOST_HOF_RETURNS
- (
- BOOST_HOF_RETURNS_CONSTRUCT(make_invoker)()(boost::hof::pack_basic(BOOST_HOF_FORWARD(Ts)(xs)...))
- );
- };
- }}
- #endif
|