40得票2回答
如何在if-constexpr中使用概念?

如何在 if constexpr 中使用概念? 给定以下示例,如果 T 满足 integral 的要求,则将什么提供给 if constexpr 以返回 1,否则返回 0? template<typename T> concept integral = std::is_inte...

39得票1回答
std::is_convertible和std::convertible_to有哪些实际应用上的区别?

根据en.cppreference.com(据我所知): - std::is_convertible是一个特征类,要求类型From和To是这样的:返回类型为To的函数可以编译并返回一个From值。 - std::convertible_to是一个概念,要求类型From和To符合上述条件,并且...

35得票2回答
为什么我不能在类范围内声明一个概念?

考虑以下代码:struct A { template <typename T> concept foo = true; }; 无法编译。我的Clang 10给出了错误:概念声明只能出现在全局或命名空间作用域中,GCC也说了类似的话。 不允许这样做的原因是什么?即使封...

32得票2回答
同时存在运算符“==”和“!=”会破坏一些概念。

升级到最新的Visual Studio 2022版本17.6后,我们的一个自定义视图不再被识别为std::ranges::range。原来问题出在视图迭代器中同时存在operator ==和operator !=。请参见下面的简化示例(不包括视图和迭代器): struct A { f...

29得票5回答
概念和接口有什么区别?

Concepts(即最近从C++0x标准中删除的概念)与Java等语言中的接口有何不同?

29得票4回答
为什么在约束条件中添加"&& true"可以使函数模板更好地重载?

考虑下面这个函数模板 foo 的两个重载版本: \{\{foo\}\}的两个重载版本如下: template <typename T> void foo(T) requires std::integral<T> { std::cout << "f...

26得票1回答
约束包容性是否只适用于概念?

考虑一下这个例子:template <typename T> inline constexpr bool C1 = true; template <typename T> inline constexpr bool C2 = true; template &l...

26得票2回答
C++多模板参数概念

Bjarne Stroustrup最近发布了一份关于C++概念的报告,他在其中提到了一些令人惊讶的内容。例子(在第7.1节中)使用了“简写模板符号”,基本上是这样的: void foo1(auto x,auto y); // x and y may have d...

26得票3回答
C++20概念:当模板参数符合多个概念时,选择哪个模板特化?

给定:#include <concepts> #include <iostream> template<class T> struct wrapper; template<std::signed_integral T> struct wrap...

25得票3回答
为什么我们不能专门化概念?

类的语法不适用于概念: template <class Type> concept C = requires(Type t) { // ... }; template <class Type> concept C<Type*> = requir...