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 really want to use std::fill
and are confined to C++98 you can use something like the following,
#include
#include
#include
#include
struct increasing {
increasing(int start) : x(start) {}
operator int () const { return x++; }
mutable int x;
};
int main(int argc, char* argv[])
{
using namespace std;
vector v(10);
fill(v.begin(), v.end(), increasing(0));
copy(v.begin(), v.end(), ostream_iterator(cout, " "));
cout << endl;
return 0;
}