Name
has_facet function template — Test for existence of a facet in a locale
Synopsis
template <typename Facet>
bool has_facet(const locale& loc) throw( );
The has_facet
function
determines whether the locale loc
supports the facet Facet
. It
returns true
if the facet is
supported or false
if it is not.
Call has_facet
to determine
whether a locale supports a user-defined facet. (Every locale must
support the standard facets that are described in this section.)
Example 13-24 shows how
has_facet
is used.
Example
// The units facet is defined under the locale::facet class (later in this // section). using std::locale; if (std::has_facet<units>(locale( )) { // Get a reference to the units facet of the locale. const units& u = std::use_facet<units>(locale( )); // Construct a value of 42 cm. units::value_t len = u.make(42, units::cm); // Print the length (42 cm) in the locale's preferred units. u.length_put(std::cout, len); }
See Also
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.