为什么在 Boost zip 迭代器上使用 C++17 并行执行算法时 MSVC 出现错误?
Why am I getting an error with MSVC when using a C++17 parallel execution algorithm on Boost zip iterators?
我在 MSVC 上使用带有 Boost 迭代器的 C++17 并行执行算法时遇到一些问题。这是我的代码:
#include <vector>
#include <execution>
#include <boost/range/combine.hpp>
int main(void)
{
std::vector<double> const v1(20, 1);
std::vector<double> const v2(20, 2);
std::vector<double> v_out;
v_out.resize(20);
auto const & combi = boost::combine(v1, v2);
auto const run = [](auto const & v)
{
return boost::get<0>(v) + boost::get<1>(v);
};
std::transform(std::execution::par, combi.begin(), combi.end(), v_out.begin(), run);
return 0;
}
我收到以下错误:
error C2338: Parallel algorithms require forward iterators or stronger.
这似乎是由于 Boost zip 迭代器,但我不明白为什么,因为它在 GCC 上编译时没有错误。我在这里错过了什么?这是 Visual C++ 中的错误实现吗?
zip 迭代器只能在 C++17 迭代器层次结构中输入,因为它们的引用类型不是真正的引用。
将输入迭代器传递给并行算法是未定义的行为。 MSVC 的实现恰好比 GCC 的更积极地检查前提条件。
我在 MSVC 上使用带有 Boost 迭代器的 C++17 并行执行算法时遇到一些问题。这是我的代码:
#include <vector>
#include <execution>
#include <boost/range/combine.hpp>
int main(void)
{
std::vector<double> const v1(20, 1);
std::vector<double> const v2(20, 2);
std::vector<double> v_out;
v_out.resize(20);
auto const & combi = boost::combine(v1, v2);
auto const run = [](auto const & v)
{
return boost::get<0>(v) + boost::get<1>(v);
};
std::transform(std::execution::par, combi.begin(), combi.end(), v_out.begin(), run);
return 0;
}
我收到以下错误:
error C2338: Parallel algorithms require forward iterators or stronger.
这似乎是由于 Boost zip 迭代器,但我不明白为什么,因为它在 GCC 上编译时没有错误。我在这里错过了什么?这是 Visual C++ 中的错误实现吗?
zip 迭代器只能在 C++17 迭代器层次结构中输入,因为它们的引用类型不是真正的引用。
将输入迭代器传递给并行算法是未定义的行为。 MSVC 的实现恰好比 GCC 的更积极地检查前提条件。