My question here is: why the second parameter type is just 'T' instead
of 'const T&' ie why doesn't the Standard declare this member function
as
void resize(size_type, const T& c = T());
But the following other member functions take 'const T&' type
parameter.
explicit vector(size_type n, const T& value = T(),
const Allocator& = Allocator());
void assign(size_type n, const T& u);
void push_back(const T& x);
iterator insert(iterator position, const T& x);
Kindly explain the reason.
Thanks
V.Subramanian
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std...@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
I assume that the original intend was to prevent an implementation
to perform tests whether the provided argument would be a member
of the container, because in this case the resizing step would
invalidate the reference before having copied it. It turns out that
this
logic - if at all - was unwarranted because the effect clause of
resize
is already specified as
if (sz > size())
insert(end(), sz-size(), c);
else if (sz < size())
erase(begin()+sz, end());
else
;
and the involved insert overload has the signature
void insert(iterator position, size_type n, const T& x);
so the corresponding problem would have to be solved by
insert anyway. And they need to do that for push_back
for the other insert overload you mentioned as well.
For these reasons the signature has been changed
in the current working draft as part of the defect report
http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#679
to the expected one:
void resize(size_type sz, const T& c);
HTH & Greetings from Bremen,
Daniel Kr�gler