I would like to fill a vector using std::fill, but instead of one value, the vector should contain numbers in increasing order after.
If you'd rather not use C++11 features, you can use std::generate:
#include
#include
#include
struct Generator {
Generator() : m_value( 0 ) { }
int operator()() { return m_value++; }
int m_value;
};
int main()
{
std::vector ivec( 10 );
std::generate( ivec.begin(), ivec.end(), Generator() );
std::vector::const_iterator it, end = ivec.end();
for ( it = ivec.begin(); it != end; ++it ) {
std::cout << *it << std::endl;
}
}
This program prints 0 to 9.