]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Forward declares `boost::hana::eval`. | |
4 | ||
b32b8144 | 5 | @copyright Louis Dionne 2013-2017 |
7c673cae FG |
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) | |
8 | */ | |
9 | ||
10 | #ifndef BOOST_HANA_FWD_EVAL_HPP | |
11 | #define BOOST_HANA_FWD_EVAL_HPP | |
12 | ||
13 | #include <boost/hana/config.hpp> | |
14 | #include <boost/hana/core/when.hpp> | |
15 | ||
16 | ||
17 | BOOST_HANA_NAMESPACE_BEGIN | |
18 | //! Evaluate a lazy value and return it. | |
19 | //! @relates hana::lazy | |
20 | //! | |
21 | //! Given a lazy expression `expr`, `eval` evaluates `expr` and returns | |
22 | //! the result as a normal value. However, for convenience, `eval` can | |
23 | //! also be used with nullary and unary function objects. Specifically, | |
24 | //! if `expr` is not a `hana::lazy`, it is called with no arguments at | |
25 | //! all and the result of that call (`expr()`) is returned. Otherwise, | |
26 | //! if `expr()` is ill-formed, then `expr(hana::id)` is returned instead. | |
27 | //! If that expression is ill-formed, then a compile-time error is | |
28 | //! triggered. | |
29 | //! | |
30 | //! The reason for allowing nullary callables in `eval` is because this | |
31 | //! allows using nullary lambdas as lazy branches to `eval_if`, which | |
32 | //! is convenient. The reason for allowing unary callables and calling | |
33 | //! them with `hana::id` is because this allows deferring the | |
34 | //! compile-time evaluation of selected expressions inside the callable. | |
35 | //! How this can be achieved is documented by `hana::eval_if`. | |
36 | //! | |
37 | //! | |
38 | //! Example | |
39 | //! ------- | |
40 | //! @include example/eval.cpp | |
41 | #ifdef BOOST_HANA_DOXYGEN_INVOKED | |
42 | constexpr auto eval = [](auto&& see_documentation) -> decltype(auto) { | |
43 | return tag-dispatched; | |
44 | }; | |
45 | #else | |
46 | template <typename T, typename = void> | |
47 | struct eval_impl : eval_impl<T, when<true>> { }; | |
48 | ||
49 | struct eval_t { | |
50 | template <typename Expr> | |
51 | constexpr decltype(auto) operator()(Expr&& expr) const; | |
52 | }; | |
53 | ||
54 | constexpr eval_t eval{}; | |
55 | #endif | |
56 | BOOST_HANA_NAMESPACE_END | |
57 | ||
58 | #endif // !BOOST_HANA_FWD_EVAL_HPP |