Has C ++ 11 implemented a case-insensitive string comparison algorithm?

Just switched to C ++ 11 in GCC 4.8 and it would be nice to move away from boost::iequals in favor of STL. I searched around interwebs, but I did not see any signs of std::iequals or the new std::basic_string methods to support this natively in the STL.

If this does not exist in C ++ 11, is there an approach to solving this problem since C ++ 03 (i.e. different workarounds?), Or is stimulus still preferred?

Thanks in advance.

+5
source share
2 answers

No, C ++ 11 did not introduce case-insensitive string comparison. Now you need to use Boost.

Hope this helps!

+10
source

There is no native string comparison, but with rich STL you can write your own very simply something like this:

`

 bool caseInsensitiveCmp(wstring str1, wstring str2) { if ( str1.size() != str2.size()) return false; else return (str1.empty() | str2.empty()) ? false : std::equal(str1.begin(), str1.end(),str2.begin(), [](wchar_t a, wchar_t b) { return tolower(a) == tolower(b); } ); }` 

The first check is std protection: it is equal to comparison from any length.

0
source

Source: https://habr.com/ru/post/1202206/


All Articles