With C 20, we can write a concept and use it like so:
template<typename T>
concept ClassType = std::is_class_v<T>;
template<ClassType T>
void foo();
Is there a way to achieve this same syntax when using template parameter packs? We could obviously do it with requires:
template<typename T, typename... Ts>
concept SameTypes = std::conjunction_v<std::is_same<T, Ts>...>;
template<typename... Ts>
requires SameTypes<Ts...>
void foo();
But my question is if there is way to do it using the syntax where the concept takes the place of typename, inside the template brackets like in the first example. Is there?
CodePudding user response:
Yes, you can do this, which is functional equivalence to your example:
#include <concepts>
template<class T, std::same_as<T>... Ts>
void foo();
