...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::proto::protect — A PrimitiveTransform which prevents another PrimitiveTransform from being applied in an ObjectTransform.
// In header: <boost/proto/transform/make.hpp> template<typename PrimitiveTransform> struct protect : proto::transform< protect<PrimitiveTransform> > { // member classes/structs/unions template<typename , typename , typename > struct impl { // types typedef PrimitiveTransform result_type; }; };
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<proto::_, Bar<proto::_>() > {}; 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<proto::_>
, 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<proto::_, Bar<proto::protect<proto::_> >() > {};