The std::vector constructor has several overloads.
For std::vector<double> a(3,5); the fill constructor is used:
explicit vector (size_type n); vector (size_type n, const value_type& val, const allocator_type& alloc = allocator_type());
This takes the size parameter as the first parameter and optional and the third parameter, the second parameter indicates the value that you want to give the newly created objects.
double p[] = {1, 2, 3, 4, 5}; std::vector<double> a(p, p+5);
Uses another constructor overload, namely a range constructor:
template <class InputIterator> vector (InputIterator first, InputIterator last, const allocator_type& alloc = allocator_type());
This takes the iterator to the beginning of the collection and the end() tetra and iterates around and adds to vector until first == last .
The reason end() implemented as one-past-the-last-element is because it allows implementations to check equality as:
while(first != last) { //savely add value of first to vector ++first; }
source share