std::collate
STD:校对
Defined in header | | |
---|---|---|
template< class CharT > class collate; | | |
类std::collate
封装特定于地区的排序规则%28比较%29和字符串散列.。此面由std::basic_regex
并且可以通过std::locale::operator()
,直接指向所有期望字符串比较谓词的标准算法。
二次
二次
继承图
标准库提供了两个独立的%28区域设置无关%29的专门化:
在标头中定义<locale>
*。
STD:校对<char>实现字节字符串的字典排序
STD::整理<wchar[医]实现宽字符串的字典排序
此外,在C++程序中构造的每个locale对象都实现了自己的%28 locale特定于这些专门化的%29版本。
成员类型
Member type | Definition |
---|---|
char_type | CharT |
string_type | std::basic_string<CharT> |
成员函数
(constructor) | constructs a new collate facet (public member function) |
---|---|
(destructor) | destructs a collate facet (protected member function) |
compare | invokes do_compare (public member function) |
transform | invokes do_transform (public member function) |
hash | invokes do_hash (public member function) |
成员对象
static std::locale::id id | id of the locale (public member object) |
---|
受保护成员函数
do_compare virtual | compares two strings using this facet's collation rules (virtual protected member function) |
---|---|
do_transform virtual | transforms a string so that collation can be replaced by comparison (virtual protected member function) |
do_hash virtual | generates an integer hash value using this facet's collation rules (virtual protected member function) |
例
二次
#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 förnamn zebra ängel år ögrupp
English locale collation order: ängel ar år förnamn ögrupp zebra Zebra
Swedish locale collation order: ar förnamn zebra Zebra år ängel ögrupp
二次
另见
operator() | lexicographically compares two strings using this locale's collate facet (public member function of std::locale) |
---|---|
collate_byname | creates a collate facet for the named locale (class template) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。