M
Matthias
Now I am confused.
I am doing a "less" comparison in my program between strings, to see
which strings in some range precede others.
This is my approach:
class SortedByName
{
public:
bool operator() (const boost::filesystem:ath& lhs,
const boost::filesystem:ath& rhs) {
std::string path1 = lhs.leaf();
std::string path2 = rhs.leaf();
boost::algorithm::to_lower( path1 );
boost::algorithm::to_lower( path2 );
return path1 < path2;
}
};
Now, there are at least two questions coming to my mind:
1. How does operator< work on strings? I wanted to look it up in my C++
implementation doc, but it doesn't exist in the std::basic_string
reference! (the comparison works by the way).
2. Meyers has an own item in his STL book which is dedicated to exactly
this topic. He doesn't even mention an operator< to do the comparison,
but suggests to use lexicographical_compare, which however would need me
to supply a (correct and portable) comparison predicate for characters.
What's the deal?
I am doing a "less" comparison in my program between strings, to see
which strings in some range precede others.
This is my approach:
class SortedByName
{
public:
bool operator() (const boost::filesystem:ath& lhs,
const boost::filesystem:ath& rhs) {
std::string path1 = lhs.leaf();
std::string path2 = rhs.leaf();
boost::algorithm::to_lower( path1 );
boost::algorithm::to_lower( path2 );
return path1 < path2;
}
};
Now, there are at least two questions coming to my mind:
1. How does operator< work on strings? I wanted to look it up in my C++
implementation doc, but it doesn't exist in the std::basic_string
reference! (the comparison works by the way).
2. Meyers has an own item in his STL book which is dedicated to exactly
this topic. He doesn't even mention an operator< to do the comparison,
but suggests to use lexicographical_compare, which however would need me
to supply a (correct and portable) comparison predicate for characters.
What's the deal?