String compare (instead of just less) that returns -1, 0 or 1
Hi, Does Boost contain a (string) compare function that returns -1 if a < b, 0 if a == b and 1 if a > b? Doing both < and == sounds like a lot of extra work in for example sorting algorithms.
Olaf van der Spek wrote:
Hi,
Does Boost contain a (string) compare function that returns -1 if a < b, 0 if a == b and 1 if a > b? Doing both < and == sounds like a lot of extra work in for example sorting algorithms.
std::string itself has a compare() member function that does this. You can use Boost.Bind to turn it into a function object. In addition, the string algorithm library has such functions in the development version, likely to be included in the next official release. Sebastian Redl
On 3/5/06, Sebastian Redl
Does Boost contain a (string) compare function that returns -1 if a < b, 0 if a == b and 1 if a > b? Doing both < and == sounds like a lot of extra work in for example sorting algorithms.
std::string itself has a compare() member function that does this. You can use Boost.Bind to turn it into a function object.
But that's only case sensitive I guess. Does STL also have such a three-way function for ints (or a generic function)?
In addition, the string algorithm library has such functions in the development version, likely to be included in the next official release.
What's the name of those?
Hi, On Sun, Mar 05, 2006 at 07:28:52PM +0100, Olaf van der Spek wrote:
On 3/5/06, Sebastian Redl
wrote: Does Boost contain a (string) compare function that returns -1 if a < b, 0 if a == b and 1 if a > b? Doing both < and == sounds like a lot of extra work in for example sorting algorithms.
std::string itself has a compare() member function that does this. You can use Boost.Bind to turn it into a function object.
But that's only case sensitive I guess. Does STL also have such a three-way function for ints (or a generic function)?
In addition, the string algorithm library has such functions in the development version, likely to be included in the next official release.
What's the name of those?
There is case-insensitive lexicographical_compare included in string_algo lib. but it has only bool return value, not integer as you require. I could add something like that in future, but I will not be included in the following release. Regards, Pavol
participants (3)
-
Olaf van der Spek
-
Pavol Droba
-
Sebastian Redl