Namespaces
Variants
Views
Actions

std::locale::id

From cppreference.com
< cpp‎ | locale‎ | locale
Revision as of 19:55, 2 November 2012 by P12bot (Talk | contribs)

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <locale>
</td>

<td></td> <td></td> <tr class="t-dcl-sep"><td></td><td></td><td></td></tr>

<tr class="t-dcl ">

<td class="t-dcl-nopad">
class locale::id;
</td>

<td class="t-dcl-nopad"> </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

The class std::locale::id provides implementation-specific identification of a locale facet. Each class derived from std::locale::facet must have a public static member of type std::locale::id and each std::locale object maintains a list of facets it implements, indexed by their ids.

Member functions

constructs a new id
(public member function)
operator=
copy assignment operator is deleted
(public member function)

Example

The following example shows how to construct a minimal custom facet.

#include <iostream>
#include <locale>
#include <iostream>
#include <locale>
 
struct myfacet : std::locale::facet
{
    myfacet(std::size_t refs=0) : facet(refs) {}
    static std::locale::id id;
};
 
std::locale::id myfacet::id;
 
int main()
{
    std::locale myloc(std::locale(), new myfacet);
    std::cout << "has_facet<myloc, myfacet> returns " << std::boolalpha
              << std::has_facet<myfacet>(myloc) << '\n';
}

Output:

has_facet<myloc, myfacet> returns true

See also

Template:cpp/locale/locale/dcl list facet