Why am I getting runtime error while trying to do:
std::vector<int> vi;
std::generate_n(std::back_inserter(vi),10,rand);
std::vector<int> vi_1;
vi_1.reserve(vi.size());
std::copy_if(vi.begin(),vi.end(),vi_1.begin(),std::bind2nd(std::greater<int>(),-20000));
//Here (in copy_if) I'm getting assert error.
Reserve doesn’t actually create the objects, it only guarantees, that every call that’s going to grow the vector to the given limit is going to be O(1). Use
resize.