Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C++

std::bind_front: binding the leading call arguments

std::bind_front creates a callable that stores a function and its leading arguments, appending later call arguments after them.

Version: C++23

Syntax

template<class F, class... Args>
constexpr /* unspecified */ bind_front(F&& function, Args&&... boundArguments);

std::bind_front(f, args...) from <functional> creates a wrapper whose call pattern is std::invoke(f, bound_args..., call_args...). It supports partial application of functions, member pointers, and other callables without the placeholders used by std::bind.

The function and bound arguments are stored as decayed types, normally by copy or move. To retain reference binding, explicitly use std::ref or std::cref and guarantee the referent’s lifetime. Exceptions while constructing the stored state propagate.

The value category of the wrapper affects how stored values are forwarded; move-only state can require invoking a moved wrapper. A call is valid only when the complete argument list is valid for std::invoke, and exceptions from the target propagate.

Examples

#include <functional>
#include <iostream>

int main() {
    auto timesSix = std::bind_front(std::multiplies<int>{}, 6);
    std::cout << timesSix(7) << '\n';
}

Result

42

std::bind_front → 42

Sources