123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- #ifndef BOOST_HOF_GUARD_RESULT_H
- #define BOOST_HOF_GUARD_RESULT_H
- #include <boost/hof/detail/callable_base.hpp>
- #include <boost/hof/is_invocable.hpp>
- #include <boost/hof/always.hpp>
- #include <boost/hof/reveal.hpp>
- namespace boost { namespace hof {
- template<class Result, class F>
- struct result_adaptor : detail::callable_base<F>
- {
- BOOST_HOF_INHERIT_CONSTRUCTOR(result_adaptor, detail::callable_base<F>)
- typedef Result result_type;
- struct failure
- : failure_for<detail::callable_base<F>>
- {};
- template<class... Ts>
- constexpr const detail::callable_base<F>& base_function(Ts&&... xs) const
- {
- return boost::hof::always_ref(*this)(xs...);
- }
- template<class... Ts, class=typename std::enable_if<(boost::hof::is_invocable<F, Ts...>::value)>::type>
- constexpr result_type operator()(Ts&&... xs) const
- {
- return this->base_function(xs...)(BOOST_HOF_FORWARD(Ts)(xs)...);
- };
- };
- template<class F>
- struct result_adaptor<void, F> : detail::callable_base<F>
- {
- BOOST_HOF_INHERIT_CONSTRUCTOR(result_adaptor, detail::callable_base<F>)
- typedef void result_type;
- template<class... Ts>
- constexpr const detail::callable_base<F>& base_function(Ts&&... xs) const
- {
- return boost::hof::always_ref(*this)(xs...);
- }
- template<class... Ts, class=typename std::enable_if<(boost::hof::is_invocable<F, Ts...>::value)>::type>
- constexpr typename detail::holder<Ts...>::type operator()(Ts&&... xs) const
- {
- return (typename detail::holder<Ts...>::type)this->base_function(xs...)(BOOST_HOF_FORWARD(Ts)(xs)...);
- };
- };
- #if BOOST_HOF_HAS_VARIABLE_TEMPLATES
- namespace result_detail {
- template<class Result>
- struct result_f
- {
- template<class F>
- constexpr result_adaptor<Result, F> operator()(F f) const
- {
- return result_adaptor<Result, F>(boost::hof::move(f));
- }
- };
- }
- template<class Result>
- static constexpr auto result = result_detail::result_f<Result>{};
- #else
- template<class Result, class F>
- constexpr result_adaptor<Result, F> result(F f)
- {
- return result_adaptor<Result, F>(boost::hof::move(f));
- }
- #endif
- }}
- #endif
|