770. std::function should use rvalue swap

Section: 23.14.13 [func.wrap] Status: CD1 Submitter: Daniel Krügler Opened: 2008-01-10 Last modified: 2016-02-10

Priority: Not Prioritized

View all issues with CD1 status.

Discussion:

It is expected that typical implementations of std::function will use dynamic memory allocations at least under given conditions, so it seems appropriate to change the current lvalue swappabilty of this class to rvalue swappability.

Proposed resolution:

In 23.14 [function.objects], header <functional> synopsis, just below of

template<class R, class... ArgTypes>
  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
template<class R, class... ArgTypes>
  void swap(function<R(ArgTypes...)>&&, function<R(ArgTypes...)>&);
template<class R, class... ArgTypes>
  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&&);

In 23.14.13.2 [func.wrap.func] class function definition, change

void swap(function&&);

In 23.14.13.2 [func.wrap.func], just below of

template <class R, class... ArgTypes>
  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
template <class R, class... ArgTypes>
  void swap(function<R(ArgTypes...)>&&, function<R(ArgTypes...)>&);
template <class R, class... ArgTypes>
  void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&&);

In 23.14.13.2.2 [func.wrap.func.mod] change

void swap(function&& other);

In 23.14.13.2.7 [func.wrap.func.alg] add the two overloads

template<class R, class... ArgTypes>
  void swap(function<R(ArgTypes...)>&& f1, function<R(ArgTypes...)>& f2);
template<class R, class... ArgTypes>
  void swap(function<R(ArgTypes...)>& f1, function<R(ArgTypes...)>&& f2);