Library: Localization
Function
A function template used to determine if a locale has a given facet
#include <locale>
namespace std {
template <class Facet>
bool has_facet(const locale&) throw();
}
The function has_facet() returns true if the requested facet is available in the locale. Otherwise, it returns false. You specify the facet type by explicitly including the template parameter (see the example below).
//
// hasfacet.cpp
//
#include <iostream> // for cout, endl
#include <locale> // for has_facet
// dummy facet, must derive from locale::facet
// and define a static member of type locale::id
struct my_facet: public std::locale::facet
{
static std::locale::id id;
};
std::locale::id my_facet::id;
int main ()
{
// see if ctype<char> is contained in the locale
// imbued in cout
std::cout << std::boolalpha
<< std::has_facet<std::ctype<char> >(std::cout.getloc ())
<< std::endl;
// see if my_facet is contained in the locale
// imbued in cout
std::cout << std::has_facet<my_facet>(std::cout.getloc ())
<< std::endl;
return 0;
}
Program Output:
false false
ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 22.1