c++ - 明确的概念特化

标签 c++ c++20 c++-concepts

我正在尝试使用概念对某些模板方法进行显式特化,但它不是在 gcc 上编译的或 msvc , 但可以在 clang 上编译...谁是对的?

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

}

最佳答案

正确的语法是

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

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

所以没有template<>template<arithmetic T>

关于c++ - 明确的概念特化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69147302/

相关文章:

c++ - 将 int* 转换为字符串,然后将字符串转换为 int*

c++ - 在自定义容器上使用范围算法

要求存在精确函数签名的 C++20 概念

c++ - std::assignable_from 可能实现背后的基本原理

c++ - sfinae 与非类型模板参数的概念

c++ - 绘制和旋转箭头

c++ - 在 Debug模式下运行时 VS2012 中的命令参数错误

c++ - 为什么通过流获取的 std::string 被覆盖?

c++ - 分区模块是否由主模块接口(interface)单元输出?

c++ - C++ 概念可以用于在 C++ 中实现混合类型 min 和 max 吗?