---
name: "std::regex_traits"
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::regex_traits/3cxx"
---

# std::regex\_traits(3cxx)

Describes aspects of a regular expression.

## NAME

std::regex\_traits\< \_Ch\_type \> - Describes aspects of a regular expression.

## SYNOPSIS

`#include <regex>`

### Public Types

**typedef** \_RegexMask **char\_class\_type**\
 **typedef** **\_Ch\_type** **char\_type**\
 **typedef** **std::locale** **locale\_type**\
 **typedef** **std::basic\_string**\< **char\_type** \> **string\_type**\

### Public Member Functions

**regex\_traits** ()\
 Constructs a default traits object.  **locale\_type** **getloc** () const\
 Gets a copy of the current locale in use by the regex\_traits object.  **locale\_type** **imbue** (**locale\_type** **\_\_loc**)\
 Imbues the regex\_traits object with a copy of a new locale.  bool **isctype** (**\_Ch\_type** \_\_c, char\_class\_type \_\_f) const\
 Determines if `c` is a member of an identified class.  template\<**typename** **\_Fwd\_iter** \> char\_class\_type **lookup\_classname** (**\_Fwd\_iter** \_\_first, **\_Fwd\_iter** \_\_last, bool **\_\_icase**=**false**) const\
 Maps one or more characters to a named character classification.  template\<**typename** **\_Fwd\_iter** \> **string\_type** **lookup\_collatename** (**\_Fwd\_iter** \_\_first, **\_Fwd\_iter** \_\_last) const\
 Gets a collation element by name.  template\<**typename** **\_Fwd\_iter** \> **string\_type** **transform** (**\_Fwd\_iter** \_\_first, **\_Fwd\_iter** \_\_last) const\
 Gets a sort key for a character sequence.  template\<**typename** **\_Fwd\_iter** \> **string\_type** **transform\_primary** (**\_Fwd\_iter** \_\_first, **\_Fwd\_iter** \_\_last) const\
 Gets a sort key for a character sequence, independent of case.  **char\_type** **translate** (**char\_type** \_\_c) const\
 Performs the identity translation.  **char\_type** **translate\_nocase** (**char\_type** \_\_c) const\
 Translates a character into a case-insensitive equivalent.  int **value** (**\_Ch\_type** **\_\_ch**, int \_\_radix) const\
 Converts a digit to an int.

### Static Public Member Functions

**static** std::size\_t **length** (const **char\_type** \*\_\_p)\
 Gives the length of a C-style string starting at `__p`.

### Protected Attributes

**locale\_type** **\_M\_locale**\

## Detailed Description

### template\<typename \_Ch\_type\>

class std::regex\_traits\< \_Ch\_type \>"Describes aspects of a regular expression.

A regular expression traits class that satisfies the requirements of section \[28.7\].

The class regex is parameterized around a set of related types and functions used to complete the definition of its semantics. This class satisfies the requirements of such a traits class.

**Since**

C++11

## Constructor & Destructor Documentation

### template\<typename \_Ch\_type \> std::regex\_traits\< \_Ch\_type \>::regex\_traits ()` [inline]`

Constructs a default traits object.

## Member Function Documentation

### template\<typename \_Ch\_type \> locale\_type std::regex\_traits\< \_Ch\_type \>::getloc () const` [inline]`

Gets a copy of the current locale in use by the regex\_traits object.

### template\<typename \_Ch\_type \> locale\_type std::regex\_traits\< \_Ch\_type \>::imbue (locale\_type \_\_loc)` [inline]`

Imbues the regex\_traits object with a copy of a new locale.

**Parameters**

*\_\_loc* A locale.

**Returns**

a copy of the previous locale in use by the regex\_traits object.

**Note**

Calling imbue with a different locale than the one currently in use invalidates all cached data held by \*this.

References **std::swap()**.

### template\<typename \_Ch\_type \> bool std::regex\_traits\< \_Ch\_type \>::isctype (\_Ch\_type \_\_c, char\_class\_type \_\_f) const

Determines if `c` is a member of an identified class.

**Parameters**

*\_\_c* a character. \
 *\_\_f* a class type (as returned from lookup\_classname).

**Returns**

true if the character `__c` is a member of the classification represented by `__f`, false otherwise.

**Exceptions**

*std::bad\_cast* if the current locale does not have a ctype facet.

### template\<typename \_Ch\_type \> static std::size\_t std::regex\_traits\< \_Ch\_type \>::length (const char\_type \* \_\_p)` [inline]`, ` [static]`

Gives the length of a C-style string starting at `__p`.

**Parameters**

*\_\_p* a pointer to the start of a character sequence.

**Returns**

the number of characters between `*__p` and the first default-initialized value of type `char_type`. In other words, uses the C-string algorithm for determining the length of a sequence of characters.

