namespace std {
template <class charT>
class collate : public locale::facet;
}
概要
collateは、文字列の照合(比較)とハッシュ計算のための機能を提供するロケールファセットである。
localeのメンバ関数テンプレートoperator()は、このファセットを使用することで、localeオブジェクトを文字列を扱うアルゴリズムやコンテナの述語として直接使えるようにしている。
規格が要求する特殊化(collate<char>とcollate<wchar_t>)は、辞書順による順序付けを行う。
メンバ関数
publicメンバ関数
| 名前 | 説明 |
|---|---|
(constructor) |
コンストラクタ |
compare |
文字列を比較する |
transform |
文字の範囲を照合順序での比較に使える文字列に変換する |
hash |
文字範囲のハッシュ値を求める |
静的メンバ変数
| 名前 | 説明 |
|---|---|
static locale::id id; |
このファセットを識別するためのID |
protectedメンバ関数
| 名前 | 説明 |
|---|---|
(destructor) |
デストラクタ |
do_compare |
文字列を比較する |
do_transform |
文字の範囲を照合順序での比較に使える文字列に変換する |
do_hash |
文字範囲のハッシュ値を求める |
メンバ型
| 名前 | 説明 |
|---|---|
char_type |
文字型 charT |
string_type |
文字列型 std::basic_string<charT> |
例
#include <iostream>
#include <locale>
int main()
{
const auto& col = std::use_facet<std::collate<char>>(std::locale::classic());
const char a[] = "abc";
const char b[] = "abd";
// ロケールの照合順序で比較する
std::cout << col.compare(a, a + 3, b, b + 3) << std::endl;
}
出力
-1
バージョン
言語
- C++98