cpp/utility/functional/bind

The function template generates a forwarding call wrapper for. Calling this wrapper is equivalent to invoking with some of its arguments bound to.

If is, or  is  for any type  in , the program is ill-formed.

If or any type in  is not  or, the behavior is undefined.

Return value
A function object of unspecified type, for which  is. It has the following members:

{{member|{{small|std::bind}} return type|2=

Member objects
The return type of holds a member object of type  constructed from, and one object per each of , of type , similarly constructed from.

Constructors
The return type of is  if all of its member objects (specified above) are CopyConstructible, and is  otherwise. The type defines the following members:

{{rrev|until=c++20|

Member type
@1@ If  is a pointer to function or a pointer to member function,  is the return type of. If is a class type with nested typedef, then  is. Otherwise no is defined.

@2@  is exactly. }}

Member function
When is invoked in a function call expression, an invocation of the stored object takes place, as if by

@1@, or @2@ ,

where is a value of type, the values and types of the bound arguments  are determined as specified below.

If some of the arguments that are supplied in the call to are not matched by any placeholders stored in, the unused arguments are evaluated and discarded.

An invocation of is non-throwing  if and only if so is the underlying  operation. participates in overload resolution only if the operation is well-formed when treated as an unevaluated operand.

If is volatile-qualified, the program is ill-formed.

If can never be a valid expression for any possible values, the behavior is undefined. }}

Bound arguments
If the stored argument is of type  (for example, std or std was used in the initial call to ), then the argument  in the  operation above is  and the type  in the same call is : the stored argument is passed by reference into the invoked function object.

If the stored argument is of type  for which  is  (for example, another  expression was passed directly into the initial call to ), then  performs function composition: instead of passing the function object that the bind subexpression would return, the subexpression is invoked eagerly, and its return value is passed to the outer invokable object. If the bind subexpression has any placeholder arguments, they are shared with the outer bind (picked out of ). Specifically, the argument in the  operation above is  and the type  in the same call is  (cv-qualification is the same as that of ).

If the stored argument is of type, for which  is not  (meaning, a placeholder such as  was used as the argument to the initial call to ), then the argument indicated by the placeholder ( for ,  for , etc) is passed to the invokable object: the argument  in the  operation above is  and the corresponding type  in the same call is.

Otherwise, the ordinary stored argument is passed to the invokable object as lvalue argument: the argument  in the  operation above is simply  and the corresponding type  is  cv, where cv is the same cv-qualification as that of.

Exceptions
Only throws if construction of from  throws, or any of the constructors for  from the corresponding  throws where  is the ith type and  is the ith argument in.