GCC: #39;std::is_same_vlt;int, Tgt;#39; is not usable in a constant expression(GCC::is_ame_vlt;int,T;不能在常量表达式中使用)
问题描述
正在尝试实现the following code:
template <typename R, typename V>
concept SizedRangeOf =
std::ranges::sized_range<R> &&
std::same_as<std::ranges::range_value_t<R>, V>;
template<typename T>
const SizedRangeOf<T> auto getView(std::vector<T>& vec) {
// helper class
class vector_view {
std::vector<T>& vec;
public:
vector_view(std::vector<T>& vec): vec(vec) {}
auto begin() const { return vec.begin(); }
auto end() const { return vec.end(); }
std::size_t size() const { return vec.size(); }
};
return vector_view { vec };
}
int main() {
std::vector<int> v = {1, 3, 5};
auto r = getView(v);
v.push_back(7);
for(auto val: r) {
std::cout << val << ' '; // 1 3 5 7
}
}
在Clang 11.0中编译和工作正常,但在GCC 10.2中失败,并出现以下错误:
the value of 'std::is_same_v<int, T>' is not usable in a constant expression
是GCC的虫子吗?还是代码有问题?
推荐答案
似乎是GCC bug:
错误97402-依赖部分概念id的值在常量表达式中不可用。
编辑2022年2月4日:Bug is fixed in GCC 11.1
Playing with the same code尝试在GCC中编译时会导致'internal compiler error: Segmentation fault',这是一个在Clang中编译得很好的代码。
编辑2022年2月4日:Also fixed in GCC 11.1
Another attempt to play with the code导致std::is_same计算为false,而Clang将其计算为true。
编辑2022年2月4日:Also fixed in GCC 11.1
Implementing our own is_same也无济于事。
编辑2022年2月4日:Also fixed in GCC 11.1
但需要注意的是,使用std::same_as作为概念的一部分,用于参数声明works fine。
这篇关于GCC::is_ame_v<;int,T&>;不能在常量表达式中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:GCC::is_ame_v<;int,T&>;不能在常量表达式中使用
基础教程推荐
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
