Hi all,
let _o_ be any proto terminal and v a vector. I would like to extract
the vector v from the expression _o_(v) to do some modification on this
vector. For this purpose i defined a grammar Rhs to extract the most
right hand side of the tree.
But unfortunately the compiler is asking me for constness for this code:
boost::result_of::type & result = Rhs()(expr);
Whereas the expression _o_ + v compiles fine without asking me for
constness.
Am I missing something?
Best regards,
Kim
Here is the code to demonstrate the problem.
# include <vector>
# include <iostream>
# include <algorithm>
# include
namespace proto = boost::proto;
namespace mpl = boost::mpl;
using proto::_;
template<typename Expr>
struct MixedExpr;
struct MixedDomain : proto::domain {};
template<typename Expr>
struct MixedExpr : proto::extends
{
explicit MixedExpr(Expr const &expr) : proto::extends(expr) {}
};
struct oo {
friend std::ostream &operator<<(std::ostream &s, oo const&)
{
return s << "oo";
}
};
proto::terminal<oo>::type const _o_ = {{}};
template<typename T> struct IsMixed : mpl::false_ {};
template struct IsMixed > :
mpl::true_ {};
namespace MixedOps
{
BOOST_PROTO_DEFINE_OPERATORS(IsMixed,MixedDomain)
};
namespace boost { namespace proto {
template
std::ostream &operator<<(std::ostream &s, std::vector const& )
{
return s << "std::vector";
}
}}
struct Rhs : proto::or_<
proto::when, proto::_value >
,proto::when<_, Rhs(proto::_child1)>
{};
template<typename Expr>
void
o_o(Expr& expr)
{
proto::display_expr(expr);
boost::result_of::type & result = Rhs()(expr);
std::fill(result.begin(), result.end(),2);
};
int main()
{
using namespace MixedOps;
std::vector<int> u(10),v(10);
//o_o( _o_(v) ); //uncomment this won't compile
o_o( u+v );
std::copy(v.begin(),v.end(),std::ostream_iterator<int>(std::cout,",") );
std::cout<