| Localization library | |||||||||||||||||||||||||
| Regular expressions library(C++11) | |||||||||||||||||||||||||
| Formatting library(C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <locale> | ||
template<class Facet> bool has_facet(const locale& loc)throw(); | (until C++11) | |
template<class Facet> bool has_facet(const locale& loc)noexcept; | (since C++11) | |
Checks if the localeloc implements the facetFacet.
The program is ill-formed if Facet is not afacet or it is a volatile-qualified facet.
Contents |
| loc | - | the locale object to query |
Returnstrue if the facetFacet was installed in the localeloc,false otherwise.
std::has_facet must returntrue for all localesloc ifFacet is one of the standard facets givenhere.
#include <iostream>#include <locale> // minimal custom facetstruct myfacet:publicstd::locale::facet{staticstd::locale::id id;}; std::locale::id myfacet::id; int main(){// loc is a "C" locale with myfacet addedstd::locale loc(std::locale::classic(), new myfacet);std::cout<<std::boolalpha<<"Can loc classify chars? "<< std::has_facet<std::ctype<char>>(loc)<<'\n'<<"Can loc classify char32_t? "<< std::has_facet<std::ctype<char32_t>>(loc)<<'\n'<<"Does loc implement myfacet? "<< std::has_facet<myfacet>(loc)<<'\n';}
Output:
Can loc classify chars? trueCan loc classify char32_t? falseDoes loc implement myfacet? true
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 436 | C++98 | it was unclear whetherFacet can be cv-qualified | it can be const-qualified, but not volatile-qualified |
| set of polymorphic facets that encapsulate cultural differences (class)[edit] | |
| obtains a facet from a locale (function template)[edit] |