Files
cppdraft_translate/cppdraft/func/bind.md
2025-10-25 03:02:53 +03:00

10 KiB
Raw Blame History

[func.bind]

22 General utilities library [utilities]

22.10 Function objects [function.objects]

22.10.15 Function object binders [func.bind]

22.10.15.1 General [func.bind.general]

1

#

Subclause [func.bind] describes a uniform mechanism for binding arguments of callable objects.

22.10.15.2 Class template is_bind_expression [func.bind.isbind]

🔗

namespace std {template struct is_bind_expression; // see below}

1

#

The class template is_bind_expression can be used to detect function objects generated by bind.

The function template bind uses is_bind_expression to detect subexpressions.

2

#

Specializations of the is_bind_expression template shall meet the Cpp17UnaryTypeTrait requirements ([meta.rqmts]).

The implementation provides a definition that has a base characteristic oftrue_type if T is a type returned from bind, otherwise it has a base characteristic of false_type.

A program may specialize this template for a program-defined type T to have a base characteristic of true_type to indicate thatT should be treated as a subexpression in a bind call.

22.10.15.3 Class template is_placeholder [func.bind.isplace]

🔗

namespace std {template struct is_placeholder; // see below}

1

#

The class template is_placeholder can be used to detect the standard placeholders_1, _2, and so on ([func.bind.place]).

The function template bind usesis_placeholder to detect placeholders.

2

#

Specializations of the is_placeholder template shall meet the Cpp17UnaryTypeTrait requirements ([meta.rqmts]).

The implementation provides a definition that has the base characteristic ofintegral_constant<int, J> if T is the type ofstd::placeholders::_J, otherwise it has a base characteristic of integral_constant<int, 0>.

A program may specialize this template for a program-defined type T to have a base characteristic of integral_constant<int, N> with N > 0 to indicate that T should be treated as a placeholder type.

22.10.15.4 Function template bind [func.bind.bind]

1

#

In the text that follows:

g is a value of the result of a bind invocation,

FD is the type decay_t,

fd is an lvalue that is a target object of g ([func.def]) of type FD direct-non-list-initialized with std::forward(f),

Ti is the ith type in the template parameter pack BoundArgs,

TDi is the type decay_t,

ti is the ith argument in the function parameter pack bound_args,

tdi is a bound argument entity of g ([func.def]) of type TDi direct-non-list-initialized with std::forward<Ti>(ti),

Uj is the jth deduced type of the UnBoundArgs&&... parameter of the argument forwarding call wrapper, and

uj is the jth argument associated with Uj.

🔗

template<class F, class... BoundArgs> constexpr unspecified bind(F&& f, BoundArgs&&... bound_args); template<class R, class F, class... BoundArgs> constexpr unspecified bind(F&& f, BoundArgs&&... bound_args);

2

#

Mandates: is_constructible_v<FD, F> is true.

For each Ti in BoundArgs, is_constructible_v<TDi, Ti> is true.

3

#

Preconditions: FD and each TDi meet the Cpp17MoveConstructible and Cpp17Destructible requirements.

INVOKE(fd, w1, w2, …,wN) ([func.require]) is a valid expression for some values w1, w2, …, wN, whereN has the value sizeof...(bound_args).

4

#

Returns: An argument forwarding call wrapper g ([func.require]).

A program that attempts to invoke a volatile-qualified g is ill-formed.

When g is not volatile-qualified, invocation ofg(u1, u2, …, uM) is expression-equivalent ([defns.expression.equivalent]) toINVOKE(static_cast(vfd), static_cast(v1), static_cast(v2), …, static_cast(vN)) for the first overload, andINVOKE(static_cast(vfd), static_cast(v1), static_cast(v2), …, static_cast(vN)) for the second overload, where the values and types of the target argument vfd and of the bound argumentsv1, v2, …, vN are determined as specified below.

5

#

Throws: Any exception thrown by the initialization of the state entities of g.

6

#

[Note 1:

If all of FD and TDi meet the requirements of Cpp17CopyConstructible, then the return type meets the requirements of Cpp17CopyConstructible.

— end note]

7

#

The values of the bound arguments v1, v2, …, vN and their corresponding types V1, V2, …, VN depend on the types TDi derived from the call to bind and the cv-qualifiers cv of the call wrapper g as follows:

if TDi is reference_wrapper, the argument is tdi.get() and its type Vi is T&;

if the value of is_bind_expression_v is true, the argument isstatic_cast<cv TDi&>(tdi)(std::forward(uj)...) and its type Vi isinvoke_result_t<cv TDi&, Uj...>&&;

if the value j of is_placeholder_v is not zero, the argument is std::forward(uj) and its type Vi is Uj&&;

otherwise, the value is tdi and its type Vi is cv TDi&.

8

#

The value of the target argument vfd is fd and its corresponding type Vfd is cv FD&.

22.10.15.5 Placeholders [func.bind.place]

namespace std::placeholders {// M is the number of placeholderssee below _1; see below _2; ⋮ see below _M;}

1

#

The number M of placeholders isimplementation-defined.

2

#

All placeholder types meet the Cpp17DefaultConstructible andCpp17CopyConstructible requirements, and their default constructors and copy/move constructors are constexpr functions that do not throw exceptions.

It is implementation-defined whether placeholder types meet the Cpp17CopyAssignable requirements, but if so, their copy assignment operators are constexpr functions that do not throw exceptions.

3

#

Placeholders should be defined as:inline constexpr unspecified _1{};

If they are not, they are declared as:extern unspecified _1;

4

#

Placeholders are freestanding items ([freestanding.item]).