1、Information technology Programming languages C+ Extensions for concepts Technologie de linformation Langages de programmation Extensions C+ pour les concepts warning ISO/IEC TS 19217 First edition 2015-11-1 5 Reference number ISO/IEC TS 19217:2015(E) TECHNICAL SPECIFICATION ISO/IEC 2015 ii ISO/IEC 2
2、015 All rights reserved COPYRIGHT PROTECTED DOCUMENT ISO/IEC 2015, Published in Switzerland 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 o
3、n the internet or an intranet, without prior written permission. Permission can be requested from either ISO at the address below or ISOs member body in the country of the requester. ISO copyright office Ch. de Blandonnet 8 CP 401 CH-1214 Vernier, Geneva, Switzerland Tel. +41 22 749 01 11 Fax +41 22
4、 749 09 47 copyrightiso.org www.iso.org ISO/IEC TS 19217:2015(E)c ISO/IEC N4549 Contents iii ivv Contents List of Tables Foreword 1 General 1 1.1 Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Normative references . . . . . . . . . . . . . .
5、 . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.3 Terms and denitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.4 Implementation compliance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.5 Feature-testing recommendations . . .
6、 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.6 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2 Lexical conventions 3 2.1 Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 5 Expr
7、essions 4 5.1 Primary expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 7 Declarations 11 7.1 Speciers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 8 Declarators 21 8.3 Meaning of declarators . . . . . . . . .
8、. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 10 Derived classes 25 10.3 Virtual functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 13 Overloading 26 13.1 Overloadable declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
9、. . . . . . 26 13.3 Overload resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 13.4 Address of overloaded function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 14 Templates 28 14.1 Template parameters . . . . . . . . . . . . . . . .
10、 . . . . . . . . . . . . . . . . . . . . . . . 28 14.2 Introduction of template parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30 14.3 Names of template specializations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 14.4 Template arguments . . . . . . . .
11、. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 14.6 Template declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 14.7 Name resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 14.8 Template instant
12、iation and specialization . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 14.9 Function template specializations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 14.10 Template constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 A C
13、ompatibility 53 A.1 C + extensions for Concepts and ISO C + 2014 . . . . . . . . . . . . . . . . . . . . . . . 53 Contents iii ISO/IEC 2015 All rights reserved ISO/IEC TS 19217:2015 (E)c ISO/IEC N4549 List of Tables A Feature-test macro(s) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14、. . . . . . . . . . . 2 10 simple-type-speciers and the types they specify . . . . . . . . . . . . . . . . . . . . . . . . . . 12 B Value of folding empty sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 List of Tables iv ISO/IEC TS 19217:2015 (E) ISO/IEC 2015 All r
15、ights reserved ISO/IEC N4549 ISO/IEC 2015 All rights reserved 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 participat
16、e 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
17、 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 th
18、e 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 possibili
19、ty 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 lis
20、t 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 wel
21、l as information about ISOs 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
22、system software interfaces. ISO/IEC TS 19217:2015 (E)c ISO/IEC N4549 1 General intro 1.1 Scope intro.scope 1 This Technical Specication describes extensions to the C + Programming Language (1.2) that enable the specication and checking of constraints on template arguments, and the ability to overloa
23、d functions and specialize class templates based on those constraints. These extensions include new syntactic forms and modications to existing language semantics. 2 The International Standard, ISO/IEC 14882, provides important context and specication for this Technical Specication. This document is
24、 written as a set of changes against that specication. Instructions to modify or add paragraphs are written as explicit instructions. Modications made directly to existing text from the International Standard use underlining to represent added text and strikethrough to represent deleted text. 3 WG21
25、 paper N4191 denes “fold expressions”, which are used to dene constraint expressions resulting from the use of constrained-parameters that declare template parameter packs. This feature is not present in ISO/IEC 14882:2014, but it is planned to be included in the next revision of that International
26、Standard. The specication of that feature is included in this document. 1.2 Normative references intro.refs 1 The following referenced document is indispensable for the application of this document. For dated refer- ences, only the edition cited applies. For undated references, the latest edition of
27、 the referenced document (including any amendments) applies. (1.1) ISO/IEC 14882:2014, Programming Languages C + ISO/IEC 14882:2014 is hereafter called the C + Standard. The numbering of Clauses, sections, and para- graphs in this document reects the numbering in the C + Standard. References to Clau
28、ses and sections not appearing in this Technical Specication refer to the original, unmodied text in the C + Standard. 1.3 Terms and denitions intro.defs Modify the denitions of “signature” to include associated constraints (14.10.2). This allows dierent trans- lation units to contain denitions of f
29、unctions with the same signature, excluding associated constraints, without violating the one denition rule (3.2). That is, without incorporating the constraints in the signa- ture, such functions would have the same mangled name, thus appearing as multiple denitions of the same function. 1.3.1 defn
30、s.signature signature name,parametertypelist(8.3.5), andenclosingnamespace(ifany),andanyassociated constraints (14.10.2) Note: Signatures are used as a basis for name mangling and linking.end note 1.3.2 defns.signature.templ signaturename, parameter type list (8.3.5), enclosing namespace (if any), r
31、eturn type, and template parameter list, and any associated constraints (14.10.2) 1.3.3 defns.signature.member 1.3 1 ISO/IEC 2015 All rights reserved ISO/IEC TS 19217:2015 (E)c ISO/IEC N4549 signaturename, parameter type list (8.3.5), class of which the function is a member, cv-qualiers (if any), an
32、d ref-qualier (if any), and any associated constraints (14.10.2) 1.3.4 defns.signature.member.templ signaturename, parameter type list (8.3.5), class of which the function is a member, cv-qualiers (if any), ref-qualier (if any), return type, and template parameter list, and any associated constraint
33、s (14.10.2) 1.4 Implementation compliance pliance 1 Conformance requirements for this specication are the same as those dened in 1.4 in the C + Standard. Note: Conformance is dened in terms of the behavior of programs. end note 1.5 Feature-testing recommendations intro.features 1 An implementation t
34、hat provides support for this Technical Specication shall dene the feature test macro(s) in Table A. Table A Feature-test macro(s) Macro name Value _cpp_concepts 201507 1.6 Acknowledgments intro.ack 1 The design of this specication is based, in part, on a concept specication of the algorithms part o
35、f the C+ standard library, known as “The Palo Alto” report (WG21 N3351), which was developed by a large group of experts as a test of the expressive power of the idea of concepts. Despite syntactic dierences between the notation of the Palo Alto report and this Technical Specication, the report can
36、be seen as a large-scale test of the expressiveness of this Technical Specication. 2 This work was funded by NSF grant ACI-1148461. 1.6 2 ISO/IEC TS 19217:2015 (E) ISO/IEC 2015 All rights reserved c ISO/IEC N4549 2 Lexical conventions lex 2.1 Keywords lex.key In 2.1, add the keywords concept and req
37、uires to Table 4. 2.1 3 ISO/IEC 2015 All rights reserved ISO/IEC TS 19217:2015 (E)c ISO/IEC N4549 5 Expressions expr Modify paragraph 8 to include a reference to requires-expressions. 1 In some contexts, unevaluated operands appear (5.1.4, 5.2.8, 5.3.3, 5.3.7). 5.1 Primary expressions expr.prim 5.1.
38、1 General expr.prim.general In this section, add the requires-expression to the rule for primary-expression. primary-expression: literal this ( expression ) id-expression lambda-expression fold-expression requires-expression In paragraph 8, add auto and constrained-type-name to nested-name-specier:
39、8 nested-name-specier: : type-name : namespace-name : decltype-specier : auto : constrained-type-name : nested-name-specier identier : nested-name-specier templateopt: Add a new paragraph after paragraph 11: 12 In a nested-name-specier of the form auto: or C:, where C is a constrained-type-name, tha
40、t nested-name-specier designates a placeholder that will be replaced later according to the rules for placeholder deduction in 7.1.6.4. If a placeholder designated by a constrained-type-specier is not a placeholder type, the program is ill-formed. Note: A constrained-type-specier can designate a pla
41、ceholder for a non-type or template (7.1.6.4.2). end note The replacement type deduced for a placeholder shall be a class or enumeration type. Example: template concept bool C = sizeof(T) = sizeof(int); template concept bool D = true; struct S1 int n; ; struct S2 char c; ; struct S3 struct X using Y
42、 = int; ; ; int auto:* p1 = / auto deduced as S1 int D:* p2 = / error: D does not designate a placeholder type int C:* p3 = / OK: C deduced as S1 char C:* p4 = / error: deduction fails because constraints are not satised 5.1.1 4 ISO/IEC TS 19217:2015 (E) ISO/IEC 2015 All rights reserved c ISO/IEC N4
43、549 void f(typename auto:X:Y); f(S1(); / error: auto cannot be deduced from S1() f(0); / OK In the declaration of f, the placeholder appears in a non-deduced context (14.8.2.5). It may be replaced later through the explicit specication of template arguments. end example Add a new paragraph after par
44、agraph 13: 14 A program that refers explicitly or implicitly to a function with associated constraints that are not satised (14.10.2), other than to declare it, is ill-formed. Example: void f(int) requires false; f(0); / error: cannot call f void (*p1)(int) = f; / error: cannot take the address of f
45、 decltype(f)* p2 = nullptr; / error: the type decltype(f) is invalid In each case the associated constraints of f are not satised. In the declaration of p2, those constraints are required to be satised even though f is an unevaluated operand (Clause 5). end example 5.1.2 Lambda expressions expr.prim
46、.lambda Insert the following paragraph after paragraph 4 to dene the term “generic lambda”. 5 A generic lambda is a lambda-expression where one or more placeholders (7.1.6.4) appear in the parameter-type-list of the lambda-declarator. Modify paragraph 5 so that the meaning of a generic lambda is den
47、ed in terms of its abbreviated member function template call operator. The closure type for a non-generic lambda-expression has a public inline function call operator (13.5.4) whose parameters and return type are described by the lambda-expressions parameter- declaration-clause and trailing-return-t
48、ype, respectively. For a generic lambda, the closure type hasapublic inline function calloperatormembertemplate (14.5.2)whosetemplate-parameter-list consists of one invented type template-parameter for each occurrence of auto in the lambdas parameter-declaration-clause, in order of appearance. The invented type template-parameter is a parameter pack if the corresponding parameter-declaration declares a function parameter pack (8.3.5). The return type and function parameters of the function call operator template are derived from the