Topic: vector::resize(size_type sz, T c = T());
Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Date: Tue, 27 Oct 2009 17:27:42 CST Raw View
On 27 Okt., 20:17, "subramanian10...@yahoo.com, India"
<subramanian10...@yahoo.com> wrote:
> In the ISO/IEC 14882:2003 document, in page 490 in section 23.2.4, the
> definition of the class template vector contains the following member
> function declaration:
> void resize(size_type sz, T c = T());
>
> 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.
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
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "subramanian100in@yahoo.com, India" <subramanian100in@yahoo.com>
Date: Tue, 27 Oct 2009 13:17:05 CST Raw View
In the ISO/IEC 14882:2003 document, in page 490 in section 23.2.4, the
definition of the class template vector contains the following member
function declaration:
void resize(size_type sz, T c = T());
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-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]