Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2005-07-05 11:12:20


Zeljko Vrba <zvrba_at_[hidden]> writes:

> Hi!
>
> I would like to use mpl to generate code along the following lines (I'm
> trying to build a reusable library for data processing in a 'pipelined'
> fashion):
>
> // Arg1 and Arg2 are instances of 'stages' providing results to this
> // stage. F is the function taking as arguments const Arg1::result_type&
> // and const Arg2::result_type&.
> template<typename Result, typename F, typename Arg1, typename Arg2>
> struct stage_2 {
> ~ typedef Result result_type;
>
> ~ Result current_;
> ~ F f_;
> ~ Arg1 input1_;
> ~ Arg2 input2_;
>
> ~ stage_2(F f, Arg1 a1, Arg2 a2) : f_(f), input1_(a1), input2_(a2) { }
>
> ~ const Result &operator() {
> ~ current_ = f_(input1_(), input2_());
> ~ return current_;
> ~ }
> };
>
> The question: is it possible not to write manually separate stage_0,
> stage_1, stage_2, ... for stages taking as input results from the
> previous 0, 1, 2, ... stages?

I don't understand yet. What is the difference between stage_1 and
stage_2? Fewer arguments in stage_1?

> == Actually, what I'm trying to design:
>
> S1 -> S2 -> S3 -> .. -> Sk -> ..-> Sn
> ~ \_______________/
>
> This is just a rough sketch; in the bottom line the arrow goes from S2
> to Sk. Each stage (S'es in the diagram) provides input to its
> 'children'.

Why don't you show an example using three or four handwritten
"stages;" then we can consider how the code might be generated.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com

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