Is there a way to pass auto as an argument in C++?

Is there a way to pass auto as an argument to another function?

int function(auto data)
{
    //DOES something
}

Answer

If you want that to mean that you can pass any type to the function, make it a template:

template <typename T> int function(T data);

There’s a proposal for C++17 to allow the syntax you used (as C++14 already does for generic lambdas), but it’s not standard yet.

Edit: C++ 2020 now supports auto function parameters. See Amir’s answer below

Attribution
Source : Link , Question Author : user3639557 , Answer Author : user3586940

Leave a Comment