/
lib-intro.tex
3120 lines (2656 loc) · 111 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!C++ 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 definitions\iref{definitions}, 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{libsumtabbase}{Library categories}{tab:library.categories}{Clause}{Category}
\ref{language.support} & & Language support library \\
\ref{diagnostics} & & Diagnostics library \\
\ref{utilities} & & General utilities library \\
\ref{strings} & & Strings library \\
\ref{localization} & & Localization library \\
\ref{containers} & & Containers library \\
\ref{iterators} & & Iterators library \\
\ref{algorithms} & & Algorithms library \\
\ref{numerics} & & Numerics library \\
\ref{input.output} & & Input/output library \\
\ref{re} & & Regular expressions library \\
\ref{atomics} & & Atomic operations library \\
\ref{thread} & & Thread support library \\
\end{libsumtabbase}
\pnum
The language support library\iref{language.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 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{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},
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[definitions]{Definitions}
\pnum
\begin{note}
\ref{intro.defs} defines additional terms used elsewhere in this document.
\end{note}
\definition{arbitrary-positional stream}{defns.arbitrary.stream}
\indexdefn{stream!arbitrary-positional}%
stream (described in \ref{input.output}) that can seek to any integral position within
the length of the stream
\begin{defnote}
Every arbitrary-positional stream is also a repositional stream.
\end{defnote}
\definition{character}{defns.character}
\indexdefn{character}%
\defncontext{\ref{strings}, \ref{localization}, \ref{input.output}, and~\ref{re}}
object which,
when treated sequentially,
can represent text
\begin{defnote}
The term does not mean only
\tcode{char},
\tcode{char16_t},
\tcode{char32_t},
and
\tcode{wchar_t}
objects,
but any value that can be represented by a type
that provides the definitions specified in these Clauses.
\end{defnote}
\definition{character container type}{defns.character.container}
\indexdefn{type!character container}%
class or a type used to
represent a character
\begin{defnote}
It is used for one of the template parameters of the string,
iostream, and regular expression class templates.
\end{defnote}
\definition{comparison function}{defns.comparison}
\indexdefn{function!comparison}%
operator function\iref{over.oper} for any of the equality\iref{expr.eq} or
relational\iref{expr.rel} operators
\definition{component}{defns.component}
\indexdefn{component}%
group of library entities directly related as members, parameters, or
return types
\begin{defnote}
For example, the class template
\tcode{basic_string}
and the non-member
function templates
that operate on
strings are referred to as the
\term{string component}.
\end{defnote}
\definition{constant subexpression}{defns.const.subexpr}
\indexdefn{constant subexpression}%
expression whose evaluation as subexpression of a
\grammarterm{conditional-expression}
\tcode{CE}\iref{expr.cond} would not prevent \tcode{CE}
from being a core constant expression\iref{expr.const}
\definition{deadlock}{defns.deadlock}
\indexdefn{deadlock}%
situation wherein
one or more threads are unable to continue execution because each is
blocked waiting for one or more of the others to satisfy some condition
\definition{default behavior}{defns.default.behavior.impl}
\indexdefn{behavior!default}%
\defncontext{implementation}
specific behavior provided by the implementation,
within the scope of the required behavior
\definition{default behavior}{defns.default.behavior.func}
\indexdefn{behavior!default}%
\defncontext{specification}
description of replacement function and handler function
semantics
\definition{direct-non-list-initialization}{defns.direct-non-list-init}
\indexdefn{direct-non-list-initialization}%
direct-initialization\iref{dcl.init}
that is not list-initialization\iref{dcl.init.list}
\definition{handler function}{defns.handler}
\indexdefn{function!handler}%
non-reserved function whose definition may be provided by a \Cpp{} program
\begin{defnote}
A \Cpp{} program may designate a handler function at various points in its execution by
supplying a pointer to the function when calling any of the library functions that install
handler functions\iref{language.support}.
\end{defnote}
\definition{iostream class templates}{defns.iostream.templates}
templates, defined in \ref{input.output},
that take two template arguments
\begin{defnote}
The arguments are named
\tcode{charT}
and
\tcode{traits}.
The argument
\tcode{charT}
is a character container class,
and the argument
\tcode{traits}
is a class which defines additional characteristics and functions
of the character type represented by
\tcode{charT}
necessary to implement the iostream class templates.
\end{defnote}
\definition{modifier function}{defns.modifier}
\indexdefn{function!modifier}%
class member function\iref{class.mfct} other than a constructor,
assignment operator, or destructor
that alters the state of an object of the class
\definition{move assignment}{defns.move.assign}
\indexdefn{assignment!move}%
assignment of an rvalue of some object type to a modifiable lvalue of the same type
\definition{move construction}{defns.move.constr}
\indexdefn{construction!move}%
direct-initialization of an object of some type with an rvalue of the same type
\definition{NTCTS}{defns.ntcts}
\indexdefn{NTCTS}%
\indexdefn{string!null-terminated character type}%
sequence of values that have
character type
that precede the terminating null character type
value
\tcode{charT()}
\definition{observer function}{defns.observer}
\indexdefn{function!observer}%
class member function\iref{class.mfct} that accesses the state of an object of the class
but does not alter that state
\begin{defnote}
Observer functions are specified as
\tcode{const}
member functions\iref{class.this}.
\end{defnote}
\definition{referenceable type}{defns.referenceable}
\indexdefn{type!referenceable}%
type that is either an
object type, a function type that does not have cv-qualifiers or a
\grammarterm{ref-qualifier}, or a reference type
\begin{defnote}
The term describes a type to which a reference can be created,
including reference types.
\end{defnote}
\definition{replacement function}{defns.replacement}
\indexdefn{function!replacement}%
non-reserved function
whose definition is provided by a \Cpp{} program
\begin{defnote}
Only one definition for such a function is in effect for the duration of the program's
execution, as the result of creating the program\iref{lex.phases} and resolving the
definitions of all translation units\iref{basic.link}.
\end{defnote}
\definition{repositional stream}{defns.repositional.stream}
\indexdefn{stream!repositional}%
stream (described in \ref{input.output}) that can seek to a position that was
previously encountered
\definition{required behavior}{defns.required.behavior}
\indexdefn{behavior!required}%
description of replacement function and handler function semantics
applicable to both the behavior provided by the implementation and
the behavior of any such function definition in the program
\begin{defnote}
If such a function defined in a \Cpp{} program fails to meet the required
behavior when it executes, the behavior is undefined.%
\indextext{undefined}
\end{defnote}
\definition{reserved function}{defns.reserved.function}
\indexdefn{function!reserved}%
function, specified as part of the \Cpp{} standard library, that is defined by the
implementation
\begin{defnote}
If a \Cpp{} program provides a definition for any reserved function, the results are undefined.%
\indextext{undefined}
\end{defnote}
\definition{stable algorithm}{defns.stable}
\indexdefn{algorithm!stable}%
\indexdefn{stable algorithm}%
algorithm that preserves, as appropriate to the particular algorithm, the order
of elements
\begin{defnote}
Requirements for stable algorithms are given in \ref{algorithm.stable}.
\end{defnote}
\definition{traits class}{defns.traits}
\indexdefn{traits}%
class that encapsulates a set of types and functions necessary for class templates and
function templates to manipulate objects of types for which they are instantiated
\definition{valid but unspecified state}{defns.valid}
\indexdefn{valid but unspecified state}%
value of an object that is not specified except that the object's invariants are
met and operations on the object behave as specified for its type
\begin{example}
If an object \tcode{x} of type \tcode{std::vector<int>} is in a
valid but unspecified state, \tcode{x.empty()} can be called unconditionally,
and \tcode{x.front()} can be called only if \tcode{x.empty()} returns
\tcode{false}.
\end{example}
\rSec1[description]{Method of description (Informative)}
\pnum
This subclause describes the conventions used to specify the \Cpp{} standard
library. \ref{structure} describes the structure of the normative
\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
\item classes and class templates
\item functions and function templates
\item objects
\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
\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 satisfy the requirements. For every set of well-defined expression
requirements there is 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
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.}
\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 functions, there
will be no ``Comparison functions'' subclause.}
\begin{itemize}
\item constructor(s) and destructor
\item copying, moving \& assignment functions
\item comparison 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, items that do not apply to a function are omitted.
For example, if a function does not specify any
further
preconditions, there will be no \requires paragraph.}
\begin{itemize}
\item \requires the preconditions for calling the function
\item \effects the actions performed by the function
\item \sync the synchronization operations\iref{intro.multithread} applicable to the function
\item \postconditions the 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 \techterm{Equivalent to} some code sequence, then the various elements are
interpreted as follows. If \tcode{F}'s semantics specifies a \Fundescx{Requires} element, then
that requirement is logically imposed prior to the \techterm{equivalent-to} semantics.
Next, the semantics of the code sequence are determined by the \Fundescx{Requires}, \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{language.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 satisfy
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}
\indextext{conventions}%
\pnum
This subclause 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[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:
\tcode{EqualityComparable},
\tcode{LessThanComparable},
\tcode{CopyConstructible}.
Examples from~\ref{iterator.requirements} include:
\tcode{InputIterator},
\tcode{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} that are used as function parameter or return types are defined
for the purpose of exposition only in order to capture their language linkage. The
declarations of such types are followed by a comment ending in \textit{exposition only}.
\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}$@, ..... };
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}$@);
.....
\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, .....
};
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}{}$@);
.....
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}
\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
\tcode{<clocale>}\iref{c.locales}.
\indextext{\idxcode{setlocale}}%
\indexlibrary{\idxcode{setlocale}}%
\indexhdr{clocale}%
\indexhdr{clocale}}
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.%
\indexhdr{cstring}%
\footnote{Many of the objects manipulated by
function signatures declared in
\tcode{<cstring>}\iref{c.strings} are character sequences or \ntbs{}s.
\indexhdr{cstring}%
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 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.
\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.ctor}, \ref{class.dtor}, \ref{class.copy}).
\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.
\pnum
For the sake of exposition, the library clauses sometimes annotate
constructors with \EXPLICIT{}. Such a constructor is conditionally declared
as either explicit or non-explicit\iref{class.conv.ctor}.
\begin{note} This is typically implemented by declaring two such constructors,
of which at most one participates in overload resolution. \end{note}
\rSec3[operators]{Operators}
\pnum
In this library, whenever a declaration is provided for an \tcode{operator!=},
\tcode{operator>}, \tcode{operator>=}, or \tcode{operator<=}
for a type \tcode{T},
its requirements and semantics are as follows,
unless explicitly specified otherwise.
\indexlibrary{\idxcode{operator"!=}}%
\begin{itemdecl}
bool operator!=(const T& x, const T& y);
\end{itemdecl}
\begin{itemdescr}
\pnum
\requires
Type \tcode{T} is \tcode{EqualityComparable} (\tref{equalitycomparable}).
\pnum
\returns
\tcode{!(x == y)}.
\end{itemdescr}
\indexlibrary{\idxcode{operator>}}%
\begin{itemdecl}
bool operator>(const T& x, const T& y);
\end{itemdecl}
\begin{itemdescr}
\pnum
\requires
Type \tcode{T} is \tcode{LessThanComparable} (\tref{lessthancomparable}).
\pnum
\returns
\tcode{y < x}.
\end{itemdescr}
\indexlibrary{\idxcode{operator<=}}%
\begin{itemdecl}
bool operator<=(const T& x, const T& y);
\end{itemdecl}
\begin{itemdescr}
\pnum
\requires
Type \tcode{T} is \tcode{LessThanComparable} (\tref{lessthancomparable}).
\pnum
\returns
\tcode{!(y < x)}.
\end{itemdescr}
\indexlibrary{\idxcode{operator>=}}%
\begin{itemdecl}
bool operator>=(const T& x, const T& y);
\end{itemdecl}
\begin{itemdescr}
\pnum
\requires
Type \tcode{T} is \tcode{LessThanComparable} (\tref{lessthancomparable}).
\pnum
\returns
\tcode{!(x < y)}.
\end{itemdescr}
\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}
\pnum
This subclause 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
Within this subclause, \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}
\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}.
\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} may 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}