Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::collate

      From cppreference.com
      <cpp‎ |locale
       
       
       
      Localization library
       
       
      Defined in header<locale>
      template<class CharT>
      class collate;

      Classstd::collate encapsulates locale-specific collation (comparison) and hashing of strings. This facet is used bystd::basic_regex and can be applied, by means ofstd::locale::operator(), directly to all standard algorithms that expect a string comparison predicate.

      std-collate-inheritance.svg

      Contents

      [edit]Specializations

      The standard library is guaranteed to provide the following specializations (they arerequired to be implemented by any locale object):

      Defined in header<locale>
      std::collate<char> implements lexicographical ordering of byte strings
      std::collate<wchar_t> implements lexicographical ordering of wide strings

      [edit]Nested types

      Type Definition
      char_typeCharT
      string_typestd::basic_string<CharT>

      [edit]Data members

      Member Description
      std::locale::idid[static] the identifier of thefacet

      [edit]Member functions

      constructs a newcollate facet
      (public member function)
      destructs acollate facet
      (protected member function)
      invokesdo_compare
      (public member function)[edit]
      invokesdo_transform
      (public member function)[edit]
      invokesdo_hash
      (public member function)[edit]

      [edit]Protected member functions

      [virtual]
      compares two strings using this facet's collation rules
      (virtual protected member function)[edit]
      [virtual]
      transforms a string so that collation can be replaced by comparison
      (virtual protected member function)[edit]
      [virtual]
      generates an integer hash value using this facet's collation rules
      (virtual protected member function)[edit]

      [edit]Example

      Run this code
      #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';}

      Output:

      Default locale collation order: Zebra ar förnamn zebra ängel år ögruppEnglish locale collation order: ängel ar år förnamn ögrupp zebra ZebraSwedish locale collation order: ar förnamn zebra Zebra år ängel ögrupp

      [edit]See also

      lexicographically compares two strings using this locale's collate facet
      (public member function ofstd::locale)[edit]
      represents the system-suppliedstd::collate for the named locale
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/locale/collate&oldid=177982"

      [8]ページ先頭

      ©2009-2025 Movatter.jp