Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
Front Page / Metafunctions / Composition and Argument Binding / protect

protect

Synopsis

template<
      typename F
    >
struct protect
{
    // unspecified
    // ...
};

Description

protect is an identity wrapper for a Metafunction Class that prevents its argument from being recognized as a bind expression.

Header

#include <boost/mpl/protect.hpp>

Parameters

Parameter Requirement Description
F Metafunction Class A metafunction class to wrap.

Expression semantics

For any Metafunction Class f:

typedef protect<f> g;
Return type:

Metafunction Class.

Semantics:

If f is a bind expression, equivalent to

struct g
{
    template<
          typename U1 = unspecified,... typename Un = unspecified
        >
    struct apply
        : apply_wrapn<f,U1,...Un>
    {
    };
};

otherwise equivalent to typedef f g;.

Example

struct f
{
    template< typename T1, typename T2 > struct apply
    {
        typedef T2 type;
    };
};

typedef bind< quote3<if_>,_1,_2,bind<f,_1,_2> > b1;
typedef bind< quote3<if_>,_1,_2,protect< bind<f,_1,_2> > > b2;

typedef apply_wrap2< b1,false_,char >::type r1;
typedef apply_wrap2< b2,false_,char >::type r2;

BOOST_MPL_ASSERT(( is_same<r1,char> ));
BOOST_MPL_ASSERT(( is_same<r2,protect< bind<f,_1,_2> > > ));

See also

Composition and Argument Binding, invocation, bind, quote, apply_wrap