### template\<typename \_Ch\_type \> template\<typename \_Fwd\_iter \> char\_class\_type std::regex\_traits\< \_Ch\_type \>::lookup\_classname (\_Fwd\_iter \_\_first, \_Fwd\_iter \_\_last, bool \_\_icase = false) const

Maps one or more characters to a named character classification.

**Parameters**

*\_\_first* beginning of the character sequence. \
 *\_\_last* one-past-the-end of the character sequence. \
 *\_\_icase* ignores the case of the classification name.

**Returns**

an unspecified value that represents the character classification named by the character sequence designated by the iterator range \[\_\_first, \_\_last). If `icase` is true, the returned mask identifies the classification regardless of the case of the characters to be matched (for example, \[\[:lower:\]\] is the same as \[\[:alpha:\]\]), otherwise a case-dependent classification is returned. The value returned shall be independent of the case of the characters in the character sequence. If the name is not recognized then returns a value that compares equal to 0.

At least the following names (or their wide-character equivalent) are supported.

- •

  d

- •

  w

- •

  s

- •

  alnum

- •

  alpha

- •

  blank

- •

  cntrl

- •

  digit

- •

  graph

- •

  lower

- •

  print

- •

  punct

- •

  space

- •

  upper

- •

  xdigit

### template\<typename \_Ch\_type \> template\<typename \_Fwd\_iter \> string\_type std::regex\_traits\< \_Ch\_type \>::lookup\_collatename (\_Fwd\_iter \_\_first, \_Fwd\_iter \_\_last) const

Gets a collation element by name.

**Parameters**

*\_\_first* beginning of the collation element name. \
 *\_\_last* one-past-the-end of the collation element name.

**Returns**

a sequence of one or more characters that represents the collating element consisting of the character sequence designated by the iterator range \[\_\_first, \_\_last). Returns an empty string if the character sequence is not a valid collating element.

### template\<typename \_Ch\_type \> template\<typename \_Fwd\_iter \> string\_type std::regex\_traits\< \_Ch\_type \>::transform (\_Fwd\_iter \_\_first, \_Fwd\_iter \_\_last) const` [inline]`

Gets a sort key for a character sequence.

**Parameters**

*\_\_first* beginning of the character sequence. \
 *\_\_last* one-past-the-end of the character sequence.

Returns a sort key for the character sequence designated by the iterator range \[F1, F2) such that if the character sequence \[G1, G2) sorts before the character sequence \[H1, H2) then v.transform(G1, G2) \< v.transform(H1, H2).

What this really does is provide a more efficient way to compare a string to multiple other strings in locales with fancy collation rules and equivalence classes.

**Returns**

a locale-specific sort key equivalent to the input range.

**Exceptions**

*std::bad\_cast* if the current locale does not have a collate facet.

Referenced by **std::regex\_traits\< \_Ch\_type \>::transform\_primary()**.

### template\<typename \_Ch\_type \> template\<typename \_Fwd\_iter \> string\_type std::regex\_traits\< \_Ch\_type \>::transform\_primary (\_Fwd\_iter \_\_first, \_Fwd\_iter \_\_last) const` [inline]`

Gets a sort key for a character sequence, independent of case.

**Parameters**

*\_\_first* beginning of the character sequence. \
 *\_\_last* one-past-the-end of the character sequence.

Effects: if typeid(use\_facet\<collate\<\_Ch\_type\> \>) == typeid(collate\_byname\<\_Ch\_type\>) and the form of the sort key returned by collate\_byname\<\_Ch\_type\>::transform(\_\_first, \_\_last) is known and can be converted into a primary sort key then returns that key, otherwise returns an empty string.

**Todo**

Implement this function correctly.

References **std::regex\_traits\< \_Ch\_type \>::transform()**.

### template\<typename \_Ch\_type \> char\_type std::regex\_traits\< \_Ch\_type \>::translate (char\_type \_\_c) const` [inline]`

Performs the identity translation.

**Parameters**

*\_\_c* A character to the locale-specific character set.

**Returns**

\_\_c.

### template\<typename \_Ch\_type \> char\_type std::regex\_traits\< \_Ch\_type \>::translate\_nocase (char\_type \_\_c) const` [inline]`

Translates a character into a case-insensitive equivalent.

**Parameters**

*\_\_c* A character to the locale-specific character set.

**Returns**

the locale-specific lower-case equivalent of \_\_c.

**Exceptions**

*std::bad\_cast* if the imbued locale does not support the ctype facet.

### template\<typename \_Ch\_type \> int std::regex\_traits\< \_Ch\_type \>::value (\_Ch\_type \_\_ch, int \_\_radix) const

Converts a digit to an int.

**Parameters**

*\_\_ch* a character representing a digit. \
 *\_\_radix* the radix if the numeric conversion (limited to 8, 10, or 16).

**Returns**

the value represented by the digit \_\_ch in base radix if the character \_\_ch is a valid digit in base radix; otherwise returns -1.

## Author

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