Localization library | |||||||||||||||||||||||||
Regular expressions library(C++11) | |||||||||||||||||||||||||
Formatting library(C++20) | |||||||||||||||||||||||||
Null-terminated sequence utilities | |||||||||||||||||||||||||
Byte strings | |||||||||||||||||||||||||
Multibyte strings | |||||||||||||||||||||||||
Wide strings | |||||||||||||||||||||||||
Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
Text encoding identifications | |||||||||||||||||||||||||
|
|
Member types | ||||
Member functions | ||||
(C++26) | ||||
(until C++20) | ||||
locale::operator() | ||||
Static member functions | ||||
template<class CharT,class Traits,class Alloc> bool operator()(conststd::basic_string<CharT,Traits,Alloc>& s1, | ||
Compares two string argumentss1 ands2 according to the lexicographic comparison rules defined by this locale'sstd::collate<CharT> facet. This operator allows any locale object that has a collate facet to be used as a binary predicate in the standard algorithms (such asstd::sort) and ordered containers (such asstd::set).
Contents |
s1 | - | the first string to compare |
s2 | - | the second string to compare |
true ifs1 is lexicographically less thans2,false otherwise.
template<class CharT,class Traits,class Alloc>bool operator()(conststd::basic_string<CharT,Traits,Alloc>& s1,conststd::basic_string<CharT,Traits,Alloc>& s2)const{returnstd::use_facet<std::collate<CharT>>(*this).compare( s1.data(), s1.data()+ s1.size(), s2.data(), s2.data()+ s2.size())<0;} |
Avector ofstrings can be sorted according to a non-default locale by using the locale object as comparator:
#include <algorithm>#include <cassert>#include <locale>#include <string>#include <vector> int main(){std::vector<std::wstring> v={L"жил", L"был", L"пёс"};std::sort(v.begin(), v.end(),std::locale("ru_RU.UTF8"));assert(v[0]== L"был");assert(v[1]== L"жил");assert(v[2]== L"пёс");}
defines lexicographical comparison and hashing of strings (class template)[edit] |