public member function


template <class Fn, class Alloc>  void assign (Fn&& fn, const Alloc& alloc);
Assign target and allocator
Assigns a new value to the function object, replacing its current target and setting alloc as the internal allocator.

The function behaves as if a new function was constructed on the stack by forwarding fn and alloc to the proper constructor, and swapping that newly constructed object with *this:


Either a function object of the same type, or some function, function pointer, pointer to member, or function object, as forwarded to function's constructor.

Return value


Data races

The object is modified (including both its target and its allocator).
If fn is an rvalue reference, the function may modify fn.

Exception safety

If fn is a function pointer or a reference_wrapper to a callable object (or a function object targeting one of these), it never throws exceptions (no-throw guarantee).
Otherwise, it can only throw if the copy- or move-construction of the target callable object throws, or if an exception (such as bad_alloc) is thrown allocating memory.

See also