| Home | Libraries | People | FAQ | More

## Struct template protect

boost::proto::protect — A PrimitiveTransform which prevents another PrimitiveTransform from being applied in an ObjectTransform.

## Synopsis

    template<typename PrimitiveTransform>
    struct protect :  proto::transform< protect<PrimitiveTransform> > {
      template<typename , typename , typename >
      struct impl {
        // types
        typedef PrimitiveTransform result_type;
      };
    };

## Description

When building higher order transforms with `proto::make<>` or `proto::lazy<>` , you sometimes would like to build types that are parameterized with Proto transforms. In such lambda-style transforms, Proto will unhelpfully find all nested transforms and apply them, even if you don't want them to be applied. Consider the following transform, which will replace the `proto::_` in `Bar<proto::_>()` with `proto::terminal<int>::type`:

    template<typename T>
    struct Bar
    {};

    struct Foo :
      proto::when<_, Bar<_>() >
    {};

    proto::terminal<int>::type i = {0};

    int main() {
      Foo()(i);
      std::cout << typeid(Foo()(i)).name() << std::endl;
    }

If you actually wanted to default-construct an object of type `Bar<_>`, you would have to protect the `_` to prevent it from being applied. You can use `proto::protect<>` as follows:

    // OK: replace anything with Bar<_>()
    struct Foo :
      proto::when<_, Bar<protect<_> >() >
    {};