没有执行策略的 std::transform_reduce 是可移植的吗?

Is std::transform_reduce without execution policy portable?

本文关键字:reduce 可移植 transform 策略 std 执行      更新时间:2023-10-16

我可以在 Fedora 和 Ubuntu 上使用 gcc 9.2.1 编译以下代码(使用std::transform_reduce(,但尝试在 clang 上编译看到 godbolt 失败,我有一个报告,一些 FSF 版本的 gcc 9.2.1 也拒绝编译代码,需要std::execution_policy作为std::transform_reduce的第一个参数。

#include <vector>
#include <algorithm>
#include <numeric>
auto brokenvector(std::vector<int> const& a, std::vector<int> const& b) 
{
return std::transform_reduce(cbegin(a), cend(a), cbegin(b), 0, std::plus<>{},std::multiplies<>{});
}

我在这里特别不能使用std::execution_policy,并且 cpp首选项和C++草案标准文档 n4659 都显示了没有执行策略重载。

我是否进入了某种政治雷区,一半的可用编译器拒绝实施标准,或者代码不正确?

这是一个libstdc++与libc++的问题。 libc ++实现了这个函数,在这个实时示例中,您可以看到它使用-stdlib=libc++在Godbolt上与Clang一起工作。 GCC 现在在 Trunk 中实现了它,但当前发布的版本没有。 该函数已添加到此提交中。