Home:ALL Converter>Comparison operator to be used in std::lower_bound

Comparison operator to be used in std::lower_bound

Ask Time:2015-05-28T11:47:14         Author:meneldal

Json Formatter

My compiler refuse to compile this simple code:

struct mystruct{
    int x;
    bool operator<(const mystruct& y) const{ return x < y.x; }
};


std::map<mystruct, int> test;
auto it = std::lower_bound(test.begin(), test.end(), mystruct{2});

I'm getting the error

error C2893: Failed to specialize function template 'unknown-type std::less<void>::operator ()(_Ty1 &&,_Ty2 &&) const'

Looking at this link, it seems that you just need to define a constant comparison operator which is exactly what I'm doing. Is there something I am missing here?

Author:meneldal,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30496881/comparison-operator-to-be-used-in-stdlower-bound
yy