From Jason Turner

[locales]

Diff to HTML by rtfpessoa

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