File indexing completed on 2025-01-18 09:38:02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_EVAL_HPP
0011 #define BOOST_HANA_EVAL_HPP
0012
0013 #include <boost/hana/fwd/eval.hpp>
0014
0015 #include <boost/hana/config.hpp>
0016 #include <boost/hana/core/dispatch.hpp>
0017 #include <boost/hana/detail/wrong.hpp>
0018 #include <boost/hana/functional/id.hpp>
0019
0020
0021 namespace boost { namespace hana {
0022
0023 template <typename Expr>
0024 constexpr decltype(auto) eval_t::operator()(Expr&& expr) const {
0025 return eval_impl<typename hana::tag_of<Expr>::type>::apply(
0026 static_cast<Expr&&>(expr)
0027 );
0028 }
0029
0030
0031 template <typename T, bool condition>
0032 struct eval_impl<T, when<condition>> : default_ {
0033 template <typename Expr>
0034 static constexpr auto eval_helper(Expr&& expr, int)
0035 -> decltype(static_cast<Expr&&>(expr)())
0036 { return static_cast<Expr&&>(expr)(); }
0037
0038 template <typename Expr>
0039 static constexpr auto eval_helper(Expr&& expr, long)
0040 -> decltype(static_cast<Expr&&>(expr)(hana::id))
0041 { return static_cast<Expr&&>(expr)(hana::id); }
0042
0043 template <typename Expr>
0044 static constexpr auto eval_helper(Expr&&, ...) {
0045 static_assert(detail::wrong<Expr>{},
0046 "hana::eval(expr) requires the expression to be a hana::lazy, "
0047 "a nullary Callable or a unary Callable that may be "
0048 "called with hana::id");
0049 }
0050
0051 template <typename Expr>
0052 static constexpr decltype(auto) apply(Expr&& expr)
0053 { return eval_helper(static_cast<Expr&&>(expr), int{}); }
0054 };
0055 }}
0056
0057 #endif