Suppose I want to construct a C++ STL vector from an array (knowing its length), i.e. I have:
size_t length = /* ... */
int *a = new int[length];
I can construct the vector this way:
std::vector<int> v(a, a + length);
but not this way:
std::vector<int> v(a, length);
Why doesn't the vector class have the latter kind of constructor?
Because that constructor is the typical
begin
-end
constructor:which copies the content from
first
tolast
(not included) and does not take ownership of the allocated dynamic array.Most of the STL's algorithms uses the
[begin, end)
range, and for consistency, also does this constructor.