GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::collate(3) C++ Standard Libary std::collate(3)

std::collate - std::collate


Defined in header <locale>
template< class CharT >
class collate;


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


std-collate-inheritance.svg


Inheritance diagram


Two standalone (locale-independent) specializations are provided by the standard
library:


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


In addition, every locale object constructed in a C++ program implements its own
(locale-specific) versions of these specializations.


Member type Definition
char_type CharT
string_type std::basic_string<CharT>


constructor constructs a new collate facet
(public member function)
destructor destructs a collate facet
(protected member function)
compare invokes do_compare
(public member function)
transform invokes do_transform
(public member function)
hash invokes do_hash
(public member function)


static std::locale::id id id of the locale
(public member object)


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

// Run this code


#include <locale>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>


int main()
{
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


lexicographically compares two strings using this locale's collate
operator() facet
(public member function of std::locale)
collate_byname creates a collate facet for the named locale
(class template)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.