22 Sep 08:02
[fusion] Short-circuited Exception-based View Iteration
From: Dean Michael Berris <mikhailberis <at> gmail.com>
Subject: [fusion] Short-circuited Exception-based View Iteration
Newsgroups: gmane.comp.parsers.spirit.devel, gmane.comp.lib.boost.devel
Date: 2007-09-22 06:06:23 GMT
Subject: [fusion] Short-circuited Exception-based View Iteration
Newsgroups: gmane.comp.parsers.spirit.devel, gmane.comp.lib.boost.devel
Date: 2007-09-22 06:06:23 GMT
Hi Everyone,
I'm not sure if the title makes sense, but I have a problem which can
be solved with a handful of preprocessor macros, but would like to see
solved with Fusion.
Let's say I have a vector of values:
fusion::vector<int, int, int, int> ints(0, 1, 2, 3);
I then have a function such as:
struct function {
void operator()(int value) {
if (value < 2)
throw runtime_error("less than 3");
cout << value << endl;
};
};
Would there be a way for me to iterate through every element of 'ints'
and apply the function object instance to each element, and stop the
iteration only when function does not throw?
I know using exceptions for control flow is pretty frowned upon, and I
can certainly use it the other way around -- to short-circuit the
iteration only when it throws.
If you're interested in the use case for this particular question, I'm
looking for a way to make the dispatcher library I'm working on
(Continue reading)
).
The former would be 'count_if'.
Regards,
Tobias
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
RSS Feed