I'm looking for a transforming iterator. I've looked at the boost transform_iterator but it doesn't quite do what I want. Well, in fact it does a little too much, it passes the dereferenced base iterator to the transform function - I would like it to pass the base iterator itself. The reason being is that the transform function is to return an object containing that base iterator (the object acts much along the lines of a boost graph edge/vertex descriptor). At the moment I've cut and pasted transform_iterator.hpp, renamed it transmute_iterator.hpp and edited it to remove one char (the dereferencing *) just so as I can try things out. Oh, I am slow! I was going to ask if such an iterator could be added to boost lib but have just realised that it is trivial for a transmute_iterator to model a transform_iterator. Hmm, so my question now is - is there some reason why the base iterator is dereferenced before being passed to the function? Wouldn't it be better to let the function decide that? thanks, Louis. BTW, you guys write some really great stuff, it's very much appreciated. And C++ Template Metaprogramming is mind blowing (especially chapters 10++). -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.322 / Virus Database: 266.11.12 - Release Date: 17/05/2005
Louis Lavery
I'm looking for a transforming iterator. I've looked at the boost transform_iterator but it doesn't quite do what I want. Well, in fact it does a little too much, it passes the dereferenced base iterator to the transform function - I would like it to pass the base iterator itself. The reason being is that the transform function is to return an object containing that base iterator (the object acts much along the lines of a boost graph edge/vertex descriptor).
At the moment I've cut and pasted transform_iterator.hpp, renamed it transmute_iterator.hpp and edited it to remove one char (the dereferencing *) just so as I can try things out.
Oh, I am slow! I was going to ask if such an iterator could be added to boost lib but have just realised that it is trivial for a transmute_iterator to model a transform_iterator.
Hmm, so my question now is - is there some reason why the base iterator is dereferenced before being passed to the function? Wouldn't it be better to let the function decide that?
Not if nearly every use of the thing would have to add a dereference operation. That would make many uses terribly inconvenient, and some impossible (i.e. if you only want to build the function object in place using Boost.Bind or the standard binders instead of Boost.Lambda). It seems to me all you really need to do is use transform_iterator over counting_iterator. counting_iterator enumerates the values of your underlying iterator, and transform_iterator operates on those values. Please let me know if you can't get that to work.
BTW, you guys write some really great stuff, it's very much appreciated. And C++ Template Metaprogramming is mind blowing (especially chapters 10++).
Thanks! It's always gratifying to know we've been useful :-) -- Dave Abrahams Boost Consulting www.boost-consulting.com
David Abrahams wrote:
Louis Lavery
writes: I'm looking for a transforming iterator. I've looked at the [snip] Hmm, so my question now is - is there some reason why the base iterator is dereferenced before being passed to the function? Wouldn't it be better to let the function decide that?
Not if nearly every use of the thing would have to add a dereference operation. That would make many uses terribly inconvenient, and some impossible (i.e. if you only want to build the function object in place using Boost.Bind or the standard binders instead of Boost.Lambda).
Yes, in the short time between my post and receiving your reply the idea had already begun to putrefy. I went back and reviewed the boost iterators, yet again, and immediately dismissed counting_iterator, yet again, as that just counts, dunnit?
It seems to me all you really need to do is use transform_iterator over counting_iterator.
Kick ouch! Kick ouch! Kick ouch! counting_iterator enumerates the values of
your underlying iterator, and transform_iterator operates on those values. Please let me know if you can't get that to work.
If I can't do that then I should be writing microcode for waffle irons and toaster ovens and not dabbling in C++ :o) Thanks a lot, that's the neat soloution I was after, Louis. -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.322 / Virus Database: 266.11.15 - Release Date: 22/05/2005
participants (2)
-
David Abrahams
-
Louis Lavery