Boost logo

Proto :

Subject: [proto] Nested Transforms
From: Nate Knight (Nate.Knight_at_[hidden])
Date: 2011-02-25 20:18:40

I'm trying to understand why the two commented out lines fail to compile. It seems to me
that ideally they would compile, but I may be missing some constraint that makes these
lines incorrect. In the first case, it seems like the return type of the default subscript evaluator
is being computed incorrectly. The second one is not as interesting, but I curious why it
doesn't compile.

I'm compiling against 1.45 with gcc 4.5.

Thanks for any help.

#include <boost/proto/proto.hpp>
#include <tr1/array>
#include <boost/mpl/bool.hpp>

using namespace boost::proto;

namespace la
    typedef std::tr1::array< double, 2 > state_type;

    struct Distribute:
        when<terminal<state_type>, _make_subscript(_, _state)>,
        nary_expr<_, vararg<Distribute> >
    struct Optimize:
          subscript<Distribute, terminal<_> >,
          Distribute(_left, _right)
        nary_expr<_, vararg<Optimize> >,

    // optimize and then evaluate
    struct EvalOpt: when<_, _default<>(Optimize)> {};

int main()
    la::state_type x = {1.0,2.0};
    la::state_type const& xc = x;

    // this compiles
    la::EvalOpt()( lit(x)[1] );

    // this fails to compile
    //la::EvalOpt()( lit(xc)[1] );

    // this fails to compile
    //_default<>()( la::Optimize()( boost::proto::lit(x)[1] ) );

    // this compiles
    _default<>()( as_expr( la::Optimize()( boost::proto::lit(x)[1] ) ) );

Proto list run by eric at