# std::collate< CharT > Class Template Reference

Facet for localized string comparison. More...

`#include <locale_facets.h>`

Inheritance diagram for std::collate< CharT >:

[legend]
Collaboration diagram for std::collate< CharT >:

[legend]
List of all members.

## Public Types

typedef CharT | char_type
| Public typedefs.
typedef basic_string< CharT > | string_type
| Public typedefs.

## Public Member Functions

| collate (size_t __refs=0)
| Constructor performs initialization.
| collate (c_locale cloc, size_t __refs=0)
| Internal constructor. Not for general use.
int | compare (const CharT *__lo1, const CharT *__hi1, const CharT *__lo2, const CharT *__hi2) const
| Compare two strings.
string_type | transform (const CharT *__lo, const CharT *__hi) const
| Transform string to comparable form.
long | hash (const CharT *__lo, const CharT *__hi) const
| Return hash of a string.

## Static Public Attributes

locale::id | id
| Numpunct facet id.

## Protected Member Functions

virtual | ~collate ()
| Destructor.
virtual int | do_compare (const CharT *__lo1, const CharT *__hi1, const CharT *__lo2, const CharT *__hi2) const
| Compare two strings.
virtual string_type | do_transform (const CharT *__lo, const CharT *__hi) const
| Transform string to comparable form.
virtual long | do_hash (const CharT *__lo, const CharT *__hi) const
| Return hash of a string.

## Detailed Description

### template<typename CharT>
class std::collate< CharT >

Facet for localized string comparison.

This facet encapsulates the code to compare strings in a localized manner.

The collate template uses protected virtual functions to provide the actual results. The public accessors forward the call to the virtual functions. These virtual functions are hooks for developers to implement the behavior they require from the collate facet.

Definition at line 2469 of file locale_facets.h.

## Member Typedef Documentation

template<typename CharT>
typedef CharT std::collate< CharT >::char_type

| Public typedefs. Definition at line 2475 of file locale_facets.h.

template<typename CharT>
typedef basic_string<CharT> std::collate< CharT >::string_type

| Public typedefs. Definition at line 2476 of file locale_facets.h.

## Constructor & Destructor Documentation

template<typename CharT>
std::collate< CharT >::collate | ( | size_t | __refs = `0` | ) | `[inline, explicit]`

Constructor performs initialization.

This is the constructor provided by the standard.

Parameters:

  | refs | Passed to the base facet class.

Definition at line 2496 of file locale_facets.h.

template<typename CharT>
std::collate< CharT >::collate | ( | c_locale | cloc,
|  | size_t | __refs = `0`
| ) | `[inline, explicit]`

Internal constructor. Not for general use.

This is a constructor for use by the library itself to set up new locales.

Parameters:

  | cloc | The "C" locale.
  | refs | Passed to the base facet class.

Definition at line 2510 of file locale_facets.h.

template<typename CharT>
virtual std::collate< CharT >::~collate | ( |  | ) | `[inline, protected, virtual]`

| Destructor. Definition at line 2573 of file locale_facets.h.

## Member Function Documentation

template<typename CharT>
int std::collate< CharT >::compare | ( | const CharT * | __lo1,
|  | const CharT * | __hi1,
|  | const CharT * | __lo2,
|  | const CharT * | __hi2
| ) | const`[inline]`

Compare two strings.

This function compares two strings and returns the result by calling collate::do_compare().

Parameters:

  | lo1 | Start of string 1.
  | hi1 | End of string 1.
  | lo2 | Start of string 2.
  | hi2 | End of string 2.

Returns:
  1 if string1 > string2, -1 if string1 < string2, else 0.

Definition at line 2527 of file locale_facets.h.

template<typename CharT>
int std::collate< CharT >::do_compare | ( | const CharT * | __lo1,
|  | const CharT * | __hi1,
|  | const CharT * | __lo2,
|  | const CharT * | __hi2
| ) | const`[protected, virtual]`

Compare two strings.

This function is a hook for derived classes to change the value returned.

See also:
  compare().

Parameters:

  | lo1 | Start of string 1.
  | hi1 | End of string 1.
  | lo2 | Start of string 2.
  | hi2 | End of string 2.

Returns:
  1 if string1 > string2, -1 if string1 < string2, else 0.

Definition at line 2297 of file locale_facets.tcc.

template<typename CharT>
long std::collate< CharT >::do_hash | ( | const CharT * | __lo,
|  | const CharT * | __hi
| ) | const`[protected, virtual]`

Return hash of a string.

This function computes and returns a hash on the input string. This function is a hook for derived classes to change the value returned.

Parameters:

  | lo | Start of string.
  | hi | End of string.

Returns:
  Hash value.

Definition at line 2380 of file locale_facets.tcc.

template<typename CharT>
collate< CharT >::string_type std::collate< CharT >::do_transform | ( | const CharT * | __lo,
|  | const CharT * | __hi
| ) | const`[protected, virtual]`

Transform string to comparable form.

This function is a hook for derived classes to change the value returned.

Parameters:

  | lo1 | Start of string 1.
  | hi1 | End of string 1.
  | lo2 | Start of string 2.
  | hi2 | End of string 2.

Returns:
  1 if string1 > string2, -1 if string1 < string2, else 0.

Definition at line 2336 of file locale_facets.tcc.

References std::basic_string< CharT, Traits, Alloc >::append(), std::basic_string< CharT, Traits, Alloc >::c_str(), std::basic_string< CharT, Traits, Alloc >::data(), std::basic_string< CharT, Traits, Alloc >::length(), and std::basic_string< CharT, Traits, Alloc >::push_back().

template<typename CharT>
long std::collate< CharT >::hash | ( | const CharT * | __lo,
|  | const CharT * | __hi
| ) | const`[inline]`

Return hash of a string.

This function computes and returns a hash on the input string. It does so by returning collate::do_hash().

Parameters:

  | lo | Start of string.
  | hi | End of string.

Returns:
  Hash value.

Definition at line 2560 of file locale_facets.h.

template<typename CharT>
string_type std::collate< CharT >::transform | ( | const CharT * | __lo,
|  | const CharT * | __hi
| ) | const`[inline]`

Transform string to comparable form.

This function is a wrapper for strxfrm functionality. It takes the input string and returns a modified string that can be directly compared to other transformed strings. In the "C" locale, this function just returns a copy of the input string. In some other locales, it may replace two chars with one, change a char for another, etc. It does so by returning collate::do_transform().

Parameters:

  | lo | Start of string.
  | hi | End of string.

Returns:
  Transformed string_type.

Definition at line 2546 of file locale_facets.h.

## Member Data Documentation

template<typename CharT>
locale::id std::collate< CharT >::id`[static]`

| Numpunct facet id. Definition at line 2622 of file locale_facets.h.

The documentation for this class was generated from the following files:

- locale_facets.h
- locale_facets.tcc