std::collate_C++中文网
| template< class CharT > |
||
类 std::collate 封装字符串的本地环境限定对照(比较)和哈希。此平面为 std::basic_regex 所用,并能以 std::locale::operator() 直接应用到所有期待 string 比较谓词的标准算法。
继承图
标准库提供二个孤立(不依赖本地环境)的特化:
| 定义于头文件 | |
| std::collate<char> | 实现字节字符串的字典序定序 |
| std::collate<wchar_t> | 实现宽字符串的字典序定序 |
另外, C++ 程序中构造的每个 locale 对象都实装这些特化的其自身(本地环境限定)版本。
成员类型
| 成员类型 | 定义 |
char_type
|
CharT
|
string_type
|
std::basic_string<CharT>
|
成员函数
成员对象
| static std::locale::id id |
locale 的 id (公开成员对象) |
受保护成员函数
示例
#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