I'm having an issue porting my functor from windows to linux. (a functor to pass to stl::map for strict-weak ordering) The original is as follows:
struct stringCompare{ // Utilized as a functor for stl::map parameter for strings
bool operator() (string lhs, string rhs){ // Returns true if lhs < rhs
if(_stricmp(lhs.c_str(), rhs.c_str()) < 0) return true;
else return false;
}
};
As linux doesnt support _stricmp but uses strcasecmp instead, I changed it to:
struct stringCompare{
bool operator() (string lhs, string rhs){ // Returns true if lhs < rhs
if(strcasecmp(lhs.c_str(), rhs.c_str()) < 0) return true;
else return false;
}
};
And it is now complaining about "const" parameters:
passing const stringCompare as this argument of bool stringCompare::operator()
(std::string, std::string)â discards qualifiers
I'm not entirely sure why it supposes stringCompare should be a constant...
And the line where it is mad about this being instantiated is:
if(masterList->artistMap.count(songArtist) == 0)
artistMap being an stl::map with a string key.
I'm not sure where I'm going wrong. I attempted to change the bool operator() parameters to const, as it appears that it's complaining about some sort of non-constant parameter passing. This didn't work, nor did changing 'bool operator()' to 'const bool operator()'.
As far as I know, strcasecmp is a const function so should case whether I pass it non-constant or constant parameters (c_str() also being const), so I'm not exactly certain where I'm going wrong.
I've googled similar issues but I still can't quite make sense of the issue from what I've seen both on stackoverflow and a couple other places.
The datatype where I'm using this is:
map<string, set<song, setSongCompare>*,stringCompare > artistMap;