Q:

C++11 vector constructor copy vs range?

I can't understand the advantages of or differences between vector copy constructors and range constructors. When I construct three vectors like this:
    vector<int> FirstVec(3, 911); //fill constructor
    vector<int> SecondVec(FirstVec.begin(), FirstVec.end()); //range constructor
    vector<int> ThirdVec(FirstVec); //copy constructor

The contents of SecondVec and ThirdVec are exactly the same. Are there any scenarios in which using one of them has advantages? Thank you.

A:

The range constructor is quite useful when you want to copy the items of a different type of container, or don't want to copy a full range. For example
int a[] = {1,2,3,4,5};
std::set<int> s{3, 911};
std::vector<int> v0{1,2,3,4,5};

std::vector<int> v1(std::begin(a), std::end(a));
std::vector<int> v2(a+1, a+3);
std::vector<int> v3(s.begin(), s.end());
vector<int> v4(v0.begin(), v0.begin() + 3);

A:

The range constructor is more generic; you can provide any valid sequence of suitable elements, not necessarily from the same type of container, or spanning a whole container, or even from a container at all.
The copy constructor is simpler and potentially more efficient; but is only suitable when you want to copy the entirety of another vector.
So use the copy constructor when you want to copy the same kind of container, as you do here; and the range constructor for more general ranges.

