|
||||
File indexing completed on 2025-01-18 09:38:15
0001 /*============================================================================= 0002 Copyright (c) 2015 Paul Fultz II 0003 eval.h 0004 Distributed under the Boost Software License, Version 1.0. (See accompanying 0005 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 0006 ==============================================================================*/ 0007 0008 #ifndef BOOST_HOF_GUARD_EVAL_H 0009 #define BOOST_HOF_GUARD_EVAL_H 0010 0011 /// eval 0012 /// ==== 0013 /// 0014 /// Description 0015 /// ----------- 0016 /// 0017 /// The `eval` function will evaluate a "thunk". This can be either a nullary 0018 /// function or it can be a unary function that takes the identity function as 0019 /// the first parameter(which is helpful to delay compile-time checking). 0020 /// Also, additional parameters can be passed to `eval` to delay 0021 /// compiliation(so that result can depend on template parameters). 0022 /// 0023 /// Synopsis 0024 /// -------- 0025 /// 0026 /// template<class F, class... Ts> 0027 /// constexpr auto eval(F&& f, Ts&&...); 0028 /// 0029 /// Requirements 0030 /// ------------ 0031 /// 0032 /// F must be: 0033 /// 0034 /// * [EvaluatableFunctionObject](EvaluatableFunctionObject) 0035 /// 0036 /// Example 0037 /// ------- 0038 /// 0039 /// #include <boost/hof.hpp> 0040 /// #include <cassert> 0041 /// 0042 /// int main() { 0043 /// assert(boost::hof::eval([]{ return 3; }) == 3); 0044 /// } 0045 /// 0046 /// References 0047 /// ---------- 0048 /// 0049 /// * [POO51](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0051r2.pdf) - Proposal for C++ 0050 /// Proposal for C++ generic overload function 0051 /// * [static_if](static_if) 0052 /// * [Ordering evaluation of arguments](<Ordering evaluation of arguments>) 0053 /// 0054 0055 #include <boost/hof/always.hpp> 0056 #include <boost/hof/identity.hpp> 0057 #include <boost/hof/first_of.hpp> 0058 #include <boost/hof/detail/result_of.hpp> 0059 0060 namespace boost { namespace hof { 0061 0062 namespace detail { 0063 0064 struct simple_eval 0065 { 0066 template<class F, class... Ts> 0067 constexpr BOOST_HOF_SFINAE_RESULT(F) 0068 operator()(F&& f, Ts&&...xs) const BOOST_HOF_SFINAE_RETURNS 0069 (boost::hof::always_ref(f)(xs...)()); 0070 }; 0071 0072 struct id_eval 0073 { 0074 template<class F, class... Ts> 0075 constexpr BOOST_HOF_SFINAE_RESULT(F, id_<decltype(boost::hof::identity)>) 0076 operator()(F&& f, Ts&&...xs) const BOOST_HOF_SFINAE_RETURNS 0077 (boost::hof::always_ref(f)(xs...)(boost::hof::identity)); 0078 }; 0079 0080 } 0081 0082 BOOST_HOF_DECLARE_STATIC_VAR(eval, boost::hof::first_of_adaptor<detail::simple_eval, detail::id_eval>); 0083 0084 }} // namespace boost::hof 0085 0086 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |