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

user3639557 picture user3639557 · Apr 29, 2015 · Viewed 26.1k times · Source

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

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

Answer

Mike Seymour picture Mike Seymour · Apr 29, 2015

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