public member function
<locale>

std::locale::combine

template <class Facet> locale combine (const locale& x) const;
Construct copy of locale modifying one facet
Returns a locale object constructed from a copy of *this, except for the facet specified by template parameter Facet, which is taken from x.

Throws runtime_error if x does not have the facet specified by Facet defined.

The resulting locale has no name.

Parameters

x
A locale objects whose facet Facet is used by the new locale.

Return value

The resulting locale object, which has no name.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// locale::combine example
#include <iostream>       // std::cout
#include <locale>         // std::locale, std::num_put

int main ()
{
  std::locale loc("");    // initialized to environment's locale

  // combine loc with the "C" locale for num_put
  loc = loc.combine< std::num_put<char> > (std::locale::classic());

  std::cout.imbue(loc);
  std::cout << 3.14159 << '\n';

  return 0;
}


Output (no matter the environment's locale):

3.14159

Data races

The locale object is modified.

Exception safety

Basic guarantee: if an exception is thrown, the object is in a valid state.
It throws an exception of type runtime_error if x is not a locale with Facet defined.

See also