Boost logo

Boost Users :

Subject: Re: [Boost-users] [Proto] callable_context
From: Hossein Haeri (powerprogman_at_[hidden])
Date: 2011-01-05 10:31:41


Dear Erik,

> > lit(1) >> &f >> &g >> &h
> >
> > So, what about this new one in Proto?
>
> Yes, that should be doable.

OK, that's good news. Here is my attempt to get it done (assuming that we only pipe integers into series of functions):

struct FuncStreamCtx: callable_context<const FuncStreamCtx>
{
        FuncStreamCtx() {}

        typedef int result_type;

        int operator () (tag::terminal, int i) const {return i;}

        template<typename L, typename R>
        int operator () (tag::shift_right, const L& l, const R& r) const
        {
                int arg = eval<L, const FuncStreamCtx>(l, *this);//***
                int (*f) (int) = value(r);
                return f(arg);
        }
};

(I know you told me that contexts make life hard. But, I'm not still comfortable with transforms...)

Now, when I try to compile this code (GCC 4.5.1, MinGW32, WinXP, SP3), I get the error in the P.S. for trying it with:

cout << eval(lit(51) >> &plus2, ctx);

>From what I understand, from line ***, GCC mistakenly thinks that I'm trying to instantiate eval<> and fails to find an appropriate ctor -- it only nags about finding the default and the copy one. Strangely enough, when I remove the template arguments from the same line, I get:

error: missing template arguments before '(' token

Any ideas?

TIA,
--Hossein

P.S.

-------------- Build: Debug in ProtoGame3 ---------------

Compiling: main.cpp
D:\My Documents\My Programmes\Tutorial\Proto\ProtoGame3\main.cpp: In member function 'int FuncStreamCtx::operator()(boost::proto::tag::shift_right, const L&, const R&) const [with L = boost::proto::utility::literal<const int&, boost::proto::domainns_::default_domain>, R = boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<int (* const&)(int)>, 0l>]':
D:\Sources\Boost\boost_1_42_0/boost/proto/context/callable.hpp:313:21: instantiated from 'boost::proto::context::callable_eval<Expr, Context, 2l>::result_type boost::proto::context::callable_eval<Expr, Context, 2l>::operator()(Expr&, Context&) const [with Expr = const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<const boost::proto::utility::literal<const int&, boost::proto::domainns_::default_domain>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<int (* const&)(int)>, 0l> >, 2l>, Context = const FuncStreamCtx, boost::proto::context::callable_eval<Expr, Context, 2l>::result_type = int]'
D:\Sources\Boost\boost_1_42_0/boost/proto/eval.hpp:100:62: instantiated from 'typename boost::proto::result_of::eval<Expr, Context>::type boost::proto::eval(Expr&, const Context&) [with Expr = const boost::proto::exprns_::expr<boost::proto::tag::shift_right, boost::proto::argsns_::list2<const boost::proto::utility::literal<const int&, boost::proto::domainns_::default_domain>&, boost::proto::exprns_::expr<boost::proto::tag::terminal, boost::proto::argsns_::term<int (* const&)(int)>, 0l> >, 2l>, Context = FuncStreamCtx, typename boost::proto::result_of::eval<Expr, Context>::type = int]'
D:\My Documents\My Programmes\Tutorial\Proto\ProtoGame3\main.cpp:38:37: instantiated from here
D:\My Documents\My Programmes\Tutorial\Proto\ProtoGame3\main.cpp:23:50: error: no matching function for call to 'boost::proto::context::callable_context<const FuncStreamCtx>::eval<boost::proto::utility::literal<const int&, boost::proto::domainns_::default_domain> >::eval(const boost::proto::utility::literal<const int&, boost::proto::domainns_::default_domain>&, const FuncStreamCtx&)'
D:\Sources\Boost\boost_1_42_0/boost/proto/context/callable.hpp:223:17: note: candidates are: boost::proto::context::callable_context<const FuncStreamCtx>::eval<boost::proto::utility::literal<const int&, boost::proto::domainns_::default_domain> >::eval()
D:\Sources\Boost\boost_1_42_0/boost/proto/context/callable.hpp:223:17: note: boost::proto::context::callable_context<const FuncStreamCtx>::eval<boost::proto::utility::literal<const int&, boost::proto::domainns_::default_domain> >::eval(const boost::proto::context::callable_context<const FuncStreamCtx>::eval<boost::proto::utility::literal<const int&, boost::proto::domainns_::default_domain> >&)
Process terminated with status 1 (0 minutes, 19 seconds)
3 errors, 0 warnings
 


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