std::collate
cppreference.com
[] |
Google. . , . , . |
<metanoindex/>
<tbody> </tbody> template< class CharT > class collate; |
||
std::collate () . std::basic_regex ,
std::locale::operator(), , .:
Class std::collate encapsulates locale-specific collation (comparison) and hashing of strings. This facet is used by std::basic_regex and can be applied, by means of
std::locale::operator(), directly to all standard algorithms that expect a string comparison predicate. , C + +
:
Two specializations are provided by the standard library and are implemented by all locale objects created in a C++ program:
<locale> | |
std::collate<char>
|
|
std::collate<wchar_t>
|
|
-
char_type
|
charT
|
string_type
|
std::basic_string<charT>
|
-
(public -) | |
(protected -) | |
do_compare (public -) | |
do_transform (public -) | |
do_hash (public -) |
static std::locale::id id |
' ( -) |
-
[virtual] |
(virtual protected -) |
[virtual] |
, (virtual protected -) |
[virtual] |
- (virtual protected -) |
#include <locale>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
int main()
{
std::wcout.imbue(std::locale(""));
std::vector<std::wstring> v = {L"ar", L"zebra", L"\u00f6grupp", L"Zebra", L"\u00e4ngel",
L"\u00e5r", L"f\u00f6rnamn"};
std::wcout << "Default locale collation order: ";
std::sort(v.begin(), v.end());
for(auto s : v) std::wcout << s << ' '; std::wcout << '\n';
std::wcout << "English locale collation order: ";
std::sort(v.begin(), v.end(), std::locale("en_US.UTF-8"));
for(auto s : v) std::wcout << s << ' '; std::wcout << '\n';
std::wcout << "Swedish locale collation order: ";
std::sort(v.begin(), v.end(), std::locale("sv_SE.UTF-8"));
for(auto s : v) std::wcout << s << ' '; std::wcout << '\n';
}
:
Default locale collation order: Zebra ar frnamn zebra ngel r grupp
English locale collation order: ngel ar r frnamn grupp zebra Zebra
Swedish locale collation order: ar frnamn zebra Zebra r ngel grupp
.
| , (public - std::locale)
| |
( ) |