/*============================================================================= Copyright (c) 2014 Paul Fultz II protect.h Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ #ifndef BOOST_HOF_GUARD_FUNCTION_PROTECT_H #define BOOST_HOF_GUARD_FUNCTION_PROTECT_H /// protect /// ======= /// /// Description /// ----------- /// /// The `protect` function adaptor can be used to make a bind expression be /// treated as a normal function instead. Both `bind` and /// [`lazy`](/include/boost/hof/lazy) eargerly evaluates nested bind expressions. /// The `protect` adaptor masks the type so `bind` or /// [`lazy`](/include/boost/hof/lazy) no longer recognizes the function as bind /// expression and evaluates it. /// /// Synopsis /// -------- /// /// template /// constexpr protect_adaptor protect(F f); /// /// Semantics /// --------- /// /// assert(lazy(f)(protect(lazy(g)(_1)))() == f(lazy(g)(_1))) /// /// Requirements /// ------------ /// /// F must be: /// /// * [ConstInvocable](ConstInvocable) /// * MoveConstructible /// /// Example /// ------- /// /// #include /// #include /// using namespace boost::hof; /// /// int main() { /// auto lazy_id = lazy(identity)(_1); /// auto lazy_apply = lazy(apply)(protect(lazy_id), _1); /// assert(lazy_apply(3) == 3); /// } /// /// See Also /// -------- /// /// * [lazy](lazy) /// #include #include #include #include #include namespace boost { namespace hof { template struct protect_adaptor : detail::callable_base { typedef protect_adaptor fit_rewritable1_tag; BOOST_HOF_INHERIT_CONSTRUCTOR(protect_adaptor, detail::callable_base) }; BOOST_HOF_DECLARE_STATIC_VAR(protect, detail::make); }} // namespace boost::hof #endif