[locale.types]

# 28 Text processing library [[text]](./#text)

## 28.3 Localization library [[localization]](localization#locale.types)

### 28.3.3 Locales [[locales]](locales#locale.types)

#### 28.3.3.1 Class locale [[locale]](locale#types)

#### 28.3.3.1.2 Types [locale.types]

#### [28.3.3.1.2.1](#locale.category) Type locale​::​category [[locale.category]](locale.category)

[ð](#lib:locale,category)

`using category = int;
`

[1](#locale.category-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L633)

*Valid* category values
include the locale member bitmask elementscollate,ctype,monetary,numeric,time,
andmessages,
each of which represents a single locale category[.](#locale.category-1.sentence-1)

In addition, locale member bitmask constant none is defined as zero and represents no category[.](#locale.category-1.sentence-2)

And locale member bitmask constant all is defined such that the expression(collate | ctype | monetary | numeric | time | messages | all) == all is true,
and represents the union of all categories[.](#locale.category-1.sentence-3)

Further, the expression (X | Y),
where X and Y each represent a single category,
represents the union of the two categories[.](#locale.category-1.sentence-4)

[2](#locale.category-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L657)

locale member functions
expecting a category argument
require one of the category values defined above, or
the union of two or more such values[.](#locale.category-2.sentence-1)

Such a category value identifies a set of locale categories[.](#locale.category-2.sentence-2)

Each locale category, in turn, identifies a set of locale facets,
including at least those shown in Table [91](#tab:locale.category.facets "Table 91: Locale category facets")[.](#locale.category-2.sentence-3)

Table [91](#tab:locale.category.facets) — Locale category facets [[tab:locale.category.facets]](./tab:locale.category.facets)  

| [ð](#tab:locale.category.facets-row-1)<br>**Category** | **Includes facets** |
| --- | --- |
| [ð](#tab:locale.category.facets-row-2)<br>collate | collate<char>, collate<wchar_t> |
| [ð](#tab:locale.category.facets-row-3)<br>ctype | ctype<char>, ctype<wchar_t> |
| [ð](#tab:locale.category.facets-row-4) | codecvt<char, char, mbstate_t> |
| [ð](#tab:locale.category.facets-row-5) | codecvt<wchar_t, char, mbstate_t> |
| [ð](#tab:locale.category.facets-row-6)<br>monetary | moneypunct<char>, moneypunct<wchar_t> |
| [ð](#tab:locale.category.facets-row-7) | moneypunct<char, true>, moneypunct<wchar_t, true> |
| [ð](#tab:locale.category.facets-row-8) | money_get<char>, money_get<wchar_t> |
| [ð](#tab:locale.category.facets-row-9) | money_put<char>, money_put<wchar_t> |
| [ð](#tab:locale.category.facets-row-10)<br>numeric | numpunct<char>, numpunct<wchar_t> |
| [ð](#tab:locale.category.facets-row-11) | num_get<char>, num_get<wchar_t> |
| [ð](#tab:locale.category.facets-row-12) | num_put<char>, num_put<wchar_t> |
| [ð](#tab:locale.category.facets-row-13)<br>time | time_get<char>, time_get<wchar_t> |
| [ð](#tab:locale.category.facets-row-14) | time_put<char>, time_put<wchar_t> |
| [ð](#tab:locale.category.facets-row-15)<br>messages | messages<char>, messages<wchar_t> |

[3](#locale.category-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L686)

For any locale loc either constructed, or returned by locale​::​classic(),
and any facet Facet shown in Table [91](#tab:locale.category.facets "Table 91: Locale category facets"),has_facet<Facet>(loc) is true[.](#locale.category-3.sentence-1)

Each locale member function
which takes a locale​::​category argument
operates on the corresponding set of facets[.](#locale.category-3.sentence-2)

[4](#locale.category-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L695)

An implementation is required to provide those specializations
for facet templates identified as members of a category, and
for those shown in Table [92](#tab:locale.spec "Table 92: Required specializations")[.](#locale.category-4.sentence-1)

Table [92](#tab:locale.spec) — Required specializations [[tab:locale.spec]](./tab:locale.spec)  

| [ð](#tab:locale.spec-row-1)<br>**Category** | **Includes facets** |
| --- | --- |
| [ð](#tab:locale.spec-row-2)<br>collate | collate_byname<char>, collate_byname<wchar_t> |
| [ð](#tab:locale.spec-row-3)<br>ctype | ctype_byname<char>, ctype_byname<wchar_t> |
| [ð](#tab:locale.spec-row-4) | codecvt_byname<char, char, mbstate_t> |
| [ð](#tab:locale.spec-row-5) | codecvt_byname<wchar_t, char, mbstate_t> |
| [ð](#tab:locale.spec-row-6)<br>monetary | moneypunct_byname<char, International> |
| [ð](#tab:locale.spec-row-7) | moneypunct_byname<wchar_t, International> |
| [ð](#tab:locale.spec-row-8) | money_get<C, InputIterator> |
| [ð](#tab:locale.spec-row-9) | money_put<C, OutputIterator> |
| [ð](#tab:locale.spec-row-10)<br>numeric | numpunct_byname<char>, numpunct_byname<wchar_t> |
| [ð](#tab:locale.spec-row-11) | num_get<C, InputIterator>, num_put<C, OutputIterator> |
| [ð](#tab:locale.spec-row-12)<br>time | time_get<char, InputIterator> |
| [ð](#tab:locale.spec-row-13) | time_get_byname<char, InputIterator> |
| [ð](#tab:locale.spec-row-14) | time_get<wchar_t, InputIterator> |
| [ð](#tab:locale.spec-row-15) | time_get_byname<wchar_t, InputIterator> |
| [ð](#tab:locale.spec-row-16) | time_put<char, OutputIterator> |
| [ð](#tab:locale.spec-row-17) | time_put_byname<char, OutputIterator> |
| [ð](#tab:locale.spec-row-18) | time_put<wchar_t, OutputIterator> |
| [ð](#tab:locale.spec-row-19) | time_put_byname<wchar_t, OutputIterator> |
| [ð](#tab:locale.spec-row-20)<br>messages | messages_byname<char>, messages_byname<wchar_t> |

[5](#locale.category-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L726)

The provided implementation of members of
facets num_get<charT> and num_put<charT> calls use_facet<F>(l) only for facet F of
types numpunct<charT> and ctype<charT>,
and for locale l the value obtained by calling member getloc() on the ios_base& argument to these functions[.](#locale.category-5.sentence-1)

[6](#locale.category-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L734)

In declarations of facets,
a template parameter with name InputIterator or OutputIterator indicates the set of all possible specializations on parameters that meet the*Cpp17InputIterator* requirements or*Cpp17OutputIterator* requirements,
respectively ([[iterator.requirements]](iterator.requirements "24.3 Iterator requirements"))[.](#locale.category-6.sentence-1)

A template parameter with name C represents
the set of types containing char, wchar_t, and any otherimplementation-defined
character container types ([[defns.character.container]](defns.character.container "3.10 character container type"))
that meet the requirements for a character
on which any of the iostream components can be instantiated[.](#locale.category-6.sentence-2)

A template parameter with name International represents the set of all possible specializations on a bool parameter[.](#locale.category-6.sentence-3)

#### [28.3.3.1.2.2](#locale.facet) Class locale​::​facet [[locale.facet]](locale.facet)

[ð](#lib:locale,facet)

namespace std {class locale::facet {protected:explicit facet(size_t refs = 0); virtual ~facet();
 facet(const facet&) = delete; void operator=(const facet&) = delete; };}

[1](#locale.facet-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L766)

Class facet is the base class for locale feature sets[.](#locale.facet-1.sentence-1)

A class is a [*facet*](#def:facet "28.3.3.1.2.2 Class locale​::​facet [locale.facet]") if it is publicly derived from another facet, or
if it is a class derived from locale​::​facet and
contains a publicly accessible declaration as follows:[215](#footnote-215 "This is a complete list of requirements; there are no other requirements. Thus, a facet class need not have a public copy constructor, assignment, default constructor, destructor, etc.")static ::std::locale::id id;

[2](#locale.facet-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L781)

Template parameters in this Clause
which are required to be facets
are those named Facet in declarations[.](#locale.facet-2.sentence-1)

A program that passes
a type that is *not* a facet, or
a type that refers to a volatile-qualified facet,
as an (explicit or deduced) template parameter to
a locale function expecting a facet,
is ill-formed[.](#locale.facet-2.sentence-2)

A const-qualified facet is a valid template argument to
any locale function that expects a Facet template parameter[.](#locale.facet-2.sentence-3)

[3](#locale.facet-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L794)

The refs argument to the constructor is used for lifetime management[.](#locale.facet-3.sentence-1)

For refs == 0,
the implementation performs delete static_cast<locale​::​facet*>(f) (where f is a pointer to the facet)
when the last locale object containing the facet is destroyed;
for refs == 1, the implementation never destroys the facet[.](#locale.facet-3.sentence-2)

[4](#locale.facet-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L802)

Constructors of all facets defined in this Clause
take such an argument and pass it along to
their facet base class constructor[.](#locale.facet-4.sentence-1)

All one-argument constructors defined in this Clause are explicit,
preventing their participation in implicit conversions[.](#locale.facet-4.sentence-2)

[5](#locale.facet-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L809)

For some standard facets a standard â…_bynameâ class,
derived from it, implements the virtual function semantics
equivalent to that facet of the locale
constructed by locale(const char*) with the same name[.](#locale.facet-5.sentence-1)

Each such facet provides a constructor that takes
a const char* argument, which names the locale, and
a refs argument, which is passed to the base class constructor[.](#locale.facet-5.sentence-2)

Each such facet also provides a constructor that takes
a string argument str and
a refs argument,
which has the same effect as calling the first constructor
with the two arguments str.c_str() and refs[.](#locale.facet-5.sentence-3)

If there is no â…_bynameâ version of a facet,
the base class implements named locale semantics itself
by reference to other facets[.](#locale.facet-5.sentence-4)

[215)](#footnote-215)[215)](#footnoteref-215)

This is a complete list of requirements; there are no other requirements[.](#footnote-215.sentence-1)

Thus, a facet class need not have a public
copy constructor, assignment, default constructor, destructor, etc[.](#footnote-215.sentence-2)

#### [28.3.3.1.2.3](#locale.id) Class locale​::​id [[locale.id]](locale.id)

[ð](#lib:locale,id)

namespace std {class locale::id {public: id(); void operator=(const id&) = delete;
 id(const id&) = delete; };}

[1](#locale.id-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L840)

The class locale​::​id provides
identification of a locale facet interface,
used as an index for lookup and to encapsulate initialization[.](#locale.id-1.sentence-1)

[2](#locale.id-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L845)

[*Note [1](#locale.id-note-1)*:

Because facets are used by iostreams,
potentially while static constructors are running,
their initialization cannot depend on programmed static initialization[.](#locale.id-2.sentence-1)

One initialization strategy is for locale to initialize each facet's id member
the first time an instance of the facet is installed into a locale[.](#locale.id-2.sentence-2)

This depends only on static storage being zero
before constructors run ([[basic.start.static]](basic.start.static "6.10.3.2 Static initialization"))[.](#locale.id-2.sentence-3)

â *end note*]
