Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

explicit specialization with concepts

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) {

}
like image 556
Vladyslav Mozhvylo Avatar asked Mar 17 '26 16:03

Vladyslav Mozhvylo


1 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>

like image 173
Botond Horváth Avatar answered Mar 20 '26 07:03

Botond Horváth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!