In PGI 19.10 community edition, some overloaded functions of std::transform_reduce() are missing while PGI claims C++17 are fully supported.
More specifically, implementations of (1),(2), and (3) in the following website are missing.
https://en.cppreference.com/w/cpp/algorithm/transform_reduce
Progam I compiled is …
#include <iostream>
#include <vector>
#include <numeric>
int main()
{
const std::vector<int> v1 = {1, 2, 3, 4, 5};
const std::vector<int> v2 = {2, 3, 4, 5, 6};
// (1) : 2つのリストを集計する
// sum1 = 1*2 + 2*3 + 3*4 + 4*5, 5*6
int sum1 = std::transform_reduce(v1.begin(), v1.end(), v2.begin(), 0);
std::cout << "sum1 : " << sum1 << std::endl;
// (2) : 2つのリストを集計する。
// リストを集計する2項演算と、2つのリストの要素を掛け合わせる2項演算を指定する
int sum2 = std::transform_reduce(v1.begin(), v1.end(), v2.begin(), 0,
[](int a, int b) { return a + b; }, // 集計関数
[](int a, int b) { return a * b; }); // 2つの要素を合成する関数
std::cout << "sum2 : " << sum2 << std::endl;
// (3) : リストの各要素を変換しながら集計する
// 1*2 + 2*2 + 3*2 + 4*2 + 5*2
int sum3 = std::transform_reduce(v1.begin(), v1.end(), 0,
[](int acc, int i) { return acc + i; }, // 集計関数
[](int x) { return x * 2; }); // 変換関数
std::cout << "sum3 : " << sum3 << std::endl;
}
And, PGI compiler spits the error described below.
"./cpprefjp_transform_reduce.cpp", line 14: error: no instance of overloaded
function "std::transform_reduce" matches the argument list
argument types are: (__gnu_cxx::__normal_iterator<const int *,
std::vector<int, std::allocator<int>>>,
__gnu_cxx::__normal_iterator<const int *,
std::vector<int, std::allocator<int>>>,
__gnu_cxx::__normal_iterator<const int *,
std::vector<int, std::allocator<int>>>, int)
int sum1 = std::transform_reduce(v1.begin(), v1.end(), v2.begin(), 0);
Note that, when I added an execution policy (std::execution::seq or par) to the first argument, functions are working as I expected.
Best,
Miya