什么是std :: function :: argument_type的替代品?

for*_*818 13 c++ function

根据cppreference.com所有follwing三个:argument_type,first_argument_typesecond_argument_type已被取消在C++ 17和C++ 20移除.

这些成员类型的标准库替换是什么?我的意思是我可以编写自己的类型特征,但我怀疑在标准库中没有正确替换的情况下会删除某些内容.

举个例子:

template <typename F> 
void call_with_user_input(F f) {
    typename F::first_argument_type x;  // what to use instead ??
    std::cin >> x;
    f(x);
}
Run Code Online (Sandbox Code Playgroud)

Nat*_*ica 3

可以通过引入模板参数来获取类型

template <typename Ret, typename Arg> 
void call_with_user_input(std::function<Ret(Arg)> f) {
    Arg x;
    std::cin >> x;
    f(x);
}
Run Code Online (Sandbox Code Playgroud)

为您提供参数类型作为模板参数。作为奖励,如果您需要的话,您还可以获得返回类型。

  • @user463035818 许多旧的 C++03 机制都需要它,但这些机制已被删除。有关更多信息,请参阅:/sf/ask/2513521811/ (2认同)