std::collate
提供: cppreference.com
ヘッダ <locale> で定義
|
||
template< class CharT > class collate; |
||
クラス std::collate はロケール固有の文字列の照合 (比較) およびハッシュ化をカプセル化します。 このファセットは std::basic_regex によって使用され、また、文字列比較の述語を期待するすべての標準アルゴリズムに直接 (std::locale::operator() の意味で) 適用できます。
2つのスタンドアロンな (ロケール非依存な) 特殊化が標準ライブラリによって提供されます。
ヘッダ
<locale> で定義 | |
std::collate<char> | バイト文字列の辞書順を実装します |
std::collate<wchar_t> | ワイド文字列の辞書順を実装します |
さらに、 C++ のプログラム内で構築されたすべてのロケールオブジェクトは、これらの特殊化の独自の (ロケール固有の) バージョンを実装します。
目次 |
[編集] メンバ型
メンバ型 | 定義 |
char_type
|
CharT
|
string_type
|
std::basic_string<CharT>
|
[編集] メンバ関数
constructs a new collate facet (パブリックメンバ関数) | |
destructs a collate facet (プロテクテッドメンバ関数) | |
do_compare を呼びます (パブリックメンバ関数) | |
do_transform を呼びます (パブリックメンバ関数) | |
do_hash を呼びます (パブリックメンバ関数) |
[編集] メンバオブジェクト
static std::locale::id id |
ロケールの id (パブリックメンバオブジェクト) |
[編集] プロテクテッドメンバ関数
[仮想] |
このファセットの照合ルールを用いて2つの文字列を比較します (仮想プロテクテッドメンバ関数) |
[仮想] |
照合を比較に置き換えられるように文字列を変換します (仮想プロテクテッドメンバ関数) |
[仮想] |
このファセットの照合ルールを用いて整数のハッシュ値を生成します (仮想プロテクテッドメンバ関数) |
[編集] 例
Run this code
#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
[編集] 関連項目
このロケールの照合ファセットを用いて2つの文字列を辞書的に比較します ( std::locale のパブリックメンバ関数)
| |
creates a collate facet for the named locale (クラステンプレート) |