Move/CopyConstructible
Section: 16.4.4.2 [utility.arg.requirements] Status: C++11 Submitter: Daniel Krügler Opened: 2010-02-03 Last modified: 2016-01-28
Priority: Not Prioritized
View all other issues in [utility.arg.requirements].
View all issues with C++11 status.
Discussion:
Table 33 — MoveConstructible requirements [moveconstructible] and Table 34 — CopyConstructible requirements [copyconstructible] support solely the following expression:
T t(rv)
where rv
is defined to be as "non-const rvalue of type T
" and
t
as a "modifiable lvalue of type T
" in 16.4.4.2 [utility.arg.requirements]/1.
This causes two different defects:
We cannot move/copy-initialize a const lvalue of type T
as in:
int get_i(); const int i1(get_i());
both in Table 33 and in Table 34.
The single support for
T t(rv)
in case of CopyConstructible
means that we cannot provide an
lvalue as a source of a copy as in
const int& get_lri(); int i2(get_lri());
I believe this second defect is due to the fact that this single expression supported both initialization situations according to the old (implicit) lvalue reference -> rvalue reference conversion rules.
Finally [copyconstructible] refers to some name u
which is not part of
the expression, and both [copyconstructible] and [moveconstructible] should
support construction expressions from temporaries - this would be a stylistic
consequence in the light of the new DefaultConstructible
requirements
and compared with existing requirements (see e.g. Container requirements or the
output/forward iterator requirements)..
[ 2010-02-09 Moved to Tentatively Ready after 5 positive votes on c++std-lib. ]
[ 2010-02-10 Reopened. The proposed wording of 1283 has been merged here. ]
[ 2010-02-10 Moved to Tentatively Ready after 5 positive votes on c++std-lib. ]
Proposed resolution:
Change 16.4.4.2 [utility.arg.requirements]/1 as indicated: [This change
suggestion is motivated to make type descriptions clearer: First, a
,
b
, and c
may also be non-const T
. Second, u
is described in a manner consistent with the container requirements tables.]
1 The template definitions in the C++ standard library refer to various named requirements whose details are set out in tables 31-38. In these tables,
T
is an object or reference type to be supplied by a C++ program instantiating a template;a
,b
, andc
are values of type (possiblyconst) T
;s
andt
are modifiable lvalues of typeT
;u
denotes an identifier;is a value of type (possiblyconst
)T
; andrv
is annon-constrvalue of typeT
; andv
is an lvalue of type (possiblyconst
)T
or an rvalue of typeconst T
.
In 16.4.4.2 [utility.arg.requirements] Table 33 ([moveconstructible])
change as indicated [Note: The symbol u
is defined to be either a
const or a non-const value and is the right one we need here]:
Table 33 — MoveConstructible
requirements [moveconstructible]Expression Post-condition T
tu(rv);is equivalent to the value of
turv
before the constructionT(rv)
T(rv)
is equivalent to the value ofrv
before the construction[Note: There is no requirement on the value ofrv
after the construction.rv
remains a valid object. Its state is unspecified. — end note]
In 16.4.4.2 [utility.arg.requirements] Table 34 ([copyconstructible])
change as indicated [Note: The symbol u
is defined to be either a
const or a non-const value and is the right one we need here. The expressions
using a
are recommended to ensure that lvalues are supported as sources
of the copy expression]:
Table 34 — CopyConstructible
requirements [copyconstructible]
(in addition toMoveConstructible
)Expression Post-condition T
tu(rv);the value of is unchanged and is equivalent to
uv
tuT(v)
the value of v
is unchanged and is equivalent toT(v)
[Note: A type that satisfies theCopyConstructible
requirements also satisfies theMoveConstructible
requirements. — end note]
In Table 35 — MoveAssignable requirements [moveassignable] change as indicated:
Table 35 — MoveAssignable
requirements [moveassignable]Expression Return type Return value Post-condition t = rv
T&
t
t
is equivalent to the value ofrv
before the assigment.[Note: There is no requirement on the value ofrv
after the assignment.rv
remains a valid object. Its state is unspecified. — end note]
In 16.4.4.2 [utility.arg.requirements] change Table 36 as indicated:
Table 36 — CopyAssignable
requirements [copyassignable]
(in addition toMoveAssignable
)Expression Return type Return value Post-condition t =
uvT&
t
t
is equivalent to, the value of
uvis unchanged
uv[Note: A type that satisfies theCopyAssignable
requirements also satisfies theMoveAssignable
requirements. — end note]