In the C++11 standard, Section 23.3.6.2 [vector.cons], the following is said:
template
vector(InputIterator first, InputI
You can even go further. This code works fine too :
#include
#include
struct A {
int n;
int v;
A(int n_, int v_ = 0) : n(n_), v(v_) {}
};
int main() {
int arr[] = {1,2,3,4,5,6,7,8,9,10};
std::vector A_vec(arr, arr+10);
for( std::vector::iterator it=A_vec.begin(); it!=A_vec.end(); ++it )
std::cout<< it->n <<" ";
std::cout<
As you have noted in the standard, in §23.3.6.2 :
Makes only N calls to the copy constructor of T
=> This constructor iterates on each element and use the copy constructor so, as long as you have a working copy constructor, it should work fine on every compilers.