名前空間
変種
操作

std::collate

From cppreference.com
< cpp‎ | locale
 
 
 
 
 
ヘッダー <locale> で定義
template< class CharT >
class collate;

クラスstd::collateは、ロケール固有の文字列の照合(比較)およびハッシュをカプセル化します。このファセットは、std::basic_regexによって使用され、std::locale::operator()を介して、文字列比較述語を期待するすべての標準アルゴリズムに直接適用できます。

cpp/locale/locale/facetstd-collate-inheritance.svg

継承図

目次

[編集] 特殊化

標準ライブラリは、以下の特殊化を提供することが保証されています(これらは あらゆるロケールオブジェクトによって実装される必要があります)。

ヘッダー <locale> で定義
std::collate<char> バイト文字列の辞書順ソートを実装します。
std::collate<wchar_t> ワイド文字列の辞書順ソートを実装します。

[編集] ネストされた型

定義
char_type CharT
string_type std::basic_string<CharT>

[編集] データメンバ

メンバ 説明
std::locale::id id [static] ファセットの識別子

[編集] メンバ関数

新しいcollateファセットを構築します。
(public member function)
collateファセットを破棄します。
(protected メンバ関数)
do_compareを呼び出します。
(public member function) [編集]
do_transformを呼び出します。
(public member function) [編集]
do_hashを呼び出します。
(public member function) [編集]

[編集] protectedメンバ関数

[virtual]
このファセットの照合規則を使用して2つの文字列を比較します。
(virtual protected member function) [編集]
[virtual]
照合を比較に置き換えることができるように文字列を変換します。
(virtual protected member function) [編集]
[virtual]
このファセットの照合規則を使用して整数ハッシュ値を生成します。
(virtual protected member function) [編集]

[編集]

#include <algorithm>
#include <iostream>
#include <locale>
#include <string>
#include <vector>
 
int main()
{
    std::locale::global(std::locale("en_US.utf8"));
    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のpublicメンバ関数) [編集]
名前付きロケールのシステム供給std::collateを表します。
(クラステンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)