|
Boost Users : |
Subject: [Boost-users] [Proto] EvalStream Revisited -- Segmentation Fault
From: Hossein Haeri (powerprogman_at_[hidden])
Date: 2011-01-03 19:37:53
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<pointer_to_unary_function<int, int> >::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 <boost/proto/proto.hpp>
#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<add_one_>::type const add_one = {};
struct GetFun
: proto::call<proto::_value(proto::_right)>
{};
struct EvalStream
: proto::or_<
proto::when<
proto::terminal<_>
, proto::_value
>
, proto::when<
proto::shift_right<EvalStream, proto::terminal<_> >
, proto::lazy< GetFun(EvalStream(proto::_left)) >
>
>
{};
int main()
{
// This prints "3"
std::cout << EvalStream()( 1 >> add_one >> add_one ) << std::endl;
}
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