Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:43:51

0001 /*=============================================================================
0002     Copyright (c) 2014 Paul Fultz II
0003     protect.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_FUNCTION_PROTECT_H
0009 #define BOOST_HOF_GUARD_FUNCTION_PROTECT_H
0010 
0011 /// protect
0012 /// =======
0013 /// 
0014 /// Description
0015 /// -----------
0016 /// 
0017 /// The `protect` function adaptor can be used to make a bind expression be
0018 /// treated as a normal function instead. Both `bind` and
0019 /// [`lazy`](/include/boost/hof/lazy) eargerly evaluates nested bind expressions.
0020 /// The `protect` adaptor masks the type so `bind` or
0021 /// [`lazy`](/include/boost/hof/lazy) no longer recognizes the function as bind
0022 /// expression and evaluates it.
0023 /// 
0024 /// Synopsis
0025 /// --------
0026 /// 
0027 ///     template<class F>
0028 ///     constexpr protect_adaptor<F> protect(F f);
0029 /// 
0030 /// Semantics
0031 /// ---------
0032 /// 
0033 ///     assert(lazy(f)(protect(lazy(g)(_1)))() == f(lazy(g)(_1)))
0034 /// 
0035 /// Requirements
0036 /// ------------
0037 /// 
0038 /// F must be:
0039 /// 
0040 /// * [ConstInvocable](ConstInvocable)
0041 /// * MoveConstructible
0042 /// 
0043 /// Example
0044 /// -------
0045 /// 
0046 ///     #include <boost/hof.hpp>
0047 ///     #include <cassert>
0048 ///     using namespace boost::hof;
0049 /// 
0050 ///     int main() {
0051 ///         auto lazy_id = lazy(identity)(_1);
0052 ///         auto lazy_apply = lazy(apply)(protect(lazy_id), _1);
0053 ///         assert(lazy_apply(3) == 3);
0054 ///     }
0055 /// 
0056 /// See Also
0057 /// --------
0058 /// 
0059 /// * [lazy](lazy)
0060 /// 
0061 
0062 #include <utility>
0063 #include <boost/hof/reveal.hpp>
0064 #include <boost/hof/detail/forward.hpp>
0065 #include <boost/hof/detail/make.hpp>
0066 #include <boost/hof/detail/static_const_var.hpp>
0067 
0068 namespace boost { namespace hof {
0069 
0070 template<class F>
0071 struct protect_adaptor : detail::callable_base<F>
0072 {
0073     typedef protect_adaptor fit_rewritable1_tag;
0074     BOOST_HOF_INHERIT_CONSTRUCTOR(protect_adaptor, detail::callable_base<F>)
0075 };
0076 
0077 BOOST_HOF_DECLARE_STATIC_VAR(protect, detail::make<protect_adaptor>);
0078 
0079 }} // namespace boost::hof
0080 #endif