|
Boost Users : |
Subject: [Boost-users] Proto: extending the example mixed.cpp
From: Kim Kuen Tang (kuentang_at_[hidden])
Date: 2008-12-11 16:09:31
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?
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