Topic: Move constructor in draft
Author: Yechezkel Mett <ymett.on.usenet@gmail.com>
Date: Sun, 14 Oct 2007 13:20:21 CST Raw View
The draft standard n2369 uses the term move constructor in a few
places, but doesn't seem to define it.
MoveConstructible requirements are defined in Table 33 in 20.1.1 as
follows:
Table 33: MoveConstructible requirements [moveconstructible]
T t = rv
t is equivalent to the value of rv before the construction
[ Note: There is no requirement on the value of rv after the
construction. -end note ]
(where rv is a non-const rvalue of type T).
So I assume the move constructor is the constructor that would be used
in filling the above requirement.
For vector::reserve, vector::resize and the vector modifiers given in
23.2.5.4 we have
Requires: If value_type has a move constructor, that constructor shall
not throw any exceptions.
Firstly "If value_type has a move constructor" is superfluous; every
type which can be put into a vector has a move constructor (a copy
constructor is also a move constructor). Secondly it means that for
any value_type which has a throwing copy constructor and no other move
constructor these functions cannot be used -- which I think will come
as a shock to people who have been using such types in vector until
now!
I can see two ways to correct this. The simpler, which is presumably
what was intended, is to say "If value_type has a move constructor and
no copy constructor, the move constructor shall not throw any
exceptions" or "If value_type has a move constructor which changes the
value of its parameter,".
The other alternative is add to MoveConstructible the requirement that
the expression does not throw. This would mean that not every type
that satisfies the CopyConstructible requirements also satisfies the
MoveConstructible requirements. It would mean changing requirements in
various places in the draft to allow either MoveConstructible or
CopyConstructible, but I think the result would be clearer and
possibly more concise too.
Yechezkel Mett
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]