##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::has_facet

From cppreference.com
< cpp‎ | locale

Defined in header `<locale>` |  |
template< class Facet > bool has_facet( const locale& loc ); |  |

Checks if the locale `loc` implements the facet `Facet`.

### [edit] Parameters

loc | - | the locale object to query

### [edit] Return value

Returns true if the facet `Facet` was installed in the locale `loc`, false otherwise.

### [edit] Exceptions

(none) | (until C++11)
`noexcept` specification: noexcept | (since C++11)

### [edit] Example

Run this code

    #include <iostream>
    #include <locale>

    // minimal custom facet
    struct myfacet : public std::locale::facet {
        static std::locale::id id;
    };

    std::locale::id myfacet::id;

    int main()
    {
        // loc is a "C" locale with myfacet added
        std::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? true
    Can loc classify char32_t? false
    Does loc implement myfacet? true

### [edit] See also

locale | set of polymorphic facets that encapsulate cultural differences (class) [edit]
use_facet | obtains a facet from a locale (function template) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/locale/has_facet&oldid=64830"