C++20 allows using auto
for function parameter type.
Does it also allow using auto
as a template argument placeholder (not similar, but in the spirit of C++17 template<auto> in a way) for function parameter type?
So the following code, pre C++20:
template<typename First, typename Second>
void printPair(const std::pair<First, Second>& p) {
std::cout << p.first << ", " << p.second;
}
Could be written as:
void printPair(const std::pair<auto, auto>& p) {
std::cout << p.first << ", " << p.second;
}
It does compile and works nicely with experimental GCC implementation for concepts.
Is it a legitimate syntax with C++20?
Related: Wildcard for C++ concepts saying "accepting anything for this template argument"
See Question&Answers more detail:os