3 Defines `boost::hana::eval`.
5 @copyright Louis Dionne 2013-2017
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
10 #ifndef BOOST_HANA_EVAL_HPP
11 #define BOOST_HANA_EVAL_HPP
13 #include <boost/hana/fwd/eval.hpp>
15 #include <boost/hana/config.hpp>
16 #include <boost/hana/core/dispatch.hpp>
17 #include <boost/hana/detail/wrong.hpp>
18 #include <boost/hana/functional/id.hpp>
21 BOOST_HANA_NAMESPACE_BEGIN
23 template <typename Expr>
24 constexpr decltype(auto) eval_t::operator()(Expr&& expr) const {
25 return eval_impl<typename hana::tag_of<Expr>::type>::apply(
26 static_cast<Expr&&>(expr)
31 template <typename T, bool condition>
32 struct eval_impl<T, when<condition>> : default_ {
33 template <typename Expr>
34 static constexpr auto eval_helper(Expr&& expr, int)
35 -> decltype(static_cast<Expr&&>(expr)())
36 { return static_cast<Expr&&>(expr)(); }
38 template <typename Expr>
39 static constexpr auto eval_helper(Expr&& expr, long)
40 -> decltype(static_cast<Expr&&>(expr)(hana::id))
41 { return static_cast<Expr&&>(expr)(hana::id); }
43 template <typename Expr>
44 static constexpr auto eval_helper(Expr&&, ...) {
45 static_assert(detail::wrong<Expr>{},
46 "hana::eval(expr) requires the expression to be a hana::lazy, "
47 "a nullary Callable or a unary Callable that may be "
48 "called with hana::id");
51 template <typename Expr>
52 static constexpr decltype(auto) apply(Expr&& expr)
53 { return eval_helper(static_cast<Expr&&>(expr), int{}); }
55 BOOST_HANA_NAMESPACE_END
57 #endif // !BOOST_HANA_EVAL_HPP