Dear all,
A few weeks ago, I asked for help about an EDSL which can handle expressions like
x >> f >> g >> h
so that they're equivalent to h(g(f(x))) once evaluated. Eric kindly provided me with the solution in the P.S.
I was just playing around with his code and thought about extending it with a simple case when f's and g's are actually functions, as opposed to function objects. So, I added the following two lines:
int plus1(int i) {return i + 1;}
const terminal >::type plus_one = {ptr_fun(&plus1)};
And, I get a segmentation fault (GCC 4.5.1, MinGW32, WinXP, SP3) when I run the following line:
1 >> plus_one >> plus_one
Any ideas?
TIA,
--Hossein
P.S.
#include
#include <iostream>
namespace proto = boost::proto;
using proto::_;
struct add_one_ {
typedef int result_type;
int operator()(int i) const {
return i + 1;
}
};
proto::terminal::type const add_one = {};
struct GetFun
: proto::callproto::_value(proto::_right)
{};
struct EvalStream
: proto::or_<
proto::when<
proto::terminal<_>
, proto::_value
>
, proto::when<
proto::shift_right >
, proto::lazy< GetFun(EvalStream(proto::_left)) >
>
>
{};
int main()
{
// This prints "3"
std::cout << EvalStream()( 1 >> add_one >> add_one ) << std::endl;
}