# std::function<R(Args...)>::assign

> C++ Atlas: `cppatlas.com/w/cpp/utility/functional/function/assign` | Source: https://en.cppreference.com/w/cpp/utility/functional/function/assign | Domain: Utility | Standards: C++11, C++17

Initializes the target with f. The alloc is used to allocate memory for any internal data structures that the function might use.

## Official Specification Summary (cppreference)

```cpp
template< class F, class Alloc >
void assign( F&& f, const Alloc& alloc ); // (since C++11) (removed in C++17)
```

Initializes the *target* with `f`. The `alloc` is used to allocate memory for any internal data structures that the `function` might use.

Equivalent to `function(std::allocator_arg, alloc, std::forward<F>(f)).swap(*this);`.

### Parameters

- `f` - callable function to initialize the *target* with
- `alloc` - allocator to use to allocate memory for the internal data structures

### Return value

(none)

### Exceptions

May throw implementation-defined exceptions.

### See also

- [`operator=`](https://en.cppreference.com/w/cpp/utility/functional/function/operator=): assigns a new target (public member function)

---
Attribution: content from https://en.cppreference.com/w/cpp/utility/functional/function/assign (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.