According to cppreference.com all of the follwing three: argument_type
, first_argument_type
and second_argument_type
are deprecated in C++17 and removed in C++20.
What is the standard library replacement for those member types? I mean I could write my own type traits, but I doubt that something gets removed without having a proper replacement in the standard library.
As an example:
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);
}
Function template std::mem_fn generates wrapper objects for pointers to members, which can store, copy, and invoke a pointer to member. Both references and pointers (including smart pointers) to an object can be used when invoking a std::mem_fn .
If it is small, like 3-5 CPU instructions then yes std::function will make it slower, because std::function is not inlined into outer calling code. You should use only lambda and pass lambda as template parameter to other functions, lambdas are inlined into calling code.
You can get the type by introducing template parameters
template <typename Ret, typename Arg>
void call_with_user_input(std::function<Ret(Arg)> f) {
Arg x;
std::cin >> x;
f(x);
}
Gives you the argument type as a template parameter. As a bonus you also get the return type if you need it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With