[cfe-dev] Couldn't infer template argument '_BinaryOp' for std::max<int>
Krzysztof Parzyszek via cfe-dev
cfe-dev at lists.llvm.org
Fri Jan 25 09:40:00 PST 2019
Hi,
I have this snippet of code and I'm trying to understand if I'm doing
something wrong, or whether this is expected to work.
I want "max" to be the reduction function in transform_reduce, and so I
passed std::max<int> as the argument, but it resulted in a compilation
error (below). When I use an equivalent lambda, it works.
--- tr.cc ---
#include <numeric>
#include <vector>
struct S {
int v;
};
int fred(std::vector<S> &v) {
// Works
return std::transform_reduce(v.begin(), v.end(), 0,
[](const int &a, const int &b) { return std::max<int>(a, b); },
[](const S &s) { return s.v; });
// Fails
// return std::transform_reduce(v.begin(), v.end(), 0,
// std::max<int>,
// [](const S &s) { return s.v; });
}
-------------
$ clang++ -std=c++17 -c tr.cc -stdlib=libc++
tr.cc:12:10: error: no matching function for call to 'transform_reduce'
return std::transform_reduce(v.begin(), v.end(), 0,
^~~~~~~~~~~~~~~~~~~~~
/w/c/org/bin/../include/c++/v1/numeric:229:1: note: candidate template
ignored:
couldn't infer template argument '_BinaryOp'
transform_reduce(_InputIterator __first, _InputIterator __last,
^
/w/c/org/bin/../include/c++/v1/numeric:241:1: note: candidate function
template
not viable: requires 6 arguments, but 5 were provided
transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
^
/w/c/org/bin/../include/c++/v1/numeric:252:1: note: candidate function
template
not viable: requires 4 arguments, but 5 were provided
transform_reduce(_InputIterator1 __first1, _InputIterator1 __last1,
^
1 error generated.
-Krzysztof
More information about the cfe-dev
mailing list