From Jason Turner

[locale]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp2g_my2en/{from.md → to.md} +35 -24
tmp/tmp2g_my2en/{from.md → to.md} RENAMED
@@ -1,7 +1,9 @@
1
  ### Class `locale` <a id="locale">[[locale]]</a>
2
 
 
 
3
  ``` cpp
4
  namespace std {
5
  class locale {
6
  public:
7
  // types
@@ -52,11 +54,11 @@ locale’s set of facets.
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<<` might 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) {
@@ -65,11 +67,11 @@ operator<< (basic_ostream<charT, traits>& s, Date d) {
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
 
@@ -86,12 +88,15 @@ installed in a locale, and used identically as may standard facets.
86
 
87
  All locale semantics are accessed via `use_facet<>` and `has_facet<>`,
88
  except that:
89
 
90
  - A member operator template
91
- `operator()(const basic_string<C, T, A>&, const basic_string<{}C, T, A>&)`
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]].)
@@ -140,14 +145,12 @@ that the expression
140
 
141
  is `true`, and represents the union of all categories. Further, the
142
  expression `(X | Y)`, where `X` and `Y` each represent a single
143
  category, represents the union of the two categories.
144
 
145
- `locale`
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>
@@ -264,11 +267,11 @@ facet) when the last `locale` object containing the facet is destroyed;
264
  for `refs == 1`, the implementation never destroys the facet.
265
 
266
  Constructors of all facets defined in this Clause take such an argument
267
  and pass it along to their `facet` base class constructor. All
268
  one-argument constructors defined in this Clause are *explicit*,
269
- preventing their participation in automatic conversions.
270
 
271
  For some standard facets a standard “…`_byname`” class, derived from it,
272
  implements the virtual function semantics equivalent to that facet of
273
  the locale constructed by `locale(const char*)` with the same name. Each
274
  such facet provides a constructor that takes a `const char*` argument,
@@ -335,51 +338,59 @@ any *implementation-defined* values.
335
 
336
  ``` cpp
337
  explicit locale(const string& std_name);
338
  ```
339
 
340
- *Effects:* The same as `locale(std_name.c_str())`.
341
 
342
  ``` cpp
343
- locale(const locale& other, const char* std_name, category);
344
  ```
345
 
 
 
346
  *Effects:* Constructs a locale as a copy of `other` except for the
347
  facets identified by the `category` argument, which instead implement
348
  the same semantics as `locale(std_name)`.
349
 
350
- *Throws:* `runtime_error` if the argument is not valid, or is null.
 
351
 
352
  *Remarks:* The locale has a name if and only if `other` has a name.
353
 
354
  ``` cpp
355
- locale(const locale& other, const string& std_name, category cat);
356
  ```
357
 
358
- *Effects:* The same as `locale(other, std_name.c_str(), cat)`.
359
 
360
  ``` cpp
361
  template<class Facet> locale(const locale& other, Facet* f);
362
  ```
363
 
364
  *Effects:* Constructs a locale incorporating all facets from the first
365
  argument except that of type `Facet`, and installs the second argument
366
  as the remaining facet. If `f` is null, the resulting object is a copy
367
  of `other`.
368
 
369
- *Remarks:* The resulting locale has no name.
 
370
 
371
  ``` cpp
372
  locale(const locale& other, const locale& one, category cats);
373
  ```
374
 
 
 
375
  *Effects:* Constructs a locale incorporating all facets from the first
376
  argument except those that implement `cats`, which are instead
377
  incorporated from the second argument.
378
 
379
- *Remarks:* The resulting locale has a name if and only if the first two
380
- arguments have names.
 
 
381
 
382
  ``` cpp
383
  const locale& operator=(const locale& other) noexcept;
384
  ```
385
 
@@ -425,25 +436,25 @@ template<class charT, class traits, class Allocator>
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(),
438
  s2.data(), s2.data() + s2.size()) < 0
439
  ```
440
 
 
 
 
 
441
  [*Example 1*:
442
 
443
  A vector of strings `v` can be collated according to collation rules in
444
- locale `loc` simply by ([[alg.sort]], [[vector]]):
445
 
446
  ``` cpp
447
  std::sort(v.begin(), v.end(), loc);
448
  ```
449
 
@@ -464,18 +475,18 @@ 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()`.
476
-
477
  ``` cpp
478
  static const locale& classic();
479
  ```
480
 
481
  The `"C"` locale.
 
1
  ### Class `locale` <a id="locale">[[locale]]</a>
2
 
3
+ #### General <a id="locale.general">[[locale.general]]</a>
4
+
5
  ``` cpp
6
  namespace std {
7
  class locale {
8
  public:
9
  // types
 
54
  Access to the facets of a `locale` is via two function templates,
55
  `use_facet<>` and `has_facet<>`.
56
 
57
  [*Example 1*:
58
 
59
+ An iostream `operator<<` can be implemented as:[^2]
60
 
61
  ``` cpp
62
  template<class charT, class traits>
63
  basic_ostream<charT, traits>&
64
  operator<< (basic_ostream<charT, traits>& s, Date d) {
 
67
  tm tmbuf; d.extract(tmbuf);
68
  bool failed =
69
  use_facet<time_put<charT, ostreambuf_iterator<charT, traits>>>(
70
  s.getloc()).put(s, s, s.fill(), &tmbuf, 'x').failed();
71
  if (failed)
72
+ s.setstate(s.badbit); // can throw
73
  }
74
  return s;
75
  }
