Two locale constructors can result in a new locale whose name is a combination of the names of two other locales:
locale(const locale& other, const char* std_name, category); locale(const locale& other, const locale& one, category);
If other has a name (and if one has a name in the case of the second constructor), then the resulting locale's name is composed from the two locales' names. A combined name locale has the format:
collate_name/ctype_name/monetary_name/numeric_name/ time_name/messages_name
Each name is the name of a locale from which that category of facets was copied.
The locale loc is created from two locales: other and one. The facets in the categories collate and numeric are taken from one. The rest of the facets are taken from other. The name of the resulting locale is:
one/other/other/one/other/other
The locale loc2 is created from the "C" locale and from loc (which already has a combined name). It takes only the monetary and collate facets from loc, and the rest from "C":
one/C/other/C/C/C
Using this format, two locales can be compared by name, and if their names are equal, then they have the same facets.
#include <locale> #include <iostream> int main() { using std::locale; locale loc(locale("other"), locale("one"), locale::collate | locale::numeric); std::cout << loc.name() << '\n'; locale loc2(locale(), loc, locale::monetary | locale::collate); std::cout << loc2.name() << '\n'; }