Member function version function::swap() has noexcept. But non member function version swap(function, function) doesn't have noexcept.
I think member function version is mistake, unnecessary noexcept. Because copy (or move) constructor of target function object may throw exception.
function constructor specification is follow:
function(const function& f);
template <class A> function(allocator_arg_t, const A& a, const function& f);
Postconditions: !*this if !f; otherwise, *this targets a copy of f.target().
Throws: shall not throw exceptions if f’s target is a callable object passed via reference_wrapper or
a function pointer. Otherwise, may throw bad_alloc or any exception thrown by the copy constructor
of the stored callable object. [Note: Implementations are encouraged to avoid the use of dynamically
allocated memory for small callable objects, for example, where f’s target is an object holding only a
pointer or reference to an object and a member function pointer. —end note ]
function::swap : remove noexcept. copy (or move) constructor of funct…
…ion object may throw exception.
In the general case, function::swap does not require any constructors as it merely swaps pointers. Only when the small callable object optimization is chosen function::swap could end up copy/move constructing the target callable, and noexcept here would restrict the types for which this optimization applies. Nevertheless, this is certainly an inconsistency not only with non-member swap but also with function's move constructor and move assignment operator.
This inconsistency looks like a defect, especially since the non-member swap is specified to just call the member swap, but this is not editorial. I suggest mailing email@example.com to get a library issue opened for this.
OK, I will submit issue to the mailing list. Thanks.
This is definitely not editorial, but there is already an issue opened to deal with it, see http://cplusplus.github.io/LWG/lwg-active.html#2062
Thanks, I missed the issue.