I'm trying to do a case-insensitive string comparsion on two std::u16string instances with boost. Based on my searching, I need to generate a locale, which I'm doing.
#include <boost/algorithm/string.hpp>
#include <boost/locale.hpp>
#include <locale>
#include <iostream>
int main() {
// Create the strings
std::u16string str1 = boost::locale::conv::utf_to_utf<char16_t>("unicode");
std::u16string str2 = boost::locale::conv::utf_to_utf<char16_t>("UNICODE");
// Create the locale
boost::locale::generator gen;
std::locale loc = gen("");
// Doesn't matter if I do this or not
//std::locale::global(loc);
// Try to compare
if (boost::iequals(str1, str2, loc)) {
std::cout << "EQUAL\n";
} else {
std::cout << "!EQUAL\n";
}
return 0;
}
This results in an std::bad_cast exception:
terminate called after throwing an instance of 'std::bad_cast'
what(): std::bad_cast
What am I doing wrong?