[Proto] callable_context

Dear all,
I am trying to use callable_contexts to evaluate expressions like:
x >> f >> g >> h;
where this would be equivalent to h(g(f(x))). I have derived my context from callable_context, and thought I have overloaded for relevant tags (terminal and shift_right). GCC 4.5.1 (MinGW32, WinXP, SP3) stops with an error message which is cryptic to my current level of knowledge about Proto. I guess that's because I haven't done the job correctely. For your reference, I have included a copy of my program as well as the error GCC gives me in the P.S. section of this posting. Any ideas please?
TIA,
--Hossein
P.S.
<code>
#include <iostream>
#include
{};
struct EmtDomain: proto::domain

Joel,
Better use transform than context, far more easy and flexible.
OK, but my insight into Proto is not enough for that yet. Furthermore, my current application seems to be much less complex than transforms. Now, is there anything you can spot in my code which can fix the problem mentioned? TIA, --Hossein

On 12/10/2010 11:57 AM, Hossein Haeri wrote:
Dear all,
I am trying to use callable_contexts to evaluate expressions like:
x >> f >> g >> h;
where this would be equivalent to h(g(f(x))). I have derived my context from callable_context, and thought I have overloaded for relevant tags (terminal and shift_right). GCC 4.5.1 (MinGW32, WinXP, SP3) stops with an error message which is cryptic to my current level of knowledge about Proto. I guess that's because I haven't done the job correctely. For your reference, I have included a copy of my program as well as the error GCC gives me in the P.S. section of this posting. Any ideas please?
Contexts make life harder, and I hope to deprecate them in the future.
Here's what the solution looks like using transforms:
#include

Hi Erik,
struct add_one_ { typedef int result_type; int operator()(int i) const { return i + 1; } };
proto::terminal
::type const add_one = {};
This needs me to wrap every function into a function object and then instantiate that function object using an aggregate syntax. This is awkward. I need something automatic for functions.
1 >> add_one >> add_one
I need something which can work with expressions like 1 >> &f >> &g >> &h where f, g, and h are ordinary functions. Is that also doable in Proto? TIA, --Hossein

On 1/4/2011 8:10 AM, Hossein Haeri wrote:
Hi Erik,
struct add_one_ { typedef int result_type; int operator()(int i) const { return i + 1; } };
proto::terminal
::type const add_one = {}; This needs me to wrap every function into a function object and then instantiate that function object using an aggregate syntax. This is awkward. I need something automatic for functions.
1 >> add_one >> add_one
I need something which can work with expressions like
1 >> &f >> &g >> &h
where f, g, and h are ordinary functions. Is that also doable in Proto?
No. It's not doable in C++, period. There are no UDTs in the above expression, so no operator overloads are considered. And there are no built-in operators that make that well-formed. -- Eric Niebler BoostPro Computing http://www.boostpro.com

Eric,
1 >> &f >> &g >> &h
where f, g, and h are ordinary functions. Is that also doable in Proto?
No. It's not doable in C++, period. There are no UDTs in the above expression, so no operator overloads are considered.
Oops! OK, I meant something like this: lit(1) >> &f >> &g >> &h So, what about this new one in Proto? TIA, --Hossein

On 1/4/2011 10:43 AM, Hossein Haeri wrote:
Eric,
1 >> &f >> &g >> &h
where f, g, and h are ordinary functions. Is that also doable in Proto?
No. It's not doable in C++, period. There are no UDTs in the above expression, so no operator overloads are considered.
Oops! OK, I meant something like this:
lit(1) >> &f >> &g >> &h
So, what about this new one in Proto?
Yes, that should be doable. -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (3)
-
Eric Niebler
-
Hossein Haeri
-
joel falcou