Đăng ký Đăng nhập
Trang chủ Công nghệ thông tin Kỹ thuật lập trình ISO/IEC 14882-2014. Information technology – Programming languages – C++...

Tài liệu ISO/IEC 14882-2014. Information technology – Programming languages – C++

.PDF
1375
374
115

Mô tả:

ISO/IEC 14882:2014 specifies requirements for implementations of the C++ programming language. The first such requirement is that they implement the language, and so this International Standard also defines C++. Other requirements and relaxations of the first requirement appear at various places within this International Standard. C++ is a general purpose programming language based on the C programming language as described in ISO/IEC 9899:1999 Programming languages ? C (hereinafter referred to as the C standard). In addition to the facilities provided by C, C++ provides additional data types, classes, templates, exceptions, namespaces, operator overloading, function name overloading, references, free store management operators, and additional library facilities.
INTERNATIONAL STANDARD ISO/IEC 14882 Fourth edition 2014-12-15 Information technology — Programming languages — C++ Technologies de l'information — Langages de programmation — C++ Reference number ISO/IEC 14882:2014(E) © ISO/IEC 2014 ISO/IEC 14882:2014(E) COPYRIGHT PROTECTED DOCUMENT © ISO/IEC 2014 All rights reserved. Unless otherwise specified, no part of this publication may be reproduced or utilized otherwise in any form or by any means, electronic or mechanical, including photocopying, or posting on the internet or an intranet, without prior written permission. Permission can be requested from either ISO at the address below or ISO’s member body in the country of the requester. ISO copyright office Case postale 56  CH-1211 Geneva 20 Tel. + 41 22 749 01 11 Fax + 41 22 749 09 47 E-mail [email protected] Web www.iso.org Published in Switzerland ii © ISO/IEC 2014 – All rights reserved ISO/IEC 14882:2014(E) Contents Contents iii List of Tables xi List of Figures xv Foreword xvi 1 General 1.1 Scope . . . . . . . . . . . . . . . . . . . . 1.2 Normative references . . . . . . . . . . . . 1.3 Terms and definitions . . . . . . . . . . . . 1.4 Implementation compliance . . . . . . . . 1.5 Structure of this International Standard . 1.6 Syntax notation . . . . . . . . . . . . . . . 1.7 The C++ memory model . . . . . . . . . . 1.8 The C++ object model . . . . . . . . . . . 1.9 Program execution . . . . . . . . . . . . . 1.10 Multi-threaded executions and data races 1.11 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 1 2 5 5 6 6 7 8 11 15 2 Lexical conventions 2.1 Separate translation . . . . 2.2 Phases of translation . . . . 2.3 Character sets . . . . . . . . 2.4 Trigraph sequences . . . . . 2.5 Preprocessing tokens . . . . 2.6 Alternative tokens . . . . . 2.7 Tokens . . . . . . . . . . . . 2.8 Comments . . . . . . . . . . 2.9 Header names . . . . . . . . 2.10 Preprocessing numbers . . . 2.11 Identifiers . . . . . . . . . . 2.12 Keywords . . . . . . . . . . 2.13 Operators and punctuators 2.14 Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 16 16 17 18 19 20 20 20 20 21 21 22 22 23 3 Basic 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 32 34 37 42 56 59 62 66 Contents concepts Declarations and definitions One definition rule . . . . . Scope . . . . . . . . . . . . Name lookup . . . . . . . . Program and linkage . . . . Start and termination . . . Storage duration . . . . . . Object lifetime . . . . . . . c ISO/IEC 2014 – All rights reserved iii ISO/IEC 14882:2014(E) 3.9 3.10 3.11 Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Lvalues and rvalues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 Standard conversions 4.1 Lvalue-to-rvalue conversion . . 4.2 Array-to-pointer conversion . . 4.3 Function-to-pointer conversion . 4.4 Qualification conversions . . . . 4.5 Integral promotions . . . . . . . 4.6 Floating point promotion . . . 4.7 Integral conversions . . . . . . . 4.8 Floating point conversions . . . 4.9 Floating-integral conversions . . 4.10 Pointer conversions . . . . . . . 4.11 Pointer to member conversions 4.12 Boolean conversions . . . . . . 4.13 Integer conversion rank . . . . . 69 75 76 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 79 79 79 80 81 81 81 82 82 82 82 83 83 5 Expressions 5.1 Primary expressions . . . . . . . . . . . . . . . . 5.2 Postfix expressions . . . . . . . . . . . . . . . . . 5.3 Unary expressions . . . . . . . . . . . . . . . . . . 5.4 Explicit type conversion (cast notation) . . . . . 5.5 Pointer-to-member operators . . . . . . . . . . . 5.6 Multiplicative operators . . . . . . . . . . . . . . 5.7 Additive operators . . . . . . . . . . . . . . . . . 5.8 Shift operators . . . . . . . . . . . . . . . . . . . 5.9 Relational operators . . . . . . . . . . . . . . . . 5.10 Equality operators . . . . . . . . . . . . . . . . . 5.11 Bitwise AND operator . . . . . . . . . . . . . . . 5.12 Bitwise exclusive OR operator . . . . . . . . . . . 5.13 Bitwise inclusive OR operator . . . . . . . . . . . 5.14 Logical AND operator . . . . . . . . . . . . . . . 5.15 Logical OR operator . . . . . . . . . . . . . . . . 5.16 Conditional operator . . . . . . . . . . . . . . . . 5.17 Assignment and compound assignment operators 5.18 Comma operator . . . . . . . . . . . . . . . . . . 5.19 Constant expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 87 97 108 117 118 118 119 120 120 121 122 122 122 123 123 123 125 126 126 6 Statements 6.1 Labeled statement . . . . . . 6.2 Expression statement . . . . . 6.3 Compound statement or block 6.4 Selection statements . . . . . 6.5 Iteration statements . . . . . 6.6 Jump statements . . . . . . . 6.7 Declaration statement . . . . 6.8 Ambiguity resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130 130 130 130 131 132 135 136 137 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Declarations Contents 139 c ISO/IEC 2014 – All rights reserved iv ISO/IEC 14882:2014(E) 7.1 7.2 7.3 7.4 7.5 7.6 Specifiers . . . . . . . . . Enumeration declarations Namespaces . . . . . . . . The asm declaration . . . Linkage specifications . . Attributes . . . . . . . . . 8 Declarators 8.1 Type names . . . . . . 8.2 Ambiguity resolution . 8.3 Meaning of declarators 8.4 Function definitions . . 8.5 Initializers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 157 161 173 173 176 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 182 183 184 196 199 9 Classes 9.1 Class names . . . . . . . 9.2 Class members . . . . . 9.3 Member functions . . . . 9.4 Static members . . . . . 9.5 Unions . . . . . . . . . . 9.6 Bit-fields . . . . . . . . . 9.7 Nested class declarations 9.8 Local class declarations 9.9 Nested type names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 216 218 220 223 224 226 227 228 228 10 Derived classes 10.1 Multiple base classes . 10.2 Member name lookup 10.3 Virtual functions . . . 10.4 Abstract classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230 231 233 236 240 . . . . . . . . . . . . base class members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242 243 244 247 250 251 251 251 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253 253 255 258 260 263 265 270 273 280 . . . . 11 Member access control 11.1 Access specifiers . . . . . . . . . 11.2 Accessibility of base classes and 11.3 Friends . . . . . . . . . . . . . . 11.4 Protected member access . . . . 11.5 Access to virtual functions . . . 11.6 Multiple access . . . . . . . . . 11.7 Nested classes . . . . . . . . . . 12 Special member functions 12.1 Constructors . . . . . . . . . . . 12.2 Temporary objects . . . . . . . . 12.3 Conversions . . . . . . . . . . . . 12.4 Destructors . . . . . . . . . . . . 12.5 Free store . . . . . . . . . . . . . 12.6 Initialization . . . . . . . . . . . . 12.7 Construction and destruction . . 12.8 Copying and moving class objects 12.9 Inheriting constructors . . . . . . Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c ISO/IEC 2014 – All rights reserved v ISO/IEC 14882:2014(E) 13 Overloading 13.1 Overloadable declarations . . . 13.2 Declaration matching . . . . . . 13.3 Overload resolution . . . . . . . 13.4 Address of overloaded function 13.5 Overloaded operators . . . . . . 13.6 Built-in operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 284 286 287 307 308 312 14 Templates 14.1 Template parameters . . . . . . . . . . . . 14.2 Names of template specializations . . . . . 14.3 Template arguments . . . . . . . . . . . . 14.4 Type equivalence . . . . . . . . . . . . . . 14.5 Template declarations . . . . . . . . . . . 14.6 Name resolution . . . . . . . . . . . . . . . 14.7 Template instantiation and specialization 14.8 Function template specializations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 317 320 322 328 329 346 359 371 15 Exception handling 15.1 Throwing an exception . . . . 15.2 Constructors and destructors 15.3 Handling an exception . . . . 15.4 Exception specifications . . . 15.5 Special functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392 393 395 395 397 400 16 Preprocessing directives 16.1 Conditional inclusion . . 16.2 Source file inclusion . . . 16.3 Macro replacement . . . 16.4 Line control . . . . . . . 16.5 Error directive . . . . . 16.6 Pragma directive . . . . 16.7 Null directive . . . . . . 16.8 Predefined macro names 16.9 Pragma operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 403 404 405 406 411 412 412 412 412 413 17 Library introduction 17.1 General . . . . . . . . . . . . . . . . 17.2 The C standard library . . . . . . . . 17.3 Definitions . . . . . . . . . . . . . . . 17.4 Additional definitions . . . . . . . . . 17.5 Method of description (Informative) 17.6 Library-wide requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414 414 415 415 418 418 423 18 Language support library 18.1 General . . . . . . . . . . . . . 18.2 Types . . . . . . . . . . . . . . 18.3 Implementation properties . . . 18.4 Integer types . . . . . . . . . . 18.5 Start and termination . . . . . 18.6 Dynamic memory management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443 443 443 444 453 455 456 Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c ISO/IEC 2014 – All rights reserved vi ISO/IEC 14882:2014(E) 18.7 18.8 18.9 18.10 Type identification . . Exception handling . . Initializer lists . . . . . Other runtime support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 463 465 470 471 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474 474 474 478 478 478 20 General utilities library 20.1 General . . . . . . . . . . . . . . . . . . . . 20.2 Utility components . . . . . . . . . . . . . . 20.3 Pairs . . . . . . . . . . . . . . . . . . . . . . 20.4 Tuples . . . . . . . . . . . . . . . . . . . . . 20.5 Compile-time integer sequences . . . . . . . 20.6 Class template bitset . . . . . . . . . . . . 20.7 Memory . . . . . . . . . . . . . . . . . . . . 20.8 Smart pointers . . . . . . . . . . . . . . . . 20.9 Function objects . . . . . . . . . . . . . . . 20.10 Metaprogramming and type traits . . . . . 20.11 Compile-time rational arithmetic . . . . . . 20.12 Time utilities . . . . . . . . . . . . . . . . . 20.13 Class template scoped_allocator_adaptor 20.14 Class type_index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490 490 490 495 500 510 511 519 534 562 584 603 606 622 629 21 Strings library 21.1 General . . . . . . . . . . . . . . 21.2 Character traits . . . . . . . . . . 21.3 String classes . . . . . . . . . . . 21.4 Class template basic_string . . 21.5 Numeric conversions . . . . . . . 21.6 Hash support . . . . . . . . . . . 21.7 Suffix for basic_string literals . 21.8 Null-terminated sequence utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631 631 631 637 641 669 671 671 671 22 Localization library 22.1 General . . . . . . . . . . . . . 22.2 Header synopsis . . . 22.3 Locales . . . . . . . . . . . . . . 22.4 Standard locale categories . . 22.5 Standard code conversion facets 22.6 C library locales . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675 675 675 676 689 729 731 23 Containers library 23.1 General . . . . . . . . . 23.2 Container requirements . 23.3 Sequence containers . . 23.4 Associative containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 732 732 732 760 791 19 Diagnostics library 19.1 General . . . . . . . 19.2 Exception classes . . 19.3 Assertions . . . . . . 19.4 Error numbers . . . 19.5 System error support Contents . . . . . . . . . . . . . . . . . . . . . c ISO/IEC 2014 – All rights reserved vii ISO/IEC 14882:2014(E) 23.5 23.6 Unordered associative containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 808 Container adaptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 825 24 Iterators library 24.1 General . . . . . . . . . . . . 24.2 Iterator requirements . . . . . 24.3 Header synopsis . 24.4 Iterator primitives . . . . . . 24.5 Iterator adaptors . . . . . . . 24.6 Stream iterators . . . . . . . . 24.7 range access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 835 835 835 840 843 847 860 867 25 Algorithms library 25.1 General . . . . . . . . . . . . . . . 25.2 Non-modifying sequence operations 25.3 Mutating sequence operations . . . 25.4 Sorting and related operations . . . 25.5 C library algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 869 869 880 885 893 906 26 Numerics library 26.1 General . . . . . . . . . . . . . 26.2 Numeric type requirements . . 26.3 The floating-point environment 26.4 Complex numbers . . . . . . . . 26.5 Random number generation . . 26.6 Numeric arrays . . . . . . . . . 26.7 Generalized numeric operations 26.8 C library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 908 908 908 909 910 921 966 987 990 27 Input/output library 27.1 General . . . . . . . . . . . . 27.2 Iostreams requirements . . . . 27.3 Forward declarations . . . . . 27.4 Standard iostream objects . . 27.5 Iostreams base classes . . . . 27.6 Stream buffers . . . . . . . . . 27.7 Formatting and manipulators 27.8 String-based streams . . . . . 27.9 File-based streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 995 995 995 996 998 1000 1019 1029 1058 1069 28 Regular expressions library 28.1 General . . . . . . . . . . . . . . . . 28.2 Definitions . . . . . . . . . . . . . . . 28.3 Requirements . . . . . . . . . . . . . 28.4 Header synopsis . . . . . . . 28.5 Namespace std::regex_constants . 28.6 Class regex_error . . . . . . . . . . 28.7 Class template regex_traits . . . . 28.8 Class template basic_regex . . . . . 28.9 Class template sub_match . . . . . . 28.10 Class template match_results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1085 1085 1085 1086 1088 1095 1098 1098 1101 1108 1114 Contents . . . . . . . . . . . . . . . . . . . . . . . c ISO/IEC 2014 – All rights reserved viii ISO/IEC 14882:2014(E) 28.11 Regular expression algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1120 28.12 Regular expression iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1125 28.13 Modified ECMAScript regular expression grammar . . . . . . . . . . . . . . . . . . . . . . . 1131 29 Atomic operations library 29.1 General . . . . . . . . . . . 29.2 Header synopsis . 29.3 Order and consistency . . . 29.4 Lock-free property . . . . . 29.5 Atomic types . . . . . . . . 29.6 Operations on atomic types 29.7 Flag type and operations . . 29.8 Fences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1134 1134 1134 1137 1139 1139 1143 1149 1150 30 Thread support library 30.1 General . . . . . . . 30.2 Requirements . . . . 30.3 Threads . . . . . . . 30.4 Mutual exclusion . . 30.5 Condition variables . 30.6 Futures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1151 1151 1151 1154 1159 1179 1187 A Grammar summary A.1 Keywords . . . . . . . . . A.2 Lexical conventions . . . . A.3 Basic concepts . . . . . . . A.4 Expressions . . . . . . . . A.5 Statements . . . . . . . . A.6 Declarations . . . . . . . . A.7 Declarators . . . . . . . . A.8 Classes . . . . . . . . . . . A.9 Derived classes . . . . . . A.10 Special member functions A.11 Overloading . . . . . . . . A.12 Templates . . . . . . . . . A.13 Exception handling . . . . A.14 Preprocessing directives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1205 1205 1205 1209 1210 1213 1214 1218 1220 1220 1221 1221 1222 1222 1223 . . . . . . . . . . . . B Implementation quantities 1225 C Compatibility C.1 C++ and ISO C . . . . . C.2 C++ and ISO C++ 2003 C.3 C++ and ISO C++ 2011 C.4 C standard library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1227 1227 1235 1242 1243 D Compatibility features D.1 Increment operator with bool operand D.2 register keyword . . . . . . . . . . . D.3 Implicit declaration of copy functions . D.4 Dynamic exception specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1247 1247 1247 1247 1247 Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . c ISO/IEC 2014 – All rights reserved ix ISO/IEC 14882:2014(E) D.5 D.6 D.7 D.8 D.9 D.10 D.11 D.12 C standard library headers . . . . Old iostreams members . . . . . char* streams . . . . . . . . . . . Function objects . . . . . . . . . Binders . . . . . . . . . . . . . . auto_ptr . . . . . . . . . . . . . Violating exception-specifications Random shuffle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1247 1248 1249 1258 1262 1263 1266 1266 E Universal character names for identifier characters 1268 E.1 Ranges of characters allowed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1268 E.2 Ranges of characters disallowed initially . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1268 F Cross references 1269 Index 1287 Index of grammar productions 1316 Index of library names 1319 Index of implementation-defined behavior 1356 Contents c ISO/IEC 2014 – All rights reserved x ISO/IEC 14882:2014(E) List of Tables 1 2 3 4 5 6 7 8 Trigraph sequences . . . . . . . Alternative tokens . . . . . . . Identifiers with special meaning Keywords . . . . . . . . . . . . Alternative representations . . Types of integer literals . . . . Escape sequences . . . . . . . . String literal concatenations . . . . . . . . . . 18 20 22 22 22 24 26 29 9 Relations on const and volatile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 10 simple-type-specifiers and the types they specify . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 11 12 Relationship between operator and function call notation . . . . . . . . . . . . . . . . . . . . . . 292 Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Library categories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C++ library headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C++ headers for C library facilities . . . . . . . . . . . . . . . . . . . . . C++ headers for freestanding implementations . . . . . . . . . . . . . . EqualityComparable requirements . . . . . . . . . . . . . . . . . . . . . LessThanComparable requirements . . . . . . . . . . . . . . . . . . . . . DefaultConstructible requirements . . . . . . . . . . . . . . . . . . . MoveConstructible requirements . . . . . . . . . . . . . . . . . . . . . CopyConstructible requirements (in addition to MoveConstructible) MoveAssignable requirements . . . . . . . . . . . . . . . . . . . . . . . CopyAssignable requirements (in addition to MoveAssignable) . . . . Destructible requirements . . . . . . . . . . . . . . . . . . . . . . . . . NullablePointer requirements . . . . . . . . . . . . . . . . . . . . . . . Hash requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Descriptive variable definitions . . . . . . . . . . . . . . . . . . . . . . . Allocator requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414 424 424 425 426 426 427 427 427 427 427 427 429 430 430 431 29 30 31 32 33 34 35 36 37 38 39 40 Language support library summary Header synopsis . . . . Header synopsis . . . . Header synopsis . . . . . Header synopsis . . . . Header synopsis . . . . Header synopsis . . . . Header synopsis . . . Header synopsis . . . . Header synopsis . . . Header synopsis . . . . Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 443 443 453 453 455 472 472 472 472 473 473 473 List of Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c ISO/IEC 2014 – All rights reserved . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi ISO/IEC 14882:2014(E) 41 42 43 Diagnostics library summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 474 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 478 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 General utilities library summary . . . . . . . Header synopsis . . . . . . . . . . Header synopsis . . . . . . . . . . Primary type category predicates . . . . . . . Composite type category predicates . . . . . Type property predicates . . . . . . . . . . . Type property queries . . . . . . . . . . . . . Type relationship predicates . . . . . . . . . . Const-volatile modifications . . . . . . . . . . Reference modifications . . . . . . . . . . . . Sign modifications . . . . . . . . . . . . . . . Array modifications . . . . . . . . . . . . . . Pointer modifications . . . . . . . . . . . . . . Other transformations . . . . . . . . . . . . . Expressions used to perform ratio arithmetic Clock requirements . . . . . . . . . . . . . . . Header synopsis . . . . . . . . . . . 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 Strings library summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 631 Character traits requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 632 basic_string(const Allocator&) effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645 basic_string(const basic_string&) effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . 646 basic_string(const basic_string&, size_type, size_type, const Allocator&) effects . 646 basic_string(const charT*, size_type, const Allocator&) effects . . . . . . . . . . . . . . 647 basic_string(const charT*, const Allocator&) effects . . . . . . . . . . . . . . . . . . . . . 647 basic_string(size_t, charT, const Allocator&) effects . . . . . . . . . . . . . . . . . . . . 647 basic_string(const basic_string&, const Allocator&) and basic_string(basic_string&&, const Allocator&) effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 648 operator=(const basic_string&) effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 648 operator=(basic_string&&) effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 649 compare() results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663 Potential mbstate_t data races . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 673 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 674 80 81 82 83 84 85 86 87 Localization library summary Locale category facets . . . . Required specializations . . . do_in/do_out result values . do_unshift result values . . Integer conversions . . . . . . Length modifier . . . . . . . . Integer conversions . . . . . . List of Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c ISO/IEC 2014 – All rights reserved . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490 533 534 588 589 590 596 597 598 598 599 600 600 601 605 609 622 675 679 679 699 699 703 703 707 xii ISO/IEC 14882:2014(E) 88 89 90 91 92 93 94 Floating-point conversions . . . Length modifier . . . . . . . . . Numeric conversions . . . . . . Fill padding . . . . . . . . . . . do_get_date effects . . . . . . Header synopsis . . Potential setlocale data races . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 707 708 708 709 716 731 731 95 96 97 98 99 100 101 102 103 Containers library summary . . . . . . . . . . . . . . . . . . . . . . . . . Container requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . Reversible container requirements . . . . . . . . . . . . . . . . . . . . . . Optional container operations . . . . . . . . . . . . . . . . . . . . . . . . Allocator-aware container requirements . . . . . . . . . . . . . . . . . . Sequence container requirements (in addition to container) . . . . . . . Optional sequence container operations . . . . . . . . . . . . . . . . . . Associative container requirements (in addition to container) . . . . . . Unordered associative container requirements (in addition to container) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 732 733 735 736 738 740 742 744 752 104 105 106 107 108 109 110 111 Iterators library summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . Relations among iterator categories . . . . . . . . . . . . . . . . . . . . . . . Iterator requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Input iterator requirements (in addition to Iterator) . . . . . . . . . . . . . Output iterator requirements (in addition to Iterator) . . . . . . . . . . . . Forward iterator requirements (in addition to input iterator) . . . . . . . . Bidirectional iterator requirements (in addition to forward iterator) . . . . . Random access iterator requirements (in addition to bidirectional iterator) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 835 835 836 837 838 839 839 840 112 Algorithms library summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 869 113 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906 114 115 116 117 118 119 120 Numerics library summary . . . . . . . . . . . . Seed sequence requirements . . . . . . . . . . . . Uniform random number generator requirements Random number engine requirements . . . . . . Random number distribution requirements . . . Header synopsis . . . . . . . . . . . . . Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 908 923 924 925 928 991 991 121 122 123 124 125 126 127 128 129 130 131 132 133 Input/output library summary fmtflags effects . . . . . . . . fmtflags constants . . . . . . iostate effects . . . . . . . . . openmode effects . . . . . . . . seekdir effects . . . . . . . . . Position type requirements . . basic_ios::init() effects . . basic_ios::copyfmt() effects seekoff positioning . . . . . . newoff values . . . . . . . . . . File open modes . . . . . . . . seekoff effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 995 1005 1005 1005 1005 1006 1010 1012 1014 1062 1063 1073 1075 List of Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c ISO/IEC 2014 – All rights reserved xiii ISO/IEC 14882:2014(E) 134 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1083 135 Header synopsis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1084 136 137 138 139 140 141 142 143 144 Regular expressions library summary . . . . . . . . . . . . . . Regular expression traits class requirements . . . . . . . . . . syntax_option_type effects . . . . . . . . . . . . . . . . . . regex_constants::match_flag_type effects when obtaining tainer sequence [first,last). . . . . . . . . . . . . . . . . . error_type values in the C locale . . . . . . . . . . . . . . . Character class names and corresponding ctype masks . . . . match_results assignment operator effects . . . . . . . . . . Effects of regex_match algorithm . . . . . . . . . . . . . . . Effects of regex_search algorithm . . . . . . . . . . . . . . . . . . a . . . . . . . . . . . . . . . . . . match . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . against a character con. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1096 1097 1102 1117 1120 1122 145 146 147 148 Atomics library summary . . . . atomic integral typedefs . . . . . atomic typedefs . Atomic arithmetic computations . . . . . . . . . . . . 1134 1143 1144 1148 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1085 1086 1096 149 Thread support library summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1151 150 151 152 153 154 Standard Standard Standard Standard Standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1243 1243 1244 1244 1245 155 156 157 158 159 160 C headers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . strstreambuf(streamsize) effects . . . . . . . . . . . . . . . . strstreambuf(void* (*)(size_t), void (*)(void*)) effects strstreambuf(charT*, streamsize, charT*) effects . . . . . . seekoff positioning . . . . . . . . . . . . . . . . . . . . . . . . . newoff values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1247 1251 1251 1251 1254 1254 List of Tables macros . values . . types . . structs . functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c ISO/IEC 2014 – All rights reserved xiv ISO/IEC 14882:2014(E) List of Figures 1 Expression category taxonomy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 3 4 5 6 Directed acyclic graph . . . . Non-virtual base . . . . . . . Virtual base . . . . . . . . . . Virtual and non-virtual base Name lookup . . . . . . . . . 7 Stream position, offset, and size types [non-normative] . . . . . . . . . . . . . . . . . . . . . . . . 995 List of Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . c ISO/IEC 2014 – All rights reserved . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 231 232 233 233 235 xv ISO/IEC 14882:2014(E) Foreword ISO (the International Organization for Standardization) and IEC (the International Electrotechnical Commission) form the specialized system for worldwide standardization. National bodies that are members of ISO or IEC participate in the development of International Standards through technical committees established by the respective organization to deal with particular fields of technical activity. ISO and IEC technical committees collaborate in fields of mutual interest. Other international organizations, governmental and non-governmental, in liaison with ISO and IEC, also take part in the work. In the field of information technology, ISO and IEC have established a joint technical committee, ISO/IEC JTC 1. The procedures used to develop this document and those intended for its further maintenance are described in the ISO/IEC Directives, Part 1. In particular the different approval criteria needed for the different types of document should be noted. This document was drafted in accordance with the editorial rules of the ISO/IEC Directives, Part 2 (see www.iso.org/directives). Attention is drawn to the possibility that some of the elements of this document may be the subject of patent rights. ISO and IEC shall not be held responsible for identifying any or all such patent rights. Details of any patent rights identified during the development of the document will be in the Introduction and/or on the ISO list of patent declarations received (see www.iso.org/patents). Any trade name used in this document is information given for the convenience of users and does not constitute an endorsement. For an explanation on the meaning of ISO specific terms and expressions related to conformity assessment, as well as information about ISO’s adherence to the WTO principles in the Technical Barriers to Trade (TBT) see the following URL: Foreword - Supplementary information The committee responsible for this document is ISO/IEC JTC 1, Information technology, SC 22, Programming languages, their environments and system software interfaces This fourth edition cancels and replaces the third edition (ISO/IEC 14882:2011), of which it constitutes a minor revision. Foreword c ISO/IEC 2014 – All rights reserved xvi ISO/IEC 14882:2014(E) 1 1.1 1 2 [intro] Scope [intro.scope] This International Standard specifies requirements for implementations of the C++ programming language. The first such requirement is that they implement the language, and so this International Standard also defines C++. Other requirements and relaxations of the first requirement appear at various places within this International Standard. C++ is a general purpose programming language based on the C programming language as described in ISO/IEC 9899:1999 Programming languages — C (hereinafter referred to as the C standard). In addition to the facilities provided by C, C++ provides additional data types, classes, templates, exceptions, namespaces, operator overloading, function name overloading, references, free store management operators, and additional library facilities. 1.2 1 General Normative references [intro.refs] The following referenced documents are indispensable for the application of this document. For dated references, only the edition cited applies. For undated references, the latest edition of the referenced document (including any amendments) applies. — Ecma International, ECMAScript Language Specification, Standard Ecma-262, third edition, 1999. — ISO/IEC 2382 (all parts), Information technology — Vocabulary — ISO/IEC 9899:1999, Programming languages — C — ISO/IEC 9899:1999/Cor.1:2001(E), Programming languages — C, Technical Corrigendum 1 — ISO/IEC 9899:1999/Cor.2:2004(E), Programming languages — C, Technical Corrigendum 2 — ISO/IEC 9899:1999/Cor.3:2007(E), Programming languages — C, Technical Corrigendum 3 — ISO/IEC 9945:2003, Information Technology — Portable Operating System Interface (POSIX) — ISO/IEC 10646-1:1993, Information technology — Universal Multiple-Octet Coded Character Set (UCS) — Part 1: Architecture and Basic Multilingual Plane — ISO/IEC TR 19769:2004, Information technology — Programming languages, their environments and system software interfaces — Extensions for the programming language C to support new character data types 2 3 4 5 The library described in Clause 7 of ISO/IEC 9899:1999 and Clause 7 of ISO/IEC 9899:1999/Cor.1:2001 and Clause 7 of ISO/IEC 9899:1999/Cor.2:2003 is hereinafter called the C standard library.1 The library described in ISO/IEC TR 19769:2004 is hereinafter called the C Unicode TR. The operating system interface described in ISO/IEC 9945:2003 is hereinafter called POSIX . The ECMAScript Language Specification described in Standard Ecma-262 is hereinafter called ECMA-262 . 1) With the qualifications noted in Clauses 18 through 30 and in C.4, the C standard library is a subset of the C++ standard library. § 1.2 c ISO/IEC 2014 – All rights reserved 1 ISO/IEC 14882:2014(E) 1.3 1 2 3 Terms and definitions [intro.defs] For the purposes of this document, the following definitions apply. 17.3 defines additional terms that are used only in Clauses 17 through 30 and Annex D. Terms that are used only in a small portion of this International Standard are defined where they are used and italicized where they are defined. 1.3.1 [defns.argument] argument actual argument actual parameter expression in the comma-separated list bounded by the parentheses 1.3.2 [defns.argument.macro] argument actual argument actual parameter sequence of preprocessing tokens in the comma-separated list bounded by the parentheses 1.3.3 argument actual argument actual parameter the operand of throw [defns.argument.throw] 1.3.4 [defns.argument.templ] argument actual argument actual parameter