tmp/tmpenpslk1o/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#### General <a id="locale.general">[[locale.general]]</a>
|
| 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);
|
| 24 |
+
locale(const locale& other, const string& std_name, category);
|
| 25 |
+
template<class Facet> locale(const locale& other, Facet* f);
|
| 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 |
+
```
|
| 46 |
+
|
| 47 |
+
Class `locale` implements a type-safe polymorphic set of facets, indexed
|
| 48 |
+
by facet *type*. In other words, a facet has a dual role: in one sense,
|
| 49 |
+
it’s just a class interface; at the same time, it’s an index into a
|
| 50 |
+
locale’s set of facets.
|
| 51 |
+
|
| 52 |
+
Access to the facets of a `locale` is via two function templates,
|
| 53 |
+
`use_facet<>` and `has_facet<>`.
|
| 54 |
+
|
| 55 |
+
[*Example 1*:
|
| 56 |
+
|
| 57 |
+
An iostream `operator<<` can be implemented as:[^2]
|
| 58 |
+
|
| 59 |
+
``` cpp
|
| 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); // can 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:
|
| 89 |
+
|
| 90 |
+
- A member operator template
|
| 91 |
+
``` cpp
|
| 92 |
+
operator()(const basic_string<C, T, A>&, const basic_string<C, T, A>&)
|
| 93 |
+
```
|
| 94 |
+
|
| 95 |
+
is provided so that a locale can be used as a predicate argument to
|
| 96 |
+
the standard collections, to collate strings.
|
| 97 |
+
- Convenient global interfaces are provided for traditional `ctype`
|
| 98 |
+
functions such as `isdigit()` and `isspace()`, so that given a locale
|
| 99 |
+
object `loc` a C++ program can call `isspace(c, loc)`. (This eases
|
| 100 |
+
upgrading existing extractors [[istream.formatted]].)
|
| 101 |
+
|
| 102 |
+
— *end note*]
|
| 103 |
+
|
| 104 |
+
Once a facet reference is obtained from a locale object by calling
|
| 105 |
+
`use_facet<>`, that reference remains usable, and the results from
|
| 106 |
+
member functions of it may be cached and re-used, as long as some locale
|
| 107 |
+
object refers to that facet.
|
| 108 |
+
|
| 109 |
+
In successive calls to a locale facet member function on a facet object
|
| 110 |
+
installed in the same locale, the returned result shall be identical.
|
| 111 |
+
|
| 112 |
+
A `locale` constructed from a name string (such as `"POSIX"`), or from
|
| 113 |
+
parts of two named locales, has a name; all others do not. Named locales
|
| 114 |
+
may be compared for equality; an unnamed locale is equal only to (copies
|
| 115 |
+
of) itself. For an unnamed locale, `locale::name()` returns the string
|
| 116 |
+
`"*"`.
|
| 117 |
+
|
| 118 |
+
Whether there is one global locale object for the entire program or one
|
| 119 |
+
global locale object per thread is *implementation-defined*.
|
| 120 |
+
Implementations should provide one global locale object per thread. If
|
| 121 |
+
there is a single global locale object for the entire program,
|
| 122 |
+
implementations are not required to avoid data races on it
|
| 123 |
+
[[res.on.data.races]].
|
| 124 |
+
|