Title
Reference Closure
Status
cd1
Section
[func.referenceclosure.cons]
Submitter
Lawrence Crowl

Created on 2008-06-02.00:00:00 last changed 172 months ago

Messages

Date: 2010-10-21.18:28:33

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&) = delete default;
     ...

In [func.referenceclosure.cons] Construct, copy, destroy, add the member function description

reference_closure& operator=(const reference_closure& f)

Postcondition: *this is a copy of f.

Returns: *this.

Date: 2008-06-02.00:00:00

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.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg4022
2008-06-02 00:00:00admincreate