I know how to fill an std::vector with non-trivial initial values, e.g. sequence numbers:
void IndexArray( unsigned int length, std::vector<unsigned int>& v ) { v.resize(length); for ( unsigned int i = 0; i < length; ++i ) { v[i] = i; } }
But this is a for-loop. Is there an elegant way to do this with less lines of code using stl functionality (and not using Boost)?
You can use the generate algorithm, for a more general way of filling up containers:
This was shamelessly lifted and edited from cplusplusreference.