---
name: "std::collate"
section: "3cxx"
platform: "linux"
package: "libstdc++-12-doc"
version: "12.4.0-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/std::collate/3cxx"
---

# std::collate(3cxx)

Facet for localized string comparison.

## NAME

std::collate\< \_CharT \> - Facet for localized string comparison.

## SYNOPSIS

`#include <locale>`

Inherits **std::locale::facet**.

Inherited by **std::collate\_byname\< \_CharT \>**.

### Public Types

**typedef** \_CharT **char\_type**\
 Public typedefs.  **typedef** **basic\_string**\< \_CharT \> **string\_type**\
 Public typedefs.

### Public Member Functions

**collate** (\_\_c\_locale **\_\_cloc**, size\_t **\_\_refs**=0)\
 Internal constructor. Not for general use.  **collate** (size\_t **\_\_refs**=0)\
 Constructor performs initialization.  int **\_M\_compare** (const \_CharT \*, const \_CharT \*) const  **throw** ()\
 int **\_M\_compare** (const char \*, const char \*) const **throw**()\
 int **\_M\_compare** (const wchar\_t \*, const wchar\_t \*) const **throw**()\
 size\_t **\_M\_transform** (\_CharT \*, const \_CharT \*, size\_t) const  **throw** ()\
 size\_t **\_M\_transform** (char \*, const char \*, size\_t) const **throw**()\
 size\_t **\_M\_transform** (wchar\_t \*, const wchar\_t \*, size\_t) const **throw**()\
 int **compare** (const \_CharT \***\_\_lo1**, const \_CharT \***\_\_hi1**, const \_CharT \***\_\_lo2**, const \_CharT \***\_\_hi2**) const\
 Compare two strings.  long **hash** (const \_CharT \***\_\_lo**, const \_CharT \***\_\_hi**) const\
 Return hash of a string.  **string\_type** **transform** (const \_CharT \***\_\_lo**, const \_CharT \***\_\_hi**) const\
 Transform string to comparable form.

### Static Public Attributes

**static** **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** long **do\_hash** (const \_CharT \***\_\_lo**, const \_CharT \***\_\_hi**) const\
 Return hash of a string.  **virtual** **string\_type** **do\_transform** (const \_CharT \***\_\_lo**, const \_CharT \***\_\_hi**) const\
 Transform string to comparable form.

### Static Protected Member Functions

**static** \_\_c\_locale **\_S\_clone\_c\_locale** (\_\_c\_locale &**\_\_cloc**)  **throw** ()\
 **static** **void** **\_S\_create\_c\_locale** (\_\_c\_locale &**\_\_cloc**, const char \***\_\_s**, \_\_c\_locale **\_\_old**=0)\
 **static** **void** **\_S\_destroy\_c\_locale** (\_\_c\_locale &**\_\_cloc**)\
 **static** \_\_c\_locale **\_S\_get\_c\_locale** ()\
 **static** const char \* **\_S\_get\_c\_name** ()  **throw** ()\
 **static** \_\_c\_locale **\_S\_lc\_ctype\_c\_locale** (\_\_c\_locale **\_\_cloc**, const char \***\_\_s**)\

### Protected Attributes

\_\_c\_locale **\_M\_c\_locale\_collate**\

## 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.

## Member Typedef Documentation

### template\<typename \_CharT \> typedef \_CharT std::collate\< \_CharT \>::char\_type

Public typedefs.

### template\<typename \_CharT \> typedef basic\_string\<\_CharT\> std::collate\< \_CharT \>::string\_type

Public typedefs.

## 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.

### 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.

### template\<typename \_CharT \> virtual std::collate\< \_CharT \>::~collate ()` [inline]`, ` [protected]`, ` [virtual]`

Destructor.

## 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.

### 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.

### 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.

### 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**

*\_\_lo* Start. \
 *\_\_hi* End.

**Returns**

transformed string.

### 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.

### 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.

## Member Data Documentation

### template\<typename \_CharT \> locale::id std::collate\< \_CharT \>::id` [static]`

Numpunct facet id.

## Author

Generated automatically by Doxygen for libstdc++ from the source code.
