dumb question: iterator dynamic_cast adapter?
I am trying to figure out iterators and I have a dumb question: I have an iterator A_iter, that can traverse in both directions ( A_iter++ and A_iter-- ) and can do input (operator*()). Value_type = type of *A_iter is A; and A is static_cast able to B: A start; B fish = static_cast<B>(start); // OK How do I use adapters to create B_iter, which is the same as A_iter, but whose value_type= typeof *B_iter is B? I am sorry if this is a dumb question. -- Paul Elliott 1(512)837-1096 pelliott@io.com PMB 181, 11900 Metric Blvd Suite J http://www.io.com/~pelliott/pme/ Austin TX 78758-3117
Paul Elliott
I am trying to figure out iterators and I have a dumb question: I have an iterator A_iter, that can traverse in both directions ( A_iter++ and A_iter-- ) and can do input (operator*()). Value_type = type of *A_iter is A;
and A is static_cast able to B:
A start; B fish = static_cast<B>(start); // OK
How do I use adapters to create B_iter, which is the same as A_iter, but whose value_type= typeof *B_iter is B?
I am sorry if this is a dumb question.
Your question isn't dumb, but it's incomplete. It's not clear how you want the B_iter to produce Bs from the As that A_iter yields. The message subject indicates you intend to use dynamic_cast. I assume if you care about dynamic_cast that B must be derived from A, but if the type of *A_iter is A (and not A&), you won't be able to dynamic_cast down to B. Same goes for static_cast, which might compile but will produce undefined behavior from downcasting if you start with an A. Aside from those considerations, you should be able to simply use transform_iterator with a function or function object that does the desired cast. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams
-
Paul Elliott