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
int operator () (tag::shift_right, const L& l, const R& r) const
{
int arg = eval(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, R = boost::proto::exprns_::expr, 0l>]':
D:\Sources\Boost\boost_1_42_0/boost/proto/context/callable.hpp:313:21: instantiated from 'boost::proto::context::callable_eval::result_type boost::proto::context::callable_eval::operator()(Expr&, Context&) const [with Expr = const boost::proto::exprns_::expr&, boost::proto::exprns_::expr, 0l> >, 2l>, Context = const FuncStreamCtx, boost::proto::context::callable_eval::result_type = int]'
D:\Sources\Boost\boost_1_42_0/boost/proto/eval.hpp:100:62: instantiated from 'typename boost::proto::result_of::eval::type boost::proto::eval(Expr&, const Context&) [with Expr = const boost::proto::exprns_::expr&, boost::proto::exprns_::expr, 0l> >, 2l>, Context = FuncStreamCtx, typename boost::proto::result_of::eval::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 >::eval(const boost::proto::utility::literal&, 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 >::eval()
D:\Sources\Boost\boost_1_42_0/boost/proto/context/callable.hpp:223:17: note: boost::proto::context::callable_context<const FuncStreamCtx>::eval >::eval(const boost::proto::context::callable_context<const FuncStreamCtx>::eval >&)
Process terminated with status 1 (0 minutes, 19 seconds)
3 errors, 0 warnings