根据cppreference.com所有follwing三个:argument_type,first_argument_type和second_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)
可以通过引入模板参数来获取类型
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)
为您提供参数类型作为模板参数。作为奖励,如果您需要的话,您还可以获得返回类型。