This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of CD1 status.

770. std::function should use rvalue swap

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

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 22.10 [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 22.10.17.3 [func.wrap.func] class function definition, change

void swap(function&&);

In 22.10.17.3 [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 22.10.17.3.3 [func.wrap.func.mod] change

void swap(function&& other);

In 22.10.17.3.8 [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);