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