gpt4 book ai didi

c++ - 明确的概念特化

转载 作者:行者123 更新时间:2023-12-04 16:36:37 24 4
gpt4 key购买 nike

我正在尝试使用概念对某些模板方法进行显式特化,但它不是在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com