https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65942
Bug ID: 65942
Summary: cannot use std::function as comparator in algorithms
Product: gcc
Version: 5.0
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: [email protected]
Target Milestone: ---
Too much template magic causes gcc 5.1 to reject the following valid code:
#include <experimental/optional>
#include <algorithm>
#include <functional>
using T1 = int;
using T2 = std::vector<T1>;
bool cmp1(const T1& a, const T1& b) { return a < b; }
std::function<bool (const T1&, const T1&)> cmp2 = cmp1;
int main(int ac, char** av) {
T2 v;
std::sort(v.begin(), v.end(), cmp1); // works
std::sort(v.begin(), v.end(), cmp2); // fails
}
Even though the two calls to sort() should be identical, the second one does
not compile.
This is a regression from 4.9