protect — Boost.HigherOrderFunctions 0.6 documentation

# protect

## Header

    #include <boost/hof/protect.hpp>

## Description

The `protect` function adaptor can be used to make a bind expression be treated as a normal function instead. Both `bind` and `lazy` eargerly evaluates nested bind expressions. The `protect` adaptor masks the type so `bind` or `lazy` no longer recognizes the function as bind expression and evaluates it.

## Synopsis

    template<class F>
    constexpr protect_adaptor<F> protect(F f);

## Semantics

    assert(lazy(f)(protect(lazy(g)(_1)))() == f(lazy(g)(_1)))

## Requirements

F must be:

- ConstInvocable

- MoveConstructible

## Example

    #include <boost/hof.hpp>
    #include <cassert>
    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