## use_facet

    Locale Function

- Summary
- Data Type and Member Function Indexes
- Synopsis
- Description
- Example
- See Also

### Summary

A template function used to obtain a facet.

### Data Type and Member Function Indexes
(exclusive of constructors and destructors)

None

### Synopsis

    #include <locale>
    template <class Facet> const Facet& use_facet(const locale&);

### Description

use_facet returns a reference to the corresponding facet contained in the locale argument. You specify the facet type by explicitly including the template parameter (see the example below). If that facet is not present, then use_facet throws runtime_error. Otherwise, the reference remains valid for as long as any copy of the locale exists.

Note that if your compiler cannot overload function templates on return type, then you need to use an alternate use_facet template. The alternate template takes an additional argument that is a pointer to the type of facet you want to extract from the locale. The declaration looks like this:

    template <class Facet>
    const Facet& use_facet(const locale&, Facet*);

The example below shows the use of both variations of use_facet.

### Example

    //
    // usefacet.cpp
    //
    #include <iostream>

    int main ()
    {
      using namespace std;

      locale loc;

      // Get a ctype facet
      const ctype<char>& ct =
    #ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE
         use_facet<ctype<char> >(loc);
    #else
         use_facet(loc,(ctype<char>*)0);
    #endif

      cout << 'a' << ct.toupper('c') << endl;

      return 0;
    }

### See Also

locale, facets, has_facet

Copyright (c) 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998