Proto: extending the example mixed.cpp

Hi all, i wnat to extend the example in the file mixed.cpp with an operator[]: double operator []( std::ptrdiff_t i ) const { DereferenceCtx const deref = {}; AdvanceCtx adctx(i); //just shift the iterator with std::advance typename boost::result_of<Begin(Expr const &)>::type expr2 = Begin()(*this); proto::eval(expr2,adctx); return proto::eval(expr2, deref); } This works well. However is it possible to let proto figure out what the result_type of this function is? I've tried to program in this way. typedef typename boost::result_of<Begin(Expr const &)>::type Expr2; typedef typename proto::result_of::eval<Expr,DereferenceCtx>::type result_type; result_type operator []( std::ptrdiff_t i ) const { DereferenceCtx const deref = {}; AdvanceCtx adctx(i); Expr2 expr2 = Begin()(*this); proto::eval(expr2,adctx); return proto::eval(expr2, deref); } But the compiler complained that the nested struct eval in the struct struct DereferenceCtx { template<typename Expr, typename EnableIf = void> struct eval : proto::default_eval<Expr, DereferenceCtx const> {}; cannot be instantiated by this particulat template. So I guess I ' ve to write a grammar for this issue. Is this true?

Kim Kuen Tang wrote:
Hi all,
i wnat to extend the example in the file mixed.cpp with an operator[]:
double operator []( std::ptrdiff_t i ) const { DereferenceCtx const deref = {}; AdvanceCtx adctx(i); //just shift the iterator with std::advance typename boost::result_of<Begin(Expr const &)>::type expr2 = Begin()(*this); proto::eval(expr2,adctx); return proto::eval(expr2, deref); } This works well.
However is it possible to let proto figure out what the result_type of this function is?
I've tried to program in this way.
typedef typename boost::result_of<Begin(Expr const &)>::type Expr2; typedef typename proto::result_of::eval<Expr,DereferenceCtx>::type <snip>
You probably need something like this: typedef typename boost::remove_reference< typename boost::result_of<Begin(Expr const &)>::type >::type Expr2; typedef typename proto::result_of::eval<Expr2, DereferenceCtx>::type result_type; HTH, -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (2)
-
Eric Niebler
-
Kim Kuen Tang