読者です 読者をやめる 読者になる 読者になる

std::bindはメンバ関数を扱えないと思ったら扱えた

C++

ので見つけたところをメモ。

20.8.11.1.3 Function template bind [func.bind.bind]

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


1 Requires: F and each Ti in BoundArgs shall be CopyConstructible. INVOKE (f, w1, w2, ..., wN) (20.8.2) shall be a valid expression for some values w1, w2, ..., wN, where N == sizeof...(bound_args).


2 Returns: A forwarding call wrapper g with a weak result type (20.8.2). The effect of g(u1, u2, ..., uM) shall be INVOKE(f, v1, v2, ..., vN, result_of::type), where cv represents the cv-qualifiers of g and the values and types of the bound arguments v1, v2, ..., vN are determined as specified below.


3 Throws: Nothing unless the copy constructor of F or of one of the types in the BoundArgs... pack expansion throws an exception.

20.8.2 Requirements [func.require]

1 Define INVOKE(f, t1, t2, ..., tN) as follows:


― (t1.*f)(t2, ..., tN) when f is a pointer to a member function of a class T and t1 is an object of type T or a reference to an object of type T or a reference to an object of a type derived from T;


― ((*t1).*f)(t2, ..., tN) when f is a pointer to a member function of a class T and t1 is not one of the types described in the previous item;


― t1.*f when f is a pointer to member data of a class T and t1 is an object of type T or a reference to an object of type T or a reference to an object of a type derived from T;


― (*t1).*f when f is a pointer to member data of a class T and t1 is not one of the types described in the previous item;


― f(t1, t2, ..., tN) in all other cases.

20.8.2って2ヶ所も書かれてるんだから気付け自分。