|
Boost Users : |
Subject: [Boost-users] [Proto] proto::function and constness
From: Kim Kuen Tang (kuentang_at_[hidden])
Date: 2009-10-11 15:36:32
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<Rhs(Expr)>::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 <boost/proto/proto.hpp>
namespace proto = boost::proto;
namespace mpl = boost::mpl;
using proto::_;
template<typename Expr>
struct MixedExpr;
struct MixedDomain : proto::domain<proto::generator<MixedExpr> > {};
template<typename Expr>
struct MixedExpr : proto::extends<Expr, MixedExpr<Expr>, MixedDomain>
{
explicit MixedExpr(Expr const &expr) : proto::extends<Expr,
MixedExpr<Expr>, MixedDomain>(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<typename T, typename A> struct IsMixed<std::vector<T, A> > :
mpl::true_ {};
namespace MixedOps
{
BOOST_PROTO_DEFINE_OPERATORS(IsMixed,MixedDomain)
};
namespace boost { namespace proto {
template<typename T, typename A>
std::ostream &operator<<(std::ostream &s, std::vector<T, A> const& )
{
return s << "std::vector";
}
}}
struct Rhs : proto::or_<
proto::when<proto::terminal<_>, proto::_value >
,proto::when<_, Rhs(proto::_child1)>
> {};
template<typename Expr>
void
o_o(Expr& expr)
{
proto::display_expr(expr);
boost::result_of<Rhs(Expr)>::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<<std::endl;
return 1;
}
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net