[locale.types] (original) (raw)
28 Localization library [localization]
28.3 Locales [locales]
28.3.1 Class locale [locale]
28.3.1.1 Types [locale.types]
28.3.1.1.1 Type locale::category [locale.category]
Valid categoryvalues include thelocalemember bitmask elementscollate,ctype,monetary,numeric,time, andmessages, each of which represents a single locale category.
In addition,localemember bitmask constantnoneis defined as zero and represents no category.
Andlocalemember bitmask constantallis defined such that the expression
(collate | ctype | monetary | numeric | time | messages | all) == all
istrue, and represents the union of all categories.
Further, the expression(X | Y), whereXandYeach represent a single category, represents the union of the two categories.
localemember functions expecting acategoryargument require one of thecategoryvalues defined above, or the union of two or more such values.
Such acategoryvalue 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 loceither constructed, or returned bylocale::classic(), and any facet Facetshown in Table 102,has_facet<Facet>(loc)is true.
Eachlocalemember function which takes alocale::categoryargument 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 facetsnum_get<charT>andnum_put<charT>callsuse_facet<F>(l)only for facetFof typesnumpunct<charT>andctype<charT>, and for localelthe value obtained by calling membergetloc()on theios_base&argument to these functions.
In declarations of facets, a template parameter with nameInputIteratororOutputIteratorindicates the set of all possible specializations on parameters that meet theCpp17InputIterator requirements or Cpp17OutputIteratorrequirements, respectively ([iterator.requirements]).
A template parameter with nameCrepresents the set of types containing char, wchar_t, and any otherimplementation-defined character types that meet the requirements for a character on which any of the iostream components can be instantiated.
A template parameter with nameInternationalrepresents the set of all possible specializations on a bool parameter.
28.3.1.1.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 facetif 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:258
static ::std::locale::id id;
Template parameters in this Clause which are required to be facets are those namedFacetin declarations.
A program that passes a type that isnota 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 aFacet template parameter.
The refsargument to the constructor is used for lifetime management.
Forrefs == 0, the implementation performsdelete static_cast<locale::facet*>(f)(wherefis a pointer to the facet) when the lastlocaleobject containing the facet is destroyed; forrefs == 1, the implementation never destroys the facet.
Constructors of all facets defined in this Clause take such an argument and pass it along to theirfacetbase class constructor.
All one-argument constructors defined in this Clause areexplicit, 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 bylocale(const char*)with the same name.
Each such facet provides a constructor that takes aconst char*argument, which names the locale, and a refsargument, which is passed to the base class constructor.
Each such facet also provides a constructor that takes astring argument str and a refsargument, 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.
28.3.1.1.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
:
Because facets are used by iostreams, potentially while static constructors are running, their initialization cannot depend on programmed static initialization.
One initialization strategy is forlocaleto initialize each facet'sidmember 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
]