Namespaces
Variants
Views
Actions

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

From cppreference.com
< cpp‎ | locale‎ | locale
(fmt, title)
(- {{dcl header|locale}})
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{cpp/locale/locale/title | combine}}
+
{{cpp/locale/locale/title|combine}}
{{cpp/locale/locale/sidebar}}
+
{{cpp/locale/locale/navbar}}
  
{{ddcl | header=locale |
+
{{ddcl|
 
template< class Facet >
 
template< class Facet >
 
locale combine( const locale& other ) const;
 
locale combine( const locale& other ) const;
 
}}
 
}}
  
Constructs a locale object which is a copy of {{cpp|*this}} except for the facet of type {{tt|Facet}}, which is copied from {{tt|other}}.
+
Constructs a locale object which is a copy of {{c|*this}} except for the facet of type {{tt|Facet}}, which is copied from {{c|other}}.
 +
 
 +
The program is ill-formed if Facet is not a {{rlp|facet#Facet class|facet}} or it is a volatile-qualified facet.
  
 
===Return value===
 
===Return value===
Line 13: Line 15:
  
 
===Exceptions===
 
===Exceptions===
{{cpp|std::runtime_error}} if {{tt|other}} does not implement {{tt|Facet}}
+
{{lc|std::runtime_error}} if {{c|other}} does not implement {{tt|Facet}}.
  
 
===Example===
 
===Example===
{{example cpp
+
{{example
|  
+
|  
| code=
+
|code=
 
#include <iostream>
 
#include <iostream>
 
#include <locale>
 
#include <locale>
Line 26: Line 28:
 
     const double number = 1000.25;
 
     const double number = 1000.25;
 
     std::cout << "\"C\" locale: " << number << '\n';
 
     std::cout << "\"C\" locale: " << number << '\n';
     std::locale loc = std::locale().combine<std::numpunct<char>>(std::locale("en_US.UTF8"));
+
     std::locale loc = std::locale()
 +
        .combine<std::numpunct<char>>(std::locale("en_US.UTF8"));
 
     std::cout.imbue(loc);
 
     std::cout.imbue(loc);
 
     std::cout << "\"C\" locale with en_US numpunct: " << number << '\n';
 
     std::cout << "\"C\" locale with en_US numpunct: " << number << '\n';
 
}
 
}
| output=
+
|output=
 
"C" locale: 1000.25
 
"C" locale: 1000.25
 
"C" locale with en_US numpunct: 1,000.25
 
"C" locale with en_US numpunct: 1,000.25
 
}}
 
}}
 +
 +
===Defect reports===
 +
{{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=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}}
  
 
===See also===
 
===See also===
{{dcl list begin}}
+
{{dsc begin}}
{{dcl list template | cpp/locale/locale/dcl list locale}}
+
{{dsc inc|cpp/locale/locale/dsc locale}}
{{dcl list end}}
+
{{dsc end}}
 +
 
 +
{{langlinks|de|es|fr|it|ja|pt|ru|zh}}

Latest revision as of 22:54, 18 October 2024

 
 
 
 
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

[edit] Return value

The new, nameless, locale.

[edit] Exceptions

std::runtime_error if other does not implement Facet.

[edit] 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

[edit] 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

[edit] See also

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