# std::isxdigit(std::locale)

> C++ Atlas: `cppatlas.com/w/cpp/locale/isxdigit` | Source: https://en.cppreference.com/w/cpp/locale/isxdigit | Domain: Localization

Checks if the given character is classified as a hexadecimal digit by the given locale's std::ctype facet.

## Official Specification Summary (cppreference)

```cpp
// Defined in header <locale>

template< class CharT >
bool isxdigit( CharT ch, const locale& loc );
```

Checks if the given character is classified as a hexadecimal digit by the given locale's `std::ctype` facet.

### Parameters

- `ch` - character
- `loc` - locale

### Return value

Returns `true` if the character is classified as a hexadecimal digit, `false` otherwise.

### Possible implementation

```cpp
template<class CharT>
bool isxdigit(CharT ch, const std::locale& loc)
{
    return std::use_facet<std::ctype<CharT>>(loc).is(std::ctype_base::xdigit, ch);
}
```

### Example

```cpp
#include <iostream>
#include <locale>
#include <string>
#include <unordered_set>

struct gxdigit_ctype : std::ctype<wchar_t>
{
    std::unordered_set<wchar_t> greek_digits{L'α', L'β', L'γ', L'δ', L'ε', L'ζ'};

    bool do_is(mask m, char_type c) const override
    {
        return (m & xdigit) && greek_digits.contains(c)
            ? true // 6 first Greek small letters will be classified as digits
            : ctype::do_is(m, c); // leave the rest to the parent class
    }
};

int main()
{
    std::wstring text = L"0123456789abcdefABCDEFαβγδεζηθικλμ";
    std::locale loc(std::locale(""), new gxdigit_ctype);

    std::locale::global(std::locale("en_US.utf8"));
    std::wcout.imbue(std::locale());

    std::wcout << "Hexadecimal digits in text: ";
    for (const wchar_t c : text)
        if (std::isxdigit(c, loc))
            std::wcout << c << L' ';
    std::wcout << L'\n';

    std::wcout << "Not hexadecimal digits in text: ";
    for (const wchar_t c : text)
        if (not std::isxdigit(c, loc))
            std::wcout << c << L' ';
    std::wcout << L'\n';
}
```

Output:

```text
Hexadecimal digits in text: 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F α β γ δ ε ζ
Not hexadecimal digits in text: η θ ι κ λ μ
```

### See also

- [`isxdigit`](https://en.cppreference.com/w/cpp/string/byte/isxdigit): checks if a character is a hexadecimal character (function)
- [`iswxdigit`](https://en.cppreference.com/w/cpp/string/wide/iswxdigit): checks if a wide character is a hexadecimal character (function)

---
Attribution: content from https://en.cppreference.com/w/cpp/locale/isxdigit (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.