Section: 99 [func.referenceclosure.cons] Status: CD1 Submitter: Lawrence Crowl Opened: 2008-06-02 Last modified: 2016-01-28
Priority: Not Prioritized
View all issues with CD1 status.
Discussion:
The std::reference_closure
type has a deleted copy assignment operator
under the theory that references cannot be assigned, and hence the
assignment of its reference member must necessarily be ill-formed.
However, other types, notably std::reference_wrapper
and std::function
provide for the "copying of references", and thus the current definition
of std::reference_closure
seems unnecessarily restrictive. In particular,
it should be possible to write generic functions using both std::function
and std::reference_closure
, but this generality is much harder when
one such type does not support assignment.
The definition of reference_closure
does not necessarily imply direct
implementation via reference types. Indeed, the reference_closure
is
best implemented via a frame pointer, for which there is no standard
type.
The semantics of assignment are effectively obtained by use of the default destructor and default copy assignment operator via
x.~reference_closure(); new (x) reference_closure(y);
So the copy assignment operator generates no significant real burden to the implementation.
Proposed resolution:
In [func.referenceclosure] Class template reference_closure,
replace the =delete
in the copy assignment operator in the synopsis
with =default
.
template<class R , class... ArgTypes > class reference_closure<R (ArgTypes...)> { public: ... reference_closure& operator=(const reference_closure&) =deletedefault; ...
In 99 [func.referenceclosure.cons] Construct, copy, destroy, add the member function description
reference_closure& operator=(const reference_closure& f)Postcondition:
*this
is a copy off
.Returns:
*this
.