Namespaces
Variants

std:: collate

From cppreference.net
ヘッダー <locale> で定義
template < class CharT >
class collate ;

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

cpp/locale/locale/facet std-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] facet の識別子

メンバー関数

新しい collate ファセットを構築する
(public member function)
collate ファセットを破棄する
(protected member function)
do_compare を呼び出す
(public member function)
do_transform を呼び出す
(public member function)
do_hash を呼び出す
(public member function)

プロテクテッドメンバー関数

[virtual]
このファセットの照合規則を使用して2つの文字列を比較する
(仮想保護メンバー関数)
[virtual]
照合を比較で置き換えられるように文字列を変換する
(仮想保護メンバー関数)
[virtual]
このファセットの照合規則を使用して整数ハッシュ値を生成する
(仮想保護メンバー関数)

#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 の公開メンバ関数)
名前付きロケールのシステム提供の std::collate を表す
(クラステンプレート)