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

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

Leave a Comment