Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/locale/locale/combine"

From cppreference.com
< cpp‎ | locale‎ | locale
(Added LWG issue #436 DR (part 2/4).)
m (Wording fix.)
Line 41: Line 41:
 
{{dr list begin}}
 
{{dr list begin}}
 
{{dr list item|wg=lwg|dr=14|std=C++98|before={{tt|locale::combine}} was non-const|after=made const}}
 
{{dr list item|wg=lwg|dr=14|std=C++98|before={{tt|locale::combine}} was non-const|after=made const}}
{{dr list item|wg=lwg|dr=436|std=C++98|before=for overload {{v|7}}, it was unclear<br>whether {{tt|Facet}} can be cv-qualified|after=it can be const-qualified,<br>but not volatile-qualified}}
+
{{dr list item|wg=lwg|dr=436|std=C++98|before=it was unclear whether {{tt|Facet}} can be cv-qualified|after=it can be const-qualified, but not volatile-qualified}}
 
{{dr list end}}
 
{{dr list end}}
  

Revision as of 01:06, 16 February 2023

 
 
 
 
Defined in header <locale>
template< class Facet >
locale combine( const locale& other ) const;

Constructs a locale object which is a copy of *this except for the facet of type Facet, which is copied from other.

The program is ill-formed if Facet is not a facet or it is a volatile-qualified facet.

Contents

Return value

The new, nameless, locale.

Exceptions

std::runtime_error if other does not implement Facet.

Example

#include <iostream>
#include <locale>
 
int main()
{
    const double number = 1000.25;
    std::cout << "\"C\" locale: " << number << '\n';
    std::locale loc = std::locale()
        .combine<std::numpunct<char>>(std::locale("en_US.UTF8"));
    std::cout.imbue(loc);
    std::cout << "\"C\" locale with en_US numpunct: " << number << '\n';
}

Output:

"C" locale: 1000.25
"C" locale with en_US numpunct: 1,000.25

Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior
LWG 14 C++98 locale::combine was non-const made const
LWG 436 C++98 it was unclear whether Facet can be cv-qualified it can be const-qualified, but not volatile-qualified

See also

constructs a new locale
(public member function) [edit]