If you do not follow Ben-Voigt 's answer, the short answer is no.
As you have it vector, there is nothing wrong with the old-fashioned for-loop. Everything else will be unnecessarily complicated.
typedef std::vector <int>::size_type size_type ;
for(size_type i = 0; i < vect.size (); ++i) {
}
, , :
template <class Container>
void DoStuff (Container &container)
{
typedef Container::size_type size_type ;
for (size_type i = 0; i < container.size (); ++i) {
}
}
- :
template <class Container>
struct StoreIndex
{
typedef typename Container::size_type size_type ;
typedef typename Container::value_type value_type ;
StoreIndex (Container &container) : container (container), index (0)
{
}
size_type index ;
Container &container ;
value_type operator () () {
if (container [index] == 0) {
return index++ ;
}
else {
return container [index++] ;
}
}
};
:
std::generate (std::begin (v), std::end (v), StoreIndex <std::vector <int> > (v)) ;
, , (, std::map).