76
  ```
77
 
 
88
 
89
  All locale semantics are accessed via `use_facet<>` and `has_facet<>`,
90
  except that:
91
 
92
  - A member operator template
93
+ ``` cpp
94
+ operator()(const basic_string<C, T, A>&, const basic_string<C, T, A>&)
95
+ ```
96
+
97
+ is provided so that a locale can be used as a predicate argument to
98
  the standard collections, to collate strings.
99
  - Convenient global interfaces are provided for traditional `ctype`
100
  functions such as `isdigit()` and `isspace()`, so that given a locale
101
  object `loc` a C++ program can call `isspace(c, loc)`. (This eases
102
  upgrading existing extractors [[istream.formatted]].)
 
145
 
146
  is `true`, and represents the union of all categories. Further, the
147
  expression `(X | Y)`, where `X` and `Y` each represent a single
148
  category, represents the union of the two categories.
149
 
150
+ `locale` member functions expecting a `category` argument require one of
151
+ the `category` values defined above, or the union of two or more such
 
 
152
  values. Such a `category` value identifies a set of locale categories.
153
  Each locale category, in turn, identifies a set of locale facets,
154
  including at least those shown in [[locale.category.facets]].
155
 
156
  **Table: Locale category facets** <a id="locale.category.facets">[locale.category.facets]</a>
 
267
  for `refs == 1`, the implementation never destroys the facet.
268
 
269
  Constructors of all facets defined in this Clause take such an argument
270
  and pass it along to their `facet` base class constructor. All
271
  one-argument constructors defined in this Clause are *explicit*,
272
+ preventing their participation in implicit conversions.
273
 
274
  For some standard facets a standard “…`_byname`” class, derived from it,
275
  implements the virtual function semantics equivalent to that facet of
276
  the locale constructed by `locale(const char*)` with the same name. Each
277
  such facet provides a constructor that takes a `const char*` argument,
 
338
 
339
  ``` cpp
340
  explicit locale(const string& std_name);
341
  ```
342
 
343
+ *Effects:* Equivalent to `locale(std_name.c_str())`.
344
 
345
  ``` cpp
346
+ locale(const locale& other, const char* std_name, category cats);
347
  ```
348
 
349
+ *Preconditions:* `cats` is a valid `category` value [[locale.category]].
350
+
351
  *Effects:* Constructs a locale as a copy of `other` except for the
352
  facets identified by the `category` argument, which instead implement
353
  the same semantics as `locale(std_name)`.
354
 
355
+ *Throws:* `runtime_error` if the second argument is not valid, or is
356
+ null.
357
 
358
  *Remarks:* The locale has a name if and only if `other` has a name.
359
 
360
  ``` cpp
361
+ locale(const locale& other, const string& std_name, category cats);
362
  ```
363
 
364
+ *Effects:* Equivalent to `locale(other, std_name.c_str(), cats)`.
365
 
366
  ``` cpp
367
  template<class Facet> locale(const locale& other, Facet* f);
368
  ```
369
 
370
  *Effects:* Constructs a locale incorporating all facets from the first
371
  argument except that of type `Facet`, and installs the second argument
372
  as the remaining facet. If `f` is null, the resulting object is a copy
373
  of `other`.
374
 
375
+ *Remarks:* If `f` is null, the resulting locale has the same name as
376
+ `other`. Otherwise, the resulting locale has no name.
377
 
378
  ``` cpp
379
  locale(const locale& other, const locale& one, category cats);
380
  ```
381
 
382
+ *Preconditions:* `cats` is a valid `category` value.
383
+
384
  *Effects:* Constructs a locale incorporating all facets from the first
385
  argument except those that implement `cats`, which are instead
386
  incorporated from the second argument.
387
 
388
+ *Remarks:* If `cats` is equal to `locale::none`, the resulting locale
389
+ has a name if and only if the first argument has a name. Otherwise, the
390
+ resulting locale has a name if and only if the first two arguments both
391
+ have names.
392
 
393
  ``` cpp
394
  const locale& operator=(const locale& other) noexcept;
395
  ```
396
 
 
436
  const basic_string<charT, traits, Allocator>& s2) const;
437
  ```
438
 
439
  *Effects:* Compares two strings according to the `collate<charT>` facet.
440
 
 
 
 
 
441
  *Returns:*
442
 
443
  ``` cpp
444
  use_facet<collate<charT>>(*this).compare(s1.data(), s1.data() + s1.size(),
445
  s2.data(), s2.data() + s2.size()) < 0
446
  ```
447
 
448
+ *Remarks:* This member operator template (and therefore `locale` itself)
449
+ meets the requirements for a comparator predicate template
450
+ argument [[algorithms]] applied to strings.
451
+
452
  [*Example 1*:
453
 
454
  A vector of strings `v` can be collated according to collation rules in
455
+ locale `loc` simply by [[alg.sort]], [[vector]]:
456
 
457
  ``` cpp
458
  std::sort(v.begin(), v.end(), loc);
459
  ```
460
 
 
475
  ```
476
 
477
  otherwise, the effect on the C locale, if any, is
478
  *implementation-defined*.
479
 
480
+ *Returns:* The previous value of `locale()`.
481
+
482
  *Remarks:* No library function other than `locale::global()` affects the
483
  value returned by `locale()`.
484
 
485
  [*Note 1*: See  [[c.locales]] for data race considerations when
486
  `setlocale` is invoked. — *end note*]
487
 
 
 
488
  ``` cpp
489
  static const locale& classic();
490
  ```
491
 
492
  The `"C"` locale.