Apache C++ Standard Library Reference Guide

## has_facet()

Library: Localization

    Function

- Local Index
- Summary
- Synopsis
- Description
- Example
- See Also
- Standards Conformance

### Local Index

No Entries

### Summary

A function template used to determine if a locale has a given facet

### Synopsis

    #include <locale>

    namespace std {
      template <class Facet>
      bool has_facet(const locale&) throw();
    }

### Description

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).

### Example

    //
    //  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

### See Also

locale, Facets, `use_facet()`

### Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems -- Programming Language C++, Section 22.1