
Den 31-10-2010 21:43, Neil Groves skrev:
On Sat, Oct 30, 2010 at 6:28 PM, Robert Jones<robertgbjones@gmail.com>wrote:
On Sat, Oct 30, 2010 at 12:38 PM, Neil Groves<neil@grovescomputing.com
wrote:
I propose that a breaking change is made to the index range adaptor so
that
it returns a pair<original_reference_type, index_type>.
Hi Neil
Could you provide a use-case example, before and after.
Certainly. I should have thought to do this in the original email. Thank you for taking the time to help me acquire information.
Before:
BOOST_FOREACH( auto item, rng | index ) { // access to the index is not possible - doh :-( // The return type of the dereferenced element from an index range adaptor loses the index const element_type& elem = item; }
After:
BOOST_FOREACH( auto item, rng | indexed ) { // After my proposed modification, the return type becomes a pair of the index // and the original reference type of the underlying iterator/range. std::size i = item.first; const element_type& elem = item.second; }
Your new version works well with foreach, but perhaps less so with other iteration mathods. Therefore I suggest that you add a new range instead of messing with the old one. -Thorsten