C++17 no matching function for call to reduce error

Viewed 708

This code is from the book C++17 Standard Library Quick Reference by Apress:

#include <numeric>
#include <vector>

using namespace std;
int main() {
  vector vec {4,2,5,1,3,6};
  int sum = reduce( begin(vec), end(vec));
}

When I compile it with g++-9.2 using the option -std=c++17 (or -std=gnu++2a) on Windows 7, I get:

error: no matching function for call to 'reduce(std::vector<int, std::allocator<int> >::iterator, std::vector<int, std::allocator<int> >::iterator)'

What's wrong with this code? Thank you.

1 Answers

As another comment already pointed out, I have tried compiling your code with x86-64 gcc (contracts) version which is, I suppose, experimental version of gcc compiler and the compilation was successful. Try it here.

Also, I run into an interesting post on Reddit with the same topic as the one we are discussing here.

EDIT

As OP posted in the comment below, gcc-10.0.0 compiles code from the question successfully.

Related