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 객체에 의해 구현되어야 합니다 ):

헤더 파일에 정의됨 <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 member function)
do_compare 를 호출합니다
(public member function)
do_transform 를 호출합니다
(public member function)
do_hash 를 호출합니다
(public member function)

보호된 멤버 함수

[virtual]
이 패싯의 문자열 정렬 규칙을 사용하여 두 문자열을 비교합니다
(가상 protected 멤버 함수)
[virtual]
문자열을 변환하여 정렬을 비교 연산으로 대체할 수 있게 합니다
(가상 protected 멤버 함수)
[virtual]
이 패싯의 문자열 정렬 규칙을 사용하여 정수 해시 값을 생성합니다
(가상 protected 멤버 함수)

예제

#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

참고 항목

이 로캘의 collate 패싯을 사용하여 두 문자열을 사전식으로 비교함
( std::locale 의 public 멤버 함수)
명명된 로캘에 대한 시스템 제공 std::collate 를 나타냄
(클래스 템플릿)