通过概念启用的成员函数的外部类别定义
以下这个问题,我试图定义成员函数由班级定义之外的概念启用: template concept MyConcept = std::is_integral::value; //could be anything... temp…
模板中的嵌套概念类型
考虑以下模板,旨在声明某些 state :: Machine : enum Strategy { Breadth, Depth, Heuristic, }; template struct Machine; 如果我们想对 MAP 类型…
为什么在std :: string` std ::功能上``std :: subrange'''std :: functional` lambda存储在``sTD :: vector'的lambda''中的行为呢?
考虑以下代码,其中包含一个模板 std :: vector std :: function 对象的类型> const& std :: range 和 std :: range :: iterator 。导致位置 std…
概念评估性&可变模板部分专业化
目前,我遇到了一个问题,三个主要编译器给我带来了三种不同的结果。 (gcc trunk,clang trunk,msvc.v19.latest,均在x86-64下)。 代码&编译…
(非)模棱两可的静态超负荷
我的类模板 NodeMaker 具有3个静态成员函数模板,称为 create_node ,使用C ++ 20概念通过其参数区分。调用 nodemaker< :: create_node(x)来自 …
C++ 20概念:要求对象具有对参数有进一步要求的方法,并返回值
假设我想指定一个对象必须具有一个方法映射(...),该方法将forward_range映射到另一个(可能不同的)向前_range。我该如何在一个概念中表达这一点?…
如果指定两个要求,为什么我的概念不起作用
我有以下代码: #include #include #include template concept OperatorLike = requires(T t, const std::string s) { { t.get_string(s) } -> std::s…
概念中的嵌套模板结构
我有这样的结构: struct i32 { template struct val { static constexpr int32_t v = x; }; template struct add { using type = val; }; template u…
在概念定义中检查成员函数模板的存在
假设我有一个概念概念和一堆类似类型的类型,这些类型提供了一个成员函数模板,如下所示: class Typical { template auto something() { return ...;…
为什么在约束中找到模板,而不是函数? C++ 20
我正在学习C ++ 20个概念和约束,但我不明白为什么在这种情况下被认为是未定义的,但它似乎在需要子句中工作正常。这里怎么了?为什么? 如果我删除了…
检查类型(a)==类型(b)还是类型(a)==类型(b带有删除的constness)
我在元素的向量存储中创建矩阵视图。 有效组合为: vector value_type 矩阵 value_type const(arithmetic) const(arithmetic) (arithmetic)(ar…
我如何检查特定的模板参数是相同的
我有一个带有三个模板参数的类: template class Unit; 然后,我有一个代表此类及其专业化的概念: template struct is_unit : std::false_type {}; t…
如何检查类型是格式化的'使用类型特征 /概念?
我想检查是否可以与 std ::格式一起使用某种类型。 这是我天真的尝试: template concept formattable = requires(const Object & obj) { std::format…