forked from cplusplus/draft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib-intro.tex
3082 lines (2682 loc) · 112 KB
/
lib-intro.tex
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
%!TEX root = std.tex
\rSec0[library]{Library introduction}
\rSec1[library.general]{General}
\pnum
This Clause describes the contents of the
\defnx{\Cpp{} standard library}{library!\Cpp{} standard},
how a well-formed \Cpp{} program makes use of the library, and
how a conforming implementation may provide the entities in the library.
\pnum
The following subclauses describe the method of
description\iref{description} and organization\iref{organization} of the
library. \ref{requirements}, \ref{\firstlibchapter}
through \ref{\lastlibchapter}, and \ref{depr} specify the contents of the
library, as well as library requirements and constraints on both well-formed
\Cpp{} programs and conforming implementations.
\pnum
Detailed specifications for each of the components in the library are in
\ref{\firstlibchapter}--\ref{\lastlibchapter}, as shown in
\tref{library.categories}.
\begin{floattable}{Library categories}{library.categories}
{ll}
\topline
\hdstyle{Clause} & \hdstyle{Category} \\ \capsep
\ref{support} & Language support library \\
\ref{concepts} & Concepts library \\
\ref{diagnostics} & Diagnostics library \\
\ref{utilities} & General utilities library \\
\ref{strings} & Strings library \\
\ref{containers} & Containers library \\
\ref{iterators} & Iterators library \\
\ref{ranges} & Ranges library \\
\ref{algorithms} & Algorithms library \\
\ref{numerics} & Numerics library \\
\ref{time} & Time library \\
\ref{localization} & Localization library \\
\ref{input.output} & Input/output library \\
\ref{re} & Regular expressions library \\
\ref{atomics} & Atomic operations library \\
\ref{thread} & Thread support library \\
\end{floattable}
\pnum
The language support library\iref{support} provides components that are
required by certain parts of the \Cpp{} language, such as memory allocation~(\ref{expr.new},
\ref{expr.delete}) and exception processing\iref{except}.
\pnum
The concepts library\iref{concepts} describes library components that \Cpp{}
programs may use to perform compile-time validation of template arguments and
perform function dispatch based on properties of types.
\pnum
The diagnostics library\iref{diagnostics} provides a consistent framework for
reporting errors in a \Cpp{} program, including predefined exception classes.
\pnum
The general utilities library\iref{utilities} includes components used
by other library elements, such as a predefined storage allocator for dynamic
storage management\iref{basic.stc.dynamic}, and components used
as infrastructure
in \Cpp{} programs,
such as tuples, function wrappers, and time facilities.
\pnum
The strings library\iref{strings} provides support for manipulating text represented
as sequences of type \tcode{char},
sequences of type \tcode{char8_t},
sequences of type \tcode{char16_t},
sequences of type \tcode{char32_t},
sequences of type \tcode{wchar_t},
and sequences of any other character-like type.
\pnum
The localization library\iref{localization} provides extended internationalization
support for text processing.
\pnum
The containers\iref{containers}, iterators\iref{iterators}, ranges\iref{ranges},
and algorithms\iref{algorithms} libraries provide a \Cpp{} program with access
to a subset of the most widely used algorithms and data structures.
\pnum
The numerics library\iref{numerics} provides
numeric algorithms and complex number components that extend support for numeric processing.
The
\tcode{valarray}
component provides support for
\textit{n}-at-a-time
processing,
potentially implemented as parallel operations on platforms that support such processing.
The random number component provides facilities for generating pseudo-random numbers.
\pnum
The input/output library\iref{input.output} provides the
\tcode{iostream}
components that are the primary mechanism for \Cpp{} program input and output.
They can be used with other elements of the library, particularly
strings, locales, and iterators.
\pnum
The regular expressions library\iref{re} provides regular expression matching and searching.
\pnum
The atomic operations library\iref{atomics} allows more fine-grained
concurrent access to shared data than is possible with locks.
\pnum
The thread support library\iref{thread} provides components to create
and manage threads, including mutual exclusion and interthread communication.
\rSec1[library.c]{The C standard library}
\pnum
The \Cpp{} standard library also makes available the facilities of the C standard library,
\indextext{library!C standard}%
suitably adjusted to ensure static type safety.
\pnum
The descriptions of many library functions rely on the C standard library for
the semantics of those functions.
In some cases,
the signatures specified in this document
may be different from the signatures in the C standard library,
and additional overloads may be declared in this document,
but the behavior and the preconditions
(including any preconditions implied by the use of an
ISO C \tcode{restrict} qualifier)
are the same unless otherwise stated.
\rSec1[description]{Method of description}
\rSec2[description.general]{General}
\pnum
Subclause \ref{description} describes the conventions used to specify the \Cpp{} standard
library. \ref{structure} describes the structure of
\ref{\firstlibchapter} through \ref{\lastlibchapter} and
\ref{depr}. \ref{conventions} describes other editorial conventions.
\rSec2[structure]{Structure of each clause}
\rSec3[structure.elements]{Elements}
\pnum
Each library clause contains the following elements, as applicable:\footnote{To
save space, items that do not apply to a Clause are omitted.
For example, if a Clause does not specify any requirements,
there will be no ``Requirements'' subclause.}
\begin{itemize}
\item Summary
\item Requirements
\item Detailed specifications
\item References to the C standard library
\end{itemize}
\rSec3[structure.summary]{Summary}
\pnum
The Summary provides a synopsis of the category, and introduces the first-level subclauses.
Each subclause also provides a summary, listing the headers specified in the
subclause and the library entities provided in each header.
\pnum
The contents of the summary and the detailed specifications include:
\begin{itemize}
\item macros
\item values
\item types and alias templates
\item classes and class templates
\item functions and function templates
\item objects and variable templates
\item concepts
\end{itemize}
\rSec3[structure.requirements]{Requirements}
\pnum
\indextext{requirements}%
Requirements describe constraints that shall be met by a \Cpp{} program that extends the standard library.
Such extensions are generally one of the following:
\begin{itemize}
\item Template arguments
\item Derived classes
\item Containers, iterators, and algorithms that meet an interface convention or
model a concept
\end{itemize}
\pnum
The string and iostream components use an explicit representation of operations
required of template arguments. They use a class template \tcode{char_traits} to
define these constraints.
\pnum
Interface convention requirements are stated as generally as possible. Instead
of stating ``class \tcode{X} has to define a member function \tcode{operator++()}'', the
interface requires ``for any object \tcode{x} of class \tcode{X}, \tcode{++x} is
defined''. That is, whether the operator is a member is unspecified.
\pnum
Requirements are stated in terms of well-defined expressions that define valid terms of
the types that meet the requirements. For every set of well-defined expression
requirements there is either a named concept or a table that specifies an initial set of the valid expressions and
their semantics. Any generic algorithm\iref{algorithms} that uses the
well-defined expression requirements is described in terms of the valid expressions for
its template type parameters.
\pnum
The library specification uses a typographical convention for naming
requirements. Names in \textit{italic} type that begin with the prefix
\oldconcept{} refer to sets of well-defined expression requirements typically
presented in tabular form, possibly with additional prose semantic requirements.
For example, \oldconcept{Destructible}~(\tref{cpp17.destructible}) is such a named
requirement. Names in \tcode{constant width} type refer to library concepts
which are presented as a concept definition\iref{temp}, possibly with additional
prose semantic requirements. For example,
\libconcept{destructible}\iref{concept.destructible}
is such a named requirement.
\pnum
Template argument requirements are sometimes referenced by name.
See~\ref{type.descriptions}.
\pnum
In some cases the semantic requirements are presented as \Cpp{} code.
Such code is intended as a
specification of equivalence of a construct to another construct, not
necessarily as the way the construct
must be implemented.\footnote{Although in some cases the code given is
unambiguously the optimum implementation.}
\pnum
Required operations of any concept defined in this document need not be
total functions; that is, some arguments to a required operation may
result in the required semantics failing to be met.
\begin{example}
The required \tcode{<} operator of the \libconcept{totally_ordered}
concept\iref{concept.totallyordered} does not meet the
semantic requirements of that concept when operating on NaNs.
\end{example}
This does not affect whether a type models the concept.
\pnum
A declaration may explicitly impose requirements through its associated
constraints\iref{temp.constr.decl}. When the associated constraints refer to a
concept\iref{temp.concept}, the semantic constraints specified for that concept
are additionally imposed on the use of the declaration.
\rSec3[structure.specifications]{Detailed specifications}
\pnum
The detailed specifications each contain the following elements:%
\begin{itemize}
\item name and brief description
\item synopsis (class definition or function declaration, as appropriate)
\item restrictions on template arguments, if any
\item description of class invariants
\item description of function semantics
\end{itemize}
\pnum
Descriptions of class member functions follow the order (as
appropriate):\footnote{To save space, items that do not apply to a class are omitted.
For example, if a class does not specify any comparison operator functions, there
will be no ``Comparison operator functions'' subclause.}
\begin{itemize}
\item constructor(s) and destructor
\item copying, moving \& assignment functions
\item comparison operator functions
\item modifier functions
\item observer functions
\item operators and other non-member functions
\end{itemize}
\pnum
Descriptions of function semantics contain the following elements (as
appropriate):\footnote{To save space, elements that do not apply to a function are omitted.
For example, if a function specifies no
preconditions, there will be no \expects element.}
\begin{itemize}
\item
\constraints
the conditions for the function's participation
in overload resolution\iref{over.match}.
\begin{note}
Failure to meet such a condition results in the function's silent non-viability.
\end{note}
\begin{example}
An implementation might express such a condition
via a \grammarterm{constraint-expression}\iref{temp.constr.decl}.
\end{example}
\item
\mandates
the conditions that, if not met, render the program ill-formed.
\begin{example}
An implementation might express such a condition
via the \grammarterm{constant-expression}
in a \grammarterm{static_assert-declaration}\iref{dcl.pre}.
If the diagnostic is to be emitted only after the function
has been selected by overload resolution,
an implementation might express such a condition
via a \grammarterm{constraint-expression}\iref{temp.constr.decl}
and also define the function as deleted.
\end{example}
\item
\expects
the conditions
that the function assumes to hold whenever it is called;
violation of any preconditions results in undefined behavior.
\item
\effects
the actions performed by the function.
\item
\sync
the synchronization operations\iref{intro.multithread} applicable to the function.
\item
\ensures
the conditions (sometimes termed observable results)
established by the function.
\item
\returns
a description of the value(s) returned by the function.
\item
\throws
any exceptions thrown by the function, and the conditions that would cause the exception.
\item
\complexity
the time and/or space complexity of the function.
\item
\remarks
additional semantic constraints on the function.
\item
\errors
the error conditions for error codes reported by the function.
\end{itemize}
\pnum
Whenever the \Fundescx{Effects} element specifies that the semantics of some function
\tcode{F} are \term{Equivalent to} some code sequence, then the various elements are
interpreted as follows.
If \tcode{F}'s semantics specifies any \Fundescx{Constraints} or \Fundescx{Mandates} elements,
then those requirements are logically imposed prior to the \term{equivalent-to} semantics.
Next, the semantics of the code sequence are determined by the
\Fundescx{Constraints}, \Fundescx{Mandates}, \Fundescx{Preconditions}, \Fundescx{Effects},
\Fundescx{Synchronization}, \Fundescx{Postconditions}, \Fundescx{Returns}, \Fundescx{Throws},
\Fundescx{Complexity}, \Fundescx{Remarks}, and \Fundescx{Error conditions}
specified for the function invocations contained in the code sequence.
The value returned from \tcode{F} is specified by \tcode{F}'s \Fundescx{Returns} element,
or if \tcode{F} has no \Fundescx{Returns} element,
a non-\tcode{void} return from \tcode{F} is specified by the
\tcode{return} statements\iref{stmt.return} in the code sequence.
If \tcode{F}'s semantics contains a \Fundescx{Throws},
\Fundescx{Postconditions}, or \Fundescx{Complexity} element,
then that supersedes any occurrences of that element in the code sequence.
\pnum
For non-reserved replacement and handler functions,
\ref{support} specifies two behaviors for the functions in question:
their required and default behavior.
The \defnx{default behavior}{behavior!default}
describes a function definition provided by the implementation.
The \defnx{required behavior}{behavior!required}
describes the semantics of a function definition provided by
either the implementation or a \Cpp{} program.
Where no distinction is explicitly made in the description, the
behavior described is the required behavior.
\pnum
If the formulation of a complexity requirement calls for a negative number of
operations, the actual requirement is zero operations.\footnote{This simplifies
the presentation of complexity requirements in some cases.}
\pnum
Complexity requirements specified in the library clauses are upper bounds,
and implementations that provide better complexity guarantees meet
the requirements.
\pnum
Error conditions specify conditions where a function may fail. The conditions
are listed, together with a suitable explanation, as the \tcode{enum class errc}
constants\iref{syserr}.
\rSec3[structure.see.also]{C library}
\pnum
Paragraphs labeled ``\textsc{See also}'' contain cross-references to the relevant portions
of other standards\iref{intro.refs}.
\rSec2[conventions]{Other conventions}
\rSec3[conventions.general]{General}
\indextext{conventions}%
\pnum
Subclause \ref{conventions} describes several editorial conventions used to describe the contents
of the \Cpp{} standard library.
These conventions are for describing
implementation-defined types\iref{type.descriptions},
and member functions\iref{functions.within.classes}.
\rSec3[expos.only.func]{Exposition-only functions}
\pnum
Several function templates
defined in \ref{\firstlibchapter} through \ref{\lastlibchapter} and \ref{depr}
are only defined for the purpose of exposition.
The declaration of such a function is followed by a comment ending in \expos.
\pnum
The following are defined for exposition only
to aid in the specification of the library:
\indexlibrary{decay-copy@\tcode{\placeholder{decay-copy}}}%
\begin{codeblock}
template<class T> constexpr decay_t<T> @\placeholdernc{decay-copy}@(T&& v)
noexcept(is_nothrow_convertible_v<T, decay_t<T>>) // \expos
{ return std::forward<T>(v); }
constexpr auto @\placeholdernc{synth-three-way}@ =
[]<class T, class U>(const T& t, const U& u)
requires requires {
{ t < u } -> @\exposconcept{boolean-testable}@;
{ u < t } -> @\exposconcept{boolean-testable}@;
}
{
if constexpr (three_way_comparable_with<T, U>) {
return t <=> u;
} else {
if (t < u) return weak_ordering::less;
if (u < t) return weak_ordering::greater;
return weak_ordering::equivalent;
}
};
template<class T, class U=T>
using @\placeholdernc{synth-three-way-result}@ = decltype(@\placeholdernc{synth-three-way}@(declval<T&>(), declval<U&>()));
\end{codeblock}
\rSec3[type.descriptions]{Type descriptions}
\rSec4[type.descriptions.general]{General}
\pnum
The Requirements subclauses may describe names that are used to specify
constraints on template arguments.\footnote{Examples
from~\ref{utility.requirements} include:
\oldconcept{EqualityComparable},
\oldconcept{LessThanComparable},
\oldconcept{CopyConstructible}.
Examples from~\ref{iterator.requirements} include:
\oldconcept{InputIterator},
\oldconcept{ForwardIterator}.}
These names are used in library Clauses
to describe the types that
may be supplied as arguments by a \Cpp{} program when instantiating template components from
the library.
\pnum
Certain types defined in \ref{input.output} are used to describe implementation-defined types.
\indextext{types!implementation-defined}%
They are based on other types, but with added constraints.
\rSec4[expos.only.types]{Exposition-only types}
\pnum
Several types defined in \ref{\firstlibchapter} through \ref{\lastlibchapter}
and \ref{depr} are defined for the purpose of exposition.
The declaration of such a type is followed by a comment ending in \expos.
\begin{example}
\begin{codeblock}
namespace std {
extern "C" using @\placeholdernc{some-handler}@ = int(int, void*, double); // \expos
}
\end{codeblock}
The type placeholder \tcode{\placeholder{some-handler}} can now be used to specify a function
that takes a callback parameter with C language linkage.
\end{example}
\rSec4[enumerated.types]{Enumerated types}
\pnum
Several types defined in \ref{input.output} are
\defnx{enumerated types}{type!enumerated}.
Each enumerated type may be implemented as an enumeration or as a synonym for
an enumeration.\footnote{Such as an integer type, with constant integer
values\iref{basic.fundamental}.}
\pnum
The enumerated type \tcode{\placeholder{enumerated}} can be written:
\begin{codeblock}
enum @\placeholder{enumerated}@ { @$\tcode{\placeholder{V}}_{0}$@, @$\tcode{\placeholder{V}}_{1}$@, @$\tcode{\placeholder{V}}_{2}$@, @$\tcode{\placeholder{V}}_{3}$@, @$\ldots$@ };
inline const @$\tcode{\placeholder{enumerated C}}_{0}$@(@$\tcode{\placeholder{V}}_{0}$@);
inline const @$\tcode{\placeholder{enumerated C}}_{1}$@(@$\tcode{\placeholder{V}}_{1}$@);
inline const @$\tcode{\placeholder{enumerated C}}_{2}$@(@$\tcode{\placeholder{V}}_{2}$@);
inline const @$\tcode{\placeholder{enumerated C}}_{3}$@(@$\tcode{\placeholder{V}}_{3}$@);
@\vdots@
\end{codeblock}
\pnum
Here, the names $\tcode{\placeholder{C}}_0$,
$\tcode{\placeholder{C}}_1$, etc.\ represent
\defnx{enumerated elements}{enumerated element}
for this particular enumerated type.
\indextext{type!enumerated}%
All such elements have distinct values.
\rSec4[bitmask.types]{Bitmask types}
\pnum
Several types defined in \ref{\firstlibchapter} through \ref{\lastlibchapter}
and \ref{depr} are
\defnx{bitmask types}{type!bitmask}.
Each bitmask type can be implemented as an
enumerated type that overloads certain operators, as an integer type,
or as a
\tcode{bitset}\iref{template.bitset}.
\indextext{type!enumerated}%
\pnum
The bitmask type \tcode{\placeholder{bitmask}} can be written:
\begin{codeblock}
// For exposition only.
// \tcode{int_type} is an integral type capable of representing all values of the bitmask type.
enum @\placeholder{bitmask}@ : int_type {
@$\tcode{\placeholder{V}}_{0}$@ = 1 << 0, @$\tcode{\placeholder{V}}_{1}$@ = 1 << 1, @$\tcode{\placeholder{V}}_{2}$@ = 1 << 2, @$\tcode{\placeholder{V}}_{3}$@ = 1 << 3, @$\ldots$@
};
inline constexpr @$\tcode{\placeholder{bitmask C}}_{0}$@(@$\tcode{\placeholder{V}}_{0}{}$@);
inline constexpr @$\tcode{\placeholder{bitmask C}}_{1}$@(@$\tcode{\placeholder{V}}_{1}{}$@);
inline constexpr @$\tcode{\placeholder{bitmask C}}_{2}$@(@$\tcode{\placeholder{V}}_{2}{}$@);
inline constexpr @$\tcode{\placeholder{bitmask C}}_{3}$@(@$\tcode{\placeholder{V}}_{3}{}$@);
@\vdots@
constexpr @\placeholder{bitmask}{}@ operator&(@\placeholder{bitmask}{}@ X, @\placeholder{bitmask}{}@ Y) {
return static_cast<@\placeholder{bitmask}{}@>(
static_cast<int_type>(X) & static_cast<int_type>(Y));
}
constexpr @\placeholder{bitmask}{}@ operator|(@\placeholder{bitmask}{}@ X, @\placeholder{bitmask}{}@ Y) {
return static_cast<@\placeholder{bitmask}{}@>(
static_cast<int_type>(X) | static_cast<int_type>(Y));
}
constexpr @\placeholder{bitmask}{}@ operator^(@\placeholder{bitmask}{}@ X, @\placeholder{bitmask}{}@ Y){
return static_cast<@\placeholder{bitmask}{}@>(
static_cast<int_type>(X) ^ static_cast<int_type>(Y));
}
constexpr @\placeholder{bitmask}{}@ operator~(@\placeholder{bitmask}{}@ X){
return static_cast<@\placeholder{bitmask}{}@>(~static_cast<int_type>(X));
}
@\placeholder{bitmask}{}@& operator&=(@\placeholder{bitmask}{}@& X, @\placeholder{bitmask}{}@ Y){
X = X & Y; return X;
}
@\placeholder{bitmask}{}@& operator|=(@\placeholder{bitmask}{}@& X, @\placeholder{bitmask}{}@ Y) {
X = X | Y; return X;
}
@\placeholder{bitmask}{}@& operator^=(@\placeholder{bitmask}{}@& X, @\placeholder{bitmask}{}@ Y) {
X = X ^ Y; return X;
}
\end{codeblock}
\pnum
Here, the names $\tcode{\placeholder{C}}_0$,
$\tcode{\placeholder{C}}_1$, etc.\ represent
\defnx{bitmask elements}{bitmask!element}
for this particular bitmask type.
\indextext{type!bitmask}%
All such elements have distinct, nonzero values such that, for any pair $\tcode{\placeholder{C}}_i$
and $\tcode{\placeholder{C}}_j$ where $i \neq j$, \tcode{$\placeholder{C}_i$ \& $\placeholder{C}_i$} is nonzero and
\tcode{$\placeholder{C}_i$ \& $\placeholder{C}_j$} is zero.
Additionally, the value \tcode{0} is used to represent an \defnx{empty bitmask}{bitmask!empty}, in which no
bitmask elements are set.
\pnum
The following terms apply to objects and values of
bitmask types:
\begin{itemize}
\item
To \defnx{set}{bitmask!value!set}
a value \textit{Y} in an object \textit{X}
is to evaluate the expression \textit{X} \tcode{|=} \textit{Y}.
\item
To \defnx{clear}{bitmask!value!clear}
a value \textit{Y} in an object
\textit{X} is to evaluate the expression \textit{X} \tcode{\&= \~}\textit{Y}.
\item
The value \textit{Y} \defnx{is set}{bitmask!value!is set} in the object
\textit{X} if the expression \textit{X} \tcode{\&} \textit{Y} is nonzero.
\end{itemize}
\rSec4[character.seq]{Character sequences}
\rSec5[character.seq.general]{General}
\pnum
The C standard library makes widespread use
\indextext{library!C standard}%
of characters and character sequences that follow a few uniform conventions:
\begin{itemize}
\item
A \defn{letter} is any of the 26 lowercase or 26
\indextext{lowercase}%
\indextext{uppercase}%
uppercase letters in the basic execution character set.
\item
The
\defnx{decimal-point character}{character!decimal-point}
is the
(single-byte) character used by functions that convert between a (single-byte)
character sequence and a value of one of the floating-point types.
It is used
in the character sequence to denote the beginning of a fractional part.
It is
represented in \ref{\firstlibchapter} through \ref{\lastlibchapter}
and \ref{depr} by a period,
\indextext{period}%
\tcode{'.'},
which is
also its value in the \tcode{"C"}
locale, but may change during program
execution by a call to
\tcode{setlocale(int, const char*)},\footnote{declared in
\libheaderref{clocale}.
\indexlibraryglobal{setlocale}%
}
or by a change to a
\tcode{locale}
object, as described in \ref{locales} and \ref{input.output}.
\item
A
\defn{character sequence}
is an array object\iref{dcl.array} \tcode{\placeholdernc{A}} that
can be declared as
\tcode{\placeholdernc{T\;A}[\placeholder{N}]},
where \tcode{\placeholder{T}} is any of the types
\tcode{char},
\tcode{unsigned char},
or
\tcode{signed char}\iref{basic.fundamental}, optionally qualified by any combination of
\tcode{const}
or
\tcode{volatile}.
The initial elements of the
array have defined contents up to and including an element determined by some
predicate.
A character sequence can be designated by a pointer value
\tcode{\placeholder{S}} that points to its first element.
\end{itemize}
\rSec5[byte.strings]{Byte strings}
\indextext{string!null-terminated byte|see{\ntbs{}}}%
\pnum
A \defnx{null-terminated byte string}{NTBS@\ntbs{}},
or \ntbs{},
is a character sequence whose highest-addressed element
with defined content has the value zero
(the \defnx{terminating null character}{character!terminating null});
no other element in the sequence has the value zero.%
\footnote{Many of the objects manipulated by
function signatures declared in
\libheaderref{cstring} are character sequences or \ntbs{}s.
The size of some of these character sequences is limited by
a length value, maintained separately from the character sequence.}
\pnum
The \defnx{length of an \ntbs{}}{NTBS@\ntbs{}!length}
is the number of elements that
precede the terminating null character.
An \defnx{empty \ntbs{}}{NTBS@\ntbs{}!empty}
has a length of zero.
\pnum
The \defnx{value of an \ntbs{}}{NTBS@\ntbs{}!value}
is the sequence of values of the
elements up to and including the terminating null character.
\pnum
A \defnx{static \ntbs{}}{NTBS@\ntbs{}!static}
is an \ntbs{} with
static storage duration.\footnote{A \grammarterm{string-literal}, such as
\tcode{"abc"},
is a static \ntbs{}.}
\rSec5[multibyte.strings]{Multibyte strings}
\indextext{string!null-terminated multibyte|see{\ntmbs{}}}%
\pnum
A \defnx{null-terminated multibyte string}{NTMBS@\ntmbs{}},
or \ntmbs{},
is an \ntbs{} that constitutes a
sequence of valid multibyte characters, beginning and ending in the initial
shift state.\footnote{An \ntbs{} that contains characters only from the
basic execution character set is also an \ntmbs{}.
Each multibyte character then
consists of a single byte.}
\pnum
A \defnx{static \ntmbs{}}{NTMBS@\ntmbs{}!static}
is an \ntmbs{} with static storage duration.
\rSec4[customization.point.object]{Customization Point Object types}
\pnum
A \term{customization point object} is a function object\iref{function.objects}
with a literal class type that interacts with program-defined types while
enforcing semantic requirements on that interaction.
\pnum
The type of a customization point object, ignoring cv-qualifiers, shall model
\libconcept{semiregular}\iref{concepts.object}.
\pnum
All instances of a specific customization point object type shall
be equal\iref{concepts.equality}.
\pnum
The type \tcode{T} of a customization point object shall model
\tcode{\libconcept{invocable}<const T\&, Args...>}\iref{concept.invocable}
when the types in \tcode{Args...} meet the requirements specified in that
customization point object's definition. When the types of \tcode{Args...} do
not meet the customization point object's requirements, \tcode{T} shall not have
a function call operator that participates in overload resolution.
\pnum
Each customization point object type constrains its return type to model a
particular concept.
\pnum
\begin{note}
Many of the customization point objects in the library evaluate function call
expressions with an unqualified name which results in a call to a
program-defined function found by argument dependent name
lookup\iref{basic.lookup.argdep}. To preclude such an expression resulting in a
call to unconstrained functions with the same name in namespace \tcode{std},
customization point objects specify that lookup for these expressions is
performed in a context that includes deleted overloads matching the signatures
of overloads defined in namespace \tcode{std}. When the deleted overloads are
viable, program-defined overloads need be more specialized\iref{temp.func.order}
or more constrained\iref{temp.constr.order} to be used by a customization point
object.
\end{note}
\rSec3[functions.within.classes]{Functions within classes}
\pnum
For the sake of exposition, \ref{\firstlibchapter} through \ref{\lastlibchapter}
and \ref{depr} do not describe copy/move constructors, assignment
operators, or (non-virtual) destructors with the same apparent
semantics as those that can be generated
by default~(\ref{class.copy.ctor}, \ref{class.copy.assign}, \ref{class.dtor}).
\indextext{constructor!copy}%
\indextext{operator!assignment}%
\indextext{destructor}%
It is unspecified whether
the implementation provides explicit definitions for such member function
signatures, or for virtual destructors that can be generated by default.
\rSec3[objects.within.classes]{Private members}
\pnum
\ref{\firstlibchapter} through \ref{\lastlibchapter} and
\ref{depr} do not specify the representation of classes, and intentionally
omit specification of class members\iref{class.mem}. An implementation may
define static or non-static class members, or both, as needed to implement the
semantics of the member functions specified in \ref{\firstlibchapter}
through \ref{\lastlibchapter} and \ref{depr}.
\pnum
For the sake of exposition,
some subclauses provide representative declarations, and semantic requirements, for
private members of classes that meet the external specifications of the classes.
The declarations for such members are
followed by a comment that ends with \expos, as in:
\begin{codeblock}
streambuf* sb; // \expos
\end{codeblock}
\pnum
An implementation may use any technique that provides equivalent observable behavior.
\rSec1[requirements]{Library-wide requirements}
\rSec2[requirements.general]{General}
\pnum
Subclause \ref{requirements} specifies requirements that apply to the entire \Cpp{} standard library.
\ref{\firstlibchapter} through \ref{\lastlibchapter} and \ref{depr}
specify the requirements of individual entities within the library.
\pnum
Requirements specified in terms of interactions between threads do not apply to
programs having only a single thread of execution.
\pnum
\ref{organization} describes the library's contents and
organization, \ref{using} describes how well-formed \Cpp{} programs gain access to library
entities,
\ref{utility.requirements} describes constraints on types and functions used with
the \Cpp{} standard library,
\ref{constraints} describes constraints on well-formed \Cpp{} programs, and
\ref{conforming} describes constraints on conforming implementations.
\rSec2[organization]{Library contents and organization}
\rSec3[organization.general]{General}
\pnum
\ref{contents} describes the entities and macros defined in the \Cpp{} standard library.
\ref{headers} lists the standard library headers and some constraints on those headers.
\ref{compliance} lists requirements for a freestanding implementation of the \Cpp{}
standard library.
\rSec3[contents]{Library contents}
\pnum
The \Cpp{} standard library provides definitions
for the entities and macros described in the synopses
of the \Cpp{} standard library headers\iref{headers},
unless otherwise specified.
\pnum
All library entities except
\tcode{operator new}
and
\tcode{operator delete}
are defined within the namespace
\tcode{std}
or namespaces nested within namespace
\tcode{std}.\footnote{The C standard library headers\iref{depr.c.headers} also define
names within the global namespace, while the \Cpp{} headers for C library
facilities\iref{headers} can also define names within the global namespace.}%
\indextext{namespace}
It is unspecified whether names declared in a specific namespace are declared
directly in that namespace or in an inline namespace inside that
namespace.\footnote{This gives implementers freedom to use inline namespaces to
support multiple configurations of the library.}
\pnum
Whenever a name \tcode{x} defined in the standard library is mentioned,
the name \tcode{x} is assumed to be fully qualified as
\tcode{::std::x},
unless explicitly described otherwise. For example, if the \effects element
for library function \tcode{F} is described as calling library function \tcode{G},
the function
\tcode{::std::G}
is meant.
\rSec3[headers]{Headers}
\pnum
Each element of the \Cpp{} standard library is declared or defined (as appropriate) in a
\defn{header}.\footnote{A header is not necessarily a source file, nor are the
sequences delimited by \tcode{<} and \tcode{>} in header names necessarily valid source
file names\iref{cpp.include}.}
\pnum
The \Cpp{} standard library provides the
\defnx{\Cpp{} library headers}{header!\Cpp{} library},
shown in \tref{headers.cpp}.
\begin{multicolfloattable}{\Cpp{} library headers}{headers.cpp}
{llll}
\tcode{<algorithm>} \\
\tcode{<any>} \\
\tcode{<array>} \\
\tcode{<atomic>} \\
\tcode{<barrier>} \\
\tcode{<bit>} \\
\tcode{<bitset>} \\
\tcode{<charconv>} \\
\tcode{<chrono>} \\
\tcode{<codecvt>} \\
\tcode{<compare>} \\
\tcode{<complex>} \\
\tcode{<concepts>} \\
\tcode{<condition_variable>} \\
\tcode{<coroutine>} \\
\tcode{<deque>} \\
\tcode{<exception>} \\
\tcode{<execution>} \\
\tcode{<filesystem>} \\
\tcode{<format>} \\
\columnbreak
\tcode{<forward_list>} \\
\tcode{<fstream>} \\
\tcode{<functional>} \\
\tcode{<future>} \\
\tcode{<initializer_list>} \\
\tcode{<iomanip>} \\
\tcode{<ios>} \\
\tcode{<iosfwd>} \\
\tcode{<iostream>} \\
\tcode{<istream>} \\
\tcode{<iterator>} \\
\tcode{<latch>} \\
\tcode{<limits>} \\
\tcode{<list>} \\
\tcode{<locale>} \\
\tcode{<map>} \\
\tcode{<memory>} \\
\tcode{<memory_resource>} \\
\tcode{<mutex>} \\
\tcode{<new>} \\
\columnbreak
\tcode{<numbers>} \\
\tcode{<numeric>} \\
\tcode{<optional>} \\
\tcode{<ostream>} \\
\tcode{<queue>} \\
\tcode{<random>} \\
\tcode{<ranges>} \\
\tcode{<ratio>} \\
\tcode{<regex>} \\
\tcode{<scoped_allocator>} \\
\tcode{<semaphore>} \\
\tcode{<set>} \\
\tcode{<shared_mutex>} \\
\tcode{<source_location>} \\
\tcode{<span>} \\
\tcode{<sstream>} \\
\tcode{<stack>} \\
\tcode{<stdexcept>} \\
\tcode{<stop_token>} \\
\tcode{<streambuf>} \\
\columnbreak
\tcode{<string>} \\
\tcode{<string_view>} \\
\tcode{<strstream>} \\
\tcode{<syncstream>} \\
\tcode{<system_error>} \\
\tcode{<thread>} \\
\tcode{<tuple>} \\
\tcode{<typeindex>} \\
\tcode{<typeinfo>} \\
\tcode{<type_traits>} \\
\tcode{<unordered_map>} \\
\tcode{<unordered_set>} \\
\tcode{<utility>} \\
\tcode{<valarray>} \\
\tcode{<variant>} \\
\tcode{<vector>} \\
\tcode{<version>} \\
\end{multicolfloattable}
\pnum
The facilities of the C standard library are provided in the
\indextext{library!C standard}%
additional headers shown in \tref{headers.cpp.c}.%
\footnote{It is intentional that there is no \Cpp{} header
for any of these C headers:
\libnoheader{stdatomic.h},
\libnoheader{stdnoreturn.h},
\libnoheader{threads.h}.}
\begin{multicolfloattable}{\Cpp{} headers for C library facilities}{headers.cpp.c}
{lllllll}
\tcode{<cassert>} \\
\tcode{<cctype>} \\
\tcode{<cerrno>} \\
\columnbreak
\tcode{<cfenv>} \\
\tcode{<cfloat>} \\
\tcode{<cinttypes>} \\
\columnbreak
\tcode{<climits>} \\
\tcode{<clocale>} \\
\tcode{<cmath>} \\
\columnbreak
\tcode{<csetjmp>} \\
\tcode{<csignal>} \\
\tcode{<cstdarg>} \\
\columnbreak
\tcode{<cstddef>} \\
\tcode{<cstdint>} \\
\tcode{<cstdio>} \\
\columnbreak
\tcode{<cstdlib>} \\