tmp/tmpyjbmzug9/{from.md → to.md}
RENAMED
|
@@ -2,22 +2,22 @@
|
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
namespace std {
|
| 5 |
class locale {
|
| 6 |
public:
|
| 7 |
-
// types
|
| 8 |
class facet;
|
| 9 |
class id;
|
| 10 |
using category = int;
|
| 11 |
static const category // values assigned here are for exposition only
|
| 12 |
none = 0,
|
| 13 |
collate = 0x010, ctype = 0x020,
|
| 14 |
monetary = 0x040, numeric = 0x080,
|
| 15 |
time = 0x100, messages = 0x200,
|
| 16 |
all = collate | ctype | monetary | numeric | time | messages;
|
| 17 |
|
| 18 |
-
// construct/copy/destroy
|
| 19 |
locale() noexcept;
|
| 20 |
locale(const locale& other) noexcept;
|
| 21 |
explicit locale(const char* std_name);
|
| 22 |
explicit locale(const string& std_name);
|
| 23 |
locale(const locale& other, const char* std_name, category);
|
|
@@ -26,21 +26,20 @@ namespace std {
|
|
| 26 |
locale(const locale& other, const locale& one, category);
|
| 27 |
~locale(); // not virtual
|
| 28 |
const locale& operator=(const locale& other) noexcept;
|
| 29 |
template<class Facet> locale combine(const locale& other) const;
|
| 30 |
|
| 31 |
-
// locale operations
|
| 32 |
-
|
| 33 |
|
| 34 |
bool operator==(const locale& other) const;
|
| 35 |
-
bool operator!=(const locale& other) const;
|
| 36 |
|
| 37 |
template<class charT, class traits, class Allocator>
|
| 38 |
bool operator()(const basic_string<charT, traits, Allocator>& s1,
|
| 39 |
const basic_string<charT, traits, Allocator>& s2) const;
|
| 40 |
|
| 41 |
-
// global locale objects
|
| 42 |
static locale global(const locale&);
|
| 43 |
static const locale& classic();
|
| 44 |
};
|
| 45 |
}
|
| 46 |
```
|
|
@@ -61,29 +60,29 @@ An iostream `operator<<` might be implemented as:[^2]
|
|
| 61 |
template<class charT, class traits>
|
| 62 |
basic_ostream<charT, traits>&
|
| 63 |
operator<< (basic_ostream<charT, traits>& s, Date d) {
|
| 64 |
typename basic_ostream<charT, traits>::sentry cerberos(s);
|
| 65 |
if (cerberos) {
|
| 66 |
-
ios_base::iostate err = ios_base::iostate::goodbit;
|
| 67 |
tm tmbuf; d.extract(tmbuf);
|
|
|
|
| 68 |
use_facet<time_put<charT, ostreambuf_iterator<charT, traits>>>(
|
| 69 |
-
|
| 70 |
-
|
|
|
|
| 71 |
}
|
| 72 |
return s;
|
| 73 |
}
|
| 74 |
```
|
| 75 |
|
| 76 |
— *end example*]
|
| 77 |
|
| 78 |
In the call to `use_facet<Facet>(loc)`, the type argument chooses a
|
| 79 |
facet, making available all members of the named type. If `Facet` is not
|
| 80 |
-
present in a locale, it throws the standard exception `bad_cast`. A
|
| 81 |
-
|
| 82 |
function template `has_facet<Facet>()`. User-defined facets may be
|
| 83 |
-
installed in a locale, and used identically as may standard facets
|
| 84 |
-
[[facets.examples]]).
|
| 85 |
|
| 86 |
[*Note 1*:
|
| 87 |
|
| 88 |
All locale semantics are accessed via `use_facet<>` and `has_facet<>`,
|
| 89 |
except that:
|
|
@@ -93,11 +92,11 @@ except that:
|
|
| 93 |
is provided so that a locale may be used as a predicate argument to
|
| 94 |
the standard collections, to collate strings.
|
| 95 |
- Convenient global interfaces are provided for traditional `ctype`
|
| 96 |
functions such as `isdigit()` and `isspace()`, so that given a locale
|
| 97 |
object `loc` a C++ program can call `isspace(c, loc)`. (This eases
|
| 98 |
-
upgrading existing extractors
|
| 99 |
|
| 100 |
— *end note*]
|
| 101 |
|
| 102 |
Once a facet reference is obtained from a locale object by calling
|
| 103 |
`use_facet<>`, that reference remains usable, and the results from
|
|
@@ -115,14 +114,14 @@ of) itself. For an unnamed locale, `locale::name()` returns the string
|
|
| 115 |
|
| 116 |
Whether there is one global locale object for the entire program or one
|
| 117 |
global locale object per thread is *implementation-defined*.
|
| 118 |
Implementations should provide one global locale object per thread. If
|
| 119 |
there is a single global locale object for the entire program,
|
| 120 |
-
implementations are not required to avoid data races on it
|
| 121 |
-
[[res.on.data.races]]
|
| 122 |
|
| 123 |
-
####
|
| 124 |
|
| 125 |
##### Type `locale::category` <a id="locale.category">[[locale.category]]</a>
|
| 126 |
|
| 127 |
``` cpp
|
| 128 |
using category = int;
|
|
@@ -147,22 +146,21 @@ category, represents the union of the two categories.
|
|
| 147 |
|
| 148 |
member functions expecting a `category` argument require one of the
|
| 149 |
`category` values defined above, or the union of two or more such
|
| 150 |
values. Such a `category` value identifies a set of locale categories.
|
| 151 |
Each locale category, in turn, identifies a set of locale facets,
|
| 152 |
-
including at least those shown in
|
| 153 |
-
[[tab:localization.category.facets]].
|
| 154 |
|
| 155 |
-
**Table: Locale category facets** <a id="
|
| 156 |
|
| 157 |
| Category | Includes facets |
|
| 158 |
| -------- | ----------------------------------------------------- |
|
| 159 |
| collate | `collate<char>`, `collate<wchar_t>` |
|
| 160 |
| ctype | `ctype<char>`, `ctype<wchar_t>` |
|
| 161 |
| | `codecvt<char, char, mbstate_t>` |
|
| 162 |
-
| | `codecvt<char16_t,
|
| 163 |
-
| | `codecvt<char32_t,
|
| 164 |
| | `codecvt<wchar_t, char, mbstate_t>` |
|
| 165 |
| monetary | `moneypunct<char>`, `moneypunct<wchar_t>` |
|
| 166 |
| | `moneypunct<char, true>`, `moneypunct<wchar_t, true>` |
|
| 167 |
| | `money_get<char>`, `money_get<wchar_t>` |
|
| 168 |
| | `money_put<char>`, `money_put<wchar_t>` |
|
|
@@ -173,28 +171,28 @@ including at least those shown in Table
|
|
| 173 |
| | `time_put<char>`, `time_put<wchar_t>` |
|
| 174 |
| messages | `messages<char>`, `messages<wchar_t>` |
|
| 175 |
|
| 176 |
|
| 177 |
For any locale `loc` either constructed, or returned by
|
| 178 |
-
`locale::classic()`, and any facet `Facet` shown in
|
| 179 |
-
[[
|
| 180 |
-
|
| 181 |
operates on the corresponding set of facets.
|
| 182 |
|
| 183 |
An implementation is required to provide those specializations for facet
|
| 184 |
templates identified as members of a category, and for those shown in
|
| 185 |
-
|
| 186 |
|
| 187 |
-
**Table: Required specializations** <a id="
|
| 188 |
|
| 189 |
| Category | Includes facets |
|
| 190 |
| -------- | --------------------------------------------------------- |
|
| 191 |
| collate | `collate_byname<char>`, `collate_byname<wchar_t>` |
|
| 192 |
| ctype | `ctype_byname<char>`, `ctype_byname<wchar_t>` |
|
| 193 |
| | `codecvt_byname<char, char, mbstate_t>` |
|
| 194 |
-
| | `codecvt_byname<char16_t,
|
| 195 |
-
| | `codecvt_byname<char32_t,
|
| 196 |
| | `codecvt_byname<wchar_t, char, mbstate_t>` |
|
| 197 |
| monetary | `moneypunct_byname<char, International>` |
|
| 198 |
| | `moneypunct_byname<wchar_t, International>` |
|
| 199 |
| | `money_get<C, InputIterator>` |
|
| 200 |
| | `money_put<C, OutputIterator>` |
|
|
@@ -217,18 +215,18 @@ The provided implementation of members of facets `num_get<charT>` and
|
|
| 217 |
obtained by calling member `getloc()` on the `ios_base&` argument to
|
| 218 |
these functions.
|
| 219 |
|
| 220 |
In declarations of facets, a template parameter with name
|
| 221 |
`InputIterator` or `OutputIterator` indicates the set of all possible
|
| 222 |
-
specializations on parameters that
|
| 223 |
-
|
| 224 |
-
[[iterator.requirements]]
|
| 225 |
-
|
| 226 |
-
*implementation-defined* character types that
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
|
| 231 |
##### Class `locale::facet` <a id="locale.facet">[[locale.facet]]</a>
|
| 232 |
|
| 233 |
``` cpp
|
| 234 |
namespace std {
|
|
@@ -254,11 +252,11 @@ static ::std::locale::id id;
|
|
| 254 |
Template parameters in this Clause which are required to be facets are
|
| 255 |
those named `Facet` in declarations. A program that passes a type that
|
| 256 |
is *not* a facet, or a type that refers to a volatile-qualified facet,
|
| 257 |
as an (explicit or deduced) template parameter to a locale function
|
| 258 |
expecting a facet, is ill-formed. A const-qualified facet is a valid
|
| 259 |
-
template argument to any locale function that expects a Facet template
|
| 260 |
parameter.
|
| 261 |
|
| 262 |
The `refs` argument to the constructor is used for lifetime management.
|
| 263 |
For `refs == 0`, the implementation performs
|
| 264 |
`delete static_cast<locale::facet*>(f)` (where `f` is a pointer to the
|
|
@@ -302,35 +300,27 @@ initialization.
|
|
| 302 |
[*Note 1*: Because facets are used by iostreams, potentially while
|
| 303 |
static constructors are running, their initialization cannot depend on
|
| 304 |
programmed static initialization. One initialization strategy is for
|
| 305 |
`locale` to initialize each facet’s `id` member the first time an
|
| 306 |
instance of the facet is installed into a locale. This depends only on
|
| 307 |
-
static storage being zero before constructors run
|
| 308 |
-
[[basic.start.static]]
|
| 309 |
|
| 310 |
-
####
|
| 311 |
|
| 312 |
``` cpp
|
| 313 |
locale() noexcept;
|
| 314 |
```
|
| 315 |
|
| 316 |
-
Default constructor: a snapshot of the current global locale.
|
| 317 |
-
|
| 318 |
*Effects:* Constructs a copy of the argument last passed to
|
| 319 |
`locale::global(locale&)`, if it has been called; else, the resulting
|
| 320 |
facets have virtual function semantics identical to those of
|
| 321 |
`locale::classic()`.
|
| 322 |
|
| 323 |
-
[*Note 1*: This constructor
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
``` cpp
|
| 328 |
-
locale(const locale& other) noexcept;
|
| 329 |
-
```
|
| 330 |
-
|
| 331 |
-
*Effects:* Constructs a locale which is a copy of `other`.
|
| 332 |
|
| 333 |
``` cpp
|
| 334 |
explicit locale(const char* std_name);
|
| 335 |
```
|
| 336 |
|
|
@@ -395,17 +385,11 @@ const locale& operator=(const locale& other) noexcept;
|
|
| 395 |
|
| 396 |
*Effects:* Creates a copy of `other`, replacing the current value.
|
| 397 |
|
| 398 |
*Returns:* `*this`.
|
| 399 |
|
| 400 |
-
|
| 401 |
-
~locale();
|
| 402 |
-
```
|
| 403 |
-
|
| 404 |
-
A non-virtual destructor that throws no exceptions.
|
| 405 |
-
|
| 406 |
-
#### `locale` members <a id="locale.members">[[locale.members]]</a>
|
| 407 |
|
| 408 |
``` cpp
|
| 409 |
template<class Facet> locale combine(const locale& other) const;
|
| 410 |
```
|
| 411 |
|
|
@@ -417,43 +401,37 @@ except for that one facet of `other` that is identified by `Facet`.
|
|
| 417 |
*Throws:* `runtime_error` if `has_facet<Facet>(other)` is `false`.
|
| 418 |
|
| 419 |
*Remarks:* The resulting locale has no name.
|
| 420 |
|
| 421 |
``` cpp
|
| 422 |
-
|
| 423 |
```
|
| 424 |
|
| 425 |
*Returns:* The name of `*this`, if it has one; otherwise, the string
|
| 426 |
`"*"`.
|
| 427 |
|
| 428 |
-
####
|
| 429 |
|
| 430 |
``` cpp
|
| 431 |
bool operator==(const locale& other) const;
|
| 432 |
```
|
| 433 |
|
| 434 |
*Returns:* `true` if both arguments are the same locale, or one is a
|
| 435 |
copy of the other, or each has a name and the names are identical;
|
| 436 |
`false` otherwise.
|
| 437 |
|
| 438 |
-
``` cpp
|
| 439 |
-
bool operator!=(const locale& other) const;
|
| 440 |
-
```
|
| 441 |
-
|
| 442 |
-
*Returns:* `!(*this == other)`.
|
| 443 |
-
|
| 444 |
``` cpp
|
| 445 |
template<class charT, class traits, class Allocator>
|
| 446 |
bool operator()(const basic_string<charT, traits, Allocator>& s1,
|
| 447 |
const basic_string<charT, traits, Allocator>& s2) const;
|
| 448 |
```
|
| 449 |
|
| 450 |
*Effects:* Compares two strings according to the `collate<charT>` facet.
|
| 451 |
|
| 452 |
*Remarks:* This member operator template (and therefore `locale` itself)
|
| 453 |
-
|
| 454 |
-
|
| 455 |
|
| 456 |
*Returns:*
|
| 457 |
|
| 458 |
``` cpp
|
| 459 |
use_facet<collate<charT>>(*this).compare(s1.data(), s1.data() + s1.size(),
|
|
@@ -469,28 +447,29 @@ locale `loc` simply by ([[alg.sort]], [[vector]]):
|
|
| 469 |
std::sort(v.begin(), v.end(), loc);
|
| 470 |
```
|
| 471 |
|
| 472 |
— *end example*]
|
| 473 |
|
| 474 |
-
####
|
| 475 |
|
| 476 |
``` cpp
|
| 477 |
static locale global(const locale& loc);
|
| 478 |
```
|
| 479 |
|
| 480 |
-
Sets the global locale to its argument.
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
copy of the argument. If the argument has a name, does
|
| 484 |
|
| 485 |
``` cpp
|
| 486 |
setlocale(LC_ALL, loc.name().c_str());
|
| 487 |
```
|
| 488 |
|
| 489 |
otherwise, the effect on the C locale, if any, is
|
| 490 |
-
*implementation-defined*.
|
| 491 |
-
|
|
|
|
|
|
|
| 492 |
|
| 493 |
[*Note 1*: See [[c.locales]] for data race considerations when
|
| 494 |
`setlocale` is invoked. — *end note*]
|
| 495 |
|
| 496 |
*Returns:* The previous value of `locale()`.
|
|
|
|
| 2 |
|
| 3 |
``` cpp
|
| 4 |
namespace std {
|
| 5 |
class locale {
|
| 6 |
public:
|
| 7 |
+
// types
|
| 8 |
class facet;
|
| 9 |
class id;
|
| 10 |
using category = int;
|
| 11 |
static const category // values assigned here are for exposition only
|
| 12 |
none = 0,
|
| 13 |
collate = 0x010, ctype = 0x020,
|
| 14 |
monetary = 0x040, numeric = 0x080,
|
| 15 |
time = 0x100, messages = 0x200,
|
| 16 |
all = collate | ctype | monetary | numeric | time | messages;
|
| 17 |
|
| 18 |
+
// construct/copy/destroy
|
| 19 |
locale() noexcept;
|
| 20 |
locale(const locale& other) noexcept;
|
| 21 |
explicit locale(const char* std_name);
|
| 22 |
explicit locale(const string& std_name);
|
| 23 |
locale(const locale& other, const char* std_name, category);
|
|
|
|
| 26 |
locale(const locale& other, const locale& one, category);
|
| 27 |
~locale(); // not virtual
|
| 28 |
const locale& operator=(const locale& other) noexcept;
|
| 29 |
template<class Facet> locale combine(const locale& other) const;
|
| 30 |
|
| 31 |
+
// locale operations
|
| 32 |
+
string name() const;
|
| 33 |
|
| 34 |
bool operator==(const locale& other) const;
|
|
|
|
| 35 |
|
| 36 |
template<class charT, class traits, class Allocator>
|
| 37 |
bool operator()(const basic_string<charT, traits, Allocator>& s1,
|
| 38 |
const basic_string<charT, traits, Allocator>& s2) const;
|
| 39 |
|
| 40 |
+
// global locale objects
|
| 41 |
static locale global(const locale&);
|
| 42 |
static const locale& classic();
|
| 43 |
};
|
| 44 |
}
|
| 45 |
```
|
|
|
|
| 60 |
template<class charT, class traits>
|
| 61 |
basic_ostream<charT, traits>&
|
| 62 |
operator<< (basic_ostream<charT, traits>& s, Date d) {
|
| 63 |
typename basic_ostream<charT, traits>::sentry cerberos(s);
|
| 64 |
if (cerberos) {
|
|
|
|
| 65 |
tm tmbuf; d.extract(tmbuf);
|
| 66 |
+
bool failed =
|
| 67 |
use_facet<time_put<charT, ostreambuf_iterator<charT, traits>>>(
|
| 68 |
+
s.getloc()).put(s, s, s.fill(), &tmbuf, 'x').failed();
|
| 69 |
+
if (failed)
|
| 70 |
+
s.setstate(s.badbit); // might throw
|
| 71 |
}
|
| 72 |
return s;
|
| 73 |
}
|
| 74 |
```
|
| 75 |
|
| 76 |
— *end example*]
|
| 77 |
|
| 78 |
In the call to `use_facet<Facet>(loc)`, the type argument chooses a
|
| 79 |
facet, making available all members of the named type. If `Facet` is not
|
| 80 |
+
present in a locale, it throws the standard exception `bad_cast`. A C++
|
| 81 |
+
program can check if a locale implements a particular facet with the
|
| 82 |
function template `has_facet<Facet>()`. User-defined facets may be
|
| 83 |
+
installed in a locale, and used identically as may standard facets.
|
|
|
|
| 84 |
|
| 85 |
[*Note 1*:
|
| 86 |
|
| 87 |
All locale semantics are accessed via `use_facet<>` and `has_facet<>`,
|
| 88 |
except that:
|
|
|
|
| 92 |
is provided so that a locale may be used as a predicate argument to
|
| 93 |
the standard collections, to collate strings.
|
| 94 |
- Convenient global interfaces are provided for traditional `ctype`
|
| 95 |
functions such as `isdigit()` and `isspace()`, so that given a locale
|
| 96 |
object `loc` a C++ program can call `isspace(c, loc)`. (This eases
|
| 97 |
+
upgrading existing extractors [[istream.formatted]].)
|
| 98 |
|
| 99 |
— *end note*]
|
| 100 |
|
| 101 |
Once a facet reference is obtained from a locale object by calling
|
| 102 |
`use_facet<>`, that reference remains usable, and the results from
|
|
|
|
| 114 |
|
| 115 |
Whether there is one global locale object for the entire program or one
|
| 116 |
global locale object per thread is *implementation-defined*.
|
| 117 |
Implementations should provide one global locale object per thread. If
|
| 118 |
there is a single global locale object for the entire program,
|
| 119 |
+
implementations are not required to avoid data races on it
|
| 120 |
+
[[res.on.data.races]].
|
| 121 |
|
| 122 |
+
#### Types <a id="locale.types">[[locale.types]]</a>
|
| 123 |
|
| 124 |
##### Type `locale::category` <a id="locale.category">[[locale.category]]</a>
|
| 125 |
|
| 126 |
``` cpp
|
| 127 |
using category = int;
|
|
|
|
| 146 |
|
| 147 |
member functions expecting a `category` argument require one of the
|
| 148 |
`category` values defined above, or the union of two or more such
|
| 149 |
values. Such a `category` value identifies a set of locale categories.
|
| 150 |
Each locale category, in turn, identifies a set of locale facets,
|
| 151 |
+
including at least those shown in [[locale.category.facets]].
|
|
|
|
| 152 |
|
| 153 |
+
**Table: Locale category facets** <a id="locale.category.facets">[locale.category.facets]</a>
|
| 154 |
|
| 155 |
| Category | Includes facets |
|
| 156 |
| -------- | ----------------------------------------------------- |
|
| 157 |
| collate | `collate<char>`, `collate<wchar_t>` |
|
| 158 |
| ctype | `ctype<char>`, `ctype<wchar_t>` |
|
| 159 |
| | `codecvt<char, char, mbstate_t>` |
|
| 160 |
+
| | `codecvt<char16_t, char8_t, mbstate_t>` |
|
| 161 |
+
| | `codecvt<char32_t, char8_t, mbstate_t>` |
|
| 162 |
| | `codecvt<wchar_t, char, mbstate_t>` |
|
| 163 |
| monetary | `moneypunct<char>`, `moneypunct<wchar_t>` |
|
| 164 |
| | `moneypunct<char, true>`, `moneypunct<wchar_t, true>` |
|
| 165 |
| | `money_get<char>`, `money_get<wchar_t>` |
|
| 166 |
| | `money_put<char>`, `money_put<wchar_t>` |
|
|
|
|
| 171 |
| | `time_put<char>`, `time_put<wchar_t>` |
|
| 172 |
| messages | `messages<char>`, `messages<wchar_t>` |
|
| 173 |
|
| 174 |
|
| 175 |
For any locale `loc` either constructed, or returned by
|
| 176 |
+
`locale::classic()`, and any facet `Facet` shown in
|
| 177 |
+
[[locale.category.facets]], `has_facet<Facet>(loc)` is `true`. Each
|
| 178 |
+
`locale` member function which takes a `locale::category` argument
|
| 179 |
operates on the corresponding set of facets.
|
| 180 |
|
| 181 |
An implementation is required to provide those specializations for facet
|
| 182 |
templates identified as members of a category, and for those shown in
|
| 183 |
+
[[locale.spec]].
|
| 184 |
|
| 185 |
+
**Table: Required specializations** <a id="locale.spec">[locale.spec]</a>
|
| 186 |
|
| 187 |
| Category | Includes facets |
|
| 188 |
| -------- | --------------------------------------------------------- |
|
| 189 |
| collate | `collate_byname<char>`, `collate_byname<wchar_t>` |
|
| 190 |
| ctype | `ctype_byname<char>`, `ctype_byname<wchar_t>` |
|
| 191 |
| | `codecvt_byname<char, char, mbstate_t>` |
|
| 192 |
+
| | `codecvt_byname<char16_t, char8_t, mbstate_t>` |
|
| 193 |
+
| | `codecvt_byname<char32_t, char8_t, mbstate_t>` |
|
| 194 |
| | `codecvt_byname<wchar_t, char, mbstate_t>` |
|
| 195 |
| monetary | `moneypunct_byname<char, International>` |
|
| 196 |
| | `moneypunct_byname<wchar_t, International>` |
|
| 197 |
| | `money_get<C, InputIterator>` |
|
| 198 |
| | `money_put<C, OutputIterator>` |
|
|
|
|
| 215 |
obtained by calling member `getloc()` on the `ios_base&` argument to
|
| 216 |
these functions.
|
| 217 |
|
| 218 |
In declarations of facets, a template parameter with name
|
| 219 |
`InputIterator` or `OutputIterator` indicates the set of all possible
|
| 220 |
+
specializations on parameters that meet the *Cpp17InputIterator*
|
| 221 |
+
requirements or *Cpp17OutputIterator* requirements, respectively
|
| 222 |
+
[[iterator.requirements]]. A template parameter with name `C` represents
|
| 223 |
+
the set of types containing `char`, `wchar_t`, and any other
|
| 224 |
+
*implementation-defined* character types that meet the requirements for
|
| 225 |
+
a character on which any of the iostream components can be instantiated.
|
| 226 |
+
A template parameter with name `International` represents the set of all
|
| 227 |
+
possible specializations on a bool parameter.
|
| 228 |
|
| 229 |
##### Class `locale::facet` <a id="locale.facet">[[locale.facet]]</a>
|
| 230 |
|
| 231 |
``` cpp
|
| 232 |
namespace std {
|
|
|
|
| 252 |
Template parameters in this Clause which are required to be facets are
|
| 253 |
those named `Facet` in declarations. A program that passes a type that
|
| 254 |
is *not* a facet, or a type that refers to a volatile-qualified facet,
|
| 255 |
as an (explicit or deduced) template parameter to a locale function
|
| 256 |
expecting a facet, is ill-formed. A const-qualified facet is a valid
|
| 257 |
+
template argument to any locale function that expects a `Facet` template
|
| 258 |
parameter.
|
| 259 |
|
| 260 |
The `refs` argument to the constructor is used for lifetime management.
|
| 261 |
For `refs == 0`, the implementation performs
|
| 262 |
`delete static_cast<locale::facet*>(f)` (where `f` is a pointer to the
|
|
|
|
| 300 |
[*Note 1*: Because facets are used by iostreams, potentially while
|
| 301 |
static constructors are running, their initialization cannot depend on
|
| 302 |
programmed static initialization. One initialization strategy is for
|
| 303 |
`locale` to initialize each facet’s `id` member the first time an
|
| 304 |
instance of the facet is installed into a locale. This depends only on
|
| 305 |
+
static storage being zero before constructors run
|
| 306 |
+
[[basic.start.static]]. — *end note*]
|
| 307 |
|
| 308 |
+
#### Constructors and destructor <a id="locale.cons">[[locale.cons]]</a>
|
| 309 |
|
| 310 |
``` cpp
|
| 311 |
locale() noexcept;
|
| 312 |
```
|
| 313 |
|
|
|
|
|
|
|
| 314 |
*Effects:* Constructs a copy of the argument last passed to
|
| 315 |
`locale::global(locale&)`, if it has been called; else, the resulting
|
| 316 |
facets have virtual function semantics identical to those of
|
| 317 |
`locale::classic()`.
|
| 318 |
|
| 319 |
+
[*Note 1*: This constructor yields a copy of the current global locale.
|
| 320 |
+
It is commonly used as a default argument for function parameters of
|
| 321 |
+
type `const locale&`. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
|
| 323 |
``` cpp
|
| 324 |
explicit locale(const char* std_name);
|
| 325 |
```
|
| 326 |
|
|
|
|
| 385 |
|
| 386 |
*Effects:* Creates a copy of `other`, replacing the current value.
|
| 387 |
|
| 388 |
*Returns:* `*this`.
|
| 389 |
|
| 390 |
+
#### Members <a id="locale.members">[[locale.members]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 391 |
|
| 392 |
``` cpp
|
| 393 |
template<class Facet> locale combine(const locale& other) const;
|
| 394 |
```
|
| 395 |
|
|
|
|
| 401 |
*Throws:* `runtime_error` if `has_facet<Facet>(other)` is `false`.
|
| 402 |
|
| 403 |
*Remarks:* The resulting locale has no name.
|
| 404 |
|
| 405 |
``` cpp
|
| 406 |
+
string name() const;
|
| 407 |
```
|
| 408 |
|
| 409 |
*Returns:* The name of `*this`, if it has one; otherwise, the string
|
| 410 |
`"*"`.
|
| 411 |
|
| 412 |
+
#### Operators <a id="locale.operators">[[locale.operators]]</a>
|
| 413 |
|
| 414 |
``` cpp
|
| 415 |
bool operator==(const locale& other) const;
|
| 416 |
```
|
| 417 |
|
| 418 |
*Returns:* `true` if both arguments are the same locale, or one is a
|
| 419 |
copy of the other, or each has a name and the names are identical;
|
| 420 |
`false` otherwise.
|
| 421 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
``` cpp
|
| 423 |
template<class charT, class traits, class Allocator>
|
| 424 |
bool operator()(const basic_string<charT, traits, Allocator>& s1,
|
| 425 |
const basic_string<charT, traits, Allocator>& s2) const;
|
| 426 |
```
|
| 427 |
|
| 428 |
*Effects:* Compares two strings according to the `collate<charT>` facet.
|
| 429 |
|
| 430 |
*Remarks:* This member operator template (and therefore `locale` itself)
|
| 431 |
+
meets the requirements for a comparator predicate template
|
| 432 |
+
argument [[algorithms]] applied to strings.
|
| 433 |
|
| 434 |
*Returns:*
|
| 435 |
|
| 436 |
``` cpp
|
| 437 |
use_facet<collate<charT>>(*this).compare(s1.data(), s1.data() + s1.size(),
|
|
|
|
| 447 |
std::sort(v.begin(), v.end(), loc);
|
| 448 |
```
|
| 449 |
|
| 450 |
— *end example*]
|
| 451 |
|
| 452 |
+
#### Static members <a id="locale.statics">[[locale.statics]]</a>
|
| 453 |
|
| 454 |
``` cpp
|
| 455 |
static locale global(const locale& loc);
|
| 456 |
```
|
| 457 |
|
| 458 |
+
*Effects:* Sets the global locale to its argument. Causes future calls
|
| 459 |
+
to the constructor `locale()` to return a copy of the argument. If the
|
| 460 |
+
argument has a name, does
|
|
|
|
| 461 |
|
| 462 |
``` cpp
|
| 463 |
setlocale(LC_ALL, loc.name().c_str());
|
| 464 |
```
|
| 465 |
|
| 466 |
otherwise, the effect on the C locale, if any, is
|
| 467 |
+
*implementation-defined*.
|
| 468 |
+
|
| 469 |
+
*Remarks:* No library function other than `locale::global()` affects the
|
| 470 |
+
value returned by `locale()`.
|
| 471 |
|
| 472 |
[*Note 1*: See [[c.locales]] for data race considerations when
|
| 473 |
`setlocale` is invoked. — *end note*]
|
| 474 |
|
| 475 |
*Returns:* The previous value of `locale()`.
|