Name
collate class template — Facet for comparing strings in collation order
Synopsis
template <typename charT> class collate : public locale::facet { public: typedef charT char_type; typedef basic_string<charT> string_type; explicit collate(size_t refs = 0); int compare(const charT* low1, const charT* high1, const charT* low2, const charT* high2) const; string_type transform(const charT* low, const charT* high) const; long hash(const charT* low, const charT* high) const; static locale::id id; protected: virtual ~collate( ); virtual int do_compare(const charT* low1, const charT* high1, const charT* low2, const charT* high2) const; virtual string_type do_transform (const charT* low, const charT* high) const; virtual long do_hash (const charT* low, const charT* high) const; };
The collate
class template
is a facet used to compare strings. In some locales, the collation
order of characters is not the same as the numerical order of their
encodings, and some characters might be logically equivalent even if
they have different encodings.
You can use a locale
object
as a comparator for algorithms that need a comparison function; the
locale’s operator( )
function uses the collate
facet to perform the
comparison.
The standard mandates the collate<char>
and collate<wchar_t>
instantiations,
which perform lexicographical (element-wise, numerical) comparison.
See lexicographical_compare
in
<algorithm>
earlier in this
chapter.
As with other facets, the public members call virtual, protected members ...
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.