boost 1.34.1 Foreach conversion to iterators.
Hi i would like to know whats the best way to use BOOST_FOREACH and iterator. Example... BOOST_FOREACH(char c, String str) { first_c = c; // blah.. first iterator = c after condition x. second_c = c; // blah... second iterator = c after condition y. } str2.insert(first_c, second_c). Thanks for any help.
chun ping wang wrote:
Hi i would like to know whats the best way to use BOOST_FOREACH and iterator.
Example...
BOOST_FOREACH(char c, String str) { first_c = c; // blah.. first iterator = c after condition x. second_c = c; // blah... second iterator = c after condition y. }
str2.insert(first_c, second_c).
You mean, you want to get an iterator representing the current position of the iteration? Sorry, you can't do that. Don't use FOREACH; use a regular for(;;) loop. -- Eric Niebler Boost Consulting www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com
reply thanks. Sort of off topic but does foreach need access to iterator
(and not const_iterator).. like i have class B deriving from private
std::vector<int> i allow const_iterator but not iterator. I get compile
time error.
On 8/5/07, Eric Niebler
chun ping wang wrote:
Hi i would like to know whats the best way to use BOOST_FOREACH and iterator.
Example...
BOOST_FOREACH(char c, String str) { first_c = c; // blah.. first iterator = c after condition x. second_c = c; // blah... second iterator = c after condition y. }
str2.insert(first_c, second_c).
You mean, you want to get an iterator representing the current position of the iteration? Sorry, you can't do that. Don't use FOREACH; use a regular for(;;) loop.
-- Eric Niebler Boost Consulting www.boost-consulting.com
The Astoria Seminar ==> http://www.astoriaseminar.com _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
chun ping wang wrote:
reply thanks. Sort of off topic but does foreach need access to iterator (and not const_iterator).. like i have class B deriving from private std::vector<int> i allow const_iterator but not iterator. I get compile time error.
FOREACH uses Boost.Range. If your type doesn't naturally meet the requirements for a range (and it sounds like it doesn't), you must hook Boost.Range's customization points. Check the documentation. http://boost.org/doc/html/foreach/extensibility.html -- Eric Niebler Boost Consulting www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com
participants (2)
-
chun ping wang
-
Eric Niebler