Opened 13 years ago

Closed 13 years ago

Last modified 9 years ago

#3158 closed Bugs (invalid)

is_iless throws exception in string algorithms library

Reported by: David Psenicka <dpsenick@…> Owned by: Pavol Droba
Milestone: Boost 1.40.0 Component: string_algo
Version: Boost Development Trunk Severity: Problem
Keywords: is_iless Cc:

Description

I'm using g++ 4.3.2 in Linux. is_iless' throws a std::bad_cast' exception:

#include <string>
#include "/tmp/testsvn/boost/algorithm/string/compare.hpp"

int main() {
  boost::algorithm::is_less()(std::string("a"), std::string("b")); // this is ok
  boost::algorithm::is_iless()(std::string("a"), std::string("b")); // this throws `std::bad_cast'
  return 0;
}

I assume I using is_iless' correctly since is_less' gives me a correct return value.

Change History (3)

comment:1 by Pavol Droba, 13 years ago

Resolution: invalid
Status: newclosed

is_iless was never intended nor designed to compare strings. its function is to compare characters. It uses C++ locale facet to convert the case of the input and that facet is obviously not specialized for std::string.

use boost::ilexicographical_compare instead.

comment:2 by anonymous, 9 years ago

But manual sayis nothing about this:

"boost::algorithm::is_iless — case insensitive version of is_less.
Case insensitive comparison predicate. Comparison is done using specified locales."

comment:3 by Steven Watanabe, 9 years ago

is_less is also not intended to work on strings, although they way it's defined allows it to work.

"Header <boost/algorithm/string/compare.hpp>

Defines element comparison predicates. Many algorithms in this library can take an additional argument with a predicate used to compare elements. This makes it possible, for instance, to have case insensitive versions of the algorithms."

Note: See TracTickets for help on using tickets.