
Hi Eric, thanks for your help. I will try to integrate this in my code. B/Rgds Kim Eric Niebler schrieb:
Deep-copying only some terminals is fundamentally unsafe. But if you really don't want to deep-copy the vector terminals, you'll need to implement your own deep-copy algorithm. It's easiest to write a grammar with transforms that does it for you. #include <vector> #include <boost/proto/proto.hpp>
namespace boost { namespace proto { // make std::vector a proto terminal extension template<typename T, typename Al> struct is_extension<std::vector<T, Al> > : mpl::true_ {}; }}
namespace proto = boost::proto; using proto::_;
// Deep-copy all terminals except vectors struct DeepCopyNotVectors : proto::or_< proto::when< proto::terminal<std::vector<_,_> > // The vector itself will be held by reference, but the // temporary proto terminal expression wrapping the // reference should be held by value. , boost::remove_const<boost::remove_reference<_> >(_) > , proto::when<proto::terminal<_>, proto::_deep_copy(_)> , proto::otherwise< proto::nary_expr<_, proto::vararg<DeepCopyNotVectors> > > > {};
int main() { using namespace proto::exops;
std::vector<int> a, b;
BOOST_AUTO(tmp0, a + b + 0.1); BOOST_AUTO(tmp1, DeepCopyNotVectors()(a + b + 0.1));
std::cout << typeid(tmp0).name() << "\n\n"; std::cout << typeid(tmp1).name() << "\n"; }
int main() { using namespace proto::exops;
std::vector<int> a, b;
BOOST_AUTO(tmp0, a + b + 0.1); BOOST_AUTO(tmp1, DeepCopyNotVectors()(a + b + 0.1));
std::cout << typeid(tmp0).name() << "\n\n"; std::cout << typeid(tmp1).name() << "\n"; }