|
|
|||
File indexing completed on 2025-12-15 09:53:03
0001 /*! 0002 @file 0003 Forward declares `boost::hana::eval`. 0004 0005 Copyright Louis Dionne 2013-2022 0006 Distributed under the Boost Software License, Version 1.0. 0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) 0008 */ 0009 0010 #ifndef BOOST_HANA_FWD_EVAL_HPP 0011 #define BOOST_HANA_FWD_EVAL_HPP 0012 0013 #include <boost/hana/config.hpp> 0014 #include <boost/hana/core/when.hpp> 0015 0016 0017 namespace boost { namespace hana { 0018 //! Evaluate a lazy value and return it. 0019 //! @relates hana::lazy 0020 //! 0021 //! Given a lazy expression `expr`, `eval` evaluates `expr` and returns 0022 //! the result as a normal value. However, for convenience, `eval` can 0023 //! also be used with nullary and unary function objects. Specifically, 0024 //! if `expr` is not a `hana::lazy`, it is called with no arguments at 0025 //! all and the result of that call (`expr()`) is returned. Otherwise, 0026 //! if `expr()` is ill-formed, then `expr(hana::id)` is returned instead. 0027 //! If that expression is ill-formed, then a compile-time error is 0028 //! triggered. 0029 //! 0030 //! The reason for allowing nullary callables in `eval` is because this 0031 //! allows using nullary lambdas as lazy branches to `eval_if`, which 0032 //! is convenient. The reason for allowing unary callables and calling 0033 //! them with `hana::id` is because this allows deferring the 0034 //! compile-time evaluation of selected expressions inside the callable. 0035 //! How this can be achieved is documented by `hana::eval_if`. 0036 //! 0037 //! 0038 //! Example 0039 //! ------- 0040 //! @include example/eval.cpp 0041 #ifdef BOOST_HANA_DOXYGEN_INVOKED 0042 constexpr auto eval = [](auto&& see_documentation) -> decltype(auto) { 0043 return tag-dispatched; 0044 }; 0045 #else 0046 template <typename T, typename = void> 0047 struct eval_impl : eval_impl<T, when<true>> { }; 0048 0049 struct eval_t { 0050 template <typename Expr> 0051 constexpr decltype(auto) operator()(Expr&& expr) const; 0052 }; 0053 0054 BOOST_HANA_INLINE_VARIABLE constexpr eval_t eval{}; 0055 #endif 0056 }} // end namespace boost::hana 0057 0058 #endif // !BOOST_HANA_FWD_EVAL_HPP
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|