28 Localization library [localization]

28.3 Locales [locales]

28.3.1 Class locale [locale]

28.3.1.2 Types [locale.types]

28.3.1.2.1 Type locale​::​category [locale.category]

using category = int;
Valid category values include the locale member bitmask elements collate, ctype, monetary, numeric, time, and messages, each of which represents a single locale category.
In addition, locale member bitmask constant none is defined as zero and represents no category.
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.
Further, the expression (X | Y), where X and Y each represent a single category, represents the union of the two categories.
locale member functions expecting a category argument require one of the category values defined above, or the union of two or more such values.
Such a category value identifies a set of locale categories.
Each locale category, in turn, identifies a set of locale facets, including at least those shown in Table 102.
Table 102: Locale category facets [tab:locale.category.facets]
Category
Includes facets
collate
collate<char>, collate<wchar_­t>
ctype
ctype<char>, ctype<wchar_­t>
codecvt<char, char, mbstate_­t>
codecvt<char16_­t, char8_­t, mbstate_­t>
codecvt<char32_­t, char8_­t, mbstate_­t>
codecvt<wchar_­t, char, mbstate_­t>
monetary
moneypunct<char>, moneypunct<wchar_­t>
moneypunct<char, true>, moneypunct<wchar_­t, true>
money_­get<char>, money_­get<wchar_­t>
money_­put<char>, money_­put<wchar_­t>
numeric
numpunct<char>, numpunct<wchar_­t>
num_­get<char>, num_­get<wchar_­t>
num_­put<char>, num_­put<wchar_­t>
time
time_­get<char>, time_­get<wchar_­t>
time_­put<char>, time_­put<wchar_­t>
messages
messages<char>, messages<wchar_­t>
For any locale loc either constructed, or returned by locale​::​classic(), and any facet Facet shown in Table 102, has_­facet<Facet>(loc) is true.
Each locale member function which takes a locale​::​category argument operates on the corresponding set of facets.
An implementation is required to provide those specializations for facet templates identified as members of a category, and for those shown in Table 103.
Table 103: Required specializations [tab:locale.spec]
Category
Includes facets
collate
collate_­byname<char>, collate_­byname<wchar_­t>
ctype
ctype_­byname<char>, ctype_­byname<wchar_­t>
codecvt_­byname<char, char, mbstate_­t>
codecvt_­byname<char16_­t, char8_­t, mbstate_­t>
codecvt_­byname<char32_­t, char8_­t, mbstate_­t>
codecvt_­byname<wchar_­t, char, mbstate_­t>
monetary
moneypunct_­byname<char, International>
moneypunct_­byname<wchar_­t, International>
money_­get<C, InputIterator>
money_­put<C, OutputIterator>
numeric
numpunct_­byname<char>, numpunct_­byname<wchar_­t>
num_­get<C, InputIterator>, num_­put<C, OutputIterator>
time
time_­get<char, InputIterator>
time_­get_­byname<char, InputIterator>
time_­get<wchar_­t, InputIterator>
time_­get_­byname<wchar_­t, InputIterator>
time_­put<char, OutputIterator>
time_­put_­byname<char, OutputIterator>
time_­put<wchar_­t, OutputIterator>
time_­put_­byname<wchar_­t, OutputIterator>
messages
messages_­byname<char>, messages_­byname<wchar_­t>
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.
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]).
A template parameter with name C represents the set of types containing char, wchar_­t, and any other implementation-defined character types that meet the requirements for a character on which any of the iostream components can be instantiated.
A template parameter with name International represents the set of all possible specializations on a bool parameter.

28.3.1.2.2 Class locale​::​facet [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; }; }
Class facet is the base class for locale feature sets.
A class is a 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:264 static ::std::locale::id id;
Template parameters in this Clause which are required to be facets are those named Facet in declarations.
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.
A const-qualified facet is a valid template argument to any locale function that expects a Facet template parameter.
The refs argument to the constructor is used for lifetime management.
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.
Constructors of all facets defined in this Clause take such an argument and pass it along to their facet base class constructor.
All one-argument constructors defined in this Clause are explicit, preventing their participation in automatic conversions.
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.
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.
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.
If there is no “_­byname” version of a facet, the base class implements named locale semantics itself by reference to other facets.
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.
 

28.3.1.2.3 Class locale​::​id [locale.id]

namespace std { class locale::id { public: id(); void operator=(const id&) = delete; id(const id&) = delete; }; }
The class locale​::​id provides identification of a locale facet interface, used as an index for lookup and to encapsulate initialization.
[Note 1:
Because facets are used by iostreams, potentially while static constructors are running, their initialization cannot depend on programmed static initialization.
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.
This depends only on static storage being zero before constructors run ([basic.start.static]).
— end note]