小编Red*_*ave的帖子

为什么std中仍然没有启用范围的归约算法?

唯一可用的选项是std::ranges::for_each简单的基于范围的for循环。没有对应的std::accumulate,std::reducestd::inner_productstd::ranges::reduce如果有的话就足够了;内积可以结合reduce和zip来实现。回到基于迭代器的算法是令人失望的。为个人代码库调整reduce并不是什么大问题,但恕我直言,std函数更可取。我想知道 std lib 或 23 地平线上是否有这样的功能。

问候,FM。

c++ std range c++23 isocpp

17
推荐指数
1
解决办法
2335
查看次数

概念和实际类型的模糊模板专业化:哪个编译器是正确的?

考虑以下代码:

#include<concepts>

template<typename>
void foo() { }

template<std::integral> 
void foo() { }

template<> 
void foo<bool>() { }

int main() { foo<bool>(); }
Run Code Online (Sandbox Code Playgroud)

它在最近的 Clang 和 MSVC 下编译没有问题,但在 GCC 下编译没有问题(godbolt 链接

使用 GCC 构建失败并显示:

error: ambiguous template specialization 'foo<bool>' for 'void foo()'
    9 | void foo<bool>() { }
      |      ^~~~~~~~~
note: candidates are: 'template<class> void foo()'
    3 | void foo() { }
      |      ^~~
note:                 'template<class>  requires  integral< <template-parameter-1-1> > void foo()'
    6 | void foo() { }
      | …
Run Code Online (Sandbox Code Playgroud)

c++ template-specialization language-lawyer explicit-specialization c++-concepts

6
推荐指数
1
解决办法
139
查看次数

`std::views` 的右关联性

左关联性已由 C++ 核心语义保证: R|V1|V2被解析为(R|V1)|V2). 如果编码员想要显式地将操作顺序更改为 ,该怎么办R|(V1|V2)?这在 C++23 下可能吗?这个问题背后的原因是它简化了自定义范围适配器的定义:

auto myV=V1|V2|V3;
for(auto& x:R1|myV)/*..*/;
for(auto& x:R2|myV)/*..*/;
Run Code Online (Sandbox Code Playgroud)

所有这些需求似乎都是对 ; 的适当约束过载std::views::operator|;这种超载是否存在?如果没有的话会添加吗?如果不是,其背后的理由是什么?

c++ std-ranges c++23

0
推荐指数
1
解决办法
92
查看次数