std::locale(3cxx)
β¨ std::locale(3cxx) β¨
πΈ NAME πΈ
std::locale β container class for localization functionality. π
π¦ SYNOPSIS π¦
#include <locale>
π Classes
class facetβ Localization functionality base class.class idβ Facet ID class.
π Public Types
typedef int categoryβ Definition oflocale::category.
π Public Member Functions
locale () throw ()β Default constructor.locale (const char *__s)β Named locale constructor.locale (const locale &__base, const char *__s, category __cat)β Construct locale with facets from another locale.locale (const locale &__base, const locale &__add, category __cat)β Construct locale with facets from another locale.locale (const locale &__base, const std::string &__s, category __cat)β Construct locale with facets from another locale.locale (const locale &__other) throw ()β Copy constructor.template<typename _Facet > locale (const locale &__other, _Facet *__f)β Construct locale with another facet.locale (const std::string &__s)β Named locale constructor.~locale () throw ()β Locale destructor.template<typename _Facet > locale combine (const locale &__other) constβ Construct locale with another facet.string name () constβ Return locale name.template<typename _Char , typename _Traits , typename _Alloc > bool operator() (const basic_string< _Char, _Traits, _Alloc > &__s1, const basic_string< _Char, _Traits, _Alloc > &__s2) constβ Compare two strings according to collate.template<typename _CharT , typename _Traits , typename _Alloc > bool operator() (const basic_string< _CharT, _Traits, _Alloc > &__s1, const basic_string< _CharT, _Traits, _Alloc > &__s2) constβ anotheroperator()overload listed in the synopsis.const locale & operator= (const locale &__other) throw ()β Assignment operator.bool operator== (const locale &__other) const throw ()β Locale equality.
π Static Public Member Functions
static const locale & classic ()β Return reference to the C locale.static locale global (const locale &__loc)β Set global locale.
π Static Public Attributes
static const category noneβ Category values.static const category ctypeβ Category values.static const category numericβ Category values.static const category collateβ Category values.static const category timeβ Category values.static const category monetaryβ Category values.static const category messagesβ Category values.static const category allβ Category values.
π Friends
template<typename _Facet > const _Facet * __try_use_facet (const locale &) noexcepttemplate<typename _Cache > struct __use_cacheclass _Implclass facettemplate<typename _Facet > bool has_facet (const locale &) throw ()β Test for the presence of a facet.template<typename _Facet > const _Facet & use_facet (const locale &)β Return a facet.
π DETAILED DESCRIPTION π
Okay so bestie, hereβs the whole vibe: std::locale is first a class wrapper for C library locales. Itβs also an extensible container for user-defined localization. A locale is a collection of facets that implement various localization features such as money, time, and number printing. πΈβ°π’
Important: Constructing C++ locales does not change the C library locale. periodt.
This library supports efficient construction and copying of locales through a reference counting implementation of the locale class. β¨
π MEMBER TYPEDEF DOCUMENTATION π
typedef int std::locale::category
Definition of locale::category.
πΈ CONSTRUCTOR & DESTRUCTOR DOCUMENTATION πΈ
std::locale::locale ()
Default constructor. Constructs a copy of the global locale. If no locale has been explicitly set, this is the C locale.
Referenced by combine().
std::locale::locale (const locale & __other)
Copy constructor. Constructs a copy of other.
Parameters
__otherβ The locale to copy.
std::locale::locale (const char * __s) [explicit]
Named locale constructor. Constructs a copy of the named C library locale.
Parameters
__sβ Name of the locale to construct.
Exceptions
std::runtime_errorif__sis null or an undefined locale.
std::locale::locale (const locale & __base, const char * __s, category __cat)
Construct locale with facets from another locale. Constructs a copy of the locale base. The facets specified by cat are replaced with those from the locale named by s. If base is named, this locale instance will also be named.
Parameters
__baseβ The locale to copy.__sβ Name of the locale to use facets from.__catβ Set of categories defining the facets to use from__s.
Exceptions
std::runtime_errorif__sis null or an undefined locale.
std::locale::locale (const std::string & __s) [inline], [explicit]
Named locale constructor. Constructs a copy of the named C library locale.
Parameters
__sβ Name of the locale to construct.
Exceptions
std::runtime_errorif__sis an undefined locale.
std::locale::locale (const locale & __base, const std::string & __s, category __cat) [inline]
Construct locale with facets from another locale. Constructs a copy of the locale base. The facets specified by cat are replaced with those from the locale named by s. If base is named, this locale instance will also be named.
Parameters
__baseβ The locale to copy.__sβ Name of the locale to use facets from.__catβ Set of categories defining the facets to use from__s.
Exceptions
std::runtime_errorif__sis an undefined locale.
std::locale::locale (const locale & __base, const locale & __add, category __cat)
Construct locale with facets from another locale. Constructs a copy of the locale base. The facets specified by cat are replaced with those from the locale add. If base and add are named, this locale instance will also be named.
Parameters
__baseβ The locale to copy.__addβ The locale to use facets from.__catβ Set of categories defining the facets to use fromadd.
template<typename _Facet > std::locale::locale (const locale & __other, _Facet * __f)
Construct locale with another facet. Constructs a copy of the locale __other. The facet __f is added to __other, replacing an existing facet of type Facet if there is one. If __f is null, this locale is a copy of __other.
Parameters
__otherβ The locale to copy.__fβ The facet to add in.
std::locale::~locale ()
Locale destructor.
π¦ MEMBER FUNCTION DOCUMENTATION π¦
static const locale & std::locale::classic () [static]
Return reference to the C locale.
template<typename _Facet > locale std::locale::combine (const locale & __other) const
Construct locale with another facet. Constructs and returns a new copy of this locale. Adds or replaces an existing facet of type Facet from the locale other into the new locale.
Template Parameters
_Facetβ The facet type to copy fromother
Parameters
__otherβ The locale to copy from.
Returns
- Newly constructed locale.
Exceptions
std::runtime_errorif__otherhas no facet of type_Facet.
References locale().
static locale std::locale::global (const locale & __loc) [static]
Set global locale. This function sets the global locale to the argument and returns a copy of the previous global locale. If the argument has a name, it will also call std::setlocale(LC_ALL, loc.name()).
Parameters
__locβ The new locale to make global.
Returns
- Copy of the old global locale.
string std::locale::name () const
Return locale name.
Returns
- Locale name or
'*'if unnamed.
template<typename _Char , typename _Traits , typename _Alloc > bool std::locale::operator() (const basic_string< _Char, _Traits, _Alloc > & __s1, const basic_string< _Char, _Traits, _Alloc > & __s2) const
Compare two strings according to collate. Template operator to compare two strings using the compare function of the collate facet in this locale. One use is to provide the locale to the sort function. For example, a vector v of strings could be sorted according to locale loc by doing:
std::sort(v.begin(), v.end(), loc);
Parameters
__s1β First string to compare.__s2β Second string to compare.
Returns
- True if
collate<_Char>facet compares__s1 < __s2, else false.
const locale & std::locale::operator= (const locale & __other)
Assignment operator. Set this locale to be a copy of other.
Parameters
__otherβ The locale to copy.
Returns
- A reference to this locale.
bool std::locale::operator== (const locale & __other) const
Locale equality.
Parameters
__otherβ The locale to compare against.
Returns
- True if
otherandthisrefer to the same locale instance, are copies, or have the same name. False otherwise.
References operator==().
Referenced by operator==().
π FRIENDS AND RELATED SYMBOL DOCUMENTATION π
template<typename _Facet > bool has_facet (const locale &) [friend]
Test for the presence of a facet. has_facet tests the locale argument for the presence of the facet type provided as the template parameter. Facets derived from the facet parameter will also return true.
Template Parameters
_Facetβ The facet type to test the presence of.
Parameters
__locβ The locale to test.
Returns
trueif__loccontains a facet of type_Facet, else false.
template<typename _Facet > const _Facet & use_facet (const locale &) [friend]
Return a facet. use_facet looks for and returns a reference to a facet of type Facet where Facet is the template parameter. If has_facet(locale) is true, there is a suitable facet to return. It throws std::bad_cast if the locale doesnβt contain a facet of type Facet.
Template Parameters
_Facetβ The facet type to access.
Parameters
__locβ The locale to use.
Returns
- Reference to facet of type
Facet.
Exceptions
std::bad_castif__locdoesnβt contain a facet of type_Facet.
πΎ Member Data Documentation
Okay bestie, this is the part where all the categories live β every single one of them is a const category static member, so let's go through them one by one, no skipping, no cap π
Here's the whole spiel once so you have it in your head, because it applies to every one of these bad boys: the standard category values are none, ctype, numeric, collate, time, monetary, and messages. They form a bitmask that supports union and intersection, and the category all is the union of these values. π«Ά
β οΈ NB: Order must match_S_facet_categoriesdefinition inlocale.ccβ yes, that's literally a requirement, do not reorder these, iykyk π
π const category std::locale::all [static]
Category values, babes. The standard category values are none, ctype, numeric, collate, time, monetary, and messages β that's the whole squad. They form a bitmask that supports union and intersection, and all is literally the union of these values, so it's giving "everyone's invited to the party" β¨
β οΈ NB: Order must match_S_facet_categoriesdefinition inlocale.cc
π const category std::locale::collate [static]
Category values, bestie. The standard category values are none, ctype, numeric, collate, time, monetary, and messages. They form a bitmask that supports union and intersection, and the category all is the union of these values. This one's the collate era π¦
β οΈ NB: Order must match_S_facet_categoriesdefinition inlocale.cc
πΈ const category std::locale::ctype [static]
Category values, fr fr. The standard category values are none, ctype, numeric, collate, time, monetary, and messages. They form a bitmask that supports union and intersection, and all is the union of these values β she's the character-classification main character here π
β οΈ NB: Order must match_S_facet_categoriesdefinition inlocale.cc
π¦ const category std::locale::messages [static]
Category values, okay so. The standard category values are none, ctype, numeric, collate, time, monetary, and messages. They form a bitmask that supports union and intersection, and the category all is the union of these values. Message catalog vibes only π¬
β οΈ NB: Order must match_S_facet_categoriesdefinition inlocale.cc
π const category std::locale::monetary [static]
Category values, ngl. The standard category values are none, ctype, numeric, collate, time, monetary, and messages. They form a bitmask that supports union and intersection, and all is the union of these values. Money moves πΈ
β οΈ NB: Order must match_S_facet_categoriesdefinition inlocale.cc
π§ const category std::locale::none [static]
Category values, lowkey the starting point. The standard category values are none, ctype, numeric, collate, time, monetary, and messages. They form a bitmask that supports union and intersection, and the category all is the union of these values. She's the empty set of the group chat π
β οΈ NB: Order must match_S_facet_categoriesdefinition inlocale.cc
π₯ const category std::locale::numeric [static]
Category values, periodt. The standard category values are none, ctype, numeric, collate, time, monetary, and messages. They form a bitmask that supports union and intersection, and all is the union of these values β numbers, formatted and iconic π’
β οΈ NB: Order must match_S_facet_categoriesdefinition inlocale.cc
β const category std::locale::time [static]
Category values, bestie, last but never least. The standard category values are none, ctype, numeric, collate, time, monetary, and messages. They form a bitmask that supports union and intersection, and the category all is the union of these values. Clock app energy β°
β οΈ NB: Order must match_S_facet_categoriesdefinition inlocale.cc
π Author
Generated automatically by Doxygen for libstdc++ from the source code. Not me writing a love letter by hand, it's the robots doing it π€π
And that's a wrap on std::locale(3cxx), bestie! π This lil masterpiece came straight out of the libstdc++ source, and it's dated the same day the doc fairies ran Doxygen on it. Go forth and localize, and remember: respect the category order, or it's giving undefined chaos πβ¨
π¦ where this page comes from
- ubuntu noble: libstdc++-14-doc 14-20240412-0ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms