   assign a raw array to an existing std::vector
  Hi, lately I've been wondering how to solve a "simple" problem. I have an existing vector<T> in an object, and I need to assign it(a deep copy) a raw array of the same T type, and whose length is known.1. I would like to use std::vector<T>::assign(...) but I doubt I can, right ?2. An other option would be to reserve(_rightSize) on the vector, and then, well push_back in a for loop, like this:myVec.reserve(SIZE);for(uint i = 0; i < SIZE; i++) myVec.push_back(rawArray); But a for loop and push_back sure sucks...Any Idea how to handle this?:::I'm concerned about performance and good practice!:::   
  myVec.assign(array_begin, array_begin + array_size);   ;  Nice that's what I was expecting.I've learnt something on easy casting of pointer to iterator :).Thanks SiCrane.   ;Quote:Original post by IshraamI've learnt something on easy casting of pointer to iterator :).Ponder this for a minute: pointers are iterators over arrays.std::vector::assign() is a function template taking a pair of iterators.Q.E.D.   ;  Oh, while we're at it, an other question!1. Let's say I'm in a similar situation as above, except that my vector is a vector<Vec3f> and my raw array is a Vec4f*. So, here again, same numbers of elements, but I'm only interested in the 3 first elements of each Vec4f (i.e. x,y,z).Is there also another elegant method to solve this problem ?EDIT : merci Fruny, c'est noté!   ;  Not unless a Vec4f can be assigned to a Vec3f. It that's not possible, a conversion function needs to be called.Either use transform() and back_insert(), or just do the loop yourself.EDIT: à ton service.   ;Quote:Original post by FrunyNot unless a Vec4f can be assigned to a Vec3f. It that's not possible, a conversion function needs to be called.Either use transform() and back_insert(), or just do the loop yourself.EDIT: à ton service.Just to show some examples:1) Conversion of Vec4f to Vec3f via an implicit conversion constructor (which will in turn allow Vec3f::operator= to be called, AFAIK):Vec3f::Vec3f(const Vec4f& v): x(v.x), y(v.y), z(v.z) {} // ignore w2) Conversion of Vec4f to Vec3f via an explicit assignment operator:Vec3f& Vec3f::operator=(const Vec4f& rhs) {  x = rhs.x; y = rhs.y; z = rhs.z;  return *this;}3) Conversion of Vec4f to Vec3f via a Vec4f cast operator (not recommended, and I'm not sure it will work anyway):Vec4f::operator Vec3f() {  return Vec3f(x, y, z);}4) Using std::transform and back_inserter with an explicit assignment function:struct converter {  Vec3f operator()(const Vec4f& v) {    return Vec3f(v.x, v.y, v.z);  }};std::transform(array_begin, array_begin + array_size, back_inserter(my_vector), converter());;  The assignment operator will proably not be called by std::vector::assign(). assign() will most likely use the allocator's construct() member for the copy construction of the elements, so the assignment operator alone won't allow the array to vector assignment.   