forked from cplusplus/draft
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocales.tex
More file actions
6016 lines (5238 loc) · 176 KB
/
Copy pathlocales.tex
File metadata and controls
6016 lines (5238 loc) · 176 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\rSec0[localization]{Localization library}
\rSec1[localization.general]{General}
\pnum
This Clause describes components that \Cpp programs may use to
encapsulate (and therefore be more portable when confronting)
cultural differences.
The locale facility includes internationalization
support for character classification and string collation, numeric,
monetary, and date/time formatting and parsing, and message retrieval.
\pnum
The following subclauses describe components for
locales themselves, the standard facets, and facilities
from the ISO C library, as summarized in Table~\ref{tab:localization.lib.summary}.
\begin{libsumtab}{Localization library summary}{tab:localization.lib.summary}
\ref{locales} & Locales & \tcode{<locale>} \\
\ref{locale.categories} & Standard \tcode{locale} Categories & \\ \rowsep
\ref{locale.stdcvt} & Standard code conversion facets & \tcode{<codecvt>} \\ \rowsep
\ref{c.locales} & C library locales & \tcode{<clocale>} \\
\end{libsumtab}
\rSec1[locale.syn]{Header \tcode{<locale>} synopsis}
\indexlibrary{\idxhdr{locale}}%
\begin{codeblock}
namespace std {
// \ref{locale}, locale:
class locale;
template <class Facet> const Facet& use_facet(const locale&);
template <class Facet> bool has_facet(const locale&) noexcept;
// \ref{locale.convenience}, convenience interfaces:
template <class charT> bool isspace (charT c, const locale& loc);
template <class charT> bool isprint (charT c, const locale& loc);
template <class charT> bool iscntrl (charT c, const locale& loc);
template <class charT> bool isupper (charT c, const locale& loc);
template <class charT> bool islower (charT c, const locale& loc);
template <class charT> bool isalpha (charT c, const locale& loc);
template <class charT> bool isdigit (charT c, const locale& loc);
template <class charT> bool ispunct (charT c, const locale& loc);
template <class charT> bool isxdigit(charT c, const locale& loc);
template <class charT> bool isalnum (charT c, const locale& loc);
template <class charT> bool isgraph (charT c, const locale& loc);
template <class charT> bool isblank (charT c, const locale& loc);
template <class charT> charT toupper(charT c, const locale& loc);
template <class charT> charT tolower(charT c, const locale& loc);
template <class Codecvt, class Elem = wchar_t,
class Wide_alloc = std::allocator<Elem>,
class Byte_alloc = std::allocator<char> > class wstring_convert;
template <class Codecvt, class Elem = wchar_t,
class Tr = char_traits<Elem@\shr{}@ class wbuffer_convert;
// \ref{category.ctype}, ctype:
class ctype_base;
template <class charT> class ctype;
template <> class ctype<char>; // specialization
template <class charT> class ctype_byname;
class codecvt_base;
template <class internT, class externT, class stateT> class codecvt;
template <class internT, class externT, class stateT> class codecvt_byname;
// \ref{category.numeric}, numeric:
template <class charT, class InputIterator = istreambuf_iterator<charT> > class num_get;
template <class charT, class OutputIterator = ostreambuf_iterator<charT> > class num_put;
template <class charT> class numpunct;
template <class charT> class numpunct_byname;
// \ref{category.collate}, collation:
template <class charT> class collate;
template <class charT> class collate_byname;
// \ref{category.time}, date and time:
class time_base;
template <class charT, class InputIterator = istreambuf_iterator<charT> >
class time_get;
template <class charT, class InputIterator = istreambuf_iterator<charT> >
class time_get_byname;
template <class charT, class OutputIterator = ostreambuf_iterator<charT> >
class time_put;
template <class charT, class OutputIterator = ostreambuf_iterator<charT> >
class time_put_byname;
// \ref{category.monetary}, money:
class money_base;
template <class charT, class InputIterator = istreambuf_iterator<charT> > class money_get;
template <class charT, class OutputIterator = ostreambuf_iterator<charT> > class money_put;
template <class charT, bool Intl = false> class moneypunct;
template <class charT, bool Intl = false> class moneypunct_byname;
// \ref{category.messages}, message retrieval:
class messages_base;
template <class charT> class messages;
template <class charT> class messages_byname;
}
\end{codeblock}
\pnum
The header
\tcode{<locale>}
defines classes and declares functions that encapsulate and manipulate
the information peculiar to a locale.\footnote{In this subclause, the type name
\tcode{struct tm}
is an incomplete type that is defined in
\indexlibrary{\idxhdr{ctime}}%
\tcode{<ctime>}.}
\rSec1[locales]{Locales}
\rSec2[locale]{Class \tcode{locale}}
\indexlibrary{\idxhdr{locale}}%
\begin{codeblock}
namespace std {
class locale {
public:
// types:
class facet;
class id;
typedef int category;
static const category // values assigned here are for exposition only
none = 0,
collate = 0x010, ctype = 0x020,
monetary = 0x040, numeric = 0x080,
time = 0x100, messages = 0x200,
all = collate | ctype | monetary | numeric | time | messages;
// construct/copy/destroy:
locale() noexcept;
locale(const locale& other) noexcept;
explicit locale(const char* std_name);
explicit locale(const string& std_name);
locale(const locale& other, const char* std_name, category);
locale(const locale& other, const string& std_name, category);
template <class Facet> locale(const locale& other, Facet* f);
locale(const locale& other, const locale& one, category);
~locale(); // not virtual
const locale& operator=(const locale& other) noexcept;
template <class Facet> locale combine(const locale& other) const;
// locale operations:
basic_string<char> name() const;
bool operator==(const locale& other) const;
bool operator!=(const locale& other) const;
template <class charT, class traits, class Allocator>
bool operator()(const basic_string<charT,traits,Allocator>& s1,
const basic_string<charT,traits,Allocator>& s2) const;
// global locale objects:
static locale global(const locale&);
static const locale& classic();
};
}
\end{codeblock}
\pnum
Class
\tcode{locale}
implements a type-safe polymorphic set of facets, indexed by facet
\textit{type}.
In other words, a facet has a dual role: in one
sense, it's just a class interface; at the same time, it's an index
into a locale's set of facets.
\pnum
Access to the facets of a
\tcode{locale}
is via two function templates,
\tcode{use_facet<>}
and
\tcode{has_facet<>}.
\pnum
\enterexample
An iostream
\tcode{operator\shl}
might be implemented as:\footnote{Note that in the call to
\tcode{put}
the stream is implicitly converted to an
\tcode{ostreambuf_iterator<charT,traits>}.}
\begin{codeblock}
template <class charT, class traits>
basic_ostream<charT,traits>&
operator<< (basic_ostream<charT,traits>& s, Date d) {
typename basic_ostream<charT,traits>::sentry cerberos(s);
if (cerberos) {
ios_base::iostate err = ios_base::iostate::goodbit;
tm tmbuf; d.extract(tmbuf);
use_facet< time_put<charT,ostreambuf_iterator<charT,traits> > >(
s.getloc()).put(s, s, s.fill(), err, &tmbuf, 'x');
s.setstate(err); // might throw
}
return s;
}
\end{codeblock}
\exitexample
\pnum
In the call to
\tcode{use_facet<Facet>(loc)},
the type argument chooses a facet, making available all members
of the named type.
If
\tcode{Facet}
is not present in a
locale,
it throws the standard exception
\tcode{bad_cast}.
A \Cpp program can check if a locale implements a particular
facet with the
function template
\tcode{has_facet<Facet>()}.
User-defined facets may be installed in a locale, and used identically as
may standard facets~(\ref{facets.examples}).
\pnum
\enternote
All locale semantics are accessed via
\tcode{use_facet<>}
and
\tcode{has_facet<>},
except that:
\begin{itemize}
\item
A member operator template
\tcode{operator()(const basic_string<C, T, A>\&, const basic_string<\brk{}C, T, A>\&)}
is provided so that a locale may be used as a predicate argument to
the standard collections, to collate strings.
\item
Convenient global interfaces are provided for traditional
\tcode{ctype}
functions such as
\tcode{isdigit()}
and
\tcode{isspace()},
so that given a locale
object \tcode{loc} a \Cpp program can call
\tcode{isspace(c,loc)}.
(This eases upgrading existing extractors~(\ref{istream.formatted}).)
\exitnote
\end{itemize}
\pnum
Once a facet reference is obtained from a locale object by calling
\tcode{use_facet<>},
that reference remains usable, and the results from member functions
of it may be cached and re-used, as long as some locale object refers
to that facet.
\pnum
In successive calls to a locale facet member function on a facet object
installed in the same locale, the returned result shall be identical.
\pnum
A
\tcode{locale}
constructed from a name string (such as \tcode{"POSIX"}), or from parts of
two named locales, has a name; all others do not.
Named locales may be compared for equality; an unnamed locale is equal
only to (copies of) itself.
For an unnamed locale,
\tcode{locale::name()}
returns the string
\tcode{"*"}.
\pnum
Whether there is one global locale object for the entire program or one global locale
object per thread is \impldef{whether locale object is global or per-thread}.
Implementations should provide one global locale object per
thread. If there is a single global locale object for the entire program,
implementations are not required to avoid data races on it~(\ref{res.on.data.races}).
\rSec3[locale.types]{\tcode{locale} types}
\rSec4[locale.category]{Type \tcode{locale::category}}
\indexlibrary{\idxcode{locale}!\idxcode{category}}%
\indexlibrary{\idxcode{category}!\idxcode{locale}}%
\begin{itemdecl}
typedef int category;
\end{itemdecl}
\pnum
\textit{Valid}
\tcode{category}
values include the
\tcode{locale}
member bitmask elements
\tcode{collate},
\tcode{ctype},
\tcode{monetary},
\tcode{numeric},
\tcode{time},
and
\tcode{messages},
each of which represents a single locale category.
In addition,
\tcode{locale}
member bitmask constant
\tcode{none}
is defined as zero and represents no category. And
\tcode{locale}
member bitmask constant
\tcode{all}
is defined such that the expression
\begin{codeblock}
(collate | ctype | monetary | numeric | time | messages | all) == all
\end{codeblock}
is
\tcode{true},
and represents the union of all categories.
Further, the expression
\tcode{(X | Y)},
where
\tcode{X}
and
\tcode{Y}
each represent a single category, represents the union of the two categories.
\pnum
\tcode{locale}
member functions expecting a
\tcode{category}
argument require one of the
\tcode{category}
values defined above, or the union of two or more such values.
Such a
\tcode{category}
value identifies a set of locale categories.
Each locale category,
in turn, identifies a set of locale facets, including at least those
shown in Table~\ref{tab:localization.category.facets}.
\begin{floattable}{Locale category facets}{tab:localization.category.facets}
{ml}
\topline
\lhdr{Category} & \rhdr{Includes facets} \\ \capsep
collate & \tcode{collate<char>}, \tcode{collate<wchar_t>} \\ \rowsep
ctype & \tcode{ctype<char>}, \tcode{ctype<wchar_t>} \\
& \tcode{codecvt<char,char,mbstate_t>} \\
& \tcode{codecvt<char16_t,char,mbstate_t>} \\
& \tcode{codecvt<char32_t,char,mbstate_t>} \\
& \tcode{codecvt<wchar_t,char,mbstate_t>} \\ \rowsep
monetary & \tcode{moneypunct<char>}, \tcode{moneypunct<wchar_t>} \\
& \tcode{moneypunct<char,true>}, \tcode{moneypunct<wchar_t,true>} \\
& \tcode{money_get<char>}, \tcode{money_get<wchar_t>} \\
& \tcode{money_put<char>}, \tcode{money_put<wchar_t>} \\ \rowsep
numeric & \tcode{numpunct<char>}, \tcode{numpunct<wchar_t>} \\
& \tcode{num_get<char>}, \tcode{num_get<wchar_t>} \\
& \tcode{num_put<char>}, \tcode{num_put<wchar_t>} \\ \rowsep
time & \tcode{time_get<char>}, \tcode{time_get<wchar_t>} \\
& \tcode{time_put<char>}, \tcode{time_put<wchar_t>} \\ \rowsep
messages & \tcode{messages<char>}, \tcode{messages<wchar_t>} \\
\end{floattable}
\pnum
For any locale \tcode{loc}
either constructed, or returned by
\tcode{locale::classic()},
and any facet \tcode{Facet}
shown in Table~\ref{tab:localization.category.facets},
\tcode{has_facet<Facet>(loc)}
is true.
Each
\tcode{locale}
member function which takes a
\tcode{locale::category}
argument operates on the corresponding set of facets.
\pnum
An implementation is required to provide those specializations for
facet templates identified as members of a category, and for those
shown in Table~\ref{tab:localization.required.specializations}.
\begin{floattable}{Required specializations}{tab:localization.required.specializations}
{ml}
\topline
\lhdr{Category} & \rhdr{Includes facets} \\ \capsep
collate & \tcode{collate_byname<char>}, \tcode{collate_byname<wchar_t>} \\ \rowsep
ctype & \tcode{ctype_byname<char>}, \tcode{ctype_byname<wchar_t>} \\
& \tcode{codecvt_byname<char,char,mbstate_t>} \\
& \tcode{codecvt_byname<char16_t,char,mbstate_t>} \\
& \tcode{codecvt_byname<char32_t,char,mbstate_t>} \\
& \tcode{codecvt_byname<wchar_t,char,mbstate_t>} \\ \rowsep
monetary & \tcode{moneypunct_byname<char,International>} \\
& \tcode{moneypunct_byname<wchar_t,International>} \\
& \tcode{money_get<C,InputIterator>} \\
& \tcode{money_put<C,OutputIterator>} \\ \rowsep
numeric & \tcode{numpunct_byname<char>}, \tcode{numpunct_byname<wchar_t>} \\
& \tcode{num_get<C,InputIterator>}, \tcode{num_put<C,OutputIterator>} \\ \rowsep
time & \tcode{time_get<char,InputIterator>} \\
& \tcode{time_get_byname<char,InputIterator>} \\
& \tcode{time_get<wchar_t,InputIterator>} \\
& \tcode{time_get_byname<wchar_t,InputIterator>} \\
& \tcode{time_put<char,OutputIterator>} \\
& \tcode{time_put_byname<char,OutputIterator>} \\
& \tcode{time_put<wchar_t,OutputIterator>} \\
& \tcode{time_put_byname<wchar_t,OutputIterator>} \\ \rowsep
messages & \tcode{messages_byname<char>}, \tcode{messages_byname<wchar_t>} \\
\end{floattable}
\pnum
The provided implementation of members of facets
\tcode{num_get<charT>}
and
\tcode{num_put<charT>}
calls
\tcode{use_fac\-et\,<F>\,(l)}
only for facet
\tcode{F}
of types
\tcode{numpunct<charT>}
and
\tcode{ctype<charT>},
and for locale
\tcode{l}
the value obtained
by calling member
\tcode{getloc()}
on the
\tcode{ios_base\&}
argument to these functions.
\pnum
In declarations of facets, a template formal parameter with name
\tcode{InputIterator}
or
\tcode{OutputIterator}
indicates the set of
all possible specializations on parameters that satisfy the
requirements of an Input Iterator or an Output Iterator, respectively~(\ref{iterator.requirements}).
A template formal parameter with name
\tcode{C}
represents the set
of types containing \tcode{char}, \tcode{wchar_t}, and any other implementation-defined
character types that satisfy
the requirements for a character on which any of the iostream
components can be instantiated.
A template formal parameter with name
\tcode{International}
represents the set of all possible specializations on a bool parameter.
\rSec4[locale.facet]{Class \tcode{locale::facet}}
\indexlibrary{\idxcode{locale}!\idxcode{facet}}%
\indexlibrary{\idxcode{facet}!\idxcode{locale}}%
\begin{codeblock}
namespace std {
class locale::facet {
protected:
explicit facet(size_t refs = 0);
virtual ~facet();
facet(const facet&) = delete;
void operator=(const facet&) = delete;
};
}
\end{codeblock}
\pnum
Template parameters in this Clause which are required to be facets are those named
\tcode{Facet}
in declarations.
A program that passes a type that is
\textit{not}
a facet, or a type that refers to a volatile-qualified facet, as an
(explicit or deduced) template parameter to a locale
function expecting a facet, is ill-formed. A const-qualified facet is a
valid template argument to any locale function that expects a Facet template
parameter.
\pnum
The \tcode{refs}
argument to the constructor is used for lifetime management.
\begin{itemize}
\item
For
\tcode{refs == 0},
the implementation performs
\tcode{delete static_cast<locale::facet*>(f)}
(where
\tcode{f}
is a point\-er to the facet) when the last
\tcode{locale}
object containing the facet is destroyed;
for
\tcode{refs == 1},
the implementation never destroys the facet.
\end{itemize}
\pnum
Constructors of all
facets defined in this Clause take such an argument and pass it
along to their
\tcode{facet}
base class constructor.
All one-argument constructors defined
in this Clause are
\term{explicit},
preventing their participation in automatic conversions.
\pnum
For some standard facets a standard
``$\ldots$\tcode{_byname}''
class, derived from it, implements the virtual function semantics
equivalent to that facet of the locale constructed by
\tcode{locale(const char*)}
with the same name.
Each such facet provides a constructor that takes a
\tcode{const char*}
argument, which names the locale, and a \tcode{refs}
argument, which is passed to the base class constructor.
Each such facet also provides a constructor that takes a
\tcode{string} argument \tcode{str} and a \tcode{refs}
argument, which has the same effect as calling the first constructor with the
two arguments \tcode{str.c_str()} and \tcode{refs}.
If there is no
``$\ldots$\tcode{_byname}''
version of a facet, the base class implements named locale
semantics itself by reference to other facets.
\rSec4[locale.id]{Class \tcode{locale::id}}
\indexlibrary{\idxcode{locale}!\idxcode{id}}%
\indexlibrary{\idxcode{id}!\idxcode{locale}}%
\begin{codeblock}
namespace std {
class locale::id {
public:
id();
void operator=(const id&) = delete;
id(const id&) = delete;
};
}
\end{codeblock}
\pnum
The class locale::id provides identification of a locale facet
interface, used as an index for lookup
and to encapsulate initialization.
\pnum
\enternote
Because facets are used by iostreams, potentially while static constructors are
running, their initialization cannot depend on programmed static
initialization.
One initialization strategy is for
\tcode{locale}
to initialize each facet's
\tcode{id}
member the first time an instance of the facet is installed into a locale.
This depends only on static storage being zero before constructors run~(\ref{basic.start.init}).
\exitnote
\rSec3[locale.cons]{\tcode{locale} constructors and destructor}
\indexlibrary{\idxcode{locale}!constructor}%
\begin{itemdecl}
locale() noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
Default constructor: a snapshot of the current global locale.
\pnum
\effects
Constructs a copy of the argument last passed to
\tcode{locale::global(locale\&)},
if it has been called; else, the resulting facets have virtual
function semantics identical to those of
\tcode{locale::classic()}.
\enternote
This constructor is commonly used as the default value for arguments
of functions that take a
\tcode{const locale\&}
argument.
\exitnote
\end{itemdescr}
\indexlibrary{\idxcode{locale}!constructor}%
\begin{itemdecl}
locale(const locale& other) noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\effects
Constructs a locale which is a copy of \tcode{other}.
\end{itemdescr}
\indexlibrary{\idxcode{locale}!constructor}%
\begin{itemdecl}
explicit locale(const char* std_name);
\end{itemdecl}
\begin{itemdescr}
\pnum
\effects
Constructs a locale using standard C locale names, e.g., \tcode{"POSIX"}.
The resulting locale implements semantics defined to be associated
with that name.
\pnum
\throws
\tcode{runtime_error}
if the argument is not valid, or is null.
\pnum
\notes
The set of valid string argument values is \tcode{"C"}, \tcode{""},
and any \impldef{locale names} values.
\end{itemdescr}
\indexlibrary{\idxcode{locale}!constructor}%
\begin{itemdecl}
explicit locale(const string& std_name);
\end{itemdecl}
\begin{itemdescr}
\pnum
\effects The same as \tcode{locale(std_name.c_str())}.
\end{itemdescr}
\indexlibrary{\idxcode{locale}!constructor}%
\begin{itemdecl}
locale(const locale& other, const char* std_name, category);
\end{itemdecl}
\begin{itemdescr}
\pnum
\effects
Constructs a locale as a copy of
\tcode{other}
except for the facets identified by the
\tcode{category}
argument, which instead implement the same semantics as
\tcode{locale(std_name)}.
\pnum
\throws
\tcode{runtime_error}
if the argument is not valid, or is null.
\pnum
\notes
The locale has a name if and only if
\tcode{other}
has a name.
\end{itemdescr}
\indexlibrary{\idxcode{locale}!constructor}%
\begin{itemdecl}
locale(const locale& other, const string& std_name, category cat);
\end{itemdecl}
\begin{itemdescr}
\pnum
\effects The same as \tcode{locale(other, std_name.c_str(), cat)}.
\end{itemdescr}
\indexlibrary{\idxcode{locale}!constructor}%
\begin{itemdecl}
template <class Facet> locale(const locale& other, Facet* f);
\end{itemdecl}
\begin{itemdescr}
\pnum
\effects
Constructs a locale incorporating all facets from the first
argument except that of type
\tcode{Facet},
and installs the second argument as the remaining facet.
If \tcode{f}
is null, the resulting object is a copy of \tcode{other}.
\pnum
\notes
The resulting locale has no name.
\end{itemdescr}
\indexlibrary{\idxcode{locale}!constructor}%
\begin{itemdecl}
locale(const locale& other, const locale& one, category cats);
\end{itemdecl}
\begin{itemdescr}
\pnum
\effects
Constructs a locale incorporating all facets from the first argument
except those that implement
\tcode{cats},
which are instead incorporated from the second argument.
\pnum
\notes
The resulting locale has a name if and only if the first two arguments
have names.
\end{itemdescr}
\indexlibrary{\idxcode{operator=}!\idxcode{locale}}%
\indexlibrary{\idxcode{locale}!\idxcode{operator=}}%
\begin{itemdecl}
const locale& operator=(const locale& other) noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\effects
Creates a copy of \tcode{other}, replacing the current value.
\pnum
\returns
\tcode{*this}
\end{itemdescr}
\indexlibrary{\idxcode{locale}!destructor}%
\begin{itemdecl}
~locale();
\end{itemdecl}
\begin{itemdescr}
\pnum
A non-virtual destructor that throws no exceptions.
\end{itemdescr}
\rSec3[locale.members]{\tcode{locale} members}
\indexlibrary{\idxcode{locale}!\idxcode{combine}}%
\indexlibrary{\idxcode{combine}!\idxcode{locale}}%
\begin{itemdecl}
template <class Facet> locale combine(const locale& other) const;
\end{itemdecl}
\begin{itemdescr}
\pnum
\effects
Constructs a locale incorporating
all facets from
\tcode{*this}
except for that one facet of
\tcode{other}
that is identified by
\tcode{Facet}.
\pnum
\returns
The newly created locale.
\pnum
\throws
\tcode{runtime_error}
if
\tcode{has_facet<Facet>(other)}
is false.
\pnum
\notes
The resulting locale has no name.
\end{itemdescr}
\indexlibrary{\idxcode{locale}!\idxcode{name}}%
\indexlibrary{\idxcode{name}!\idxcode{locale}}%
\begin{itemdecl}
basic_string<char> name() const;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns
The name of
\tcode{*this},
if it has one; otherwise, the string \tcode{"*"}.
If
\tcode{*this}
has a name, then
\tcode{locale(name().\brk{}c\textunderscore{}str())}
is equivalent to
\tcode{*this}.
Details of the contents of the resulting string are otherwise implementation-defined.%
\indextext{implementation-defined}
\end{itemdescr}
\rSec3[locale.operators]{\tcode{locale} operators}
\indexlibrary{\idxcode{locale}!\idxcode{operators==}}%
\indexlibrary{\idxcode{operators==}!\idxcode{locale}}%
\begin{itemdecl}
bool operator==(const locale& other) const;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns
\tcode{true}
if both arguments are the same locale, or one is a copy of the
other, or each has a name and the names are identical;
\tcode{false}
otherwise.
\end{itemdescr}
\indexlibrary{\idxcode{locale}!\idxcode{operator"!=}}%
\indexlibrary{\idxcode{operator"!=}!\idxcode{locale}}%
\begin{itemdecl}
bool operator!=(const locale& other) const;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns
The result of the expression:
\tcode{!(*this == other)}.
\end{itemdescr}
\indexlibrary{\idxcode{locale}!\idxcode{operator()}}%
\indexlibrary{\idxcode{operator()}!\idxcode{locale}}%
\begin{itemdecl}
template <class charT, class traits, class Allocator>
bool operator()(const basic_string<charT,traits,Allocator>& s1,
const basic_string<charT,traits,Allocator>& s2) const;
\end{itemdecl}
\begin{itemdescr}
\pnum
\effects
Compares two strings according to the
\tcode{collate<charT>}
facet.
\pnum
\notes
This member operator template (and therefore
\tcode{locale}
itself) satisfies requirements for a comparator predicate template argument
(Clause~\ref{algorithms}) applied to strings.
\pnum
\returns
The result of the following expression:
\begin{codeblock}
use_facet< collate<charT> >(*this).compare
(s1.data(), s1.data()+s1.size(), s2.data(), s2.data()+s2.size()) < 0;
\end{codeblock}
\pnum
\enterexample
A vector of strings
\tcode{v}
can be collated according to collation rules in locale
\tcode{loc}
simply by~(\ref{alg.sort}, \ref{vector}):
\begin{codeblock}
std::sort(v.begin(), v.end(), loc);
\end{codeblock}
\exitexample
\end{itemdescr}
\rSec3[locale.statics]{\tcode{locale} static members}
\indexlibrary{\idxcode{locale}!\idxcode{global}}%
\indexlibrary{\idxcode{global}!\idxcode{locale}}%
\begin{itemdecl}
static locale global(const locale& loc);
\end{itemdecl}
\begin{itemdescr}
\pnum
Sets the global locale to its argument.
\pnum
\effects
Causes future calls to the constructor
\tcode{locale()}
to return a copy of the argument.
If the argument has a name, does
\begin{codeblock}
std::setlocale(LC_ALL, loc.name().c_str());
\end{codeblock}
otherwise, the effect on the C locale, if any, is \impldef{effect on C locale of calling
\tcode{locale::global}}.
No library function other than
\tcode{locale\colcol{}global()}
shall affect the value returned by
\tcode{locale()}.
\enternote See~\ref{c.locales} for data race considerations when
\tcode{setlocale} is invoked. \exitnote
\pnum
\returns
The previous value of
\tcode{locale()}.
\end{itemdescr}
\indexlibrary{\idxcode{locale}!\idxcode{classic}}%
\indexlibrary{\idxcode{classic}!\idxcode{locale}}%
\begin{itemdecl}
static const locale& classic();
\end{itemdecl}
\begin{itemdescr}
\pnum
The \tcode{"C"} locale.
\pnum
\returns
A locale that implements the classic \tcode{"C"} locale semantics, equivalent
to the value \tcode{locale("C")}.
\pnum
\notes
This locale, its facets, and their member functions, do not change
with time.
\end{itemdescr}
\rSec2[locale.global.templates]{\tcode{locale} globals}
\indexlibrary{\idxcode{locale}!\idxcode{use_facet}}%
\indexlibrary{\idxcode{use_facet}!\idxcode{locale}}%
\begin{itemdecl}
template <class Facet> const Facet& use_facet(const locale& loc);
\end{itemdecl}
\begin{itemdescr}
\pnum
\requires
\tcode{Facet}
is a facet class whose definition contains the public static member
\tcode{id}
as defined in~\ref{locale.facet}.
\pnum
\returns
A reference to the corresponding facet of \tcode{loc}, if present.
\pnum
\throws
\tcode{bad_cast}
if
\tcode{has_facet<Facet>(loc)}
is
\tcode{false}.
\pnum
\notes
The reference returned remains valid at least as long as any copy of
\tcode{loc} exists.
\end{itemdescr}
\indexlibrary{\idxcode{locale}!\idxcode{has_facet}}%
\indexlibrary{\idxcode{has_facet}!\idxcode{locale}}%
\begin{itemdecl}
template <class Facet> bool has_facet(const locale& loc) noexcept;
\end{itemdecl}
\begin{itemdescr}
\pnum
\returns
True if the facet requested is present in \tcode{loc}; otherwise false.
\end{itemdescr}
\rSec2[locale.convenience]{Convenience interfaces}
\rSec3[classification]{Character classification}
\indexlibrary{\idxcode{isspace}}%
\indexlibrary{\idxcode{isprint}}%
\indexlibrary{\idxcode{iscntrl}}%
\indexlibrary{\idxcode{isupper}}%
\indexlibrary{\idxcode{islower}}%
\indexlibrary{\idxcode{isalpha}}%
\indexlibrary{\idxcode{isdigit}}%
\indexlibrary{\idxcode{ispunct}}%
\indexlibrary{\idxcode{isxdigit}}%
\indexlibrary{\idxcode{isalnum}}%
\indexlibrary{\idxcode{isgraph}}%
\indexlibrary{\idxcode{isblank}}%
\begin{itemdecl}
template <class charT> bool isspace (charT c, const locale& loc);
template <class charT> bool isprint (charT c, const locale& loc);
template <class charT> bool iscntrl (charT c, const locale& loc);
template <class charT> bool isupper (charT c, const locale& loc);
template <class charT> bool islower (charT c, const locale& loc);
template <class charT> bool isalpha (charT c, const locale& loc);
template <class charT> bool isdigit (charT c, const locale& loc);
template <class charT> bool ispunct (charT c, const locale& loc);
template <class charT> bool isxdigit(charT c, const locale& loc);