explicit specialization with concepts

Viewed 94

I'm trying to use concepts to do explicit specialization of some template method, but it isn't compiled on gcc or msvc, but can compile on clang... Who is right?

#include <type_traits>

template<typename T> 
concept arithmetic = std::is_arithmetic_v<T> && !std::is_same_v<T, bool>;

template<typename T>
void foo(const T &value, int &result);

template<>
void foo(const arithmetic auto &value, int &result) {

}
2 Answers

The correct syntax is

template<arithmetic T>
void foo(const T &value, int &result){}

or

void foo(const arithmetic auto &value, int &result){} 

So no template<> or template<arithmetic T>

Explicit specializations can’t have the template parameter implied by const arithmetic auto; Clang is wrong, perhaps in that it is ignoring the template<> and just overloading the template like you probably want to do.

Related