-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160
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
Zeljko Vrba
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
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
-----BEGIN PGP SIGNED MESSAGE-----
Hash: RIPEMD160
David Abrahams wrote:
|
| I don't understand yet. What is the difference between stage_1 and
| stage_2? Fewer arguments in stage_1?
|
exactly.
e.g. stage reading from file:
template<typename Result>
struct file_reader {
~ typedef Result result_type;
~ istream f_;
~ const std::pair
Zeljko Vrba
David Abrahams wrote: | | I don't understand yet. What is the difference between stage_1 and | stage_2? Fewer arguments in stage_1? | exactly.
e.g. stage reading from file:
template<typename Result> struct file_reader { ~ typedef Result result_type; ~ istream f_;
~ const std::pair
&operator()() { ~ static std::pair r; ~ f_.read(&r.first, sizeof(Result)); ~ r.second = f_;
<Snip> I know this must sound very fussy, but would you mind posting this material without the leading tildes? I have a hard time reading it. -- Dave Abrahams Boost Consulting www.boost-consulting.com
OK, here it is without leading ~s. It seems GPG inserts them for some
strange reason when there is leading space on the line.
David Abrahams wrote:
|
| I don't understand yet. What is the difference between stage_1 and
| stage_2? Fewer arguments in stage_1?
|
exactly.
e.g. stage reading from file:
template<typename Result>
struct file_reader {
typedef Result result_type;
istream f_;
const std::pair
Zeljko Vrba
OK, here it is without leading ~s. It seems GPG inserts them for some strange reason when there is leading space on the line.
David Abrahams wrote: | | I don't understand yet. What is the difference between stage_1 and | stage_2? Fewer arguments in stage_1? | exactly.
I'm sorry to say this, but I've spent a few minutes trying to understand what you're doing, and I still don't get it. I can't afford to invest a great deal of volunteer time in a general question like this one. If you can condense it into a simple statement, I'm willing to try again, but otherwise I'm not sure I can help you. -- Dave Abrahams Boost Consulting www.boost-consulting.com
-----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 David Abrahams wrote: | | like this one. If you can condense it into a simple statement, I'm | willing to try again, but otherwise I'm not sure I can help you. | Think UNIX pipelines: ls -l | sort | gzip > /tmp/blah 1 stage == one operation over the data. ls is provider fo sort which is provider to gzip. i want to mimick the same in C++. each stage consumes data until its provider has some, does some processing on the data and feeds the result to its consumer (but only when its consumer asks it to provide the data - - the model is consumer-driven). but I need more powerful semantic: each stage can have more than one input, it can feed its output to more than one stage and types on input and output may differ. is it a bit clearer now? -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.1 (FreeBSD) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCzA0CFtofFpCIfhMRA7SXAJ9d1F+/LqYid5ZCmv5T0AuAmTaGFQCfeR1F YIuUU/GYzfe1Ny8V77dBJ94= =Yz7J -----END PGP SIGNATURE-----
Zeljko Vrba
David Abrahams wrote: | | like this one. If you can condense it into a simple statement, I'm | willing to try again, but otherwise I'm not sure I can help you. | Think UNIX pipelines: ls -l | sort | gzip > /tmp/blah
1 stage == one operation over the data. ls is provider fo sort which is provider to gzip.
i want to mimick the same in C++. each stage consumes data until its provider has some, does some processing on the data and feeds the result to its consumer (but only when its consumer asks it to provide the data - the model is consumer-driven).
but I need more powerful semantic: each stage can have more than one input, it can feed its output to more than one stage and types on input and output may differ.
is it a bit clearer now?
Seems like you want to build a dataflow machine at compile-time. It's a nontrivial problem because, among other things -- since you may have multiple consumers for any piece of data -- you have to buffer results. There aren't any simple answers, AFAICT. If you have a specific question, I can try to answer, but solving the whole design problem is beyond my capacity in my "free" time. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Zeljko Vrba