---
name: "std::collate"
section: "3"
platform: "linux"
package: "libstdc++6-4.1-doc"
version: "4.1.2-25"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://new.carta.tech/std::collate"
---

# std::collate(3)

## NAME

std::collate -

## SYNOPSIS

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

Inherited by **collate\_byname**.

## Detailed Description

### template\<typename \_CharT\> class std::collate\< \_CharT \>

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 2494 of file locale\_facets.h.

### Public Types

typedef \_CharT **char\_type**\
 typedef **basic\_string**\< \_CharT \> **string\_type**\

### Public Member Functions

template\<\> int **\_M\_compare** (const wchar\_t \*, const wchar\_t \*) const\
 template\<\> int **\_M\_compare** (const char \*, const char \*) const\
 int **\_M\_compare** (const \_CharT \*, const \_CharT \*) const \
 template\<\> size\_t **\_M\_transform** (wchar\_t \*, const wchar\_t \*, size\_t) const\
 template\<\> size\_t **\_M\_transform** (char \*, const char \*, size\_t) const\
 size\_t **\_M\_transform** (\_CharT \*, const \_CharT \*, size\_t) const \
 **collate** (\_\_c\_locale \_\_cloc, size\_t \_\_refs=0)\
 **collate** (size\_t \_\_refs=0)\
 int **compare** (const \_CharT \*\_\_lo1, const \_CharT \*\_\_hi1, const \_CharT \*\_\_lo2, const \_CharT \*\_\_hi2) const \
 long **hash** (const \_CharT \*\_\_lo, const \_CharT \*\_\_hi) const \
 **string\_type** **transform** (const \_CharT \*\_\_lo, const \_CharT \*\_\_hi) const \

### Static Public Attributes

static **locale::id** **id**\

### Protected Member Functions

virtual int **do\_compare** (const \_CharT \*\_\_lo1, const \_CharT \*\_\_hi1, const \_CharT \*\_\_lo2, const \_CharT \*\_\_hi2) const \
 virtual long **do\_hash** (const \_CharT \*\_\_lo, const \_CharT \*\_\_hi) const \
 virtual **string\_type** **do\_transform** (const \_CharT \*\_\_lo, const \_CharT \*\_\_hi) const \
 virtual **~collate** ()\

### Static Protected Member Functions

static \_\_c\_locale **\_S\_clone\_c\_locale** (\_\_c\_locale &\_\_cloc)\
 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** ()\

### Protected Attributes

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

### Friends

class **locale::\_Impl**\

## Member Typedef Documentation

### typedef \_CharT char\_type

Public typedefs.

Reimplemented in **collate\_byname**.

Definition at line 2500 of file locale\_facets.h.

### typedef basic\_string\<\_CharT\> string\_type

Public typedefs.

Reimplemented in **collate\_byname**.

Definition at line 2501 of file locale\_facets.h.

## Constructor & Destructor Documentation

### 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 2521 of file locale\_facets.h.

### 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 2535 of file locale\_facets.h.

### virtual ~collate ()` [inline, protected, virtual]`

Destructor.

Definition at line 2598 of file locale\_facets.h.

## Member Function Documentation

### int 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 2552 of file locale\_facets.h.

### int do\_compare (const \_CharT \* \_\_lo1, const \_CharT \* \_\_hi1, const \_CharT \* \_\_lo2, const \_CharT \* \_\_hi2) const` [inline, 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 2366 of file locale\_facets.tcc.

References basic\_string::c\_str(), basic\_string::data(), and basic\_string::length().

### long do\_hash (const \_CharT \* \_\_lo, const \_CharT \* \_\_hi) const` [inline, 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 2449 of file locale\_facets.tcc.

### collate\< \_CharT \>::string\_type do\_transform (const \_CharT \* \_\_lo, const \_CharT \* \_\_hi) const` [inline, 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 2405 of file locale\_facets.tcc.

References basic\_string::append(), basic\_string::c\_str(), basic\_string::data(), basic\_string::length(), and basic\_string::push\_back().

### long 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 2585 of file locale\_facets.h.

### string\_type 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 2571 of file locale\_facets.h.

## Member Data Documentation

### locale::id id` [inline, static]`

Numpunct facet id.

Definition at line 2511 of file locale\_facets.h.

## Author

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