Init
This commit is contained in:
59
cppdraft/over/assign.md
Normal file
59
cppdraft/over/assign.md
Normal file
@@ -0,0 +1,59 @@
|
||||
[over.assign]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.4 Overloaded operators [[over.oper]](over.oper#over.assign)
|
||||
|
||||
### 12.4.3 Binary operators [[over.binary]](over.binary#over.assign)
|
||||
|
||||
#### 12.4.3.2 Simple assignment [over.assign]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3566)
|
||||
|
||||
A [*simple assignment operator function*](#def:operator_function,simple_assignment "12.4.3.2 Simple assignment [over.assign]") is a binary operator function named operator=[.](#1.sentence-1)
|
||||
|
||||
A simple assignment operator function shall be a non-static member function[.](#1.sentence-2)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
Because only standard conversion sequences are considered when converting
|
||||
to the left operand of an assignment operation ([[over.best.ics]](over.best.ics "12.2.4.2 Implicit conversion sequences")),
|
||||
an expression x = y with a subexpression x of class type
|
||||
is always interpreted as x.operator=(y)[.](#1.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3577)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
Since a copy assignment operator is implicitly declared for a class
|
||||
if not declared by the user ([[class.copy.assign]](class.copy.assign "11.4.6 Copy/move assignment operator")),
|
||||
a base class assignment operator function is always hidden by
|
||||
the copy assignment operator function of the derived class[.](#2.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3585)
|
||||
|
||||
[*Note [3](#note-3)*:
|
||||
|
||||
Any assignment operator function, even the copy and move assignment operators,
|
||||
can be virtual[.](#3.sentence-1)
|
||||
|
||||
For a derived class D with a base class B for which a virtual copy/move assignment has been declared,
|
||||
the copy/move assignment operator in D does not overrideB's virtual copy/move assignment operator[.](#3.sentence-2)
|
||||
|
||||
[*Example [1](#example-1)*: struct B {virtual int operator= (int); virtual B& operator= (const B&);};struct D : B {virtual int operator= (int); virtual D& operator= (const B&);};
|
||||
|
||||
D dobj1;
|
||||
D dobj2;
|
||||
B* bptr = &dobj1;void f() { bptr->operator=(99); // calls D::operator=(int)*bptr = 99; // ditto bptr->operator=(dobj2); // calls D::operator=(const B&)*bptr = dobj2; // ditto dobj1 = dobj2; // calls implicitly-declared D::operator=(const D&)} â *end example*]
|
||||
|
||||
â *end note*]
|
||||
675
cppdraft/over/best/ics.md
Normal file
675
cppdraft/over/best/ics.md
Normal file
@@ -0,0 +1,675 @@
|
||||
[over.best.ics]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#over.best.ics)
|
||||
|
||||
### 12.2.4 Best viable function [[over.match.best]](over.match.best#over.best.ics)
|
||||
|
||||
#### 12.2.4.2 Implicit conversion sequences [over.best.ics]
|
||||
|
||||
#### [12.2.4.2.1](#general) General [[over.best.ics.general]](over.best.ics.general)
|
||||
|
||||
[1](#general-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2095)
|
||||
|
||||
An [*implicit conversion sequence*](#def:conversion_sequence,implicit "12.2.4.2.1 General [over.best.ics.general]") is a sequence of conversions used
|
||||
to convert an argument in a function call to the type of the
|
||||
corresponding parameter of the function being called[.](#general-1.sentence-1)
|
||||
|
||||
The
|
||||
sequence of conversions is an implicit conversion as defined in[[conv]](conv "7.3 Standard conversions"), which means it is governed by the rules for
|
||||
initialization of an object or reference by a single
|
||||
expression ([[dcl.init]](dcl.init "9.5 Initializers"), [[dcl.init.ref]](dcl.init.ref "9.5.4 References"))[.](#general-1.sentence-2)
|
||||
|
||||
[2](#general-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2106)
|
||||
|
||||
Implicit conversion sequences are concerned only with the type,
|
||||
cv-qualification, and value category of the argument and how these
|
||||
are converted to match the corresponding properties of the
|
||||
parameter[.](#general-2.sentence-1)
|
||||
|
||||
[*Note [1](#general-note-1)*:
|
||||
|
||||
Other properties, such as the lifetime, storage duration, linkage,
|
||||
alignment, accessibility of the argument, whether the argument is a bit-field,
|
||||
and whether a function is [deleted](dcl.fct.def.delete "9.6.3 Deleted definitions [dcl.fct.def.delete]"), are ignored[.](#general-2.sentence-2)
|
||||
|
||||
So, although an implicit
|
||||
conversion sequence can be defined for a given argument-parameter
|
||||
pair, the conversion from the argument to the parameter might still
|
||||
be ill-formed in the final analysis[.](#general-2.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[3](#general-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2121)
|
||||
|
||||
A
|
||||
well-formed implicit conversion
|
||||
sequence is one of the following forms:
|
||||
|
||||
- [(3.1)](#general-3.1)
|
||||
|
||||
a [standard conversion sequence](#over.ics.scs "12.2.4.2.2 Standard conversion sequences [over.ics.scs]"),
|
||||
|
||||
- [(3.2)](#general-3.2)
|
||||
|
||||
a [user-defined conversion sequence](#over.ics.user "12.2.4.2.3 User-defined conversion sequences [over.ics.user]"), or
|
||||
|
||||
- [(3.3)](#general-3.3)
|
||||
|
||||
an [ellipsis conversion sequence](#over.ics.ellipsis "12.2.4.2.4 Ellipsis conversion sequences [over.ics.ellipsis]")[.](#general-3.sentence-1)
|
||||
|
||||
[4](#general-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2134)
|
||||
|
||||
However, if the target is
|
||||
|
||||
- [(4.1)](#general-4.1)
|
||||
|
||||
the first parameter of a constructor or
|
||||
|
||||
- [(4.2)](#general-4.2)
|
||||
|
||||
the object parameter of a user-defined conversion function
|
||||
|
||||
and the constructor or user-defined conversion function is a candidate by
|
||||
|
||||
- [(4.3)](#general-4.3)
|
||||
|
||||
[[over.match.ctor]](over.match.ctor "12.2.2.4 Initialization by constructor"), when the argument is the temporary in the second
|
||||
step of a class copy-initialization,
|
||||
|
||||
- [(4.4)](#general-4.4)
|
||||
|
||||
[[over.match.copy]](over.match.copy "12.2.2.5 Copy-initialization of class by user-defined conversion"), [[over.match.conv]](over.match.conv "12.2.2.6 Initialization by conversion function"), or [[over.match.ref]](over.match.ref "12.2.2.7 Initialization by conversion function for direct reference binding") (in all cases), or
|
||||
|
||||
- [(4.5)](#general-4.5)
|
||||
|
||||
the second phase of [[over.match.list]](over.match.list "12.2.2.8 Initialization by list-initialization") when the initializer list has exactly one element that
|
||||
is itself an initializer list, and
|
||||
the target is the first parameter of a constructor of class X, and
|
||||
the conversion is to X or reference to cv X,
|
||||
|
||||
user-defined conversion sequences are not considered[.](#general-4.sentence-1)
|
||||
|
||||
[*Note [2](#general-note-2)*:
|
||||
|
||||
These rules prevent more than one user-defined conversion from being
|
||||
applied during overload resolution, thereby avoiding infinite recursion[.](#general-4.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Example [1](#general-example-1)*: struct Y { Y(int); };struct A { operator int(); };
|
||||
Y y1 = A(); // error: A::operator int() is not a candidatestruct X { X(); };struct B { operator X(); };
|
||||
B b;
|
||||
X x{{b}}; // error: B::operator X() is not a candidate â *end example*]
|
||||
|
||||
[5](#general-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2170)
|
||||
|
||||
For the case where the parameter type is a reference, see [[over.ics.ref]](#over.ics.ref "12.2.4.2.5 Reference binding")[.](#general-5.sentence-1)
|
||||
|
||||
[6](#general-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2173)
|
||||
|
||||
When the parameter type is not a reference, the implicit conversion
|
||||
sequence models a copy-initialization of the parameter from the argument
|
||||
expression[.](#general-6.sentence-1)
|
||||
|
||||
The implicit conversion sequence is the one required to convert the
|
||||
argument expression to a prvalue of the type of
|
||||
the parameter[.](#general-6.sentence-2)
|
||||
|
||||
[*Note [3](#general-note-3)*:
|
||||
|
||||
When the parameter has a class type, this is a conceptual conversion
|
||||
defined for the purposes of [[over]](over "12 Overloading"); the actual initialization is
|
||||
defined in terms of constructors and is not a conversion[.](#general-6.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[7](#general-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2186)
|
||||
|
||||
When the cv-unqualified version of the type of the argument expression
|
||||
is the same as the parameter type,
|
||||
the implicit conversion sequence is an identity conversion[.](#general-7.sentence-1)
|
||||
|
||||
When the parameter has a class type and the argument expression has a
|
||||
(possibly cv-qualified)
|
||||
derived class type, the implicit conversion sequence is a
|
||||
derived-to-baseconversion from the derived class to the base class[.](#general-7.sentence-2)
|
||||
|
||||
A derived-to-base conversion has Conversion rank ([[over.ics.scs]](#over.ics.scs "12.2.4.2.2 Standard conversion sequences"))[.](#general-7.sentence-3)
|
||||
|
||||
[*Note [4](#general-note-4)*:
|
||||
|
||||
There is no such standard conversion; this derived-to-base conversion exists
|
||||
only in the description of implicit conversion sequences[.](#general-7.sentence-4)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Example [2](#general-example-2)*:
|
||||
|
||||
An implicit conversion sequence from an argument of type const A to a parameter of type A can be formed,
|
||||
even if overload resolution for copy-initialization of A from the argument would not find a viable function ([[over.match.ctor]](over.match.ctor "12.2.2.4 Initialization by constructor"), [[over.match.viable]](over.match.viable "12.2.3 Viable functions"))[.](#general-7.sentence-5)
|
||||
|
||||
The implicit conversion sequence for that case is the identity sequence; it
|
||||
contains no âconversionâ from const A to A[.](#general-7.sentence-6)
|
||||
|
||||
â *end example*]
|
||||
|
||||
[8](#general-8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2210)
|
||||
|
||||
When the parameter is the implicit object parameter of a static member function,
|
||||
the implicit conversion sequence is a standard conversion sequence
|
||||
that is neither better nor worse than any other standard conversion sequence[.](#general-8.sentence-1)
|
||||
|
||||
[9](#general-9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2215)
|
||||
|
||||
In all contexts, when converting to the implicit object parameter
|
||||
or when converting to the left operand of an assignment operation
|
||||
only standard conversion sequences are allowed[.](#general-9.sentence-1)
|
||||
|
||||
[*Note [5](#general-note-5)*:
|
||||
|
||||
When a conversion to the explicit object parameter occurs,
|
||||
it can include user-defined conversion sequences[.](#general-9.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[10](#general-10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2224)
|
||||
|
||||
If no conversions are required to match an argument to a
|
||||
parameter type, the implicit conversion sequence is the standard
|
||||
conversion sequence consisting of the identity conversion ([[over.ics.scs]](#over.ics.scs "12.2.4.2.2 Standard conversion sequences"))[.](#general-10.sentence-1)
|
||||
|
||||
[11](#general-11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2229)
|
||||
|
||||
If no sequence of conversions can be found to convert an argument
|
||||
to a parameter type, an implicit conversion sequence cannot be formed[.](#general-11.sentence-1)
|
||||
|
||||
[12](#general-12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2233)
|
||||
|
||||
If there are multiple well-formed implicit conversion sequences
|
||||
converting the argument to the parameter type, the implicit
|
||||
conversion sequence associated with the parameter is defined to be
|
||||
the unique conversion sequence designated the[*ambiguous conversion sequence*](#def:conversion_sequence,ambiguous "12.2.4.2.1 General [over.best.ics.general]")[.](#general-12.sentence-1)
|
||||
|
||||
For the purpose of ranking implicit conversion sequences as described
|
||||
in [[over.ics.rank]](over.ics.rank "12.2.4.3 Ranking implicit conversion sequences"), the ambiguous conversion sequence is treated
|
||||
as a user-defined conversion sequence that is indistinguishable from any
|
||||
other user-defined conversion sequence[.](#general-12.sentence-2)
|
||||
|
||||
[*Note [6](#general-note-6)*:
|
||||
|
||||
This rule prevents a function from becoming non-viable because of an ambiguous
|
||||
conversion sequence for one of its parameters[.](#general-12.sentence-3)
|
||||
|
||||
[*Example [3](#general-example-3)*: class B;class A { A (B&);};class B { operator A (); };class C { C (B&); };void f(A) { }void f(C) { } B b;
|
||||
f(b); // error: ambiguous because there is a conversion b â C (via constructor)// and an (ambiguous) conversion b â A (via constructor or conversion function)void f(B) { } f(b); // OK, unambiguous â *end example*]
|
||||
|
||||
â *end note*]
|
||||
|
||||
If a function that uses the ambiguous conversion sequence is selected
|
||||
as the best viable function, the call will be ill-formed because the conversion
|
||||
of one of the arguments in the call is ambiguous[.](#general-12.sentence-4)
|
||||
|
||||
[13](#general-13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2266)
|
||||
|
||||
The three forms of implicit conversion sequences mentioned above
|
||||
are defined in the following subclauses[.](#general-13.sentence-1)
|
||||
|
||||
#### [12.2.4.2.2](#over.ics.scs) Standard conversion sequences [[over.ics.scs]](over.ics.scs)
|
||||
|
||||
[1](#over.ics.scs-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2272)
|
||||
|
||||
Table [19](#tab:over.ics.scs "Table 19: Conversions") summarizes the conversions defined in [[conv]](conv "7.3 Standard conversions") and
|
||||
partitions them into four disjoint categories: Lvalue Transformation,
|
||||
Qualification Adjustment, Promotion, and Conversion[.](#over.ics.scs-1.sentence-1)
|
||||
|
||||
[*Note [1](#over.ics.scs-note-1)*:
|
||||
|
||||
These categories are orthogonal with respect to value category,
|
||||
cv-qualification, and data representation: the Lvalue Transformations
|
||||
do not change the cv-qualification or data
|
||||
representation of the type; the Qualification Adjustments do not
|
||||
change the value category or data representation of the type; and
|
||||
the Promotions and Conversions do not change the
|
||||
value category or cv-qualification of the type[.](#over.ics.scs-1.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#over.ics.scs-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2287)
|
||||
|
||||
[*Note [2](#over.ics.scs-note-2)*:
|
||||
|
||||
As described in [[conv]](conv "7.3 Standard conversions"),
|
||||
a standard conversion sequence either is the Identity conversion
|
||||
by itself (that is, no conversion) or consists of one to three
|
||||
conversions from the other
|
||||
four categories[.](#over.ics.scs-2.sentence-1)
|
||||
|
||||
If there are two or more conversions in the sequence, the
|
||||
conversions are applied in the canonical order:**Lvalue Transformation**,**Promotion** or**Conversion**,**Qualification Adjustment**[.](#over.ics.scs-2.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[3](#over.ics.scs-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2303)
|
||||
|
||||
Each conversion in Table [19](#tab:over.ics.scs "Table 19: Conversions") also has an associated rank (Exact
|
||||
Match, Promotion, or Conversion)[.](#over.ics.scs-3.sentence-1)
|
||||
|
||||
These are used
|
||||
to [rank standard conversion sequences](over.ics.rank "12.2.4.3 Ranking implicit conversion sequences [over.ics.rank]")[.](#over.ics.scs-3.sentence-2)
|
||||
|
||||
The rank of a conversion sequence is determined by considering the
|
||||
rank of each conversion in the sequence and the rank of any [reference
|
||||
binding](#over.ics.ref "12.2.4.2.5 Reference binding [over.ics.ref]")[.](#over.ics.scs-3.sentence-3)
|
||||
|
||||
If any of those has Conversion rank, the
|
||||
sequence has Conversion rank; otherwise, if any of those has Promotion rank,
|
||||
the sequence has Promotion rank; otherwise, the sequence has Exact
|
||||
Match rank[.](#over.ics.scs-3.sentence-4)
|
||||
|
||||
Table [19](#tab:over.ics.scs) — Conversions [[tab:over.ics.scs]](./tab:over.ics.scs)
|
||||
|
||||
| [ð](#tab:over.ics.scs-row-1)<br>**Conversion** | **Category** | **Rank** | **Subclause** |
|
||||
| --- | --- | --- | --- |
|
||||
| [ð](#tab:over.ics.scs-row-2)<br>No conversions required | Identity | | |
|
||||
| [ð](#tab:over.ics.scs-row-3)<br> Lvalue-to-rvalue conversion | | | [[conv.lval]](conv.lval "7.3.2 Lvalue-to-rvalue conversion") |
|
||||
| [ð](#tab:over.ics.scs-row-4)<br> Array-to-pointer conversion | Lvalue Transformation | | [[conv.array]](conv.array "7.3.3 Array-to-pointer conversion") |
|
||||
| [ð](#tab:over.ics.scs-row-5)<br> Function-to-pointer conversion | | Exact Match | [[conv.func]](conv.func "7.3.4 Function-to-pointer conversion") |
|
||||
| [ð](#tab:over.ics.scs-row-6)<br> Qualification conversions | | | [[conv.qual]](conv.qual "7.3.6 Qualification conversions") |
|
||||
| [ð](#tab:over.ics.scs-row-7)<br> Function pointer conversion | Qualification Adjustment | | [[conv.fctptr]](conv.fctptr "7.3.14 Function pointer conversions") |
|
||||
| [ð](#tab:over.ics.scs-row-8)<br>Integral promotions | | | [[conv.prom]](conv.prom "7.3.7 Integral promotions") |
|
||||
| [ð](#tab:over.ics.scs-row-9)<br> Floating-point promotion | Promotion | Promotion | [[conv.fpprom]](conv.fpprom "7.3.8 Floating-point promotion") |
|
||||
| [ð](#tab:over.ics.scs-row-10)<br>Integral conversions | | | [[conv.integral]](conv.integral "7.3.9 Integral conversions") |
|
||||
| [ð](#tab:over.ics.scs-row-11)<br> Floating-point conversions | | | [[conv.double]](conv.double "7.3.10 Floating-point conversions") |
|
||||
| [ð](#tab:over.ics.scs-row-12)<br> Floating-integral conversions | | | [[conv.fpint]](conv.fpint "7.3.11 Floating-integral conversions") |
|
||||
| [ð](#tab:over.ics.scs-row-13)<br> Pointer conversions | Conversion | Conversion | [[conv.ptr]](conv.ptr "7.3.12 Pointer conversions") |
|
||||
| [ð](#tab:over.ics.scs-row-14)<br> Pointer-to-member conversions | | | [[conv.mem]](conv.mem "7.3.13 Pointer-to-member conversions") |
|
||||
| [ð](#tab:over.ics.scs-row-15)<br> Boolean conversions | | | [[conv.bool]](conv.bool "7.3.15 Boolean conversions") |
|
||||
|
||||
#### [12.2.4.2.3](#over.ics.user) User-defined conversion sequences [[over.ics.user]](over.ics.user)
|
||||
|
||||
[1](#over.ics.user-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2339)
|
||||
|
||||
A [*user-defined conversion sequence*](#def:conversion_sequence,user-defined "12.2.4.2.3 User-defined conversion sequences [over.ics.user]") consists of an initial
|
||||
standard conversion sequence followed by a user-defined
|
||||
conversion ([[class.conv]](class.conv "11.4.8 Conversions")) followed by a second standard
|
||||
conversion sequence[.](#over.ics.user-1.sentence-1)
|
||||
|
||||
If the user-defined conversion is specified
|
||||
by a constructor ([[class.conv.ctor]](class.conv.ctor "11.4.8.2 Conversion by constructor")), the initial standard
|
||||
conversion sequence converts the source type to the type of the
|
||||
first parameter of that constructor[.](#over.ics.user-1.sentence-2)
|
||||
|
||||
If the user-defined
|
||||
conversion is specified by a [conversion function](class.conv.fct "11.4.8.3 Conversion functions [class.conv.fct]"), the
|
||||
initial standard conversion sequence
|
||||
converts the source type to the type of the
|
||||
object parameter of that conversion function[.](#over.ics.user-1.sentence-3)
|
||||
|
||||
[2](#over.ics.user-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2354)
|
||||
|
||||
The second standard conversion sequence converts the result of
|
||||
the user-defined conversion to the target type for the sequence;
|
||||
any reference binding is included in the second standard
|
||||
conversion sequence[.](#over.ics.user-2.sentence-1)
|
||||
|
||||
Since an implicit conversion sequence is an initialization, the
|
||||
special rules for initialization by user-defined conversion apply
|
||||
when selecting the best user-defined conversion for a
|
||||
user-defined conversion sequence (see [[over.match.best]](over.match.best "12.2.4 Best viable function") and [over.best.ics])[.](#over.ics.user-2.sentence-2)
|
||||
|
||||
[3](#over.ics.user-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2364)
|
||||
|
||||
If the user-defined conversion is specified by a
|
||||
specialization of a conversion function template,
|
||||
the second standard conversion sequence shall have Exact Match rank[.](#over.ics.user-3.sentence-1)
|
||||
|
||||
[4](#over.ics.user-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2369)
|
||||
|
||||
A conversion of an expression of class type
|
||||
to the same class type is given Exact Match rank, and
|
||||
a conversion of an expression of class type
|
||||
to a base class of that type is given Conversion rank,
|
||||
in spite of the
|
||||
fact that a constructor (i.e., a user-defined conversion
|
||||
function) is called for those cases[.](#over.ics.user-4.sentence-1)
|
||||
|
||||
#### [12.2.4.2.4](#over.ics.ellipsis) Ellipsis conversion sequences [[over.ics.ellipsis]](over.ics.ellipsis)
|
||||
|
||||
[1](#over.ics.ellipsis-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2380)
|
||||
|
||||
An ellipsis conversion sequence occurs when an argument in a
|
||||
function call is matched with the ellipsis parameter
|
||||
specification of the function called (see [[expr.call]](expr.call "7.6.1.3 Function call"))[.](#over.ics.ellipsis-1.sentence-1)
|
||||
|
||||
#### [12.2.4.2.5](#over.ics.ref) Reference binding [[over.ics.ref]](over.ics.ref)
|
||||
|
||||
[1](#over.ics.ref-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2388)
|
||||
|
||||
When a parameter of type âreference to cv Tâ
|
||||
binds directly ([[dcl.init.ref]](dcl.init.ref "9.5.4 References")) to an argument expression:
|
||||
|
||||
- [(1.1)](#over.ics.ref-1.1)
|
||||
|
||||
If the argument expression has a type that
|
||||
is a derived class of the parameter type,
|
||||
the implicit conversion sequence is a derived-to-base
|
||||
conversion ([over.best.ics])[.](#over.ics.ref-1.1.sentence-1)
|
||||
|
||||
- [(1.2)](#over.ics.ref-1.2)
|
||||
|
||||
Otherwise,
|
||||
if the type of the argument is possibly cv-qualified T, or
|
||||
if T is an array type of unknown bound with element type U and
|
||||
the argument has an array type of known bound whose
|
||||
element type is possibly cv-qualified U,
|
||||
the implicit conversion sequence is the identity conversion[.](#over.ics.ref-1.2.sentence-1)
|
||||
|
||||
- [(1.3)](#over.ics.ref-1.3)
|
||||
|
||||
Otherwise,
|
||||
if T is a function type,
|
||||
the implicit conversion sequence is a function pointer conversion[.](#over.ics.ref-1.3.sentence-1)
|
||||
|
||||
- [(1.4)](#over.ics.ref-1.4)
|
||||
|
||||
Otherwise, the implicit conversion sequence is a qualification conversion[.](#over.ics.ref-1.4.sentence-1)
|
||||
|
||||
[*Example [1](#over.ics.ref-example-1)*: struct A {};struct B : public A {} b;int f(A&);int f(B&);int i = f(b); // calls f(B&), an exact match, rather than f(A&), a conversionvoid g() noexcept;int h(void (&)() noexcept); // #1int h(void (&)()); // #2int j = h(g); // calls #1, an exact match, rather than #2, a function pointer conversion â *end example*]
|
||||
|
||||
If the parameter binds directly to the result of
|
||||
applying a conversion function to the argument expression, the implicit
|
||||
conversion sequence is a user-defined conversion sequence ([[over.ics.user]](#over.ics.user "12.2.4.2.3 User-defined conversion sequences"))
|
||||
whose second standard conversion sequence is
|
||||
determined by the above rules[.](#over.ics.ref-1.sentence-2)
|
||||
|
||||
[2](#over.ics.ref-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2435)
|
||||
|
||||
When a parameter of reference type is not bound directly to an argument
|
||||
expression, the conversion sequence is the one required to convert the argument
|
||||
expression to the referenced type according to [over.best.ics][.](#over.ics.ref-2.sentence-1)
|
||||
|
||||
Conceptually, this conversion sequence corresponds to copy-initializing a
|
||||
temporary of the referenced type with the argument expression[.](#over.ics.ref-2.sentence-2)
|
||||
|
||||
Any difference
|
||||
in top-level cv-qualification is subsumed by the initialization itself and
|
||||
does not constitute a conversion[.](#over.ics.ref-2.sentence-3)
|
||||
|
||||
[3](#over.ics.ref-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2445)
|
||||
|
||||
Except for an implicit object parameter, for which see [[over.match.funcs]](over.match.funcs "12.2.2 Candidate functions and argument lists"),
|
||||
an implicit conversion sequence cannot be formed if it requires
|
||||
binding an lvalue reference
|
||||
other than a reference to a non-volatile const type
|
||||
to an rvalue
|
||||
or binding an rvalue reference to an lvalue of object type[.](#over.ics.ref-3.sentence-1)
|
||||
|
||||
[*Note [1](#over.ics.ref-note-1)*:
|
||||
|
||||
This means, for example, that a candidate function cannot be a viable
|
||||
function if it has a non-const lvalue reference parameter (other than
|
||||
the implicit object parameter) and the corresponding argument
|
||||
would require a temporary to be created to initialize the lvalue
|
||||
reference (see [[dcl.init.ref]](dcl.init.ref "9.5.4 References"))[.](#over.ics.ref-3.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[4](#over.ics.ref-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2460)
|
||||
|
||||
Other restrictions on binding a reference to a particular argument
|
||||
that are not based on the types of the reference and the argument
|
||||
do not affect the formation of an implicit conversion
|
||||
sequence, however[.](#over.ics.ref-4.sentence-1)
|
||||
|
||||
[*Example [2](#over.ics.ref-example-2)*:
|
||||
|
||||
A function with an âlvalue reference to intâ parameter can
|
||||
be a viable candidate even if the corresponding argument is anint bit-field[.](#over.ics.ref-4.sentence-2)
|
||||
|
||||
The formation of implicit conversion sequences
|
||||
treats theint bit-field as anint lvalue and finds an exact
|
||||
match with the parameter[.](#over.ics.ref-4.sentence-3)
|
||||
|
||||
If the function is selected by overload
|
||||
resolution, the call will nonetheless be ill-formed because of
|
||||
the prohibition on binding a non-const lvalue reference to a bit-field ([[dcl.init.ref]](dcl.init.ref "9.5.4 References"))[.](#over.ics.ref-4.sentence-4)
|
||||
|
||||
â *end example*]
|
||||
|
||||
#### [12.2.4.2.6](#over.ics.list) List-initialization sequence [[over.ics.list]](over.ics.list)
|
||||
|
||||
[1](#over.ics.list-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2484)
|
||||
|
||||
When an argument is an initializer list ([[dcl.init.list]](dcl.init.list "9.5.5 List-initialization")), it is not an expression and special rules apply for converting it to a parameter type[.](#over.ics.list-1.sentence-1)
|
||||
|
||||
[2](#over.ics.list-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2488)
|
||||
|
||||
If the initializer list is a [*designated-initializer-list*](dcl.init.general#nt:designated-initializer-list "9.5.1 General [dcl.init.general]") and the parameter is not a reference,
|
||||
a conversion is only possible if
|
||||
the parameter has an aggregate type
|
||||
that can be initialized from the initializer list
|
||||
according to the rules for aggregate initialization ([[dcl.init.aggr]](dcl.init.aggr "9.5.2 Aggregates")),
|
||||
in which case the implicit conversion sequence is
|
||||
a user-defined conversion sequence
|
||||
whose second standard conversion sequence
|
||||
is an identity conversion[.](#over.ics.list-2.sentence-1)
|
||||
|
||||
[*Note [1](#over.ics.list-note-1)*:
|
||||
|
||||
Aggregate initialization does not require that
|
||||
the members are declared in designation order[.](#over.ics.list-2.sentence-2)
|
||||
|
||||
If, after overload resolution, the order does not match
|
||||
for the selected overload,
|
||||
the initialization of the parameter will be ill-formed ([[dcl.init.list]](dcl.init.list "9.5.5 List-initialization"))[.](#over.ics.list-2.sentence-3)
|
||||
|
||||
[*Example [1](#over.ics.list-example-1)*: struct A { int x, y; };struct B { int y, x; };void f(A a, int); // #1void f(B b, ...); // #2void g(A a); // #3void g(B b); // #4void h() { f({.x = 1, .y = 2}, 0); // OK; calls #1 f({.y = 2, .x = 1}, 0); // error: selects #1, initialization of a fails// due to non-matching member order ([[dcl.init.list]](dcl.init.list "9.5.5 List-initialization")) g({.x = 1, .y = 2}); // error: ambiguous between #3 and #4} â *end example*]
|
||||
|
||||
â *end note*]
|
||||
|
||||
[3](#over.ics.list-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2523)
|
||||
|
||||
Otherwise,
|
||||
if the parameter type is an aggregate class X and the initializer list has a
|
||||
single element of type cv U, where U is X or a class derived from X, the implicit conversion sequence is the one
|
||||
required to convert the element to the parameter type[.](#over.ics.list-3.sentence-1)
|
||||
|
||||
[4](#over.ics.list-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2530)
|
||||
|
||||
Otherwise, if the parameter type is a character array[106](#footnote-106 "Since there are no parameters of array type, this will only occur as the referenced type of a reference parameter.") and the initializer list has a single element that is an appropriately-typed[*string-literal*](lex.string#nt:string-literal "5.13.5 String literals [lex.string]") ([[dcl.init.string]](dcl.init.string "9.5.3 Character arrays")), the implicit conversion
|
||||
sequence is the identity conversion[.](#over.ics.list-4.sentence-1)
|
||||
|
||||
[5](#over.ics.list-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2540)
|
||||
|
||||
Otherwise, if the parameter type is std::initializer_list<X> and all the elements
|
||||
of the initializer list can be implicitly converted to X, the implicit
|
||||
conversion sequence is the worst conversion necessary to convert an element of
|
||||
the list to X, or if the initializer list has no elements, the identity
|
||||
conversion[.](#over.ics.list-5.sentence-1)
|
||||
|
||||
This conversion can be a user-defined conversion even in
|
||||
the context of a call to an initializer-list constructor[.](#over.ics.list-5.sentence-2)
|
||||
|
||||
[*Example [2](#over.ics.list-example-2)*: void f(std::initializer_list<int>);
|
||||
f( {} ); // OK, f(initializer_list<int>) identity conversion f( {1,2,3} ); // OK, f(initializer_list<int>) identity conversion f( {'a','b'} ); // OK, f(initializer_list<int>) integral promotion f( {1.0} ); // error: narrowingstruct A { A(std::initializer_list<double>); // #1 A(std::initializer_list<std::complex<double>>); // #2 A(std::initializer_list<std::string>); // #3};
|
||||
A a{ 1.0,2.0 }; // OK, uses #1void g(A);
|
||||
g({ "foo", "bar" }); // OK, uses #3typedef int IA[3];void h(const IA&);
|
||||
h({ 1, 2, 3 }); // OK, identity conversion â *end example*]
|
||||
|
||||
[6](#over.ics.list-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2572)
|
||||
|
||||
Otherwise, if the parameter type is âarray of N Xâ
|
||||
or âarray of unknown bound of Xâ,
|
||||
if there exists an implicit conversion sequence
|
||||
from each element of the initializer list
|
||||
(and from {} in the former case
|
||||
if N exceeds the number of elements in the initializer list)
|
||||
to X, the implicit conversion sequence is
|
||||
the worst such implicit conversion sequence[.](#over.ics.list-6.sentence-1)
|
||||
|
||||
[7](#over.ics.list-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2582)
|
||||
|
||||
Otherwise, if the parameter is a non-aggregate class X and overload
|
||||
resolution per [[over.match.list]](over.match.list "12.2.2.8 Initialization by list-initialization") chooses a single best constructor C ofX to perform the initialization of an object of type X from the
|
||||
argument initializer list:
|
||||
|
||||
- [(7.1)](#over.ics.list-7.1)
|
||||
|
||||
If C is not an initializer-list constructor
|
||||
and the initializer list has a single element of type cv U,
|
||||
where U is X or a class derived from X,
|
||||
the implicit conversion sequence has Exact Match rank if U is X,
|
||||
or Conversion rank if U is derived from X[.](#over.ics.list-7.1.sentence-1)
|
||||
|
||||
- [(7.2)](#over.ics.list-7.2)
|
||||
|
||||
Otherwise, the implicit conversion sequence is a user-defined
|
||||
conversion sequence whose second standard conversion sequence is an
|
||||
identity conversion[.](#over.ics.list-7.2.sentence-1)
|
||||
|
||||
If multiple constructors are viable but none is better than
|
||||
the others, the implicit conversion sequence is the ambiguous conversion
|
||||
sequence[.](#over.ics.list-7.sentence-2)
|
||||
|
||||
User-defined conversions are allowed for conversion of the initializer
|
||||
list elements to the constructor parameter types except as noted
|
||||
in [over.best.ics][.](#over.ics.list-7.sentence-3)
|
||||
|
||||
[*Example [3](#over.ics.list-example-3)*: struct A { A(std::initializer_list<int>);};void f(A);
|
||||
f( {'a', 'b'} ); // OK, f(A(std::initializer_list<int>)) user-defined conversionstruct B { B(int, double);};void g(B);
|
||||
g( {'a', 'b'} ); // OK, g(B(int, double)) user-defined conversion g( {1.0, 1.0} ); // error: narrowingvoid f(B);
|
||||
f( {'a', 'b'} ); // error: ambiguous f(A) or f(B)struct C { C(std::string);};void h(C);
|
||||
h({"foo"}); // OK, h(C(std::string("foo")))struct D { D(A, C);};void i(D);
|
||||
i({ {1,2}, {"bar"} }); // OK, i(D(A(std::initializer_list<int>{1,2}), C(std::string("bar")))) â *end example*]
|
||||
|
||||
[8](#over.ics.list-8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2636)
|
||||
|
||||
Otherwise, if the parameter has an aggregate type which can be initialized from
|
||||
the initializer list according to the rules for aggregate
|
||||
initialization ([[dcl.init.aggr]](dcl.init.aggr "9.5.2 Aggregates")), the implicit conversion sequence is a
|
||||
user-defined conversion sequence whose second standard conversion
|
||||
sequence is an identity conversion[.](#over.ics.list-8.sentence-1)
|
||||
|
||||
[*Example [4](#over.ics.list-example-4)*: struct A {int m1; double m2;};
|
||||
|
||||
void f(A);
|
||||
f( {'a', 'b'} ); // OK, f(A(int,double)) user-defined conversion f( {1.0} ); // error: narrowing â *end example*]
|
||||
|
||||
[9](#over.ics.list-9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2655)
|
||||
|
||||
Otherwise, if the parameter is a reference, see [[over.ics.ref]](#over.ics.ref "12.2.4.2.5 Reference binding")[.](#over.ics.list-9.sentence-1)
|
||||
|
||||
[*Note [2](#over.ics.list-note-2)*:
|
||||
|
||||
The rules in this subclause will apply for initializing the underlying temporary
|
||||
for the reference[.](#over.ics.list-9.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Example [5](#over.ics.list-example-5)*: struct A {int m1; double m2;};
|
||||
|
||||
void f(const A&);
|
||||
f( {'a', 'b'} ); // OK, f(A(int,double)) user-defined conversion f( {1.0} ); // error: narrowingvoid g(const double &);
|
||||
g({1}); // same conversion as int to double â *end example*]
|
||||
|
||||
[10](#over.ics.list-10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2677)
|
||||
|
||||
Otherwise, if the parameter type is not a class:
|
||||
|
||||
- [(10.1)](#over.ics.list-10.1)
|
||||
|
||||
if the initializer list has one element that is not itself an initializer list,
|
||||
the implicit conversion sequence is the one required to convert the element to
|
||||
the parameter type;
|
||||
[*Example [6](#over.ics.list-example-6)*: void f(int);
|
||||
f( {'a'} ); // OK, same conversion as char to int f( {1.0} ); // error: narrowing â *end example*]
|
||||
|
||||
- [(10.2)](#over.ics.list-10.2)
|
||||
|
||||
if the initializer list has no elements, the implicit conversion sequence
|
||||
is the identity conversion[.](#over.ics.list-10.sentence-1)
|
||||
[*Example [7](#over.ics.list-example-7)*: void f(int);
|
||||
f( { } ); // OK, identity conversion â *end example*]
|
||||
|
||||
[11](#over.ics.list-11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2701)
|
||||
|
||||
In all cases other than those enumerated above, no conversion is possible[.](#over.ics.list-11.sentence-1)
|
||||
|
||||
[106)](#footnote-106)[106)](#footnoteref-106)
|
||||
|
||||
Since there are no parameters of array type,
|
||||
this will only occur as the referenced type of a reference parameter[.](#footnote-106.sentence-1)
|
||||
243
cppdraft/over/best/ics/general.md
Normal file
243
cppdraft/over/best/ics/general.md
Normal file
@@ -0,0 +1,243 @@
|
||||
[over.best.ics.general]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#over.best.ics.general)
|
||||
|
||||
### 12.2.4 Best viable function [[over.match.best]](over.match.best#over.best.ics.general)
|
||||
|
||||
#### 12.2.4.2 Implicit conversion sequences [[over.best.ics]](over.best.ics#general)
|
||||
|
||||
#### 12.2.4.2.1 General [over.best.ics.general]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2095)
|
||||
|
||||
An [*implicit conversion sequence*](#def:conversion_sequence,implicit "12.2.4.2.1 General [over.best.ics.general]") is a sequence of conversions used
|
||||
to convert an argument in a function call to the type of the
|
||||
corresponding parameter of the function being called[.](#1.sentence-1)
|
||||
|
||||
The
|
||||
sequence of conversions is an implicit conversion as defined in[[conv]](conv "7.3 Standard conversions"), which means it is governed by the rules for
|
||||
initialization of an object or reference by a single
|
||||
expression ([[dcl.init]](dcl.init "9.5 Initializers"), [[dcl.init.ref]](dcl.init.ref "9.5.4 References"))[.](#1.sentence-2)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2106)
|
||||
|
||||
Implicit conversion sequences are concerned only with the type,
|
||||
cv-qualification, and value category of the argument and how these
|
||||
are converted to match the corresponding properties of the
|
||||
parameter[.](#2.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
Other properties, such as the lifetime, storage duration, linkage,
|
||||
alignment, accessibility of the argument, whether the argument is a bit-field,
|
||||
and whether a function is [deleted](dcl.fct.def.delete "9.6.3 Deleted definitions [dcl.fct.def.delete]"), are ignored[.](#2.sentence-2)
|
||||
|
||||
So, although an implicit
|
||||
conversion sequence can be defined for a given argument-parameter
|
||||
pair, the conversion from the argument to the parameter might still
|
||||
be ill-formed in the final analysis[.](#2.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2121)
|
||||
|
||||
A
|
||||
well-formed implicit conversion
|
||||
sequence is one of the following forms:
|
||||
|
||||
- [(3.1)](#3.1)
|
||||
|
||||
a [standard conversion sequence](over.ics.scs "12.2.4.2.2 Standard conversion sequences [over.ics.scs]"),
|
||||
|
||||
- [(3.2)](#3.2)
|
||||
|
||||
a [user-defined conversion sequence](over.ics.user "12.2.4.2.3 User-defined conversion sequences [over.ics.user]"), or
|
||||
|
||||
- [(3.3)](#3.3)
|
||||
|
||||
an [ellipsis conversion sequence](over.ics.ellipsis "12.2.4.2.4 Ellipsis conversion sequences [over.ics.ellipsis]")[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2134)
|
||||
|
||||
However, if the target is
|
||||
|
||||
- [(4.1)](#4.1)
|
||||
|
||||
the first parameter of a constructor or
|
||||
|
||||
- [(4.2)](#4.2)
|
||||
|
||||
the object parameter of a user-defined conversion function
|
||||
|
||||
and the constructor or user-defined conversion function is a candidate by
|
||||
|
||||
- [(4.3)](#4.3)
|
||||
|
||||
[[over.match.ctor]](over.match.ctor "12.2.2.4 Initialization by constructor"), when the argument is the temporary in the second
|
||||
step of a class copy-initialization,
|
||||
|
||||
- [(4.4)](#4.4)
|
||||
|
||||
[[over.match.copy]](over.match.copy "12.2.2.5 Copy-initialization of class by user-defined conversion"), [[over.match.conv]](over.match.conv "12.2.2.6 Initialization by conversion function"), or [[over.match.ref]](over.match.ref "12.2.2.7 Initialization by conversion function for direct reference binding") (in all cases), or
|
||||
|
||||
- [(4.5)](#4.5)
|
||||
|
||||
the second phase of [[over.match.list]](over.match.list "12.2.2.8 Initialization by list-initialization") when the initializer list has exactly one element that
|
||||
is itself an initializer list, and
|
||||
the target is the first parameter of a constructor of class X, and
|
||||
the conversion is to X or reference to cv X,
|
||||
|
||||
user-defined conversion sequences are not considered[.](#4.sentence-1)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
These rules prevent more than one user-defined conversion from being
|
||||
applied during overload resolution, thereby avoiding infinite recursion[.](#4.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Example [1](#example-1)*: struct Y { Y(int); };struct A { operator int(); };
|
||||
Y y1 = A(); // error: A::operator int() is not a candidatestruct X { X(); };struct B { operator X(); };
|
||||
B b;
|
||||
X x{{b}}; // error: B::operator X() is not a candidate â *end example*]
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2170)
|
||||
|
||||
For the case where the parameter type is a reference, see [[over.ics.ref]](over.ics.ref "12.2.4.2.5 Reference binding")[.](#5.sentence-1)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2173)
|
||||
|
||||
When the parameter type is not a reference, the implicit conversion
|
||||
sequence models a copy-initialization of the parameter from the argument
|
||||
expression[.](#6.sentence-1)
|
||||
|
||||
The implicit conversion sequence is the one required to convert the
|
||||
argument expression to a prvalue of the type of
|
||||
the parameter[.](#6.sentence-2)
|
||||
|
||||
[*Note [3](#note-3)*:
|
||||
|
||||
When the parameter has a class type, this is a conceptual conversion
|
||||
defined for the purposes of [[over]](over "12 Overloading"); the actual initialization is
|
||||
defined in terms of constructors and is not a conversion[.](#6.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2186)
|
||||
|
||||
When the cv-unqualified version of the type of the argument expression
|
||||
is the same as the parameter type,
|
||||
the implicit conversion sequence is an identity conversion[.](#7.sentence-1)
|
||||
|
||||
When the parameter has a class type and the argument expression has a
|
||||
(possibly cv-qualified)
|
||||
derived class type, the implicit conversion sequence is a
|
||||
derived-to-baseconversion from the derived class to the base class[.](#7.sentence-2)
|
||||
|
||||
A derived-to-base conversion has Conversion rank ([[over.ics.scs]](over.ics.scs "12.2.4.2.2 Standard conversion sequences"))[.](#7.sentence-3)
|
||||
|
||||
[*Note [4](#note-4)*:
|
||||
|
||||
There is no such standard conversion; this derived-to-base conversion exists
|
||||
only in the description of implicit conversion sequences[.](#7.sentence-4)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Example [2](#example-2)*:
|
||||
|
||||
An implicit conversion sequence from an argument of type const A to a parameter of type A can be formed,
|
||||
even if overload resolution for copy-initialization of A from the argument would not find a viable function ([[over.match.ctor]](over.match.ctor "12.2.2.4 Initialization by constructor"), [[over.match.viable]](over.match.viable "12.2.3 Viable functions"))[.](#7.sentence-5)
|
||||
|
||||
The implicit conversion sequence for that case is the identity sequence; it
|
||||
contains no âconversionâ from const A to A[.](#7.sentence-6)
|
||||
|
||||
â *end example*]
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2210)
|
||||
|
||||
When the parameter is the implicit object parameter of a static member function,
|
||||
the implicit conversion sequence is a standard conversion sequence
|
||||
that is neither better nor worse than any other standard conversion sequence[.](#8.sentence-1)
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2215)
|
||||
|
||||
In all contexts, when converting to the implicit object parameter
|
||||
or when converting to the left operand of an assignment operation
|
||||
only standard conversion sequences are allowed[.](#9.sentence-1)
|
||||
|
||||
[*Note [5](#note-5)*:
|
||||
|
||||
When a conversion to the explicit object parameter occurs,
|
||||
it can include user-defined conversion sequences[.](#9.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2224)
|
||||
|
||||
If no conversions are required to match an argument to a
|
||||
parameter type, the implicit conversion sequence is the standard
|
||||
conversion sequence consisting of the identity conversion ([[over.ics.scs]](over.ics.scs "12.2.4.2.2 Standard conversion sequences"))[.](#10.sentence-1)
|
||||
|
||||
[11](#11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2229)
|
||||
|
||||
If no sequence of conversions can be found to convert an argument
|
||||
to a parameter type, an implicit conversion sequence cannot be formed[.](#11.sentence-1)
|
||||
|
||||
[12](#12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2233)
|
||||
|
||||
If there are multiple well-formed implicit conversion sequences
|
||||
converting the argument to the parameter type, the implicit
|
||||
conversion sequence associated with the parameter is defined to be
|
||||
the unique conversion sequence designated the[*ambiguous conversion sequence*](#def:conversion_sequence,ambiguous "12.2.4.2.1 General [over.best.ics.general]")[.](#12.sentence-1)
|
||||
|
||||
For the purpose of ranking implicit conversion sequences as described
|
||||
in [[over.ics.rank]](over.ics.rank "12.2.4.3 Ranking implicit conversion sequences"), the ambiguous conversion sequence is treated
|
||||
as a user-defined conversion sequence that is indistinguishable from any
|
||||
other user-defined conversion sequence[.](#12.sentence-2)
|
||||
|
||||
[*Note [6](#note-6)*:
|
||||
|
||||
This rule prevents a function from becoming non-viable because of an ambiguous
|
||||
conversion sequence for one of its parameters[.](#12.sentence-3)
|
||||
|
||||
[*Example [3](#example-3)*: class B;class A { A (B&);};class B { operator A (); };class C { C (B&); };void f(A) { }void f(C) { } B b;
|
||||
f(b); // error: ambiguous because there is a conversion b â C (via constructor)// and an (ambiguous) conversion b â A (via constructor or conversion function)void f(B) { } f(b); // OK, unambiguous â *end example*]
|
||||
|
||||
â *end note*]
|
||||
|
||||
If a function that uses the ambiguous conversion sequence is selected
|
||||
as the best viable function, the call will be ill-formed because the conversion
|
||||
of one of the arguments in the call is ambiguous[.](#12.sentence-4)
|
||||
|
||||
[13](#13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2266)
|
||||
|
||||
The three forms of implicit conversion sequences mentioned above
|
||||
are defined in the following subclauses[.](#13.sentence-1)
|
||||
100
cppdraft/over/binary.md
Normal file
100
cppdraft/over/binary.md
Normal file
@@ -0,0 +1,100 @@
|
||||
[over.binary]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.4 Overloaded operators [[over.oper]](over.oper#over.binary)
|
||||
|
||||
### 12.4.3 Binary operators [over.binary]
|
||||
|
||||
#### [12.4.3.1](#general) General [[over.binary.general]](over.binary.general)
|
||||
|
||||
[1](#general-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3530)
|
||||
|
||||
A [*binary operator function*](#def:operator_function,binary "12.4.3.1 General [over.binary.general]") is a function named operator@ for a binary operator @ that is either
|
||||
a non-static member function ([[class.mfct]](class.mfct "11.4.2 Member functions")) with one non-object parameter or
|
||||
a non-member function with two parameters[.](#general-1.sentence-1)
|
||||
|
||||
For an expression x @ y with subexpressions x and y,
|
||||
the operator function is selected by overload resolution ([[over.match.oper]](over.match.oper "12.2.2.3 Operators in expressions"))[.](#general-1.sentence-2)
|
||||
|
||||
If a member function is selected,
|
||||
the expression is interpreted as
|
||||
|
||||
x . operator @ ( y )
|
||||
|
||||
Otherwise, if a non-member function is selected,
|
||||
the expression is interpreted as
|
||||
|
||||
operator @ ( x , y )
|
||||
|
||||
[2](#general-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3550)
|
||||
|
||||
An [*equality operator function*](#def:operator_function,equality "12.4.3.1 General [over.binary.general]") is an operator function
|
||||
for an equality operator ([[expr.eq]](expr.eq "7.6.10 Equality operators"))[.](#general-2.sentence-1)
|
||||
|
||||
A [*relational operator function*](#def:operator_function,relational "12.4.3.1 General [over.binary.general]") is an operator function
|
||||
for a relational operator ([[expr.rel]](expr.rel "7.6.9 Relational operators"))[.](#general-2.sentence-2)
|
||||
|
||||
A [*three-way comparison operator function*](#def:operator_function,three-way_comparison "12.4.3.1 General [over.binary.general]") is an operator function
|
||||
for the three-way comparison operator ([[expr.spaceship]](expr.spaceship "7.6.8 Three-way comparison operator"))[.](#general-2.sentence-3)
|
||||
|
||||
A [*comparison operator function*](#def:operator_function,comparison "12.4.3.1 General [over.binary.general]") is
|
||||
an equality operator function,
|
||||
a relational operator function, or
|
||||
a three-way comparison operator function[.](#general-2.sentence-4)
|
||||
|
||||
#### [12.4.3.2](#over.assign) Simple assignment [[over.assign]](over.assign)
|
||||
|
||||
[1](#over.assign-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3566)
|
||||
|
||||
A [*simple assignment operator function*](#def:operator_function,simple_assignment "12.4.3.2 Simple assignment [over.assign]") is a binary operator function named operator=[.](#over.assign-1.sentence-1)
|
||||
|
||||
A simple assignment operator function shall be a non-static member function[.](#over.assign-1.sentence-2)
|
||||
|
||||
[*Note [1](#over.assign-note-1)*:
|
||||
|
||||
Because only standard conversion sequences are considered when converting
|
||||
to the left operand of an assignment operation ([[over.best.ics]](over.best.ics "12.2.4.2 Implicit conversion sequences")),
|
||||
an expression x = y with a subexpression x of class type
|
||||
is always interpreted as x.operator=(y)[.](#over.assign-1.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#over.assign-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3577)
|
||||
|
||||
[*Note [2](#over.assign-note-2)*:
|
||||
|
||||
Since a copy assignment operator is implicitly declared for a class
|
||||
if not declared by the user ([[class.copy.assign]](class.copy.assign "11.4.6 Copy/move assignment operator")),
|
||||
a base class assignment operator function is always hidden by
|
||||
the copy assignment operator function of the derived class[.](#over.assign-2.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[3](#over.assign-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3585)
|
||||
|
||||
[*Note [3](#over.assign-note-3)*:
|
||||
|
||||
Any assignment operator function, even the copy and move assignment operators,
|
||||
can be virtual[.](#over.assign-3.sentence-1)
|
||||
|
||||
For a derived class D with a base class B for which a virtual copy/move assignment has been declared,
|
||||
the copy/move assignment operator in D does not overrideB's virtual copy/move assignment operator[.](#over.assign-3.sentence-2)
|
||||
|
||||
[*Example [1](#over.assign-example-1)*: struct B {virtual int operator= (int); virtual B& operator= (const B&);};struct D : B {virtual int operator= (int); virtual D& operator= (const B&);};
|
||||
|
||||
D dobj1;
|
||||
D dobj2;
|
||||
B* bptr = &dobj1;void f() { bptr->operator=(99); // calls D::operator=(int)*bptr = 99; // ditto bptr->operator=(dobj2); // calls D::operator=(const B&)*bptr = dobj2; // ditto dobj1 = dobj2; // calls implicitly-declared D::operator=(const D&)} â *end example*]
|
||||
|
||||
â *end note*]
|
||||
48
cppdraft/over/binary/general.md
Normal file
48
cppdraft/over/binary/general.md
Normal file
@@ -0,0 +1,48 @@
|
||||
[over.binary.general]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.4 Overloaded operators [[over.oper]](over.oper#over.binary.general)
|
||||
|
||||
### 12.4.3 Binary operators [[over.binary]](over.binary#general)
|
||||
|
||||
#### 12.4.3.1 General [over.binary.general]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3530)
|
||||
|
||||
A [*binary operator function*](#def:operator_function,binary "12.4.3.1 General [over.binary.general]") is a function named operator@ for a binary operator @ that is either
|
||||
a non-static member function ([[class.mfct]](class.mfct "11.4.2 Member functions")) with one non-object parameter or
|
||||
a non-member function with two parameters[.](#1.sentence-1)
|
||||
|
||||
For an expression x @ y with subexpressions x and y,
|
||||
the operator function is selected by overload resolution ([[over.match.oper]](over.match.oper "12.2.2.3 Operators in expressions"))[.](#1.sentence-2)
|
||||
|
||||
If a member function is selected,
|
||||
the expression is interpreted as
|
||||
|
||||
x . operator @ ( y )
|
||||
|
||||
Otherwise, if a non-member function is selected,
|
||||
the expression is interpreted as
|
||||
|
||||
operator @ ( x , y )
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3550)
|
||||
|
||||
An [*equality operator function*](#def:operator_function,equality "12.4.3.1 General [over.binary.general]") is an operator function
|
||||
for an equality operator ([[expr.eq]](expr.eq "7.6.10 Equality operators"))[.](#2.sentence-1)
|
||||
|
||||
A [*relational operator function*](#def:operator_function,relational "12.4.3.1 General [over.binary.general]") is an operator function
|
||||
for a relational operator ([[expr.rel]](expr.rel "7.6.9 Relational operators"))[.](#2.sentence-2)
|
||||
|
||||
A [*three-way comparison operator function*](#def:operator_function,three-way_comparison "12.4.3.1 General [over.binary.general]") is an operator function
|
||||
for the three-way comparison operator ([[expr.spaceship]](expr.spaceship "7.6.8 Three-way comparison operator"))[.](#2.sentence-3)
|
||||
|
||||
A [*comparison operator function*](#def:operator_function,comparison "12.4.3.1 General [over.binary.general]") is
|
||||
an equality operator function,
|
||||
a relational operator function, or
|
||||
a three-way comparison operator function[.](#2.sentence-4)
|
||||
248
cppdraft/over/built.md
Normal file
248
cppdraft/over/built.md
Normal file
@@ -0,0 +1,248 @@
|
||||
[over.built]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.5 Built-in operators [over.built]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3775)
|
||||
|
||||
The candidate operator functions that represent the built-in operators
|
||||
defined in [[expr.compound]](expr.compound "7.6 Compound expressions") are specified in this subclause[.](#1.sentence-1)
|
||||
|
||||
These candidate
|
||||
functions participate in the operator overload resolution process as
|
||||
described in [[over.match.oper]](over.match.oper "12.2.2.3 Operators in expressions") and are used for no other purpose[.](#1.sentence-2)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
Because built-in operators take only operands with non-class type,
|
||||
and operator overload resolution occurs only when an operand expression
|
||||
originally has class or enumeration type,
|
||||
operator overload resolution can resolve to a built-in operator only
|
||||
when an operand has a class type that has a user-defined conversion to
|
||||
a non-class type appropriate for the operator, or when an operand has
|
||||
an enumeration type that can be converted to a type appropriate
|
||||
for the operator[.](#1.sentence-3)
|
||||
|
||||
Also note that some of the candidate operator functions given in this subclause are
|
||||
more permissive than the built-in operators themselves[.](#1.sentence-4)
|
||||
|
||||
As
|
||||
described in [[over.match.oper]](over.match.oper "12.2.2.3 Operators in expressions"), after a built-in operator is selected
|
||||
by overload resolution the expression is subject to the requirements for
|
||||
the built-in operator given in [[expr.compound]](expr.compound "7.6 Compound expressions"), and therefore to any
|
||||
additional semantic constraints given there[.](#1.sentence-5)
|
||||
|
||||
In some cases, user-written candidates
|
||||
with the same name and parameter types as a built-in
|
||||
candidate operator function cause the built-in operator function
|
||||
to not be included in the set of candidate functions[.](#1.sentence-6)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3803)
|
||||
|
||||
In this subclause, the term[*promoted integral type*](#def:promoted_integral_type "12.5 Built-in operators [over.built]") is used to refer to those cv-unqualified integral types which are preserved by[integral promotion](conv.prom "7.3.7 Integral promotions [conv.prom]") (including e.g.int andlong but excluding e.g.char)[.](#2.sentence-1)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
In all cases where a promoted integral type is
|
||||
required, an operand of unscoped enumeration type will be acceptable by way of the
|
||||
integral promotions[.](#2.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3821)
|
||||
|
||||
In the remainder of this subclause, *vq* represents eithervolatile or no cv-qualifier[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3825)
|
||||
|
||||
For every pair
|
||||
(*T*,*vq*),
|
||||
where*T* is a cv-unqualified arithmetic type other than bool or a cv-unqualified pointer to (possibly cv-qualified) object type,
|
||||
there exist candidate operator functions of the form*vq* *T*& operator++(*vq* *T*&);*T* operator++(*vq* *T*&, int);*vq* *T*& operator--(*vq* *T*&);*T* operator--(*vq* *T*&, int);
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3841)
|
||||
|
||||
For every (possibly cv-qualified) object type *T* and
|
||||
for every function type *T* that has neither [*cv-qualifier*](dcl.decl.general#nt:cv-qualifier "9.3.1 General [dcl.decl.general]")*s* nor a [*ref-qualifier*](dcl.decl.general#nt:ref-qualifier "9.3.1 General [dcl.decl.general]"),
|
||||
there exist candidate operator functions of the form*T*& operator*(*T**);
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3850)
|
||||
|
||||
For every type *T* there exist candidate operator functions of the form*T** operator+(*T**);
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3856)
|
||||
|
||||
For every cv-unqualified floating-point or promoted integral type *T*,
|
||||
there exist candidate operator functions of the form*T* operator+(*T*);*T* operator-(*T*);
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3864)
|
||||
|
||||
For every promoted integral type*T*,
|
||||
there exist candidate operator functions of the form*T* operator~(*T*);
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3872)
|
||||
|
||||
For every quintuple
|
||||
(*C1*,*C2*,*T*,*cv1*,*cv2*),
|
||||
where*C2* is a class type,*C1* is the same type as *C2* or is a derived class of *C2*, and*T* is an object type or a function type,
|
||||
there exist candidate operator functions of the form*cv12* *T*& operator->*(*cv1* *C1**, *cv2* *T C2*::*); where *cv12* is the union of *cv1* and *cv2*[.](#9.sentence-1)
|
||||
|
||||
The return type is shown for exposition only; see [[expr.mptr.oper]](expr.mptr.oper "7.6.4 Pointer-to-member operators") for the
|
||||
determination of the operator's result type[.](#9.sentence-2)
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3894)
|
||||
|
||||
For every pair of types *L* and *R*,
|
||||
where each of *L* and *R* is a
|
||||
floating-point or promoted integral type,
|
||||
there exist candidate operator functions of the form*LR* operator*(*L*, *R*);*LR* operator/(*L*, *R*);*LR* operator+(*L*, *R*);*LR* operator-(*L*, *R*);bool operator==(*L*, *R*);bool operator!=(*L*, *R*);bool operator<(*L*, *R*);bool operator>(*L*, *R*);bool operator<=(*L*, *R*);bool operator>=(*L*, *R*); where*LR* is the result of the usual arithmetic conversions ([[expr.arith.conv]](expr.arith.conv "7.4 Usual arithmetic conversions")) between types*L* and*R*[.](#10.sentence-1)
|
||||
|
||||
[11](#11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3918)
|
||||
|
||||
For every integral type *T* there exists a candidate operator function of the formstd::strong_ordering operator<=>(*T*, *T*);
|
||||
|
||||
[12](#12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3925)
|
||||
|
||||
For every pair of floating-point types*L* and *R*,
|
||||
there exists a candidate operator function of the formstd::partial_ordering operator<=>(*L*, *R*);
|
||||
|
||||
[13](#13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3933)
|
||||
|
||||
For every cv-qualified or cv-unqualified object type*T* there exist candidate operator functions of the form*T** operator+(*T**, std::ptrdiff_t);*T*& operator[](*T**, std::ptrdiff_t);*T** operator-(*T**, std::ptrdiff_t);*T** operator+(std::ptrdiff_t, *T**);*T*& operator[](std::ptrdiff_t, *T**);
|
||||
|
||||
[14](#14)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3945)
|
||||
|
||||
For every*T*,
|
||||
where*T* is a pointer to object type,
|
||||
there exist candidate operator functions of the formstd::ptrdiff_t operator-(*T*, *T*);
|
||||
|
||||
[15](#15)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3956)
|
||||
|
||||
For every *T*, where *T* is an enumeration type or a pointer type,
|
||||
there exist candidate operator functions of the formbool operator==(*T*, *T*);bool operator!=(*T*, *T*);bool operator<(*T*, *T*);bool operator>(*T*, *T*);bool operator<=(*T*, *T*);bool operator>=(*T*, *T*);*R* operator<=>(*T*, *T*); where *R* is the result type specified in [[expr.spaceship]](expr.spaceship "7.6.8 Three-way comparison operator")[.](#15.sentence-1)
|
||||
|
||||
[16](#16)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3970)
|
||||
|
||||
For every *T*, where *T* is a pointer-to-member type, std::meta::info, or std::nullptr_t,
|
||||
there exist candidate operator functions of the formbool operator==(*T*, *T*);bool operator!=(*T*, *T*);
|
||||
|
||||
[17](#17)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3979)
|
||||
|
||||
For every pair of promoted integral types*L* and*R*,
|
||||
there exist candidate operator functions of the form*LR* operator%(*L*, *R*);*LR* operator&(*L*, *R*);*LR* operator^(*L*, *R*);*LR* operator|(*L*, *R*);*L* operator<<(*L*, *R*);*L* operator>>(*L*, *R*); where*LR* is the result of the usual arithmetic conversions ([[expr.arith.conv]](expr.arith.conv "7.4 Usual arithmetic conversions")) between types*L* and*R*[.](#17.sentence-1)
|
||||
|
||||
[18](#18)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L4000)
|
||||
|
||||
For every triple
|
||||
(*L*, *vq*, *R*),
|
||||
where *L* is an arithmetic type,
|
||||
and *R* is a floating-point or promoted integral type,
|
||||
there exist candidate operator functions of the form*vq* *L*& operator=(*vq* *L*&, *R*);*vq* *L*& operator*=(*vq* *L*&, *R*);*vq* *L*& operator/=(*vq* *L*&, *R*);*vq* *L*& operator+=(*vq* *L*&, *R*);*vq* *L*& operator-=(*vq* *L*&, *R*);
|
||||
|
||||
[19](#19)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L4014)
|
||||
|
||||
For every pair (*T*, *vq*),
|
||||
where *T* is any type,
|
||||
there exist candidate operator functions of the form*T***vq*& operator=(*T***vq*&, *T**);
|
||||
|
||||
[20](#20)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L4022)
|
||||
|
||||
For every pair
|
||||
(*T*,*vq*),
|
||||
where*T* is an enumeration or pointer-to-member type,
|
||||
there exist candidate operator functions of the form*vq* *T*& operator=(*vq* *T*&, *T*);
|
||||
|
||||
[21](#21)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L4034)
|
||||
|
||||
For every pair
|
||||
(*T*,*vq*),
|
||||
where*T* is a cv-qualified or cv-unqualified object type,
|
||||
there exist candidate operator functions of the form*T***vq*& operator+=(*T***vq*&, std::ptrdiff_t);*T***vq*& operator-=(*T***vq*&, std::ptrdiff_t);
|
||||
|
||||
[22](#22)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L4047)
|
||||
|
||||
For every triple
|
||||
(*L*,*vq*,*R*),
|
||||
where*L* is an integral type, and*R* is a promoted integral type,
|
||||
there exist candidate operator functions of the form*vq* *L*& operator%=(*vq* *L*&, *R*);*vq* *L*& operator<<=(*vq* *L*&, *R*);*vq* *L*& operator>>=(*vq* *L*&, *R*);*vq* *L*& operator&=(*vq* *L*&, *R*);*vq* *L*& operator^=(*vq* *L*&, *R*);*vq* *L*& operator|=(*vq* *L*&, *R*);
|
||||
|
||||
[23](#23)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L4067)
|
||||
|
||||
There also exist candidate operator functions of the formbool operator!(bool);bool operator&&(bool, bool);bool operator||(bool, bool);
|
||||
|
||||
[24](#24)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L4075)
|
||||
|
||||
For every pair of types *L* and *R*,
|
||||
where each of *L* and *R* is a
|
||||
floating-point or promoted integral type,
|
||||
there exist candidate operator functions of the form*LR* operator?:(bool, *L*, *R*); where*LR* is the result of the usual arithmetic conversions ([[expr.arith.conv]](expr.arith.conv "7.4 Usual arithmetic conversions")) between types*L* and*R*[.](#24.sentence-1)
|
||||
|
||||
[*Note [3](#note-3)*:
|
||||
|
||||
As with all these descriptions of candidate functions, this declaration serves
|
||||
only to describe the built-in operator for purposes of overload resolution[.](#24.sentence-2)
|
||||
|
||||
The operator
|
||||
â?:â
|
||||
cannot be overloaded[.](#24.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[25](#25)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L4097)
|
||||
|
||||
For every type*T*,
|
||||
where*T* is a pointer, pointer-to-member, or scoped enumeration type, there exist candidate operator
|
||||
functions of the form*T* operator?:(bool, *T*, *T*);
|
||||
34
cppdraft/over/call.md
Normal file
34
cppdraft/over/call.md
Normal file
@@ -0,0 +1,34 @@
|
||||
[over.call]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.4 Overloaded operators [[over.oper]](over.oper#over.call)
|
||||
|
||||
### 12.4.4 Function call [over.call]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3622)
|
||||
|
||||
A [*function call operator function*](#def:operator_function,function_call "12.4.4 Function call [over.call]") is a function named operator() that is a member function with an arbitrary number of parameters[.](#1.sentence-1)
|
||||
|
||||
It may have default arguments[.](#1.sentence-2)
|
||||
|
||||
For an expression of the form
|
||||
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") ( [*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]")opt )
|
||||
|
||||
where the [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") is of class type,
|
||||
the operator function
|
||||
is selected by overload resolution ([[over.call.object]](over.call.object "12.2.2.2.3 Call to object of class type"))[.](#1.sentence-3)
|
||||
|
||||
If a surrogate call function is selected,
|
||||
let e be the result of invoking the corresponding conversion operator function on the [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]");
|
||||
|
||||
the expression is interpreted as
|
||||
|
||||
e ( [*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]")opt )
|
||||
|
||||
Otherwise, the expression is interpreted as
|
||||
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") . operator () ( [*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]")opt )
|
||||
139
cppdraft/over/call/func.md
Normal file
139
cppdraft/over/call/func.md
Normal file
@@ -0,0 +1,139 @@
|
||||
[over.call.func]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#over.call.func)
|
||||
|
||||
### 12.2.2 Candidate functions and argument lists [[over.match.funcs]](over.match.funcs#over.call.func)
|
||||
|
||||
#### 12.2.2.2 Function call syntax [[over.match.call]](over.match.call#over.call.func)
|
||||
|
||||
#### 12.2.2.2.2 Call to designated function [over.call.func]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L389)
|
||||
|
||||
Of interest in [over.call.func] are only those function calls
|
||||
in which the [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") ultimately contains
|
||||
an [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") or [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]") that designates one or more functions[.](#1.sentence-1)
|
||||
|
||||
Such a[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]"),
|
||||
perhaps nested arbitrarily deep in
|
||||
parentheses, has one of the following forms:
|
||||
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]"):
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") . [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]")
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") . [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]")
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") -> [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]")
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") -> [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]")
|
||||
[*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]")
|
||||
[*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]")
|
||||
|
||||
These represent two syntactic subcategories of function calls:
|
||||
qualified function calls and unqualified function calls[.](#1.sentence-3)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L411)
|
||||
|
||||
In qualified function calls,
|
||||
the function is designated by
|
||||
an [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") or [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]") E preceded by an -> or . operator[.](#2.sentence-1)
|
||||
|
||||
Since the
|
||||
constructA->B is generally equivalent to(*A).B,
|
||||
the rest of[[over]](over "12 Overloading") assumes, without loss of generality, that all member
|
||||
function calls have been normalized to the form that uses an
|
||||
object and the. operator[.](#2.sentence-2)
|
||||
|
||||
Furthermore, [[over]](over "12 Overloading") assumes that
|
||||
the[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") that is the left operand of the. operator
|
||||
has type âcv Tâ
|
||||
whereT denotes a class[.](#2.sentence-3)[100](#footnote-100 "Note that cv-qualifiers on the type of objects are significant in overload resolution for both glvalue and class prvalue objects.")
|
||||
|
||||
The set of candidate functions either
|
||||
is the set found by name lookup ([[class.member.lookup]](class.member.lookup "6.5.2 Member name lookup"))
|
||||
if E is an [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") or
|
||||
is the set determined as specified in [[expr.prim.splice]](expr.prim.splice "7.5.9 Expression splicing") if E is a [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]")[.](#2.sentence-4)
|
||||
|
||||
The argument list is the[*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]") in the call augmented by the addition of the left operand of
|
||||
the. operator in the normalized member function call as the
|
||||
implied object argument ([[over.match.funcs]](over.match.funcs "12.2.2 Candidate functions and argument lists"))[.](#2.sentence-5)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L456)
|
||||
|
||||
In unqualified function calls, the function is designated by
|
||||
an [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") or a [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]") E[.](#3.sentence-1)
|
||||
|
||||
The set of candidate functions either
|
||||
is the set found by name lookup ([[basic.lookup]](basic.lookup "6.5 Name lookup"))
|
||||
if E is an [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") or
|
||||
is the set determined as specified in [[expr.prim.splice]](expr.prim.splice "7.5.9 Expression splicing") if E is a [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]")[.](#3.sentence-2)
|
||||
|
||||
The set of candidate functions
|
||||
consists either entirely of non-member functions or entirely of
|
||||
member functions of some classT[.](#3.sentence-3)
|
||||
|
||||
In the former case or
|
||||
if E is either a [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]") or
|
||||
the address of an overload set,
|
||||
the argument list is
|
||||
the same as the[*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]") in the call[.](#3.sentence-4)
|
||||
|
||||
Otherwise, the argument list is the[*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]") in the call augmented by the addition of an implied object
|
||||
argument as in a qualified function call[.](#3.sentence-5)
|
||||
|
||||
If the current class is, or is derived from, T, and the keywordthis ([[expr.prim.this]](expr.prim.this "7.5.3 This")) refers to it,
|
||||
|
||||
- [(3.1)](#3.1)
|
||||
|
||||
if the unqualified function call
|
||||
appears in a precondition assertion of a constructor
|
||||
or a postcondition assertion of a destructor
|
||||
and overload resolution selects a non-static member function,
|
||||
the call is ill-formed;
|
||||
|
||||
- [(3.2)](#3.2)
|
||||
|
||||
otherwise,
|
||||
the implied object argument is(*this)[.](#3.sentence-6)
|
||||
|
||||
Otherwise,
|
||||
|
||||
- [(3.3)](#3.3)
|
||||
|
||||
if overload resolution selects a non-static member function,
|
||||
the call is ill-formed;
|
||||
|
||||
- [(3.4)](#3.4)
|
||||
|
||||
otherwise,
|
||||
a contrived object of typeT becomes the implied object argument[.](#3.sentence-7)[101](#footnote-101 "An implied object argument is contrived to correspond to the implicit object parameter attributed to member functions during overload resolution. It is not used in the call to the selected function. Since the member functions all have the same implicit object parameter, the contrived object will not be the cause to select or reject a function.")
|
||||
|
||||
[*Example [1](#example-1)*: struct C {bool a(); void b() { a(); // OK, (*this).a()}void c(this const C&); // #1void c() &; // #2static void c(int = 0); // #3void d() { c(); // error: ambiguous between #2 and #3(C::c)(); // error: as above(&(C::c))(); // error: cannot resolve address of overloaded this->C::c ([[over.over]](over.over "12.3 Address of an overload set"))(&C::c)(C{}); // selects #1(&C::c)(*this); // error: selects #2, and is ill-formed ([[over.match.call.general]](over.match.call.general "12.2.2.2.1 General"))(&C::c)(); // selects #3}void f(this const C&); void g() const { f(); // OK, (*this).f() f(*this); // error: no viable candidate for (*this).f(*this)this->f(); // OK}static void h() { f(); // error: contrived object argument, but overload resolution// picked a non-static member function f(C{}); // error: no viable candidate C{}.f(); // OK}void k(this int); operator int() const; void m(this const C& c) { c.k(); // OK} C() pre(a()) // error: implied this in constructor precondition pre(this->a()) // OK post(a()); // OK~C() pre(a()) // OK post(a()) // error: implied this in destructor postcondition post(this->a()); // OK}; â *end example*]
|
||||
|
||||
[100)](#footnote-100)[100)](#footnoteref-100)
|
||||
|
||||
Note that cv-qualifiers on the type of objects are
|
||||
significant in overload
|
||||
resolution for
|
||||
both glvalue and class prvalue objects[.](#footnote-100.sentence-1)
|
||||
|
||||
[101)](#footnote-101)[101)](#footnoteref-101)
|
||||
|
||||
An implied object argument is contrived to
|
||||
correspond to the implicit object
|
||||
parameter attributed to member functions during overload resolution[.](#footnote-101.sentence-1)
|
||||
|
||||
It is not
|
||||
used in
|
||||
the call to the selected function[.](#footnote-101.sentence-2)
|
||||
|
||||
Since the member functions all have the
|
||||
same implicit
|
||||
object parameter, the contrived object will not be the cause to select or
|
||||
reject a
|
||||
function[.](#footnote-101.sentence-3)
|
||||
85
cppdraft/over/call/object.md
Normal file
85
cppdraft/over/call/object.md
Normal file
@@ -0,0 +1,85 @@
|
||||
[over.call.object]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#over.call.object)
|
||||
|
||||
### 12.2.2 Candidate functions and argument lists [[over.match.funcs]](over.match.funcs#over.call.object)
|
||||
|
||||
#### 12.2.2.2 Function call syntax [[over.match.call]](over.match.call#over.call.object)
|
||||
|
||||
#### 12.2.2.2.3 Call to object of class type [over.call.object]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L573)
|
||||
|
||||
If the [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") E in the function call syntax evaluates
|
||||
to a class object of type âcv Tâ,
|
||||
then the set of candidate functions
|
||||
includes at least the function call operators of T[.](#1.sentence-1)
|
||||
|
||||
The function call operators of T are the results of a search for the name operator() in the scope of T[.](#1.sentence-2)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L583)
|
||||
|
||||
In addition, for each non-explicit conversion function declared in T of the
|
||||
form
|
||||
|
||||
operator [*conversion-type-id*](class.conv.fct#nt:conversion-type-id "11.4.8.3 Conversion functions [class.conv.fct]") ( ) [*cv-qualifier-seq*](dcl.decl.general#nt:cv-qualifier-seq "9.3.1 General [dcl.decl.general]")opt [*ref-qualifier*](dcl.decl.general#nt:ref-qualifier "9.3.1 General [dcl.decl.general]")opt [*noexcept-specifier*](except.spec#nt:noexcept-specifier "14.5 Exception specifications [except.spec]")opt [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]")opt ;
|
||||
|
||||
where the optional[*cv-qualifier-seq*](dcl.decl.general#nt:cv-qualifier-seq "9.3.1 General [dcl.decl.general]") is the same cv-qualification as, or a greater cv-qualification than,cv,
|
||||
and where[*conversion-type-id*](class.conv.fct#nt:conversion-type-id "11.4.8.3 Conversion functions [class.conv.fct]") denotes the type âpointer to function
|
||||
of (P1,â¦,Pn) returning Râ,
|
||||
or the type âreference to pointer to function
|
||||
of (P1,â¦,Pn) returning Râ,
|
||||
or the type
|
||||
âreference to function of (P1,â¦,Pn)
|
||||
returning Râ, a [*surrogate call function*](#def:surrogate_call_function "12.2.2.2.3 Call to object of class type [over.call.object]") with the unique name*call-function* and having the form
|
||||
|
||||
R *call-function* ( [*conversion-type-id*](class.conv.fct#nt:conversion-type-id "11.4.8.3 Conversion functions [class.conv.fct]") F, P1 a1, …, Pn an) { return F (a1, …, an); }
|
||||
|
||||
is also considered as a candidate function[.](#2.sentence-1)
|
||||
|
||||
Similarly, surrogate
|
||||
call functions are added to the set of candidate functions for
|
||||
each non-explicit conversion function declared in a base class ofT provided the function is not hidden withinT by another
|
||||
intervening declaration[.](#2.sentence-2)[102](#footnote-102 "Note that this construction can yield candidate call functions that cannot be differentiated one from the other by overload resolution because they have identical declarations or differ only in their return type. The call will be ambiguous if overload resolution cannot select a match to the call that is uniquely better than such undifferentiable functions.")
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L629)
|
||||
|
||||
The argument list submitted to overload resolution consists of
|
||||
the argument expressions present in the function call syntax
|
||||
preceded by the implied object argument(E)[.](#3.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
When comparing the
|
||||
call against the function call operators, the implied object
|
||||
argument is compared against the object parameter of the
|
||||
function call operator[.](#3.sentence-2)
|
||||
|
||||
When comparing the call against a
|
||||
surrogate call function, the implied object argument is compared
|
||||
against the first parameter of the surrogate call function[.](#3.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Example [1](#example-1)*: int f1(int);int f2(float);typedef int (*fp1)(int);typedef int (*fp2)(float);struct A {operator fp1() { return f1; }operator fp2() { return f2; }} a;int i = a(1); // calls f1 via pointer returned from conversion function â *end example*]
|
||||
|
||||
[102)](#footnote-102)[102)](#footnoteref-102)
|
||||
|
||||
Note that this construction can yield
|
||||
candidate call functions that cannot be
|
||||
differentiated one from the other by overload resolution because they have
|
||||
identical
|
||||
declarations or differ only in their return type[.](#footnote-102.sentence-1)
|
||||
|
||||
The call will be ambiguous
|
||||
if overload
|
||||
resolution cannot select a match to the call that is uniquely better than such
|
||||
undifferentiable functions[.](#footnote-102.sentence-2)
|
||||
19
cppdraft/over/ics/ellipsis.md
Normal file
19
cppdraft/over/ics/ellipsis.md
Normal file
@@ -0,0 +1,19 @@
|
||||
[over.ics.ellipsis]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#over.ics.ellipsis)
|
||||
|
||||
### 12.2.4 Best viable function [[over.match.best]](over.match.best#over.ics.ellipsis)
|
||||
|
||||
#### 12.2.4.2 Implicit conversion sequences [[over.best.ics]](over.best.ics#over.ics.ellipsis)
|
||||
|
||||
#### 12.2.4.2.4 Ellipsis conversion sequences [over.ics.ellipsis]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2380)
|
||||
|
||||
An ellipsis conversion sequence occurs when an argument in a
|
||||
function call is matched with the ellipsis parameter
|
||||
specification of the function called (see [[expr.call]](expr.call "7.6.1.3 Function call"))[.](#1.sentence-1)
|
||||
195
cppdraft/over/ics/list.md
Normal file
195
cppdraft/over/ics/list.md
Normal file
@@ -0,0 +1,195 @@
|
||||
[over.ics.list]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#over.ics.list)
|
||||
|
||||
### 12.2.4 Best viable function [[over.match.best]](over.match.best#over.ics.list)
|
||||
|
||||
#### 12.2.4.2 Implicit conversion sequences [[over.best.ics]](over.best.ics#over.ics.list)
|
||||
|
||||
#### 12.2.4.2.6 List-initialization sequence [over.ics.list]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2484)
|
||||
|
||||
When an argument is an initializer list ([[dcl.init.list]](dcl.init.list "9.5.5 List-initialization")), it is not an expression and special rules apply for converting it to a parameter type[.](#1.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2488)
|
||||
|
||||
If the initializer list is a [*designated-initializer-list*](dcl.init.general#nt:designated-initializer-list "9.5.1 General [dcl.init.general]") and the parameter is not a reference,
|
||||
a conversion is only possible if
|
||||
the parameter has an aggregate type
|
||||
that can be initialized from the initializer list
|
||||
according to the rules for aggregate initialization ([[dcl.init.aggr]](dcl.init.aggr "9.5.2 Aggregates")),
|
||||
in which case the implicit conversion sequence is
|
||||
a user-defined conversion sequence
|
||||
whose second standard conversion sequence
|
||||
is an identity conversion[.](#2.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
Aggregate initialization does not require that
|
||||
the members are declared in designation order[.](#2.sentence-2)
|
||||
|
||||
If, after overload resolution, the order does not match
|
||||
for the selected overload,
|
||||
the initialization of the parameter will be ill-formed ([[dcl.init.list]](dcl.init.list "9.5.5 List-initialization"))[.](#2.sentence-3)
|
||||
|
||||
[*Example [1](#example-1)*: struct A { int x, y; };struct B { int y, x; };void f(A a, int); // #1void f(B b, ...); // #2void g(A a); // #3void g(B b); // #4void h() { f({.x = 1, .y = 2}, 0); // OK; calls #1 f({.y = 2, .x = 1}, 0); // error: selects #1, initialization of a fails// due to non-matching member order ([[dcl.init.list]](dcl.init.list "9.5.5 List-initialization")) g({.x = 1, .y = 2}); // error: ambiguous between #3 and #4} â *end example*]
|
||||
|
||||
â *end note*]
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2523)
|
||||
|
||||
Otherwise,
|
||||
if the parameter type is an aggregate class X and the initializer list has a
|
||||
single element of type cv U, where U is X or a class derived from X, the implicit conversion sequence is the one
|
||||
required to convert the element to the parameter type[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2530)
|
||||
|
||||
Otherwise, if the parameter type is a character array[106](#footnote-106 "Since there are no parameters of array type, this will only occur as the referenced type of a reference parameter.") and the initializer list has a single element that is an appropriately-typed[*string-literal*](lex.string#nt:string-literal "5.13.5 String literals [lex.string]") ([[dcl.init.string]](dcl.init.string "9.5.3 Character arrays")), the implicit conversion
|
||||
sequence is the identity conversion[.](#4.sentence-1)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2540)
|
||||
|
||||
Otherwise, if the parameter type is std::initializer_list<X> and all the elements
|
||||
of the initializer list can be implicitly converted to X, the implicit
|
||||
conversion sequence is the worst conversion necessary to convert an element of
|
||||
the list to X, or if the initializer list has no elements, the identity
|
||||
conversion[.](#5.sentence-1)
|
||||
|
||||
This conversion can be a user-defined conversion even in
|
||||
the context of a call to an initializer-list constructor[.](#5.sentence-2)
|
||||
|
||||
[*Example [2](#example-2)*: void f(std::initializer_list<int>);
|
||||
f( {} ); // OK, f(initializer_list<int>) identity conversion f( {1,2,3} ); // OK, f(initializer_list<int>) identity conversion f( {'a','b'} ); // OK, f(initializer_list<int>) integral promotion f( {1.0} ); // error: narrowingstruct A { A(std::initializer_list<double>); // #1 A(std::initializer_list<std::complex<double>>); // #2 A(std::initializer_list<std::string>); // #3};
|
||||
A a{ 1.0,2.0 }; // OK, uses #1void g(A);
|
||||
g({ "foo", "bar" }); // OK, uses #3typedef int IA[3];void h(const IA&);
|
||||
h({ 1, 2, 3 }); // OK, identity conversion â *end example*]
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2572)
|
||||
|
||||
Otherwise, if the parameter type is âarray of N Xâ
|
||||
or âarray of unknown bound of Xâ,
|
||||
if there exists an implicit conversion sequence
|
||||
from each element of the initializer list
|
||||
(and from {} in the former case
|
||||
if N exceeds the number of elements in the initializer list)
|
||||
to X, the implicit conversion sequence is
|
||||
the worst such implicit conversion sequence[.](#6.sentence-1)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2582)
|
||||
|
||||
Otherwise, if the parameter is a non-aggregate class X and overload
|
||||
resolution per [[over.match.list]](over.match.list "12.2.2.8 Initialization by list-initialization") chooses a single best constructor C ofX to perform the initialization of an object of type X from the
|
||||
argument initializer list:
|
||||
|
||||
- [(7.1)](#7.1)
|
||||
|
||||
If C is not an initializer-list constructor
|
||||
and the initializer list has a single element of type cv U,
|
||||
where U is X or a class derived from X,
|
||||
the implicit conversion sequence has Exact Match rank if U is X,
|
||||
or Conversion rank if U is derived from X[.](#7.1.sentence-1)
|
||||
|
||||
- [(7.2)](#7.2)
|
||||
|
||||
Otherwise, the implicit conversion sequence is a user-defined
|
||||
conversion sequence whose second standard conversion sequence is an
|
||||
identity conversion[.](#7.2.sentence-1)
|
||||
|
||||
If multiple constructors are viable but none is better than
|
||||
the others, the implicit conversion sequence is the ambiguous conversion
|
||||
sequence[.](#7.sentence-2)
|
||||
|
||||
User-defined conversions are allowed for conversion of the initializer
|
||||
list elements to the constructor parameter types except as noted
|
||||
in [[over.best.ics]](over.best.ics "12.2.4.2 Implicit conversion sequences")[.](#7.sentence-3)
|
||||
|
||||
[*Example [3](#example-3)*: struct A { A(std::initializer_list<int>);};void f(A);
|
||||
f( {'a', 'b'} ); // OK, f(A(std::initializer_list<int>)) user-defined conversionstruct B { B(int, double);};void g(B);
|
||||
g( {'a', 'b'} ); // OK, g(B(int, double)) user-defined conversion g( {1.0, 1.0} ); // error: narrowingvoid f(B);
|
||||
f( {'a', 'b'} ); // error: ambiguous f(A) or f(B)struct C { C(std::string);};void h(C);
|
||||
h({"foo"}); // OK, h(C(std::string("foo")))struct D { D(A, C);};void i(D);
|
||||
i({ {1,2}, {"bar"} }); // OK, i(D(A(std::initializer_list<int>{1,2}), C(std::string("bar")))) â *end example*]
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2636)
|
||||
|
||||
Otherwise, if the parameter has an aggregate type which can be initialized from
|
||||
the initializer list according to the rules for aggregate
|
||||
initialization ([[dcl.init.aggr]](dcl.init.aggr "9.5.2 Aggregates")), the implicit conversion sequence is a
|
||||
user-defined conversion sequence whose second standard conversion
|
||||
sequence is an identity conversion[.](#8.sentence-1)
|
||||
|
||||
[*Example [4](#example-4)*: struct A {int m1; double m2;};
|
||||
|
||||
void f(A);
|
||||
f( {'a', 'b'} ); // OK, f(A(int,double)) user-defined conversion f( {1.0} ); // error: narrowing â *end example*]
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2655)
|
||||
|
||||
Otherwise, if the parameter is a reference, see [[over.ics.ref]](over.ics.ref "12.2.4.2.5 Reference binding")[.](#9.sentence-1)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
The rules in this subclause will apply for initializing the underlying temporary
|
||||
for the reference[.](#9.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Example [5](#example-5)*: struct A {int m1; double m2;};
|
||||
|
||||
void f(const A&);
|
||||
f( {'a', 'b'} ); // OK, f(A(int,double)) user-defined conversion f( {1.0} ); // error: narrowingvoid g(const double &);
|
||||
g({1}); // same conversion as int to double â *end example*]
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2677)
|
||||
|
||||
Otherwise, if the parameter type is not a class:
|
||||
|
||||
- [(10.1)](#10.1)
|
||||
|
||||
if the initializer list has one element that is not itself an initializer list,
|
||||
the implicit conversion sequence is the one required to convert the element to
|
||||
the parameter type;
|
||||
[*Example [6](#example-6)*: void f(int);
|
||||
f( {'a'} ); // OK, same conversion as char to int f( {1.0} ); // error: narrowing â *end example*]
|
||||
|
||||
- [(10.2)](#10.2)
|
||||
|
||||
if the initializer list has no elements, the implicit conversion sequence
|
||||
is the identity conversion[.](#10.sentence-1)
|
||||
[*Example [7](#example-7)*: void f(int);
|
||||
f( { } ); // OK, identity conversion â *end example*]
|
||||
|
||||
[11](#11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2701)
|
||||
|
||||
In all cases other than those enumerated above, no conversion is possible[.](#11.sentence-1)
|
||||
|
||||
[106)](#footnote-106)[106)](#footnoteref-106)
|
||||
|
||||
Since there are no parameters of array type,
|
||||
this will only occur as the referenced type of a reference parameter[.](#footnote-106.sentence-1)
|
||||
245
cppdraft/over/ics/rank.md
Normal file
245
cppdraft/over/ics/rank.md
Normal file
@@ -0,0 +1,245 @@
|
||||
[over.ics.rank]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#over.ics.rank)
|
||||
|
||||
### 12.2.4 Best viable function [[over.match.best]](over.match.best#over.ics.rank)
|
||||
|
||||
#### 12.2.4.3 Ranking implicit conversion sequences [over.ics.rank]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2706)
|
||||
|
||||
This subclause defines a partial ordering of implicit conversion
|
||||
sequences based on the relationships[*better conversion sequence*](#def:conversion_sequence,better "12.2.4.3 Ranking implicit conversion sequences [over.ics.rank]") and[*better conversion*](#def:conversion,better "12.2.4.3 Ranking implicit conversion sequences [over.ics.rank]")[.](#1.sentence-1)
|
||||
|
||||
If an implicit conversion sequence S1 is
|
||||
defined by these rules to be a better conversion sequence than
|
||||
S2, then it is also the case that S2 is a[*worse conversion sequence*](#def:conversion_sequence,worse "12.2.4.3 Ranking implicit conversion sequences [over.ics.rank]") than S1[.](#1.sentence-2)
|
||||
|
||||
If conversion sequence S1 is neither better
|
||||
than nor worse than conversion sequence S2, S1 and S2 are said to
|
||||
be[*indistinguishable conversion sequences*](#def:conversion_sequence,indistinguishable "12.2.4.3 Ranking implicit conversion sequences [over.ics.rank]")[.](#1.sentence-3)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2722)
|
||||
|
||||
When comparing the basic forms of implicit conversion sequences
|
||||
(as defined in [[over.best.ics]](over.best.ics "12.2.4.2 Implicit conversion sequences"))
|
||||
|
||||
- [(2.1)](#2.1)
|
||||
|
||||
a [standard conversion sequence](over.ics.scs "12.2.4.2.2 Standard conversion sequences [over.ics.scs]") is a better
|
||||
conversion sequence than a user-defined conversion sequence
|
||||
or an ellipsis conversion sequence, and
|
||||
|
||||
- [(2.2)](#2.2)
|
||||
|
||||
a [user-defined conversion sequence](over.ics.user "12.2.4.2.3 User-defined conversion sequences [over.ics.user]") is a
|
||||
better conversion sequence than an [ellipsis conversion
|
||||
sequence](over.ics.ellipsis "12.2.4.2.4 Ellipsis conversion sequences [over.ics.ellipsis]")[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2736)
|
||||
|
||||
Two implicit conversion sequences of the same form are
|
||||
indistinguishable conversion sequences unless one of the
|
||||
following rules applies:
|
||||
|
||||
- [(3.1)](#3.1)
|
||||
|
||||
List-initialization sequence L1 is a better conversion sequence than
|
||||
list-initialization sequence L2 if
|
||||
* [(3.1.1)](#3.1.1)
|
||||
|
||||
L1 converts to std::initializer_list<X> for some X andL2 does not, or, if not that,
|
||||
|
||||
* [(3.1.2)](#3.1.2)
|
||||
|
||||
L1 and L2 convert to arrays of the same element type, and
|
||||
either the number of elements n1 initialized by L1 is less than the number of elements n2 initialized by L2, orn1=n2 andL2 converts to an array of unknown bound and L1 does not,
|
||||
|
||||
even if one of the other rules in this paragraph would otherwise apply[.](#3.1.sentence-1)
|
||||
[*Example [1](#example-1)*: void f1(int); // #1void f1(std::initializer_list<long>); // #2void g1() { f1({42}); } // chooses #2void f2(std::pair<const char*, const char*>); // #3void f2(std::initializer_list<std::string>); // #4void g2() { f2({"foo","bar"}); } // chooses #4 â *end example*]
|
||||
[*Example [2](#example-2)*: void f(int (&&)[] ); // #1void f(double (&&)[] ); // #2void f(int (&&)[2]); // #3 f( {1} ); // Calls #1: Better than #2 due to conversion, better than #3 due to bounds f( {1.0} ); // Calls #2: Identity conversion is better than floating-integral conversion f( {1.0, 2.0} ); // Calls #2: Identity conversion is better than floating-integral conversion f( {1, 2} ); // Calls #3: Converting to array of known bound is better than to unknown bound,// and an identity conversion is better than floating-integral conversion â *end example*]
|
||||
|
||||
- [(3.2)](#3.2)
|
||||
|
||||
Standard conversion sequenceS1 is a better conversion
|
||||
sequence than standard conversion sequenceS2 if
|
||||
* [(3.2.1)](#3.2.1)
|
||||
|
||||
S1 is a proper subsequence ofS2 (comparing the conversion sequences in the canonical form defined
|
||||
by [[over.ics.scs]](over.ics.scs "12.2.4.2.2 Standard conversion sequences"), excluding any Lvalue Transformation;
|
||||
the identity conversion sequence is considered to be a
|
||||
subsequence of any non-identity conversion sequence)
|
||||
or, if not that,
|
||||
|
||||
* [(3.2.2)](#3.2.2)
|
||||
|
||||
the rank ofS1 is better than the rank ofS2,
|
||||
orS1 andS2 have the same rank and are distinguishable by the rules
|
||||
in the paragraph below,
|
||||
or, if not that,
|
||||
|
||||
* [(3.2.3)](#3.2.3)
|
||||
|
||||
S1 and S2 include reference bindings ([[dcl.init.ref]](dcl.init.ref "9.5.4 References")) and
|
||||
neither refers to an implicit object parameter of a non-static member function
|
||||
declared without a [*ref-qualifier*](dcl.decl.general#nt:ref-qualifier "9.3.1 General [dcl.decl.general]"),
|
||||
and S1 binds an rvalue reference to an
|
||||
rvalue and S2 binds an lvalue reference
|
||||
[*Example [3](#example-3)*: int i;int f1();int&& f2();int g(const int&);int g(const int&&);int j = g(i); // calls g(const int&)int k = g(f1()); // calls g(const int&&)int l = g(f2()); // calls g(const int&&)struct A { A& operator<<(int); void p() &; void p() &&;};
|
||||
A& operator<<(A&&, char);
|
||||
A() << 1; // calls A::operator<<(int) A() << 'c'; // calls operator<<(A&&, char) A a;
|
||||
a << 1; // calls A::operator<<(int) a << 'c'; // calls A::operator<<(int) A().p(); // calls A::p()&& a.p(); // calls A::p()& â *end example*]
|
||||
or, if not that,
|
||||
|
||||
* [(3.2.4)](#3.2.4)
|
||||
|
||||
S1 and S2 include reference bindings ([[dcl.init.ref]](dcl.init.ref "9.5.4 References")) andS1 binds an lvalue reference to an lvalue of function type andS2 binds an rvalue reference to an lvalue of function type
|
||||
[*Example [4](#example-4)*: int f(void(&)()); // #1int f(void(&&)()); // #2void g();int i1 = f(g); // calls #1 â *end example*]
|
||||
or, if not that,
|
||||
|
||||
* [(3.2.5)](#3.2.5)
|
||||
|
||||
S1 and S2 differ only
|
||||
in their qualification conversion ([[conv.qual]](conv.qual "7.3.6 Qualification conversions")) and
|
||||
yield similar types T1 and T2, respectively
|
||||
(where a standard conversion sequence that is a reference binding
|
||||
is considered to yield the cv-unqualified referenced type),
|
||||
where T1 and T2 are not the same type, andconst T2 is reference-compatible with T1 ([[dcl.init.ref]](dcl.init.ref "9.5.4 References"))
|
||||
[*Example [5](#example-5)*: int f(const volatile int *);int f(const int *);int i;int j = f(&i); // calls f(const int*)int g(const int*);int g(const volatile int* const&);int* p;int k = g(p); // calls g(const int*) â *end example*]
|
||||
or, if not that,
|
||||
|
||||
* [(3.2.6)](#3.2.6)
|
||||
|
||||
S1 andS2 bind âreference to T1â and âreference to T2â,
|
||||
respectively ([[dcl.init.ref]](dcl.init.ref "9.5.4 References")),
|
||||
where T1 and T2 are not the same type, andT2 is reference-compatible with T1
|
||||
[*Example [6](#example-6)*: int f(const int &);int f(int &);int g(const int &);int g(int);
|
||||
|
||||
int i;int j = f(i); // calls f(int &)int k = g(i); // ambiguousstruct X {void f() const; void f();};void g(const X& a, X b) { a.f(); // calls X::f() const b.f(); // calls X::f()}int h(int (&)[]);int h(int (&)[1]);void g2() {int a[1];
|
||||
h(a); // calls h(int (&)[1])} â *end example*]
|
||||
or, if not that,
|
||||
|
||||
* [(3.2.7)](#3.2.7)
|
||||
|
||||
S1 and S2 bind the same reference type âreference to Tâ and
|
||||
have source types V1 and V2, respectively,
|
||||
where the standard conversion sequence from V1* to T* is better than the standard conversion sequence from V2* to T*[.](#3.2.sentence-1)
|
||||
[*Example [7](#example-7)*: struct Z {};
|
||||
|
||||
struct A {operator Z&(); operator const Z&(); // #1};
|
||||
|
||||
struct B {operator Z(); operator const Z&&(); // #2};
|
||||
|
||||
const Z& r1 = A(); // OK, uses #1const Z&& r2 = B(); // OK, uses #2 â *end example*]
|
||||
|
||||
- [(3.3)](#3.3)
|
||||
|
||||
User-defined conversion sequenceU1 is a better conversion sequence than another user-defined conversion
|
||||
sequenceU2 if they contain the same user-defined conversion function or
|
||||
constructor or they initialize the same class in an aggregate
|
||||
initialization and in either case the second standard conversion
|
||||
sequence ofU1 is better than
|
||||
the second standard conversion sequence ofU2[.](#3.3.sentence-1)
|
||||
[*Example [8](#example-8)*: struct A {operator short();} a;int f(int);int f(float);int i = f(a); // calls f(int), because short â int is// better than short â float. â *end example*]
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2973)
|
||||
|
||||
Standard conversion sequences are ordered by their ranks: an Exact Match is a
|
||||
better conversion than a Promotion, which is a better conversion than
|
||||
a Conversion[.](#4.sentence-1)
|
||||
|
||||
Two conversion sequences with the same rank are indistinguishable unless
|
||||
one of the following rules applies:
|
||||
|
||||
- [(4.1)](#4.1)
|
||||
|
||||
A conversion that does not convert a pointer or a pointer to member
|
||||
tobool is better than one that does[.](#4.1.sentence-1)
|
||||
|
||||
- [(4.2)](#4.2)
|
||||
|
||||
A conversion that promotes an enumeration whose underlying type is fixed to its underlying
|
||||
type is better than one that promotes to the promoted underlying type, if the two are
|
||||
different[.](#4.2.sentence-1)
|
||||
|
||||
- [(4.3)](#4.3)
|
||||
|
||||
A conversion in either direction
|
||||
between floating-point type FP1 and floating-point type FP2 is better than a conversion in the same direction
|
||||
between FP1 and arithmetic type T3 if
|
||||
* [(4.3.1)](#4.3.1)
|
||||
|
||||
the floating-point conversion rank ([[conv.rank]](conv.rank "6.9.6 Conversion ranks")) of FP1 is equal to the rank of FP2, and
|
||||
|
||||
* [(4.3.2)](#4.3.2)
|
||||
|
||||
T3 is not a floating-point type, orT3 is a floating-point type
|
||||
whose rank is not equal to the rank of FP1, or
|
||||
the floating-point conversion subrank ([[conv.rank]](conv.rank "6.9.6 Conversion ranks")) of FP2 is greater than the subrank of T3[.](#4.3.sentence-1)
|
||||
[*Example [9](#example-9)*: int f(std::float32_t);int f(std::float64_t);int f(long long);float x;
|
||||
std::float16_t y;int i = f(x); // calls f(std::float32_t) on implementations where// float and std::float32_t have equal conversion ranksint j = f(y); // error: ambiguous, no equal conversion rank â *end example*]
|
||||
|
||||
- [(4.4)](#4.4)
|
||||
|
||||
If classB is derived directly or indirectly from classA,
|
||||
conversion ofB* toA* is better than conversion ofB* tovoid*,
|
||||
and conversion ofA* tovoid* is better than conversion
|
||||
ofB* tovoid*[.](#4.4.sentence-1)
|
||||
|
||||
- [(4.5)](#4.5)
|
||||
|
||||
If classB is derived directly or indirectly from classA and classC is derived directly or indirectly fromB,
|
||||
* [(4.5.1)](#4.5.1)
|
||||
|
||||
conversion ofC* toB* is better than conversion ofC* toA*,
|
||||
[*Example [10](#example-10)*: struct A {};struct B : public A {};struct C : public B {};
|
||||
C* pc;int f(A*);int f(B*);int i = f(pc); // calls f(B*) â *end example*]
|
||||
|
||||
* [(4.5.2)](#4.5.2)
|
||||
|
||||
binding of an expression of typeC to a reference to typeB is better than binding an expression of typeC to a reference to typeA,
|
||||
|
||||
* [(4.5.3)](#4.5.3)
|
||||
|
||||
conversion ofA::* toB::* is better than conversion ofA::* toC::*,
|
||||
|
||||
* [(4.5.4)](#4.5.4)
|
||||
|
||||
conversion ofC toB is better than conversion ofC toA,
|
||||
|
||||
* [(4.5.5)](#4.5.5)
|
||||
|
||||
conversion ofB* toA* is better than conversion ofC* toA*,
|
||||
|
||||
* [(4.5.6)](#4.5.6)
|
||||
|
||||
binding of an expression of typeB to a reference to typeA is better than binding an expression of typeC to a
|
||||
reference to typeA,
|
||||
|
||||
* [(4.5.7)](#4.5.7)
|
||||
|
||||
conversion ofB::* toC::* is better than conversion
|
||||
ofA::* toC::*,
|
||||
and
|
||||
|
||||
* [(4.5.8)](#4.5.8)
|
||||
|
||||
conversion ofB toA is better than conversion ofC toA[.](#4.5.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
Compared conversion sequences will have different source types only in the
|
||||
context of comparing the second standard conversion sequence of an
|
||||
initialization by user-defined conversion (see [[over.match.best]](over.match.best "12.2.4 Best viable function")); in
|
||||
all other contexts, the source types will be the same and the target
|
||||
types will be different[.](#4.5.sentence-2)
|
||||
â *end note*]
|
||||
112
cppdraft/over/ics/ref.md
Normal file
112
cppdraft/over/ics/ref.md
Normal file
@@ -0,0 +1,112 @@
|
||||
[over.ics.ref]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#over.ics.ref)
|
||||
|
||||
### 12.2.4 Best viable function [[over.match.best]](over.match.best#over.ics.ref)
|
||||
|
||||
#### 12.2.4.2 Implicit conversion sequences [[over.best.ics]](over.best.ics#over.ics.ref)
|
||||
|
||||
#### 12.2.4.2.5 Reference binding [over.ics.ref]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2388)
|
||||
|
||||
When a parameter of type âreference to cv Tâ
|
||||
binds directly ([[dcl.init.ref]](dcl.init.ref "9.5.4 References")) to an argument expression:
|
||||
|
||||
- [(1.1)](#1.1)
|
||||
|
||||
If the argument expression has a type that
|
||||
is a derived class of the parameter type,
|
||||
the implicit conversion sequence is a derived-to-base
|
||||
conversion ([[over.best.ics]](over.best.ics "12.2.4.2 Implicit conversion sequences"))[.](#1.1.sentence-1)
|
||||
|
||||
- [(1.2)](#1.2)
|
||||
|
||||
Otherwise,
|
||||
if the type of the argument is possibly cv-qualified T, or
|
||||
if T is an array type of unknown bound with element type U and
|
||||
the argument has an array type of known bound whose
|
||||
element type is possibly cv-qualified U,
|
||||
the implicit conversion sequence is the identity conversion[.](#1.2.sentence-1)
|
||||
|
||||
- [(1.3)](#1.3)
|
||||
|
||||
Otherwise,
|
||||
if T is a function type,
|
||||
the implicit conversion sequence is a function pointer conversion[.](#1.3.sentence-1)
|
||||
|
||||
- [(1.4)](#1.4)
|
||||
|
||||
Otherwise, the implicit conversion sequence is a qualification conversion[.](#1.4.sentence-1)
|
||||
|
||||
[*Example [1](#example-1)*: struct A {};struct B : public A {} b;int f(A&);int f(B&);int i = f(b); // calls f(B&), an exact match, rather than f(A&), a conversionvoid g() noexcept;int h(void (&)() noexcept); // #1int h(void (&)()); // #2int j = h(g); // calls #1, an exact match, rather than #2, a function pointer conversion â *end example*]
|
||||
|
||||
If the parameter binds directly to the result of
|
||||
applying a conversion function to the argument expression, the implicit
|
||||
conversion sequence is a user-defined conversion sequence ([[over.ics.user]](over.ics.user "12.2.4.2.3 User-defined conversion sequences"))
|
||||
whose second standard conversion sequence is
|
||||
determined by the above rules[.](#1.sentence-2)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2435)
|
||||
|
||||
When a parameter of reference type is not bound directly to an argument
|
||||
expression, the conversion sequence is the one required to convert the argument
|
||||
expression to the referenced type according to [[over.best.ics]](over.best.ics "12.2.4.2 Implicit conversion sequences")[.](#2.sentence-1)
|
||||
|
||||
Conceptually, this conversion sequence corresponds to copy-initializing a
|
||||
temporary of the referenced type with the argument expression[.](#2.sentence-2)
|
||||
|
||||
Any difference
|
||||
in top-level cv-qualification is subsumed by the initialization itself and
|
||||
does not constitute a conversion[.](#2.sentence-3)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2445)
|
||||
|
||||
Except for an implicit object parameter, for which see [[over.match.funcs]](over.match.funcs "12.2.2 Candidate functions and argument lists"),
|
||||
an implicit conversion sequence cannot be formed if it requires
|
||||
binding an lvalue reference
|
||||
other than a reference to a non-volatile const type
|
||||
to an rvalue
|
||||
or binding an rvalue reference to an lvalue of object type[.](#3.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
This means, for example, that a candidate function cannot be a viable
|
||||
function if it has a non-const lvalue reference parameter (other than
|
||||
the implicit object parameter) and the corresponding argument
|
||||
would require a temporary to be created to initialize the lvalue
|
||||
reference (see [[dcl.init.ref]](dcl.init.ref "9.5.4 References"))[.](#3.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2460)
|
||||
|
||||
Other restrictions on binding a reference to a particular argument
|
||||
that are not based on the types of the reference and the argument
|
||||
do not affect the formation of an implicit conversion
|
||||
sequence, however[.](#4.sentence-1)
|
||||
|
||||
[*Example [2](#example-2)*:
|
||||
|
||||
A function with an âlvalue reference to intâ parameter can
|
||||
be a viable candidate even if the corresponding argument is anint bit-field[.](#4.sentence-2)
|
||||
|
||||
The formation of implicit conversion sequences
|
||||
treats theint bit-field as anint lvalue and finds an exact
|
||||
match with the parameter[.](#4.sentence-3)
|
||||
|
||||
If the function is selected by overload
|
||||
resolution, the call will nonetheless be ill-formed because of
|
||||
the prohibition on binding a non-const lvalue reference to a bit-field ([[dcl.init.ref]](dcl.init.ref "9.5.4 References"))[.](#4.sentence-4)
|
||||
|
||||
â *end example*]
|
||||
86
cppdraft/over/ics/scs.md
Normal file
86
cppdraft/over/ics/scs.md
Normal file
@@ -0,0 +1,86 @@
|
||||
[over.ics.scs]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#over.ics.scs)
|
||||
|
||||
### 12.2.4 Best viable function [[over.match.best]](over.match.best#over.ics.scs)
|
||||
|
||||
#### 12.2.4.2 Implicit conversion sequences [[over.best.ics]](over.best.ics#over.ics.scs)
|
||||
|
||||
#### 12.2.4.2.2 Standard conversion sequences [over.ics.scs]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2272)
|
||||
|
||||
Table [19](#tab:over.ics.scs "Table 19: Conversions") summarizes the conversions defined in [[conv]](conv "7.3 Standard conversions") and
|
||||
partitions them into four disjoint categories: Lvalue Transformation,
|
||||
Qualification Adjustment, Promotion, and Conversion[.](#1.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
These categories are orthogonal with respect to value category,
|
||||
cv-qualification, and data representation: the Lvalue Transformations
|
||||
do not change the cv-qualification or data
|
||||
representation of the type; the Qualification Adjustments do not
|
||||
change the value category or data representation of the type; and
|
||||
the Promotions and Conversions do not change the
|
||||
value category or cv-qualification of the type[.](#1.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2287)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
As described in [[conv]](conv "7.3 Standard conversions"),
|
||||
a standard conversion sequence either is the Identity conversion
|
||||
by itself (that is, no conversion) or consists of one to three
|
||||
conversions from the other
|
||||
four categories[.](#2.sentence-1)
|
||||
|
||||
If there are two or more conversions in the sequence, the
|
||||
conversions are applied in the canonical order:**Lvalue Transformation**,**Promotion** or**Conversion**,**Qualification Adjustment**[.](#2.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2303)
|
||||
|
||||
Each conversion in Table [19](#tab:over.ics.scs "Table 19: Conversions") also has an associated rank (Exact
|
||||
Match, Promotion, or Conversion)[.](#3.sentence-1)
|
||||
|
||||
These are used
|
||||
to [rank standard conversion sequences](over.ics.rank "12.2.4.3 Ranking implicit conversion sequences [over.ics.rank]")[.](#3.sentence-2)
|
||||
|
||||
The rank of a conversion sequence is determined by considering the
|
||||
rank of each conversion in the sequence and the rank of any [reference
|
||||
binding](over.ics.ref "12.2.4.2.5 Reference binding [over.ics.ref]")[.](#3.sentence-3)
|
||||
|
||||
If any of those has Conversion rank, the
|
||||
sequence has Conversion rank; otherwise, if any of those has Promotion rank,
|
||||
the sequence has Promotion rank; otherwise, the sequence has Exact
|
||||
Match rank[.](#3.sentence-4)
|
||||
|
||||
Table [19](#tab:over.ics.scs) — Conversions [[tab:over.ics.scs]](./tab:over.ics.scs)
|
||||
|
||||
| [ð](#tab:over.ics.scs-row-1)<br>**Conversion** | **Category** | **Rank** | **Subclause** |
|
||||
| --- | --- | --- | --- |
|
||||
| [ð](#tab:over.ics.scs-row-2)<br>No conversions required | Identity | | |
|
||||
| [ð](#tab:over.ics.scs-row-3)<br> Lvalue-to-rvalue conversion | | | [[conv.lval]](conv.lval "7.3.2 Lvalue-to-rvalue conversion") |
|
||||
| [ð](#tab:over.ics.scs-row-4)<br> Array-to-pointer conversion | Lvalue Transformation | | [[conv.array]](conv.array "7.3.3 Array-to-pointer conversion") |
|
||||
| [ð](#tab:over.ics.scs-row-5)<br> Function-to-pointer conversion | | Exact Match | [[conv.func]](conv.func "7.3.4 Function-to-pointer conversion") |
|
||||
| [ð](#tab:over.ics.scs-row-6)<br> Qualification conversions | | | [[conv.qual]](conv.qual "7.3.6 Qualification conversions") |
|
||||
| [ð](#tab:over.ics.scs-row-7)<br> Function pointer conversion | Qualification Adjustment | | [[conv.fctptr]](conv.fctptr "7.3.14 Function pointer conversions") |
|
||||
| [ð](#tab:over.ics.scs-row-8)<br>Integral promotions | | | [[conv.prom]](conv.prom "7.3.7 Integral promotions") |
|
||||
| [ð](#tab:over.ics.scs-row-9)<br> Floating-point promotion | Promotion | Promotion | [[conv.fpprom]](conv.fpprom "7.3.8 Floating-point promotion") |
|
||||
| [ð](#tab:over.ics.scs-row-10)<br>Integral conversions | | | [[conv.integral]](conv.integral "7.3.9 Integral conversions") |
|
||||
| [ð](#tab:over.ics.scs-row-11)<br> Floating-point conversions | | | [[conv.double]](conv.double "7.3.10 Floating-point conversions") |
|
||||
| [ð](#tab:over.ics.scs-row-12)<br> Floating-integral conversions | | | [[conv.fpint]](conv.fpint "7.3.11 Floating-integral conversions") |
|
||||
| [ð](#tab:over.ics.scs-row-13)<br> Pointer conversions | Conversion | Conversion | [[conv.ptr]](conv.ptr "7.3.12 Pointer conversions") |
|
||||
| [ð](#tab:over.ics.scs-row-14)<br> Pointer-to-member conversions | | | [[conv.mem]](conv.mem "7.3.13 Pointer-to-member conversions") |
|
||||
| [ð](#tab:over.ics.scs-row-15)<br> Boolean conversions | | | [[conv.bool]](conv.bool "7.3.15 Boolean conversions") |
|
||||
65
cppdraft/over/ics/user.md
Normal file
65
cppdraft/over/ics/user.md
Normal file
@@ -0,0 +1,65 @@
|
||||
[over.ics.user]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#over.ics.user)
|
||||
|
||||
### 12.2.4 Best viable function [[over.match.best]](over.match.best#over.ics.user)
|
||||
|
||||
#### 12.2.4.2 Implicit conversion sequences [[over.best.ics]](over.best.ics#over.ics.user)
|
||||
|
||||
#### 12.2.4.2.3 User-defined conversion sequences [over.ics.user]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2339)
|
||||
|
||||
A [*user-defined conversion sequence*](#def:conversion_sequence,user-defined "12.2.4.2.3 User-defined conversion sequences [over.ics.user]") consists of an initial
|
||||
standard conversion sequence followed by a user-defined
|
||||
conversion ([[class.conv]](class.conv "11.4.8 Conversions")) followed by a second standard
|
||||
conversion sequence[.](#1.sentence-1)
|
||||
|
||||
If the user-defined conversion is specified
|
||||
by a constructor ([[class.conv.ctor]](class.conv.ctor "11.4.8.2 Conversion by constructor")), the initial standard
|
||||
conversion sequence converts the source type to the type of the
|
||||
first parameter of that constructor[.](#1.sentence-2)
|
||||
|
||||
If the user-defined
|
||||
conversion is specified by a [conversion function](class.conv.fct "11.4.8.3 Conversion functions [class.conv.fct]"), the
|
||||
initial standard conversion sequence
|
||||
converts the source type to the type of the
|
||||
object parameter of that conversion function[.](#1.sentence-3)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2354)
|
||||
|
||||
The second standard conversion sequence converts the result of
|
||||
the user-defined conversion to the target type for the sequence;
|
||||
any reference binding is included in the second standard
|
||||
conversion sequence[.](#2.sentence-1)
|
||||
|
||||
Since an implicit conversion sequence is an initialization, the
|
||||
special rules for initialization by user-defined conversion apply
|
||||
when selecting the best user-defined conversion for a
|
||||
user-defined conversion sequence (see [[over.match.best]](over.match.best "12.2.4 Best viable function") and [[over.best.ics]](over.best.ics "12.2.4.2 Implicit conversion sequences"))[.](#2.sentence-2)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2364)
|
||||
|
||||
If the user-defined conversion is specified by a
|
||||
specialization of a conversion function template,
|
||||
the second standard conversion sequence shall have Exact Match rank[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2369)
|
||||
|
||||
A conversion of an expression of class type
|
||||
to the same class type is given Exact Match rank, and
|
||||
a conversion of an expression of class type
|
||||
to a base class of that type is given Conversion rank,
|
||||
in spite of the
|
||||
fact that a constructor (i.e., a user-defined conversion
|
||||
function) is called for those cases[.](#4.sentence-1)
|
||||
40
cppdraft/over/inc.md
Normal file
40
cppdraft/over/inc.md
Normal file
@@ -0,0 +1,40 @@
|
||||
[over.inc]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.4 Overloaded operators [[over.oper]](over.oper#over.inc)
|
||||
|
||||
### 12.4.7 Increment and decrement [over.inc]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3708)
|
||||
|
||||
An [*increment operator function*](#def:operator_function,increment "12.4.7 Increment and decrement [over.inc]") is a function named operator++[.](#1.sentence-1)
|
||||
|
||||
If this function is a non-static member function with no non-object parameters, or a non-member
|
||||
function with one parameter,
|
||||
it defines the prefix increment operator++ for objects of that type[.](#1.sentence-2)
|
||||
|
||||
If the function is a non-static member function with one non-object parameter (which shall be of typeint)
|
||||
or a non-member function with two parameters (the second of which shall be of typeint),
|
||||
it defines the postfix increment operator++ for objects of that type[.](#1.sentence-3)
|
||||
|
||||
When the postfix increment is called as a result of using the++ operator, theint argument will have value zero[.](#1.sentence-4)[107](#footnote-107 "Calling operator++ explicitly, as in expressions like a.operator++(2), has no special properties: The argument to operator++ is 2.")
|
||||
|
||||
[*Example [1](#example-1)*: struct X { X& operator++(); // prefix ++a X operator++(int); // postfix a++};
|
||||
|
||||
struct Y { };
|
||||
Y& operator++(Y&); // prefix ++b Y operator++(Y&, int); // postfix b++void f(X a, Y b) {++a; // a.operator++(); a++; // a.operator++(0);++b; // operator++(b); b++; // operator++(b, 0); a.operator++(); // explicit call: like ++a; a.operator++(0); // explicit call: like a++;operator++(b); // explicit call: like ++b;operator++(b, 0); // explicit call: like b++;} â *end example*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3765)
|
||||
|
||||
A [*decrement operator function*](#def:operator_function,decrement "12.4.7 Increment and decrement [over.inc]") is a function named operator-- and is handled analogously to an increment operator function[.](#2.sentence-1)
|
||||
|
||||
[107)](#footnote-107)[107)](#footnoteref-107)
|
||||
|
||||
Callingoperator++ explicitly, as in expressions likea.operator++(2),
|
||||
has no special properties:
|
||||
The argument tooperator++ is2[.](#footnote-107.sentence-1)
|
||||
108
cppdraft/over/literal.md
Normal file
108
cppdraft/over/literal.md
Normal file
@@ -0,0 +1,108 @@
|
||||
[over.literal]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.6 User-defined literals [over.literal]
|
||||
|
||||
[literal-operator-id:](#nt:literal-operator-id "12.6 User-defined literals [over.literal]")
|
||||
operator [*unevaluated-string*](lex.string.uneval#nt:unevaluated-string "5.13.6 Unevaluated strings [lex.string.uneval]") [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]")
|
||||
operator [*user-defined-string-literal*](lex.ext#nt:user-defined-string-literal "5.13.9 User-defined literals [lex.ext]")
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L4119)
|
||||
|
||||
The [*user-defined-string-literal*](lex.ext#nt:user-defined-string-literal "5.13.9 User-defined literals [lex.ext]") in a [*literal-operator-id*](#nt:literal-operator-id "12.6 User-defined literals [over.literal]") shall have no [*encoding-prefix*](lex.ccon#nt:encoding-prefix "5.13.3 Character literals [lex.ccon]")[.](#1.sentence-1)
|
||||
|
||||
The [*unevaluated-string*](lex.string.uneval#nt:unevaluated-string "5.13.6 Unevaluated strings [lex.string.uneval]") or[*user-defined-string-literal*](lex.ext#nt:user-defined-string-literal "5.13.9 User-defined literals [lex.ext]") shall be empty[.](#1.sentence-2)
|
||||
|
||||
The [*ud-suffix*](lex.ext#nt:ud-suffix "5.13.9 User-defined literals [lex.ext]") of the [*user-defined-string-literal*](lex.ext#nt:user-defined-string-literal "5.13.9 User-defined literals [lex.ext]") or
|
||||
the [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") in a [*literal-operator-id*](#nt:literal-operator-id "12.6 User-defined literals [over.literal]") is called a[*literal suffix identifier*](#def:literal,suffix_identifier "12.6 User-defined literals [over.literal]")[.](#1.sentence-3)
|
||||
|
||||
The first form of [*literal-operator-id*](#nt:literal-operator-id "12.6 User-defined literals [over.literal]") is deprecated ([[depr.lit]](depr.lit "D.8 Literal operator function declarations using an identifier"))[.](#1.sentence-4)
|
||||
|
||||
Some literal suffix identifiers are reserved for future standardization;
|
||||
see [[usrlit.suffix]](usrlit.suffix "16.4.5.3.6 User-defined literal suffixes")[.](#1.sentence-5)
|
||||
|
||||
A declaration whose [*literal-operator-id*](#nt:literal-operator-id "12.6 User-defined literals [over.literal]") uses
|
||||
such a literal suffix identifier is ill-formed, no diagnostic required[.](#1.sentence-6)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L4133)
|
||||
|
||||
A declaration whose [*declarator-id*](dcl.decl.general#nt:declarator-id "9.3.1 General [dcl.decl.general]") is a[*literal-operator-id*](#nt:literal-operator-id "12.6 User-defined literals [over.literal]") shall declare a function or function template
|
||||
that belongs to a namespace (it could be a friend function ([[class.friend]](class.friend "11.8.4 Friends"))) or
|
||||
an explicit instantiation or specialization of a function template[.](#2.sentence-1)
|
||||
|
||||
A function declared with a [*literal-operator-id*](#nt:literal-operator-id "12.6 User-defined literals [over.literal]") is a [*literal
|
||||
operator*](#def:literal,operator "12.6 User-defined literals [over.literal]")[.](#2.sentence-2)
|
||||
|
||||
A function template declared with a [*literal-operator-id*](#nt:literal-operator-id "12.6 User-defined literals [over.literal]") is a [*literal operator template*](#def:literal,operator,template "12.6 User-defined literals [over.literal]")[.](#2.sentence-3)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L4142)
|
||||
|
||||
The declaration of a literal operator shall have a[*parameter-declaration-clause*](dcl.fct#nt:parameter-declaration-clause "9.3.4.6 Functions [dcl.fct]") equivalent to one of the following:const char*unsigned long long intlong doublecharwchar_tchar8_tchar16_tchar32_tconst char*, std::size_tconst wchar_t*, std::size_tconst char8_t*, std::size_tconst char16_t*, std::size_tconst char32_t*, std::size_t
|
||||
|
||||
If a parameter has a default argument ([[dcl.fct.default]](dcl.fct.default "9.3.4.7 Default arguments")), the program is
|
||||
ill-formed[.](#3.sentence-2)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L4164)
|
||||
|
||||
A [*raw literal operator*](#def:literal,operator,raw "12.6 User-defined literals [over.literal]") is a literal operator with a single parameter
|
||||
whose type is const char*[.](#4.sentence-1)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L4168)
|
||||
|
||||
A [*numeric literal operator template*](#def:literal,operator,template_numeric "12.6 User-defined literals [over.literal]") is a literal operator template whose [*template-parameter-list*](temp.pre#nt:template-parameter-list "13.1 Preamble [temp.pre]") has a single [*template-parameter*](temp.param#nt:template-parameter "13.2 Template parameters [temp.param]") that is a constant template parameter pack ([[temp.variadic]](temp.variadic "13.7.4 Variadic templates"))
|
||||
with element type char[.](#5.sentence-1)
|
||||
|
||||
A [*string literal operator template*](#def:literal,operator,template_string "12.6 User-defined literals [over.literal]") is a literal operator template whose [*template-parameter-list*](temp.pre#nt:template-parameter-list "13.1 Preamble [temp.pre]") comprises
|
||||
a single [*parameter-declaration*](dcl.fct#nt:parameter-declaration "9.3.4.6 Functions [dcl.fct]") that declares a
|
||||
constant template parameter of class type[.](#5.sentence-2)
|
||||
|
||||
The declaration of a literal operator template
|
||||
shall have an empty [*parameter-declaration-clause*](dcl.fct#nt:parameter-declaration-clause "9.3.4.6 Functions [dcl.fct]") and shall declare either a numeric literal operator template
|
||||
or a string literal operator template[.](#5.sentence-3)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L4184)
|
||||
|
||||
Literal operators and literal operator templates shall not have C language linkage[.](#6.sentence-1)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L4187)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
Literal operators and literal operator templates are usually invoked
|
||||
implicitly through user-defined literals ([[lex.ext]](lex.ext "5.13.9 User-defined literals"))[.](#7.sentence-1)
|
||||
|
||||
However, except for
|
||||
the constraints described above, they are ordinary namespace-scope functions and
|
||||
function templates[.](#7.sentence-2)
|
||||
|
||||
In particular, they are looked up like ordinary functions
|
||||
and function templates and they follow the same overload resolution rules[.](#7.sentence-3)
|
||||
|
||||
Also,
|
||||
they can be declared inline or constexpr,
|
||||
they can have internal, module, or external linkage,
|
||||
they can be called explicitly, their addresses can be
|
||||
taken, etc[.](#7.sentence-4)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L4200)
|
||||
|
||||
[*Example [1](#example-1)*: void operator ""_km(long double); // OK string operator "" _i18n(const char*, std::size_t); // OK, deprecatedtemplate <char...> double operator ""_\u03C0(); // OK, UCN for lowercase pifloat operator ""_e(const char*); // OKfloat operator ""E(const char*); // ill-formed, no diagnostic required:// reserved literal suffix ([[usrlit.suffix]](usrlit.suffix "16.4.5.3.6 User-defined literal suffixes"), [[lex.ext]](lex.ext "5.13.9 User-defined literals"))double operator""_Bq(long double); // OK, does not use the reserved [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") _Bq ([[lex.name]](lex.name "5.11 Identifiers"))double operator"" _Bq(long double); // ill-formed, no diagnostic required:// uses the reserved [*identifier*](lex.name#nt:identifier "5.11 Identifiers [lex.name]") _Bq ([[lex.name]](lex.name "5.11 Identifiers"))float operator " "B(const char*); // error: non-empty [*string-literal*](lex.string#nt:string-literal "5.13.5 String literals [lex.string]") string operator ""5X(const char*, std::size_t); // error: invalid literal suffix identifierdouble operator ""_miles(double); // error: invalid [*parameter-declaration-clause*](dcl.fct#nt:parameter-declaration-clause "9.3.4.6 Functions [dcl.fct]")template <char...> int operator ""_j(const char*); // error: invalid [*parameter-declaration-clause*](dcl.fct#nt:parameter-declaration-clause "9.3.4.6 Functions [dcl.fct]")extern "C" void operator ""_m(long double); // error: C language linkage â *end example*]
|
||||
2699
cppdraft/over/match.md
Normal file
2699
cppdraft/over/match.md
Normal file
File diff suppressed because it is too large
Load Diff
1089
cppdraft/over/match/best.md
Normal file
1089
cppdraft/over/match/best.md
Normal file
File diff suppressed because it is too large
Load Diff
183
cppdraft/over/match/best/general.md
Normal file
183
cppdraft/over/match/best/general.md
Normal file
@@ -0,0 +1,183 @@
|
||||
[over.match.best.general]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#best.general)
|
||||
|
||||
### 12.2.4 Best viable function [[over.match.best]](over.match.best#general)
|
||||
|
||||
#### 12.2.4.1 General [over.match.best.general]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1808)
|
||||
|
||||
Define ICSi(F) as
|
||||
the implicit conversion sequence that converts
|
||||
the ith argument in the list to the type of
|
||||
the ith parameter of viable function F[.](#1.sentence-1)
|
||||
|
||||
[[over.best.ics]](over.best.ics "12.2.4.2 Implicit conversion sequences") defines the implicit conversion sequences and [[over.ics.rank]](over.ics.rank "12.2.4.3 Ranking implicit conversion sequences") defines what it means for one implicit conversion sequence to be
|
||||
a better conversion sequence or worse conversion sequence than
|
||||
another[.](#1.sentence-2)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1819)
|
||||
|
||||
Given these definitions,
|
||||
a viable function F1 is defined to be a[*better*](#def:overloading,resolution,better_viable_function "12.2.4.1 General [over.match.best.general]") function than another viable function F2 if for all arguments i,ICSi(F1) is not a worse conversion
|
||||
sequence than ICSi(F2), and then
|
||||
|
||||
- [(2.1)](#2.1)
|
||||
|
||||
for some argument j,ICSj(F1) is a better conversion sequence thanICSj(F2), or, if not that,
|
||||
|
||||
- [(2.2)](#2.2)
|
||||
|
||||
the context is an initialization by user-defined conversion
|
||||
(see [[dcl.init]](dcl.init "9.5 Initializers"),[[over.match.conv]](over.match.conv "12.2.2.6 Initialization by conversion function"), and [[over.match.ref]](over.match.ref "12.2.2.7 Initialization by conversion function for direct reference binding"))
|
||||
and the standard conversion sequence
|
||||
from the result of F1 to the destination type
|
||||
(i.e., the type of the entity being initialized)
|
||||
is a better conversion sequence than the standard conversion sequence
|
||||
from the result of F2 to the destination type
|
||||
[*Example [1](#example-1)*: struct A { A(); operator int(); operator double();} a;int i = a; // a.operator int() followed by no conversion is better than// a.operator double() followed by a conversion to intfloat x = a; // ambiguous: both possibilities require conversions,// and neither is better than the other â *end example*]
|
||||
or, if not that,
|
||||
|
||||
- [(2.3)](#2.3)
|
||||
|
||||
the context is an initialization by conversion function for [direct
|
||||
reference binding](over.match.ref "12.2.2.7 Initialization by conversion function for direct reference binding [over.match.ref]") of a reference to function type, the
|
||||
return type of F1 is the same kind of reference (lvalue or rvalue)
|
||||
as the reference being initialized, and the return type of F2 is not
|
||||
[*Example [2](#example-2)*: template <class T> struct A {operator T&(); // #1operator T&&(); // #2};typedef int Fn();
|
||||
A<Fn> a;
|
||||
Fn& lf = a; // calls #1 Fn&& rf = a; // calls #2 â *end example*]
|
||||
or, if not that,
|
||||
|
||||
- [(2.4)](#2.4)
|
||||
|
||||
F1 is not a function template specialization andF2 is a
|
||||
function template
|
||||
specialization, or, if not that,
|
||||
|
||||
- [(2.5)](#2.5)
|
||||
|
||||
F1 andF2 are
|
||||
function template specializations,
|
||||
and the function template
|
||||
forF1 is more specialized than the template forF2 according to the partial ordering rules described in [[temp.func.order]](temp.func.order "13.7.7.3 Partial ordering of function templates"),
|
||||
or, if not that,
|
||||
|
||||
- [(2.6)](#2.6)
|
||||
|
||||
F1 and F2 are non-template functions andF1 is more partial-ordering-constrained thanF2 ([[temp.constr.order]](temp.constr.order "13.5.5 Partial ordering by constraints"))
|
||||
[*Example [3](#example-3)*: template <typename T = int>struct S {constexpr void f(); // #1constexpr void f(this S&) requires true; // #2};
|
||||
|
||||
void test() { S<> s;
|
||||
s.f(); // calls #2} â *end example*]
|
||||
or, if not that,
|
||||
|
||||
- [(2.7)](#2.7)
|
||||
|
||||
F1 is a constructor for a class D,F2 is a constructor for a base class B of D, and
|
||||
for all arguments
|
||||
the corresponding parameters of F1 and F2 have the same type
|
||||
[*Example [4](#example-4)*: struct A { A(int = 0);};
|
||||
|
||||
struct B: A {using A::A;
|
||||
B();};
|
||||
|
||||
int main() { B b; // OK, B::B()} â *end example*]
|
||||
or, if not that,
|
||||
|
||||
- [(2.8)](#2.8)
|
||||
|
||||
F2 is a rewritten candidate ([[over.match.oper]](over.match.oper "12.2.2.3 Operators in expressions")) andF1 is not
|
||||
[*Example [5](#example-5)*: struct S {friend auto operator<=>(const S&, const S&) = default; // #1friend bool operator<(const S&, const S&); // #2};bool b = S() < S(); // calls #2 â *end example*]
|
||||
or, if not that,
|
||||
|
||||
- [(2.9)](#2.9)
|
||||
|
||||
F1 and F2 are rewritten candidates, andF2 is a synthesized candidate
|
||||
with reversed order of parameters
|
||||
and F1 is not
|
||||
[*Example [6](#example-6)*: struct S {friend std::weak_ordering operator<=>(const S&, int); // #1friend std::weak_ordering operator<=>(int, const S&); // #2};bool b = 1 < S(); // calls #2 â *end example*]
|
||||
or, if not that,
|
||||
|
||||
- [(2.10)](#2.10)
|
||||
|
||||
F1 and F2 are generated
|
||||
from class template argument deduction ([[over.match.class.deduct]](over.match.class.deduct "12.2.2.9 Class template argument deduction"))
|
||||
for a class D, andF2 is generated
|
||||
from inheriting constructors from a base class of D while F1 is not, and
|
||||
for each explicit function argument,
|
||||
the corresponding parameters of F1 and F2 are either both ellipses or have the same type,
|
||||
or, if not that,
|
||||
|
||||
- [(2.11)](#2.11)
|
||||
|
||||
F1 is generated from a[*deduction-guide*](temp.deduct.guide#nt:deduction-guide "13.7.2.3 Deduction guides [temp.deduct.guide]") ([[over.match.class.deduct]](over.match.class.deduct "12.2.2.9 Class template argument deduction"))
|
||||
and F2 is not, or, if not that,
|
||||
|
||||
- [(2.12)](#2.12)
|
||||
|
||||
F1 is the [copy deduction candidate](over.match.class.deduct#def:copy_deduction_candidate "12.2.2.9 Class template argument deduction [over.match.class.deduct]") and F2 is not, or, if not that,
|
||||
|
||||
- [(2.13)](#2.13)
|
||||
|
||||
F1 is generated from a non-template constructor
|
||||
and F2 is generated from a constructor template[.](#2.sentence-1)
|
||||
[*Example [7](#example-7)*: template <class T> struct A {using value_type = T;
|
||||
A(value_type); // #1 A(const A&); // #2 A(T, T, int); // #3template<class U> A(int, T, U); // #4// #5 is the copy deduction candidate, A(A)};
|
||||
|
||||
A x(1, 2, 3); // uses #3, generated from a non-template constructortemplate <class T> A(T) -> A<T>; // #6, less specialized than #5 A a(42); // uses #6 to deduce A<int> and #1 to initialize A b = a; // uses #5 to deduce A<int> and #2 to initializetemplate <class T> A(A<T>) -> A<A<T>>; // #7, as specialized as #5 A b2 = a; // uses #7 to deduce A<A<int>> and #1 to initialize â *end example*]
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2022)
|
||||
|
||||
If there is exactly one viable function that is a better function
|
||||
than all other viable functions, then it is the one selected by
|
||||
overload resolution; otherwise the call is ill-formed[.](#3.sentence-1)[105](#footnote-105 "The algorithm for selecting the best viable function is linear in the number of viable functions. Run a simple tournament to find a function W that is not worse than any opponent it faced. Although it is possible that another function F that W did not face is at least as good as W, F cannot be the best function because at some point in the tournament F encountered another function G such that F was not better than G. Hence, either W is the best function or there is no best function. So, make a second pass over the viable functions to verify that W is better than all other functions.")
|
||||
|
||||
[*Example [8](#example-8)*: void Fcn(const int*, short);void Fcn(int*, int);
|
||||
|
||||
int i;short s = 0;
|
||||
|
||||
void f() { Fcn(&i, s); // is ambiguous because &i â int* is better than &i â const int*// but s â short is also better than s â int Fcn(&i, 1L); // calls Fcn(int*, int), because &i â int* is better than &i â const int*// and 1L â short and 1L â int are indistinguishable Fcn(&i, 'c'); // calls Fcn(int*, int), because &i â int* is better than &i â const int*// and 'c' â int is better than 'c' â short} â *end example*]
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L2083)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
If the best viable function was made viable by one or more default arguments,
|
||||
additional requirements apply ([[over.match.viable]](over.match.viable "12.2.3 Viable functions"))[.](#4.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[105)](#footnote-105)[105)](#footnoteref-105)
|
||||
|
||||
The algorithm
|
||||
for selecting the best viable function is linear in the number
|
||||
of viable
|
||||
functions[.](#footnote-105.sentence-1)
|
||||
|
||||
Run a simple tournament to find a functionW that is not
|
||||
worse than any
|
||||
opponent it faced[.](#footnote-105.sentence-2)
|
||||
|
||||
Although it is possible that another functionF thatW did not face
|
||||
is at least as good asW,F cannot be the best function because at some point in the
|
||||
tournamentF encountered another functionG such thatF was not better thanG[.](#footnote-105.sentence-3)
|
||||
|
||||
Hence,
|
||||
either W is
|
||||
the best function or there is no best function[.](#footnote-105.sentence-4)
|
||||
|
||||
So, make a second pass over
|
||||
the viable
|
||||
functions to verify thatW is better than all other functions[.](#footnote-105.sentence-5)
|
||||
256
cppdraft/over/match/call.md
Normal file
256
cppdraft/over/match/call.md
Normal file
@@ -0,0 +1,256 @@
|
||||
[over.match.call]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#call)
|
||||
|
||||
### 12.2.2 Candidate functions and argument lists [[over.match.funcs]](over.match.funcs#over.match.call)
|
||||
|
||||
#### 12.2.2.2 Function call syntax [over.match.call]
|
||||
|
||||
#### [12.2.2.2.1](#general) General [[over.match.call.general]](over.match.call.general)
|
||||
|
||||
[1](#general-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L362)
|
||||
|
||||
In a [function call](expr.call "7.6.1.3 Function call [expr.call]")
|
||||
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") ( [*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]")opt )
|
||||
|
||||
if the [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") names at least one function or
|
||||
function template,
|
||||
overload resolution is applied as specified in [[over.call.func]](#over.call.func "12.2.2.2.2 Call to designated function")[.](#general-1.sentence-1)
|
||||
|
||||
If the [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") denotes an object of class type, overload
|
||||
resolution is applied as specified in [[over.call.object]](#over.call.object "12.2.2.2.3 Call to object of class type")[.](#general-1.sentence-2)
|
||||
|
||||
[2](#general-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L373)
|
||||
|
||||
If the [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") is the address of an overload set,
|
||||
overload resolution is applied using that set as described above[.](#general-2.sentence-1)
|
||||
|
||||
[*Note [1](#general-note-1)*:
|
||||
|
||||
No implied object argument is added in this case[.](#general-2.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
If the function selected by overload resolution is
|
||||
an implicit object member function,
|
||||
the program is ill-formed[.](#general-2.sentence-3)
|
||||
|
||||
[*Note [2](#general-note-2)*:
|
||||
|
||||
The resolution of the address of an
|
||||
overload set in other contexts is described in [[over.over]](over.over "12.3 Address of an overload set")[.](#general-2.sentence-4)
|
||||
|
||||
â *end note*]
|
||||
|
||||
#### [12.2.2.2.2](#over.call.func) Call to designated function [[over.call.func]](over.call.func)
|
||||
|
||||
[1](#over.call.func-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L389)
|
||||
|
||||
Of interest in [[over.call.func]](#over.call.func "12.2.2.2.2 Call to designated function") are only those function calls
|
||||
in which the [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") ultimately contains
|
||||
an [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") or [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]") that designates one or more functions[.](#over.call.func-1.sentence-1)
|
||||
|
||||
Such a[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]"),
|
||||
perhaps nested arbitrarily deep in
|
||||
parentheses, has one of the following forms:
|
||||
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]"):
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") . [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]")
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") . [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]")
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") -> [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]")
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") -> [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]")
|
||||
[*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]")
|
||||
[*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]")
|
||||
|
||||
These represent two syntactic subcategories of function calls:
|
||||
qualified function calls and unqualified function calls[.](#over.call.func-1.sentence-3)
|
||||
|
||||
[2](#over.call.func-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L411)
|
||||
|
||||
In qualified function calls,
|
||||
the function is designated by
|
||||
an [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") or [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]") E preceded by an -> or . operator[.](#over.call.func-2.sentence-1)
|
||||
|
||||
Since the
|
||||
constructA->B is generally equivalent to(*A).B,
|
||||
the rest of[[over]](over "12 Overloading") assumes, without loss of generality, that all member
|
||||
function calls have been normalized to the form that uses an
|
||||
object and the. operator[.](#over.call.func-2.sentence-2)
|
||||
|
||||
Furthermore, [[over]](over "12 Overloading") assumes that
|
||||
the[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") that is the left operand of the. operator
|
||||
has type âcv Tâ
|
||||
whereT denotes a class[.](#over.call.func-2.sentence-3)[100](#footnote-100 "Note that cv-qualifiers on the type of objects are significant in overload resolution for both glvalue and class prvalue objects.")
|
||||
|
||||
The set of candidate functions either
|
||||
is the set found by name lookup ([[class.member.lookup]](class.member.lookup "6.5.2 Member name lookup"))
|
||||
if E is an [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") or
|
||||
is the set determined as specified in [[expr.prim.splice]](expr.prim.splice "7.5.9 Expression splicing") if E is a [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]")[.](#over.call.func-2.sentence-4)
|
||||
|
||||
The argument list is the[*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]") in the call augmented by the addition of the left operand of
|
||||
the. operator in the normalized member function call as the
|
||||
implied object argument ([[over.match.funcs]](over.match.funcs "12.2.2 Candidate functions and argument lists"))[.](#over.call.func-2.sentence-5)
|
||||
|
||||
[3](#over.call.func-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L456)
|
||||
|
||||
In unqualified function calls, the function is designated by
|
||||
an [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") or a [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]") E[.](#over.call.func-3.sentence-1)
|
||||
|
||||
The set of candidate functions either
|
||||
is the set found by name lookup ([[basic.lookup]](basic.lookup "6.5 Name lookup"))
|
||||
if E is an [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]") or
|
||||
is the set determined as specified in [[expr.prim.splice]](expr.prim.splice "7.5.9 Expression splicing") if E is a [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]")[.](#over.call.func-3.sentence-2)
|
||||
|
||||
The set of candidate functions
|
||||
consists either entirely of non-member functions or entirely of
|
||||
member functions of some classT[.](#over.call.func-3.sentence-3)
|
||||
|
||||
In the former case or
|
||||
if E is either a [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]") or
|
||||
the address of an overload set,
|
||||
the argument list is
|
||||
the same as the[*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]") in the call[.](#over.call.func-3.sentence-4)
|
||||
|
||||
Otherwise, the argument list is the[*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]") in the call augmented by the addition of an implied object
|
||||
argument as in a qualified function call[.](#over.call.func-3.sentence-5)
|
||||
|
||||
If the current class is, or is derived from, T, and the keywordthis ([[expr.prim.this]](expr.prim.this "7.5.3 This")) refers to it,
|
||||
|
||||
- [(3.1)](#over.call.func-3.1)
|
||||
|
||||
if the unqualified function call
|
||||
appears in a precondition assertion of a constructor
|
||||
or a postcondition assertion of a destructor
|
||||
and overload resolution selects a non-static member function,
|
||||
the call is ill-formed;
|
||||
|
||||
- [(3.2)](#over.call.func-3.2)
|
||||
|
||||
otherwise,
|
||||
the implied object argument is(*this)[.](#over.call.func-3.sentence-6)
|
||||
|
||||
Otherwise,
|
||||
|
||||
- [(3.3)](#over.call.func-3.3)
|
||||
|
||||
if overload resolution selects a non-static member function,
|
||||
the call is ill-formed;
|
||||
|
||||
- [(3.4)](#over.call.func-3.4)
|
||||
|
||||
otherwise,
|
||||
a contrived object of typeT becomes the implied object argument[.](#over.call.func-3.sentence-7)[101](#footnote-101 "An implied object argument is contrived to correspond to the implicit object parameter attributed to member functions during overload resolution. It is not used in the call to the selected function. Since the member functions all have the same implicit object parameter, the contrived object will not be the cause to select or reject a function.")
|
||||
|
||||
[*Example [1](#over.call.func-example-1)*: struct C {bool a(); void b() { a(); // OK, (*this).a()}void c(this const C&); // #1void c() &; // #2static void c(int = 0); // #3void d() { c(); // error: ambiguous between #2 and #3(C::c)(); // error: as above(&(C::c))(); // error: cannot resolve address of overloaded this->C::c ([[over.over]](over.over "12.3 Address of an overload set"))(&C::c)(C{}); // selects #1(&C::c)(*this); // error: selects #2, and is ill-formed ([[over.match.call.general]](#general "12.2.2.2.1 General"))(&C::c)(); // selects #3}void f(this const C&); void g() const { f(); // OK, (*this).f() f(*this); // error: no viable candidate for (*this).f(*this)this->f(); // OK}static void h() { f(); // error: contrived object argument, but overload resolution// picked a non-static member function f(C{}); // error: no viable candidate C{}.f(); // OK}void k(this int); operator int() const; void m(this const C& c) { c.k(); // OK} C() pre(a()) // error: implied this in constructor precondition pre(this->a()) // OK post(a()); // OK~C() pre(a()) // OK post(a()) // error: implied this in destructor postcondition post(this->a()); // OK}; â *end example*]
|
||||
|
||||
[100)](#footnote-100)[100)](#footnoteref-100)
|
||||
|
||||
Note that cv-qualifiers on the type of objects are
|
||||
significant in overload
|
||||
resolution for
|
||||
both glvalue and class prvalue objects[.](#footnote-100.sentence-1)
|
||||
|
||||
[101)](#footnote-101)[101)](#footnoteref-101)
|
||||
|
||||
An implied object argument is contrived to
|
||||
correspond to the implicit object
|
||||
parameter attributed to member functions during overload resolution[.](#footnote-101.sentence-1)
|
||||
|
||||
It is not
|
||||
used in
|
||||
the call to the selected function[.](#footnote-101.sentence-2)
|
||||
|
||||
Since the member functions all have the
|
||||
same implicit
|
||||
object parameter, the contrived object will not be the cause to select or
|
||||
reject a
|
||||
function[.](#footnote-101.sentence-3)
|
||||
|
||||
#### [12.2.2.2.3](#over.call.object) Call to object of class type [[over.call.object]](over.call.object)
|
||||
|
||||
[1](#over.call.object-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L573)
|
||||
|
||||
If the [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") E in the function call syntax evaluates
|
||||
to a class object of type âcv Tâ,
|
||||
then the set of candidate functions
|
||||
includes at least the function call operators of T[.](#over.call.object-1.sentence-1)
|
||||
|
||||
The function call operators of T are the results of a search for the name operator() in the scope of T[.](#over.call.object-1.sentence-2)
|
||||
|
||||
[2](#over.call.object-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L583)
|
||||
|
||||
In addition, for each non-explicit conversion function declared in T of the
|
||||
form
|
||||
|
||||
operator [*conversion-type-id*](class.conv.fct#nt:conversion-type-id "11.4.8.3 Conversion functions [class.conv.fct]") ( ) [*cv-qualifier-seq*](dcl.decl.general#nt:cv-qualifier-seq "9.3.1 General [dcl.decl.general]")opt [*ref-qualifier*](dcl.decl.general#nt:ref-qualifier "9.3.1 General [dcl.decl.general]")opt [*noexcept-specifier*](except.spec#nt:noexcept-specifier "14.5 Exception specifications [except.spec]")opt [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]")opt ;
|
||||
|
||||
where the optional[*cv-qualifier-seq*](dcl.decl.general#nt:cv-qualifier-seq "9.3.1 General [dcl.decl.general]") is the same cv-qualification as, or a greater cv-qualification than,cv,
|
||||
and where[*conversion-type-id*](class.conv.fct#nt:conversion-type-id "11.4.8.3 Conversion functions [class.conv.fct]") denotes the type âpointer to function
|
||||
of (P1,â¦,Pn) returning Râ,
|
||||
or the type âreference to pointer to function
|
||||
of (P1,â¦,Pn) returning Râ,
|
||||
or the type
|
||||
âreference to function of (P1,â¦,Pn)
|
||||
returning Râ, a [*surrogate call function*](#def:surrogate_call_function "12.2.2.2.3 Call to object of class type [over.call.object]") with the unique name*call-function* and having the form
|
||||
|
||||
R *call-function* ( [*conversion-type-id*](class.conv.fct#nt:conversion-type-id "11.4.8.3 Conversion functions [class.conv.fct]") F, P1 a1, …, Pn an) { return F (a1, …, an); }
|
||||
|
||||
is also considered as a candidate function[.](#over.call.object-2.sentence-1)
|
||||
|
||||
Similarly, surrogate
|
||||
call functions are added to the set of candidate functions for
|
||||
each non-explicit conversion function declared in a base class ofT provided the function is not hidden withinT by another
|
||||
intervening declaration[.](#over.call.object-2.sentence-2)[102](#footnote-102 "Note that this construction can yield candidate call functions that cannot be differentiated one from the other by overload resolution because they have identical declarations or differ only in their return type. The call will be ambiguous if overload resolution cannot select a match to the call that is uniquely better than such undifferentiable functions.")
|
||||
|
||||
[3](#over.call.object-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L629)
|
||||
|
||||
The argument list submitted to overload resolution consists of
|
||||
the argument expressions present in the function call syntax
|
||||
preceded by the implied object argument(E)[.](#over.call.object-3.sentence-1)
|
||||
|
||||
[*Note [1](#over.call.object-note-1)*:
|
||||
|
||||
When comparing the
|
||||
call against the function call operators, the implied object
|
||||
argument is compared against the object parameter of the
|
||||
function call operator[.](#over.call.object-3.sentence-2)
|
||||
|
||||
When comparing the call against a
|
||||
surrogate call function, the implied object argument is compared
|
||||
against the first parameter of the surrogate call function[.](#over.call.object-3.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Example [1](#over.call.object-example-1)*: int f1(int);int f2(float);typedef int (*fp1)(int);typedef int (*fp2)(float);struct A {operator fp1() { return f1; }operator fp2() { return f2; }} a;int i = a(1); // calls f1 via pointer returned from conversion function â *end example*]
|
||||
|
||||
[102)](#footnote-102)[102)](#footnoteref-102)
|
||||
|
||||
Note that this construction can yield
|
||||
candidate call functions that cannot be
|
||||
differentiated one from the other by overload resolution because they have
|
||||
identical
|
||||
declarations or differ only in their return type[.](#footnote-102.sentence-1)
|
||||
|
||||
The call will be ambiguous
|
||||
if overload
|
||||
resolution cannot select a match to the call that is uniquely better than such
|
||||
undifferentiable functions[.](#footnote-102.sentence-2)
|
||||
50
cppdraft/over/match/call/general.md
Normal file
50
cppdraft/over/match/call/general.md
Normal file
@@ -0,0 +1,50 @@
|
||||
[over.match.call.general]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#call.general)
|
||||
|
||||
### 12.2.2 Candidate functions and argument lists [[over.match.funcs]](over.match.funcs#over.match.call.general)
|
||||
|
||||
#### 12.2.2.2 Function call syntax [[over.match.call]](over.match.call#general)
|
||||
|
||||
#### 12.2.2.2.1 General [over.match.call.general]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L362)
|
||||
|
||||
In a [function call](expr.call "7.6.1.3 Function call [expr.call]")
|
||||
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") ( [*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]")opt )
|
||||
|
||||
if the [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") names at least one function or
|
||||
function template,
|
||||
overload resolution is applied as specified in [[over.call.func]](over.call.func "12.2.2.2.2 Call to designated function")[.](#1.sentence-1)
|
||||
|
||||
If the [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") denotes an object of class type, overload
|
||||
resolution is applied as specified in [[over.call.object]](over.call.object "12.2.2.2.3 Call to object of class type")[.](#1.sentence-2)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L373)
|
||||
|
||||
If the [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") is the address of an overload set,
|
||||
overload resolution is applied using that set as described above[.](#2.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
No implied object argument is added in this case[.](#2.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
If the function selected by overload resolution is
|
||||
an implicit object member function,
|
||||
the program is ill-formed[.](#2.sentence-3)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
The resolution of the address of an
|
||||
overload set in other contexts is described in [[over.over]](over.over "12.3 Address of an overload set")[.](#2.sentence-4)
|
||||
|
||||
â *end note*]
|
||||
361
cppdraft/over/match/class/deduct.md
Normal file
361
cppdraft/over/match/class/deduct.md
Normal file
@@ -0,0 +1,361 @@
|
||||
[over.match.class.deduct]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#class.deduct)
|
||||
|
||||
### 12.2.2 Candidate functions and argument lists [[over.match.funcs]](over.match.funcs#over.match.class.deduct)
|
||||
|
||||
#### 12.2.2.9 Class template argument deduction [over.match.class.deduct]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1221)
|
||||
|
||||
When resolving a placeholder for a deduced class type ([[dcl.type.class.deduct]](dcl.type.class.deduct "9.2.9.8 Deduced class template specialization types"))
|
||||
where the [*template-name*](temp.names#nt:template-name "13.3 Names of template specializations [temp.names]") or [*splice-type-specifier*](dcl.type.splice#nt:splice-type-specifier "9.2.9.9 Type splicing [dcl.type.splice]") designates a primary class template C,
|
||||
a set of functions and function templates, called the guides of C,
|
||||
is formed comprising:
|
||||
|
||||
- [(1.1)](#1.1)
|
||||
|
||||
If C is defined,
|
||||
for each constructor of C,
|
||||
a function template with the following properties:
|
||||
* [(1.1.1)](#1.1.1)
|
||||
|
||||
The template parameters are the template parameters of C followed
|
||||
by the template parameters (including default template arguments) of the constructor,
|
||||
if any[.](#1.1.1.sentence-1)
|
||||
|
||||
* [(1.1.2)](#1.1.2)
|
||||
|
||||
The associated constraints ([[temp.constr.decl]](temp.constr.decl "13.5.3 Constrained declarations")) are the conjunction of
|
||||
the associated constraints of C and
|
||||
the associated constraints of the constructor, if any[.](#1.1.2.sentence-1)
|
||||
[*Note [1](#note-1)*:
|
||||
A [*constraint-expression*](temp.constr.decl#nt:constraint-expression "13.5.3 Constrained declarations [temp.constr.decl]") in
|
||||
the [*template-head*](temp.pre#nt:template-head "13.1 Preamble [temp.pre]") of C is checked for satisfaction before any constraints from
|
||||
the [*template-head*](temp.pre#nt:template-head "13.1 Preamble [temp.pre]") or trailing [*requires-clause*](temp.pre#nt:requires-clause "13.1 Preamble [temp.pre]") of the constructor[.](#1.1.2.sentence-2)
|
||||
â *end note*]
|
||||
|
||||
* [(1.1.3)](#1.1.3)
|
||||
|
||||
The [*parameter-declaration-clause*](dcl.fct#nt:parameter-declaration-clause "9.3.4.6 Functions [dcl.fct]") is that of the constructor[.](#1.1.3.sentence-1)
|
||||
|
||||
* [(1.1.4)](#1.1.4)
|
||||
|
||||
The return type is the class template specialization
|
||||
designated by C and template arguments
|
||||
corresponding to the template parameters of C[.](#1.1.4.sentence-1)
|
||||
|
||||
- [(1.2)](#1.2)
|
||||
|
||||
If C is not defined or does not declare any constructors,
|
||||
an additional function template derived as above
|
||||
from a hypothetical constructor C()[.](#1.2.sentence-1)
|
||||
|
||||
- [(1.3)](#1.3)
|
||||
|
||||
An additional function template derived as above
|
||||
from a hypothetical constructor C(C),
|
||||
called the [*copy deduction candidate*](#def:copy_deduction_candidate "12.2.2.9 Class template argument deduction [over.match.class.deduct]")[.](#1.3.sentence-1)
|
||||
|
||||
- [(1.4)](#1.4)
|
||||
|
||||
For each [*deduction-guide*](temp.deduct.guide#nt:deduction-guide "13.7.2.3 Deduction guides [temp.deduct.guide]"),
|
||||
a function or function template
|
||||
with the following properties:
|
||||
* [(1.4.1)](#1.4.1)
|
||||
|
||||
The [*template-head*](temp.pre#nt:template-head "13.1 Preamble [temp.pre]"), if any,
|
||||
and [*parameter-declaration-clause*](dcl.fct#nt:parameter-declaration-clause "9.3.4.6 Functions [dcl.fct]") are those of the [*deduction-guide*](temp.deduct.guide#nt:deduction-guide "13.7.2.3 Deduction guides [temp.deduct.guide]")[.](#1.4.1.sentence-1)
|
||||
|
||||
* [(1.4.2)](#1.4.2)
|
||||
|
||||
The return type
|
||||
is the [*simple-template-id*](temp.names#nt:simple-template-id "13.3 Names of template specializations [temp.names]") of the [*deduction-guide*](temp.deduct.guide#nt:deduction-guide "13.7.2.3 Deduction guides [temp.deduct.guide]")[.](#1.4.2.sentence-1)
|
||||
|
||||
In addition, if C is defined
|
||||
and its definition satisfies the conditions for
|
||||
an aggregate class ([[dcl.init.aggr]](dcl.init.aggr "9.5.2 Aggregates"))
|
||||
with the assumption that any dependent base class has
|
||||
no virtual functions and no virtual base classes, and
|
||||
the initializer is a non-empty [*braced-init-list*](dcl.init.general#nt:braced-init-list "9.5.1 General [dcl.init.general]") or
|
||||
parenthesized [*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]"), and
|
||||
there are no [*deduction-guide*](temp.deduct.guide#nt:deduction-guide "13.7.2.3 Deduction guides [temp.deduct.guide]")*s* for C,
|
||||
the set contains an additional function template,
|
||||
called the [*aggregate deduction candidate*](#def:candidate,aggregate_deduction "12.2.2.9 Class template argument deduction [over.match.class.deduct]"), defined as follows[.](#1.sentence-2)
|
||||
|
||||
Let x1,â¦,xn be the elements
|
||||
of the [*initializer-list*](dcl.init.general#nt:initializer-list "9.5.1 General [dcl.init.general]") or[*designated-initializer-list*](dcl.init.general#nt:designated-initializer-list "9.5.1 General [dcl.init.general]") of the [*braced-init-list*](dcl.init.general#nt:braced-init-list "9.5.1 General [dcl.init.general]"), or
|
||||
of the [*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]")[.](#1.sentence-3)
|
||||
|
||||
For each xi, let ei be the corresponding aggregate element
|
||||
of C or of one of its (possibly recursive) subaggregates
|
||||
that would be initialized by xi ([[dcl.init.aggr]](dcl.init.aggr "9.5.2 Aggregates")) if
|
||||
|
||||
- [(1.5)](#1.5)
|
||||
|
||||
brace elision is not considered for any aggregate element
|
||||
that has
|
||||
* [(1.5.1)](#1.5.1)
|
||||
|
||||
a dependent non-array type,
|
||||
|
||||
* [(1.5.2)](#1.5.2)
|
||||
|
||||
an array type with a value-dependent bound, or
|
||||
|
||||
* [(1.5.3)](#1.5.3)
|
||||
|
||||
an array type with a dependent array element type and xi is a string literal; and
|
||||
|
||||
- [(1.6)](#1.6)
|
||||
|
||||
each non-trailing aggregate element that is a pack expansion
|
||||
is assumed to correspond to no elements of the initializer list, and
|
||||
|
||||
- [(1.7)](#1.7)
|
||||
|
||||
a trailing aggregate element that is a pack expansion is assumed to correspond
|
||||
to all remaining elements of the initializer list (if any)[.](#1.sentence-4)
|
||||
|
||||
If there is no such aggregate element ei for any xi,
|
||||
the aggregate deduction candidate is not added to the set[.](#1.sentence-5)
|
||||
|
||||
The aggregate deduction candidate is derived as above
|
||||
from a hypothetical constructor C(T1,â¦,Tn),
|
||||
where
|
||||
|
||||
- [(1.8)](#1.8)
|
||||
|
||||
if ei is of array type andxi is a [*braced-init-list*](dcl.init.general#nt:braced-init-list "9.5.1 General [dcl.init.general]"),Ti is an rvalue reference to the declared type of ei, and
|
||||
|
||||
- [(1.9)](#1.9)
|
||||
|
||||
if ei is of array type andxi is a [*string-literal*](lex.string#nt:string-literal "5.13.5 String literals [lex.string]"),Ti is an lvalue reference to
|
||||
the const-qualified declared type of ei, and
|
||||
|
||||
- [(1.10)](#1.10)
|
||||
|
||||
otherwise, Ti is the declared type of ei,
|
||||
|
||||
except that additional parameter packs of the form Pj... are inserted into the parameter list in their original aggregate element position corresponding to each non-trailing aggregate element of type Pj that was skipped because it was a parameter pack, and
|
||||
the trailing sequence of parameters corresponding
|
||||
to a trailing aggregate element that is a pack expansion (if any)
|
||||
is replaced by a single parameter of the form Tn...[.](#1.sentence-6)
|
||||
|
||||
In addition,
|
||||
if C is defined and
|
||||
inherits constructors ([[namespace.udecl]](namespace.udecl "9.10 The using declaration"))
|
||||
from a direct base class denoted in the [*base-specifier-list*](class.derived.general#nt:base-specifier-list "11.7.1 General [class.derived.general]") by a [*class-or-decltype*](class.derived.general#nt:class-or-decltype "11.7.1 General [class.derived.general]") B,
|
||||
let A be an alias template
|
||||
whose template parameter list is that of C and
|
||||
whose [*defining-type-id*](dcl.name#nt:defining-type-id "9.3.2 Type names [dcl.name]") is B[.](#1.sentence-7)
|
||||
|
||||
If A is a deducible template ([[dcl.type.simple]](dcl.type.simple "9.2.9.3 Simple type specifiers")),
|
||||
the set contains the guides of A with the return type R of each guide
|
||||
replaced with typename CC<R>::type given a class templatetemplate <typename> class CC; whose primary template is not defined and
|
||||
with a single partial specialization
|
||||
whose template parameter list is that of A and
|
||||
whose template argument list is a specialization of A with
|
||||
the template argument list of A ([[temp.dep.type]](temp.dep.type "13.8.3.2 Dependent types"))
|
||||
having a member typedef type designating a template specialization with
|
||||
the template argument list of A but
|
||||
with C as the template[.](#1.sentence-8)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
Equivalently,
|
||||
the template parameter list of the specialization is that of C,
|
||||
the template argument list of the specialization is B, and
|
||||
the member typedef names C with the template argument list of C[.](#1.sentence-9)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1373)
|
||||
|
||||
[*Example [1](#example-1)*: template <typename T> struct B { B(T);};template <typename T> struct C : public B<T> {using B<T>::B;};template <typename T> struct D : public B<T> {};
|
||||
|
||||
C c(42); // OK, deduces C<int> D d(42); // error: deduction failed, no inherited deduction guides B(int) -> B<char>;
|
||||
C c2(42); // OK, deduces C<char>template <typename T> struct E : public B<int> {using B<int>::B;};
|
||||
|
||||
E e(42); // error: deduction failed, arguments of E cannot be deduced from introduced guidestemplate <typename T, typename U, typename V> struct F { F(T, U, V);};template <typename T, typename U> struct G : F<U, T, int> {using G::F::F;} G g(true, 'a', 1); // OK, deduces G<char, bool>template<class T, std::size_t N>struct H { T array[N];};template<class T, std::size_t N>struct I {volatile T array[N];};template<std::size_t N>struct J {unsigned char array[N];};
|
||||
|
||||
H h = { "abc" }; // OK, deduces H<char, 4> (not T = const char) I i = { "def" }; // OK, deduces I<char, 4> J j = { "ghi" }; // error: cannot bind reference to array of unsigned char to array of char in deduction â *end example*]
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1423)
|
||||
|
||||
When resolving a placeholder for a deduced class type ([[dcl.type.simple]](dcl.type.simple "9.2.9.3 Simple type specifiers"))
|
||||
where
|
||||
the [*template-name*](temp.names#nt:template-name "13.3 Names of template specializations [temp.names]") or [*splice-type-specifier*](dcl.type.splice#nt:splice-type-specifier "9.2.9.9 Type splicing [dcl.type.splice]") designates an alias template A,
|
||||
the [*defining-type-id*](dcl.name#nt:defining-type-id "9.3.2 Type names [dcl.name]") of A must be of the form
|
||||
|
||||
typenameopt [*nested-name-specifier*](expr.prim.id.qual#nt:nested-name-specifier "7.5.5.3 Qualified names [expr.prim.id.qual]")opt templateopt [*simple-template-id*](temp.names#nt:simple-template-id "13.3 Names of template specializations [temp.names]")
|
||||
|
||||
as specified in [[dcl.type.simple]](dcl.type.simple "9.2.9.3 Simple type specifiers")[.](#3.sentence-1)
|
||||
|
||||
The guides of A are the set of functions or function templates
|
||||
formed as follows[.](#3.sentence-2)
|
||||
|
||||
For each function or function template f in the guides of
|
||||
the template named by the [*simple-template-id*](temp.names#nt:simple-template-id "13.3 Names of template specializations [temp.names]") of the [*defining-type-id*](dcl.name#nt:defining-type-id "9.3.2 Type names [dcl.name]"),
|
||||
the template arguments of the return type of f are deduced
|
||||
from the [*defining-type-id*](dcl.name#nt:defining-type-id "9.3.2 Type names [dcl.name]") of A according to the process in [[temp.deduct.type]](temp.deduct.type "13.10.3.6 Deducing template arguments from a type") with the exception that deduction does not fail
|
||||
if not all template arguments are deduced[.](#3.sentence-3)
|
||||
|
||||
If deduction fails for another reason,
|
||||
proceed with an empty set of deduced template arguments[.](#3.sentence-4)
|
||||
|
||||
Let g denote the result of substituting
|
||||
these deductions into f[.](#3.sentence-5)
|
||||
|
||||
If substitution succeeds,
|
||||
form a function or function template f' with the following properties and add it to the set
|
||||
of guides of A:
|
||||
|
||||
- [(3.1)](#3.1)
|
||||
|
||||
The function type of f' is the function type of g[.](#3.1.sentence-1)
|
||||
|
||||
- [(3.2)](#3.2)
|
||||
|
||||
If f is a function template,f' is a function template whose
|
||||
template parameter list consists of
|
||||
all the template parameters of A (including their default template arguments)
|
||||
that appear in the above deductions or
|
||||
(recursively) in their default template arguments,
|
||||
followed by the template parameters of f that were not deduced
|
||||
(including their default template arguments),
|
||||
otherwise f' is not a function template[.](#3.2.sentence-1)
|
||||
|
||||
- [(3.3)](#3.3)
|
||||
|
||||
The associated constraints ([[temp.constr.decl]](temp.constr.decl "13.5.3 Constrained declarations")) are
|
||||
the conjunction of the associated constraints of g and
|
||||
a constraint that is satisfied if and only if
|
||||
the arguments of A are deducible (see below) from the return type[.](#3.3.sentence-1)
|
||||
|
||||
- [(3.4)](#3.4)
|
||||
|
||||
If f is a copy deduction candidate,
|
||||
then f' is considered to be so as well[.](#3.4.sentence-1)
|
||||
|
||||
- [(3.5)](#3.5)
|
||||
|
||||
If f was generated
|
||||
from a [*deduction-guide*](temp.deduct.guide#nt:deduction-guide "13.7.2.3 Deduction guides [temp.deduct.guide]") ([[temp.deduct.guide]](temp.deduct.guide "13.7.2.3 Deduction guides")),
|
||||
then f' is considered to be so as well[.](#3.5.sentence-1)
|
||||
|
||||
- [(3.6)](#3.6)
|
||||
|
||||
The [*explicit-specifier*](dcl.fct.spec#nt:explicit-specifier "9.2.3 Function specifiers [dcl.fct.spec]") of f' is
|
||||
the [*explicit-specifier*](dcl.fct.spec#nt:explicit-specifier "9.2.3 Function specifiers [dcl.fct.spec]") of g (if any)[.](#3.6.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1489)
|
||||
|
||||
The arguments of a template A are said to be
|
||||
deducible from a type T if, given a class templatetemplate <typename> class AA; with a single partial specialization
|
||||
whose template parameter list is that of A and
|
||||
whose template argument list is a specialization of A with the template argument list of A ([[temp.dep.type]](temp.dep.type "13.8.3.2 Dependent types")),AA<T> matches the partial specialization[.](#4.sentence-1)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1501)
|
||||
|
||||
Initialization and overload resolution are performed as described
|
||||
in [[dcl.init]](dcl.init "9.5 Initializers") and [[over.match.ctor]](over.match.ctor "12.2.2.4 Initialization by constructor"), [[over.match.copy]](over.match.copy "12.2.2.5 Copy-initialization of class by user-defined conversion"),
|
||||
or [[over.match.list]](over.match.list "12.2.2.8 Initialization by list-initialization") (as appropriate for the type of initialization
|
||||
performed) for an object of a hypothetical class type, where
|
||||
the guides of the template named by the placeholder are considered to be the
|
||||
constructors of that class type for the purpose of forming an overload
|
||||
set, and the initializer is provided by the context in which class
|
||||
template argument deduction was performed[.](#5.sentence-1)
|
||||
|
||||
The following exceptions apply:
|
||||
|
||||
- [(5.1)](#5.1)
|
||||
|
||||
The first phase in [[over.match.list]](over.match.list "12.2.2.8 Initialization by list-initialization") (considering initializer-list constructors)
|
||||
is omitted if the initializer list consists of
|
||||
a single expression of type cv U,
|
||||
where U is, or is derived from,
|
||||
a specialization of the class template
|
||||
directly or indirectly named by the placeholder[.](#5.1.sentence-1)
|
||||
|
||||
- [(5.2)](#5.2)
|
||||
|
||||
During template argument deduction for the aggregate deduction candidate,
|
||||
the number of elements in a trailing parameter pack
|
||||
is only deduced from the number of remaining function arguments
|
||||
if it is not otherwise deduced[.](#5.2.sentence-1)
|
||||
|
||||
If the function or function template was generated from
|
||||
a constructor or [*deduction-guide*](temp.deduct.guide#nt:deduction-guide "13.7.2.3 Deduction guides [temp.deduct.guide]") that had an [*explicit-specifier*](dcl.fct.spec#nt:explicit-specifier "9.2.3 Function specifiers [dcl.fct.spec]"),
|
||||
each such notional constructor is considered to have
|
||||
that same [*explicit-specifier*](dcl.fct.spec#nt:explicit-specifier "9.2.3 Function specifiers [dcl.fct.spec]")[.](#5.sentence-3)
|
||||
|
||||
All such notional constructors are considered to be
|
||||
public members of the hypothetical class type[.](#5.sentence-4)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1534)
|
||||
|
||||
[*Example [2](#example-2)*: template <class T> struct A {explicit A(const T&, ...) noexcept; // #1 A(T&&, ...); // #2};
|
||||
|
||||
int i;
|
||||
A a1 = { i, i }; // error: explicit constructor #1 selected in copy-list-initialization during deduction,// cannot deduce from non-forwarding rvalue reference in #2 A a2{i, i}; // OK, #1 deduces to A<int> and also initializes A a3{0, i}; // OK, #2 deduces to A<int> and also initializes A a4 = {0, i}; // OK, #2 deduces to A<int> and also initializestemplate <class T> A(const T&, const T&) -> A<T&>; // #3template <class T> explicit A(T&&, T&&) -> A<T>; // #4 A a5 = {0, 1}; // error: explicit deduction guide #4 selected in copy-list-initialization during deduction A a6{0,1}; // OK, #4 deduces to A<int> and #2 initializes A a7 = {0, i}; // error: #3 deduces to A<int&>, #1 and #2 declare same constructor A a8{0,i}; // error: #3 deduces to A<int&>, #1 and #2 declare same constructortemplate <class T> struct B {template <class U> using TA = T; template <class U> B(U, TA<U>);};
|
||||
|
||||
B b{(int*)0, (char*)0}; // OK, deduces B<char*>template <typename T>struct S { T x;
|
||||
T y;};
|
||||
|
||||
template <typename T>struct C { S<T> s;
|
||||
T t;};
|
||||
|
||||
template <typename T>struct D { S<int> s;
|
||||
T t;};
|
||||
|
||||
C c1 = {1, 2}; // error: deduction failed C c2 = {1, 2, 3}; // error: deduction failed C c3 = {{1u, 2u}, 3}; // OK, deduces C<int> D d1 = {1, 2}; // error: deduction failed D d2 = {1, 2, 3}; // OK, braces elided, deduces D<int>template <typename T>struct E { T t; decltype(t) t2;};
|
||||
|
||||
E e1 = {1, 2}; // OK, deduces E<int>template <typename... T>struct Types {};
|
||||
|
||||
template <typename... T>struct F : Types<T...>, T... {};
|
||||
|
||||
struct X {};struct Y {};struct Z {};struct W { operator Y(); };
|
||||
|
||||
F f1 = {Types<X, Y, Z>{}, {}, {}}; // OK, F<X, Y, Z> deduced F f2 = {Types<X, Y, Z>{}, X{}, Y{}}; // OK, F<X, Y, Z> deduced F f3 = {Types<X, Y, Z>{}, X{}, W{}}; // error: conflicting types deduced; operator Y not considered â *end example*]
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1615)
|
||||
|
||||
[*Example [3](#example-3)*: template <class T, class U> struct C { C(T, U); // #1};template<class T, class U> C(T, U) -> C<T, std::type_identity_t<U>>; // #2template<class V> using A = C<V *, V *>;template<std::[integral](concepts.arithmetic#concept:integral "18.4.7 Arithmetic concepts [concepts.arithmetic]") W> using B = A<W>;
|
||||
|
||||
int i{};double d{};
|
||||
A a1(&i, &i); // deduces A<int> A a2(i, i); // error: cannot deduce V * from i A a3(&i, &d); // error: #1: cannot deduce (V*, V*) from (int *, double *)// #2: cannot deduce A<V> from C<int *, double *> B b1(&i, &i); // deduces B<int> B b2(&d, &d); // error: cannot deduce B<W> from C<double *, double *>
|
||||
|
||||
Possible exposition-only implementation of the above procedure:// The following concept ensures a specialization of A is deduced.template <class> class AA;template <class V> class AA<A<V>> { };template <class T> concept deduces_A = requires { sizeof(AA<T>); };
|
||||
|
||||
// f1 is formed from the constructor #1 of C, generating the following function templatetemplate<class T, class U>auto f1(T, U) -> C<T, U>;
|
||||
|
||||
// Deducing arguments for C<T, U> from C<V *, V*> deduces T as V * and U as V *;// f1' is obtained by transforming f1 as described by the above procedure.template<class V> requires deduces_A<C<V *, V *>>auto f1_prime(V *, V*) -> C<V *, V *>;
|
||||
|
||||
// f2 is formed from the deduction-guide #2 of Ctemplate<class T, class U> auto f2(T, U) -> C<T, std::type_identity_t<U>>;
|
||||
|
||||
// Deducing arguments for C<T, std::type_identity_t<U>> from C<V *, V*> deduces T as V *;// f2' is obtained by transforming f2 as described by the above procedure.template<class V, class U>requires deduces_A<C<V *, std::type_identity_t<U>>>auto f2_prime(V *, U) -> C<V *, std::type_identity_t<U>>;
|
||||
|
||||
// The following concept ensures a specialization of B is deduced.template <class> class BB;template <class V> class BB<B<V>> { };template <class T> concept deduces_B = requires { sizeof(BB<T>); };
|
||||
|
||||
// The guides for B derived from the above f1' and f2' for A are as follows:template<std::[integral](concepts.arithmetic#concept:integral "18.4.7 Arithmetic concepts [concepts.arithmetic]") W>requires deduces_A<C<W *, W *>> && deduces_B<C<W *, W *>>auto f1_prime_for_B(W *, W *) -> C<W *, W *>;
|
||||
|
||||
template<std::[integral](concepts.arithmetic#concept:integral "18.4.7 Arithmetic concepts [concepts.arithmetic]") W, class U>requires deduces_A<C<W *, std::type_identity_t<U>>> && deduces_B<C<W *, std::type_identity_t<U>>>auto f2_prime_for_B(W *, U) -> C<W *, std::type_identity_t<U>>;
|
||||
|
||||
â *end example*]
|
||||
48
cppdraft/over/match/conv.md
Normal file
48
cppdraft/over/match/conv.md
Normal file
@@ -0,0 +1,48 @@
|
||||
[over.match.conv]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#conv)
|
||||
|
||||
### 12.2.2 Candidate functions and argument lists [[over.match.funcs]](over.match.funcs#over.match.conv)
|
||||
|
||||
#### 12.2.2.6 Initialization by conversion function [over.match.conv]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1110)
|
||||
|
||||
Under the conditions specified in [[dcl.init]](dcl.init "9.5 Initializers"), as
|
||||
part of an initialization of an object of non-class type,
|
||||
a conversion function can be invoked to convert an initializer
|
||||
expression of class type to the type of the object
|
||||
being initialized[.](#1.sentence-1)
|
||||
|
||||
Overload resolution is used to select the
|
||||
conversion function to be invoked[.](#1.sentence-2)
|
||||
|
||||
Assuming that âcv Tâ is the
|
||||
type of the object being initialized,
|
||||
the candidate functions are selected as follows:
|
||||
|
||||
- [(1.1)](#1.1)
|
||||
|
||||
The permissible types for non-explicit conversion functions are
|
||||
those that can be converted to type T via a standard conversion sequence ([[over.ics.scs]](over.ics.scs "12.2.4.2.2 Standard conversion sequences"))[.](#1.sentence-3)
|
||||
For direct-initialization,
|
||||
the permissible types for explicit conversion functions are
|
||||
those that can be converted to type T with a (possibly trivial) qualification conversion ([[conv.qual]](conv.qual "7.3.6 Qualification conversions"));
|
||||
otherwise there are none[.](#1.1.sentence-2)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1133)
|
||||
|
||||
The argument list has one argument, which is the initializer expression[.](#2.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
This argument will be compared against
|
||||
the object parameter of the conversion functions[.](#2.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
68
cppdraft/over/match/copy.md
Normal file
68
cppdraft/over/match/copy.md
Normal file
@@ -0,0 +1,68 @@
|
||||
[over.match.copy]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#copy)
|
||||
|
||||
### 12.2.2 Candidate functions and argument lists [[over.match.funcs]](over.match.funcs#over.match.copy)
|
||||
|
||||
#### 12.2.2.5 Copy-initialization of class by user-defined conversion [over.match.copy]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1059)
|
||||
|
||||
Under the conditions specified in [[dcl.init]](dcl.init "9.5 Initializers"), as
|
||||
part of a copy-initialization of an object of class type, a user-defined
|
||||
conversion can be invoked to convert an initializer expression to the
|
||||
type of the object being initialized[.](#1.sentence-1)
|
||||
|
||||
Overload resolution is used
|
||||
to select the user-defined conversion to be invoked[.](#1.sentence-2)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
The conversion performed for indirect binding to a reference to a possibly
|
||||
cv-qualified class type is determined in terms of a corresponding non-reference
|
||||
copy-initialization[.](#1.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
Assuming that
|
||||
â*cv1* Tâ is the type of the object being initialized, withT a class type,
|
||||
the candidate functions are selected as follows:
|
||||
|
||||
- [(1.1)](#1.1)
|
||||
|
||||
The non-explicit constructors ([[class.conv.ctor]](class.conv.ctor "11.4.8.2 Conversion by constructor")) ofT are candidate functions[.](#1.1.sentence-1)
|
||||
|
||||
- [(1.2)](#1.2)
|
||||
|
||||
When the type of the initializer expression is a class type
|
||||
âcv Sâ,
|
||||
conversion functions are considered[.](#1.2.sentence-1)
|
||||
The permissible types for non-explicit conversion functions areT and any class derived from T[.](#1.2.sentence-2)
|
||||
When initializing a temporary object ([[class.mem]](class.mem "11.4 Class members"))
|
||||
to be bound to the first parameter of a constructor
|
||||
where the parameter is of type
|
||||
âreference to *cv2* Tâ
|
||||
and the constructor is
|
||||
called with a single argument in the context of
|
||||
direct-initialization of an object of type â*cv3* Tâ,
|
||||
the permissible types for explicit conversion functions are the same;
|
||||
otherwise there are none[.](#1.2.sentence-3)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1098)
|
||||
|
||||
In both cases, the argument list has one argument, which is the initializer
|
||||
expression[.](#2.sentence-1)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
This argument will be compared against
|
||||
the first parameter of the constructors and against the
|
||||
object parameter of the conversion functions[.](#2.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
34
cppdraft/over/match/ctor.md
Normal file
34
cppdraft/over/match/ctor.md
Normal file
@@ -0,0 +1,34 @@
|
||||
[over.match.ctor]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#ctor)
|
||||
|
||||
### 12.2.2 Candidate functions and argument lists [[over.match.funcs]](over.match.funcs#over.match.ctor)
|
||||
|
||||
#### 12.2.2.4 Initialization by constructor [over.match.ctor]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1036)
|
||||
|
||||
When objects of class type are [direct-initialized](dcl.init#def:direct-initialization "9.5 Initializers [dcl.init]"),
|
||||
copy-initialized from an expression of the same or a
|
||||
derived class type ([[dcl.init]](dcl.init "9.5 Initializers")),
|
||||
or [default-initialized](dcl.init#def:default-initialization "9.5 Initializers [dcl.init]"),
|
||||
overload resolution selects the constructor[.](#1.sentence-1)
|
||||
|
||||
For direct-initialization or default-initialization
|
||||
(including default-initialization in the context of copy-list-initialization),
|
||||
the candidate functions are
|
||||
all the constructors of the class of the object being
|
||||
initialized[.](#1.sentence-2)
|
||||
|
||||
Otherwise, the candidate functions are all
|
||||
the non-explicit constructors ([[class.conv.ctor]](class.conv.ctor "11.4.8.2 Conversion by constructor")) of that
|
||||
class[.](#1.sentence-3)
|
||||
|
||||
The argument list is the[*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]") or [*assignment-expression*](expr.assign#nt:assignment-expression "7.6.19 Assignment and compound assignment operators [expr.assign]") of the [*initializer*](dcl.init.general#nt:initializer "9.5.1 General [dcl.init.general]")[.](#1.sentence-4)
|
||||
|
||||
For default-initialization in the context of copy-list-initialization,
|
||||
if an explicit constructor is chosen, the initialization is ill-formed[.](#1.sentence-5)
|
||||
1395
cppdraft/over/match/funcs.md
Normal file
1395
cppdraft/over/match/funcs.md
Normal file
File diff suppressed because it is too large
Load Diff
245
cppdraft/over/match/funcs/general.md
Normal file
245
cppdraft/over/match/funcs/general.md
Normal file
@@ -0,0 +1,245 @@
|
||||
[over.match.funcs.general]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#funcs.general)
|
||||
|
||||
### 12.2.2 Candidate functions and argument lists [[over.match.funcs]](over.match.funcs#general)
|
||||
|
||||
#### 12.2.2.1 General [over.match.funcs.general]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L145)
|
||||
|
||||
The subclauses of [[over.match.funcs]](over.match.funcs "12.2.2 Candidate functions and argument lists") describe
|
||||
the set of candidate functions and the argument list submitted to
|
||||
overload resolution in each context in which
|
||||
overload resolution is used[.](#1.sentence-1)
|
||||
|
||||
The source transformations and constructions defined
|
||||
in these subclauses are only for the purpose of describing the
|
||||
overload resolution process[.](#1.sentence-2)
|
||||
|
||||
An implementation is not required
|
||||
to use such transformations and constructions[.](#1.sentence-3)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L156)
|
||||
|
||||
The set of candidate functions can contain both member and non-member
|
||||
functions to be resolved against the same argument list[.](#2.sentence-1)
|
||||
|
||||
If a member function is
|
||||
|
||||
- [(2.1)](#2.1)
|
||||
|
||||
an implicit object member function that is not a constructor, or
|
||||
|
||||
- [(2.2)](#2.2)
|
||||
|
||||
a static member function and
|
||||
the argument list includes an implied object argument,
|
||||
|
||||
it is considered to have an extra first parameter,
|
||||
called the [*implicit object parameter*](#def:object_parameter,implicit "12.2.2.1 General [over.match.funcs.general]"),
|
||||
which represents the object for which the member function has been called[.](#2.sentence-2)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L173)
|
||||
|
||||
Similarly, when appropriate, the context can construct an
|
||||
argument list that contains an[*implied object argument*](#def:implied_object_argument "12.2.2.1 General [over.match.funcs.general]") as the first argument in the list to denote
|
||||
the object to be operated on[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L180)
|
||||
|
||||
For implicit object member functions, the type of the implicit object
|
||||
parameter is
|
||||
|
||||
- [(4.1)](#4.1)
|
||||
|
||||
âlvalue reference to cv Xâ for functions declared
|
||||
without a [*ref-qualifier*](dcl.decl.general#nt:ref-qualifier "9.3.1 General [dcl.decl.general]") or with the& [*ref-qualifier*](dcl.decl.general#nt:ref-qualifier "9.3.1 General [dcl.decl.general]")
|
||||
|
||||
- [(4.2)](#4.2)
|
||||
|
||||
ârvalue reference to cv Xâ for functions declared with the&& [*ref-qualifier*](dcl.decl.general#nt:ref-qualifier "9.3.1 General [dcl.decl.general]")
|
||||
|
||||
whereX is the class of which the function is a direct member andcv is the cv-qualification on the
|
||||
member function declaration[.](#4.sentence-1)
|
||||
|
||||
[*Example [1](#example-1)*:
|
||||
|
||||
For aconst member
|
||||
function of classX,
|
||||
the extra parameter is assumed to have type
|
||||
âlvalue reference toconst Xâ[.](#4.sentence-2)
|
||||
|
||||
â *end example*]
|
||||
|
||||
For conversion functions that are implicit object member functions,
|
||||
the function is considered to be a member of the
|
||||
class of the implied object argument for the purpose of defining the
|
||||
type of the implicit object parameter[.](#4.sentence-3)
|
||||
|
||||
For non-conversion functions that are implicit object member functions
|
||||
nominated by a [*using-declaration*](namespace.udecl#nt:using-declaration "9.10 The using declaration [namespace.udecl]") in a derived class, the function is
|
||||
considered to be a member of the derived class for the purpose of defining
|
||||
the type of the implicit object parameter[.](#4.sentence-4)
|
||||
|
||||
For static member functions, the implicit object parameter is considered
|
||||
to match any object (since if the function is selected, the object is
|
||||
discarded)[.](#4.sentence-5)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
No actual type is established for the implicit object parameter
|
||||
of a static member function, and no attempt will be made to determine a
|
||||
conversion sequence for that parameter ([[over.match.best]](over.match.best "12.2.4 Best viable function"))[.](#4.sentence-6)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L224)
|
||||
|
||||
During overload resolution, the implied object argument is
|
||||
indistinguishable from other arguments[.](#5.sentence-1)
|
||||
|
||||
The implicit object
|
||||
parameter, however, retains its identity since
|
||||
no user-defined conversions can be applied to achieve a type
|
||||
match with it[.](#5.sentence-2)
|
||||
|
||||
For implicit object member functions declared without a [*ref-qualifier*](dcl.decl.general#nt:ref-qualifier "9.3.1 General [dcl.decl.general]"),
|
||||
even if the implicit object parameter is not const-qualified,
|
||||
an rvalue can be bound to the parameter
|
||||
as long as in all other respects the argument can be
|
||||
converted to the type of the implicit object parameter[.](#5.sentence-3)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
The fact that such an argument is an rvalue does not
|
||||
affect the [ranking](over.ics.rank "12.2.4.3 Ranking implicit conversion sequences [over.ics.rank]") of implicit conversion sequences[.](#5.sentence-4)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L243)
|
||||
|
||||
Because other than in list-initialization only one user-defined conversion
|
||||
is allowed
|
||||
in an
|
||||
implicit conversion sequence, special rules apply when selecting
|
||||
the best user-defined conversion ([[over.match.best]](over.match.best "12.2.4 Best viable function"), [[over.best.ics]](over.best.ics "12.2.4.2 Implicit conversion sequences"))[.](#6.sentence-1)
|
||||
|
||||
[*Example [2](#example-2)*: class T {public: T();};
|
||||
|
||||
class C : T {public: C(int);};
|
||||
T a = 1; // error: no viable conversion (T(C(1)) not considered) â *end example*]
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L264)
|
||||
|
||||
In each case where conversion functions of a class S are considered
|
||||
for initializing an object or reference of type T,
|
||||
the candidate functions include the result of a search
|
||||
for the [*conversion-function-id*](class.conv.fct#nt:conversion-function-id "11.4.8.3 Conversion functions [class.conv.fct]") operator T in S[.](#7.sentence-1)
|
||||
|
||||
[*Note [3](#note-3)*:
|
||||
|
||||
This search can find a specialization of
|
||||
a conversion function template ([[basic.lookup]](basic.lookup "6.5 Name lookup"))[.](#7.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
Each such case also defines sets of [*permissible types*](#def:types,permissible "12.2.2.1 General [over.match.funcs.general]") for explicit and non-explicit conversion functions;
|
||||
each (non-template) conversion function
|
||||
that
|
||||
|
||||
- [(7.1)](#7.1)
|
||||
|
||||
is a non-hidden member of S,
|
||||
|
||||
- [(7.2)](#7.2)
|
||||
|
||||
yields a permissible type, and,
|
||||
|
||||
- [(7.3)](#7.3)
|
||||
|
||||
for the former set, is non-explicit
|
||||
|
||||
is also a candidate function[.](#7.sentence-3)
|
||||
|
||||
If initializing an object, for any permissible type cv U, any*cv2* U, *cv2* U&, or *cv2* U&& is also a permissible type[.](#7.sentence-4)
|
||||
|
||||
If the set of permissible types for explicit conversion functions is empty,
|
||||
any candidates that are explicit are discarded[.](#7.sentence-5)
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L290)
|
||||
|
||||
In each case where a candidate is a function template, candidate
|
||||
function template specializations
|
||||
are generated using template argument deduction ([[temp.over]](temp.over "13.10.4 Overload resolution"), [[temp.deduct]](temp.deduct "13.10.3 Template argument deduction"))[.](#8.sentence-1)
|
||||
|
||||
If a constructor template or conversion function template
|
||||
has an [*explicit-specifier*](dcl.fct.spec#nt:explicit-specifier "9.2.3 Function specifiers [dcl.fct.spec]") whose [*constant-expression*](expr.const#nt:constant-expression "7.7 Constant expressions [expr.const]") is value-dependent ([[temp.dep]](temp.dep "13.8.3 Dependent names")),
|
||||
template argument deduction is performed first and then,
|
||||
if the context admits only candidates that
|
||||
are not explicit and the generated specialization is explicit ([[dcl.fct.spec]](dcl.fct.spec "9.2.3 Function specifiers")),
|
||||
it will be removed from the candidate set[.](#8.sentence-2)
|
||||
|
||||
Those candidates are then handled as candidate
|
||||
functions in the usual way[.](#8.sentence-3)[99](#footnote-99 "The process of argument deduction fully determines the parameter types of the function template specializations, i.e., the parameters of function template specializations contain no template parameter types. Therefore, except where specified otherwise, function template specializations and non-template functions ([dcl.fct]) are treated equivalently for the remainder of overload resolution.")
|
||||
|
||||
A given name can refer to, or a conversion can consider,
|
||||
one or more function templates as well as a set of non-template functions[.](#8.sentence-4)
|
||||
|
||||
In such a case, the
|
||||
candidate functions generated from each function template are combined
|
||||
with the set of non-template candidate functions[.](#8.sentence-5)
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L323)
|
||||
|
||||
A
|
||||
defaulted move special member function ([[class.copy.ctor]](class.copy.ctor "11.4.5.3 Copy/move constructors"), [[class.copy.assign]](class.copy.assign "11.4.6 Copy/move assignment operator"))
|
||||
that is defined as deleted
|
||||
is excluded from the set of candidate functions in all contexts[.](#9.sentence-1)
|
||||
|
||||
A constructor inherited from class type C ([[class.inhctor.init]](class.inhctor.init "11.9.4 Initialization by inherited constructor"))
|
||||
that has a first parameter of type âreference to *cv1* Pâ
|
||||
(including such a constructor instantiated from a template)
|
||||
is excluded from the set of candidate functions
|
||||
when constructing an object of type *cv2* D if the argument list has exactly one argument andC is reference-related to P andP is reference-related to D[.](#9.sentence-2)
|
||||
|
||||
[*Example [3](#example-3)*: struct A { A(); // #1 A(A &&); // #2template<typename T> A(T &&); // #3};struct B : A {using A::A;
|
||||
B(const B &); // #4 B(B &&) = default; // #5, implicitly deletedstruct X { X(X &&) = delete; } x;};extern B b1;
|
||||
B b2 = static_cast<B&&>(b1); // calls #4: #1 is not viable, #2, #3, and #5 are not candidatesstruct C { operator B&&(); };
|
||||
B b3 = C(); // calls #4 â *end example*]
|
||||
|
||||
[99)](#footnote-99)[99)](#footnoteref-99)
|
||||
|
||||
The process of argument deduction fully
|
||||
determines the parameter types of
|
||||
the
|
||||
function template specializations,
|
||||
i.e., the parameters of
|
||||
function template specializations
|
||||
contain
|
||||
no template parameter types[.](#footnote-99.sentence-1)
|
||||
|
||||
Therefore, except where specified otherwise,
|
||||
function template specializations
|
||||
and non-template functions ([[dcl.fct]](dcl.fct "9.3.4.6 Functions")) are treated equivalently
|
||||
for the remainder of overload resolution[.](#footnote-99.sentence-2)
|
||||
123
cppdraft/over/match/general.md
Normal file
123
cppdraft/over/match/general.md
Normal file
@@ -0,0 +1,123 @@
|
||||
[over.match.general]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#general)
|
||||
|
||||
### 12.2.1 General [over.match.general]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L49)
|
||||
|
||||
Overload resolution is a mechanism for selecting the best
|
||||
function to call given a list of expressions that are to be the
|
||||
arguments of the call and a set of[*candidate functions*](#def:candidate "12.2.1 General [over.match.general]") that can
|
||||
be called based on the context of the call[.](#1.sentence-1)
|
||||
|
||||
The selection
|
||||
criteria for the best function are the number of arguments, how
|
||||
well the arguments match the parameter-type-list of the
|
||||
candidate function,
|
||||
how well (for non-static member functions) the object
|
||||
matches the object parameter,
|
||||
and certain other properties of the candidate function[.](#1.sentence-2)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
The function selected by overload resolution is not
|
||||
guaranteed to be appropriate for the context[.](#1.sentence-3)
|
||||
|
||||
Other restrictions,
|
||||
such as the accessibility of the function, can make its use in
|
||||
the calling context ill-formed[.](#1.sentence-4)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L71)
|
||||
|
||||
Overload resolution selects the function to call in seven distinct
|
||||
contexts within the language:
|
||||
|
||||
- [(2.1)](#2.1)
|
||||
|
||||
invocation of a function named in the [function call syntax](over.call.func "12.2.2.2.2 Call to designated function [over.call.func]");
|
||||
|
||||
- [(2.2)](#2.2)
|
||||
|
||||
invocation of a function call operator, a pointer-to-function
|
||||
conversion function, a reference-to-pointer-to-function conversion
|
||||
function, or a reference-to-function
|
||||
conversion function on a class object named in the function
|
||||
call syntax ([[over.call.object]](over.call.object "12.2.2.2.3 Call to object of class type"));
|
||||
|
||||
- [(2.3)](#2.3)
|
||||
|
||||
invocation of the operator referenced in an expression ([[over.match.oper]](over.match.oper "12.2.2.3 Operators in expressions"));
|
||||
|
||||
- [(2.4)](#2.4)
|
||||
|
||||
invocation of a constructor for default- or direct-initialization ([[dcl.init]](dcl.init "9.5 Initializers"))
|
||||
of a class object ([[over.match.ctor]](over.match.ctor "12.2.2.4 Initialization by constructor"));
|
||||
|
||||
- [(2.5)](#2.5)
|
||||
|
||||
invocation of a user-defined conversion for[copy-initialization](dcl.init#def:copy-initialization "9.5 Initializers [dcl.init]") of a class object ([[over.match.copy]](over.match.copy "12.2.2.5 Copy-initialization of class by user-defined conversion"));
|
||||
|
||||
- [(2.6)](#2.6)
|
||||
|
||||
invocation of a conversion function for initialization of an object of a
|
||||
non-class type from an expression of class type ([[over.match.conv]](over.match.conv "12.2.2.6 Initialization by conversion function")); and
|
||||
|
||||
- [(2.7)](#2.7)
|
||||
|
||||
invocation of a conversion function for conversion
|
||||
in which a reference ([[dcl.init.ref]](dcl.init.ref "9.5.4 References"))
|
||||
will be [directly bound](over.match.ref "12.2.2.7 Initialization by conversion function for direct reference binding [over.match.ref]")[.](#2.sentence-1)
|
||||
|
||||
Each of these contexts defines the set of candidate functions and
|
||||
the list of arguments in its own unique way[.](#2.sentence-2)
|
||||
|
||||
But, once the
|
||||
candidate functions and argument lists have been identified, the
|
||||
selection of the best function is the same in all cases:
|
||||
|
||||
- [(2.8)](#2.8)
|
||||
|
||||
First, a subset of the candidate functions (those that have
|
||||
the proper number of arguments and meet certain other
|
||||
conditions) is selected to form a set ofviable functions ([[over.match.viable]](over.match.viable "12.2.3 Viable functions"))[.](#2.8.sentence-1)
|
||||
|
||||
- [(2.9)](#2.9)
|
||||
|
||||
Then the best viable function is selected based on the[implicit conversion sequences](over.best.ics "12.2.4.2 Implicit conversion sequences [over.best.ics]") needed to
|
||||
match each argument to the corresponding parameter of each
|
||||
viable function[.](#2.9.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L120)
|
||||
|
||||
If a best viable function exists and is unique, overload
|
||||
resolution succeeds and produces it as the result[.](#3.sentence-1)
|
||||
|
||||
Otherwise
|
||||
overload resolution fails and the invocation is ill-formed[.](#3.sentence-2)
|
||||
|
||||
When overload resolution succeeds,
|
||||
and the best viable function is not [accessible](class.access "11.8 Member access control [class.access]") in the context
|
||||
in which it is used,
|
||||
the program is ill-formed[.](#3.sentence-3)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L130)
|
||||
|
||||
Overload resolution results in a [*usable candidate*](#def:candidate,usable "12.2.1 General [over.match.general]") if overload resolution succeeds and
|
||||
the selected candidate
|
||||
is either not a function ([[over.built]](over.built "12.5 Built-in operators")), or
|
||||
is a function that is not deleted and
|
||||
is accessible from the context
|
||||
in which overload resolution was performed[.](#4.sentence-1)
|
||||
49
cppdraft/over/match/list.md
Normal file
49
cppdraft/over/match/list.md
Normal file
@@ -0,0 +1,49 @@
|
||||
[over.match.list]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#list)
|
||||
|
||||
### 12.2.2 Candidate functions and argument lists [[over.match.funcs]](over.match.funcs#over.match.list)
|
||||
|
||||
#### 12.2.2.8 Initialization by list-initialization [over.match.list]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1186)
|
||||
|
||||
When objects of non-aggregate class type T are
|
||||
list-initialized such that [[dcl.init.list]](dcl.init.list "9.5.5 List-initialization") specifies that overload resolution
|
||||
is performed according to the rules in this subclause
|
||||
or when forming a list-initialization sequence according to [[over.ics.list]](over.ics.list "12.2.4.2.6 List-initialization sequence"),
|
||||
overload resolution selects the constructor in two phases:
|
||||
|
||||
- [(1.1)](#1.1)
|
||||
|
||||
If the initializer list is not empty or T has no default constructor,
|
||||
overload resolution is first performed
|
||||
where the candidate functions are the initializer-list constructors ([[dcl.init.list]](dcl.init.list "9.5.5 List-initialization"))
|
||||
of the class T and
|
||||
the argument list consists of the initializer list as a single argument[.](#1.1.sentence-1)
|
||||
|
||||
- [(1.2)](#1.2)
|
||||
|
||||
Otherwise, or if no viable initializer-list constructor is found,
|
||||
overload resolution is
|
||||
performed again, where the candidate functions are all the constructors of
|
||||
the class T and
|
||||
the argument list consists of the elements of the initializer list[.](#1.2.sentence-1)
|
||||
|
||||
In copy-list-initialization, if an explicit constructor is
|
||||
chosen, the initialization is ill-formed[.](#1.sentence-2)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
This differs from other situations ([[over.match.ctor]](over.match.ctor "12.2.2.4 Initialization by constructor"), [[over.match.copy]](over.match.copy "12.2.2.5 Copy-initialization of class by user-defined conversion")),
|
||||
where only non-explicit constructors are considered for copy-initialization[.](#1.sentence-3)
|
||||
|
||||
This restriction only
|
||||
applies if this initialization is part of the final result of overload
|
||||
resolution[.](#1.sentence-4)
|
||||
|
||||
â *end note*]
|
||||
331
cppdraft/over/match/oper.md
Normal file
331
cppdraft/over/match/oper.md
Normal file
@@ -0,0 +1,331 @@
|
||||
[over.match.oper]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#oper)
|
||||
|
||||
### 12.2.2 Candidate functions and argument lists [[over.match.funcs]](over.match.funcs#over.match.oper)
|
||||
|
||||
#### 12.2.2.3 Operators in expressions [over.match.oper]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L661)
|
||||
|
||||
If no operand of an operator in an expression has a type that is a class
|
||||
or an enumeration, the operator is assumed to be a built-in operator
|
||||
and interpreted according to [[expr.compound]](expr.compound "7.6 Compound expressions")[.](#1.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
Because.,.*,
|
||||
and:: cannot be overloaded,
|
||||
these operators are always built-in operators interpreted according to[[expr.compound]](expr.compound "7.6 Compound expressions")[.](#1.sentence-2)
|
||||
|
||||
?: cannot be overloaded, but the rules in this subclause are used to determine
|
||||
the conversions to be applied to the second and third operands when they
|
||||
have class or enumeration type ([[expr.cond]](expr.cond "7.6.16 Conditional operator"))[.](#1.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Example [1](#example-1)*: struct String { String (const String&);
|
||||
String (const char*); operator const char* ();};
|
||||
String operator + (const String&, const String&);
|
||||
|
||||
void f() {const char* p= "one" + "two"; // error: cannot add two pointers; overloaded operator+ not considered// because neither operand has class or enumeration typeint I = 1 + 1; // always evaluates to 2 even if class or enumeration types exist// that would perform the operation.} â *end example*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L697)
|
||||
|
||||
If either operand has a type that is a class or an enumeration, a
|
||||
user-defined operator function can be declared that implements
|
||||
this operator or a user-defined conversion can be necessary to
|
||||
convert the operand to a type that is appropriate for a built-in
|
||||
operator[.](#2.sentence-1)
|
||||
|
||||
In this case, overload resolution is used to determine
|
||||
which operator function or built-in operator is to be invoked to implement the
|
||||
operator[.](#2.sentence-2)
|
||||
|
||||
Therefore, the operator notation is first transformed
|
||||
to the equivalent function-call notation as summarized in
|
||||
Table [18](#tab:over.match.oper "Table 18: Relationship between operator and function call notation") (where @ denotes one of the operators covered in the specified subclause)[.](#2.sentence-3)
|
||||
|
||||
However, the operands are sequenced in the order prescribed
|
||||
for the built-in operator ([[expr.compound]](expr.compound "7.6 Compound expressions"))[.](#2.sentence-4)
|
||||
|
||||
Table [18](#tab:over.match.oper) — Relationship between operator and function call notation [[tab:over.match.oper]](./tab:over.match.oper)
|
||||
|
||||
| [ð](#tab:over.match.oper-row-1)<br>**Subclause** | **Expression** | **As member function** | **As non-member function** |
|
||||
| --- | --- | --- | --- |
|
||||
| [ð](#tab:over.match.oper-row-2)<br>[[over.unary]](over.unary "12.4.2 Unary operators") | @a | (a).operator@ ( ) | operator@(a) |
|
||||
| [ð](#tab:over.match.oper-row-3)<br>[[over.binary]](over.binary "12.4.3 Binary operators") | a@b | (a).operator@ (b) | operator@(a, b) |
|
||||
| [ð](#tab:over.match.oper-row-4)<br>[[over.assign]](over.assign "12.4.3.2 Simple assignment") | a=b | (a).operator= (b) | |
|
||||
| [ð](#tab:over.match.oper-row-5)<br>[[over.sub]](over.sub "12.4.5 Subscripting") | a[b] | (a).operator[](b) | |
|
||||
| [ð](#tab:over.match.oper-row-6)<br>[[over.ref]](over.ref "12.4.6 Class member access") | a-> | (a).operator->( ) | |
|
||||
| [ð](#tab:over.match.oper-row-7)<br>[[over.inc]](over.inc "12.4.7 Increment and decrement") | a@ | (a).operator@ (0) | operator@(a, 0) |
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L725)
|
||||
|
||||
For a unary operator @ with an operand of type *cv1* T1,
|
||||
and for a binary operator @ with a left operand of type *cv1* T1 and a right operand of type *cv2* T2,
|
||||
four sets of candidate functions, designated[*member candidates*](#def:member_candidate "12.2.2.3 Operators in expressions [over.match.oper]"),[*non-member candidates*](#def:non-member_candidate "12.2.2.3 Operators in expressions [over.match.oper]"),[*built-in candidates*](#def:built-in_candidate "12.2.2.3 Operators in expressions [over.match.oper]"),
|
||||
and[*rewritten candidates*](#def:rewritten_candidate "12.2.2.3 Operators in expressions [over.match.oper]"),
|
||||
are constructed as follows:
|
||||
|
||||
- [(3.1)](#3.1)
|
||||
|
||||
If T1 is a complete class type or a class currently being defined,
|
||||
the set of member candidates is the result of a search foroperator@ in the scope of T1;
|
||||
otherwise, the set of member candidates is empty[.](#3.1.sentence-1)
|
||||
|
||||
- [(3.2)](#3.2)
|
||||
|
||||
For the operators =, [], or ->,
|
||||
the set of non-member candidates is empty;
|
||||
otherwise, it includes the result of unqualified lookup foroperator@ in the rewritten function call ([[basic.lookup.unqual]](basic.lookup.unqual "6.5.3 Unqualified name lookup"), [[basic.lookup.argdep]](basic.lookup.argdep "6.5.4 Argument-dependent name lookup")),
|
||||
ignoring all member functions[.](#3.2.sentence-1)
|
||||
However, if no operand has a class type, only those non-member
|
||||
functions in the lookup set that have a first parameter of typeT1 or âreference to cv T1â,
|
||||
whenT1 is an enumeration type,
|
||||
or (if there is a right operand) a second parameter of typeT2 or âreference to cv T2â,
|
||||
whenT2 is an enumeration type,
|
||||
are candidate functions[.](#3.2.sentence-2)
|
||||
|
||||
- [(3.3)](#3.3)
|
||||
|
||||
For the operator,,
|
||||
the unary operator&,
|
||||
or the operator->,
|
||||
the built-in candidates set is empty[.](#3.3.sentence-1)
|
||||
For all other operators, the built-in candidates include all
|
||||
of the candidate operator functions defined in [[over.built]](over.built "12.5 Built-in operators") that,
|
||||
compared to the given operator,
|
||||
* [(3.3.1)](#3.3.1)
|
||||
|
||||
have the same operator name, and
|
||||
|
||||
* [(3.3.2)](#3.3.2)
|
||||
|
||||
accept the same number of operands, and
|
||||
|
||||
* [(3.3.3)](#3.3.3)
|
||||
|
||||
accept operand types to which the given operand or
|
||||
operands can be converted according to [[over.best.ics]](over.best.ics "12.2.4.2 Implicit conversion sequences"), and
|
||||
|
||||
* [(3.3.4)](#3.3.4)
|
||||
|
||||
do not have the same parameter-type-list as any non-member candidate
|
||||
or rewritten non-member candidate
|
||||
that is not a function template specialization[.](#3.3.sentence-2)
|
||||
|
||||
- [(3.4)](#3.4)
|
||||
|
||||
The rewritten candidate set is determined as follows:
|
||||
* [(3.4.1)](#3.4.1)
|
||||
|
||||
For the relational ([[expr.rel]](expr.rel "7.6.9 Relational operators")) operators,
|
||||
the rewritten candidates include
|
||||
all non-rewritten candidates
|
||||
for the expression x <=> y[.](#3.4.1.sentence-1)
|
||||
|
||||
* [(3.4.2)](#3.4.2)
|
||||
|
||||
For the
|
||||
relational ([[expr.rel]](expr.rel "7.6.9 Relational operators")) and
|
||||
three-way comparison ([[expr.spaceship]](expr.spaceship "7.6.8 Three-way comparison operator"))
|
||||
operators,
|
||||
the rewritten candidates also include
|
||||
a synthesized candidate,
|
||||
with the order of the two parameters reversed,
|
||||
for each non-rewritten candidate
|
||||
for the expressiony <=> x[.](#3.4.2.sentence-1)
|
||||
|
||||
* [(3.4.3)](#3.4.3)
|
||||
|
||||
For the != operator ([[expr.eq]](expr.eq "7.6.10 Equality operators")),
|
||||
the rewritten candidates
|
||||
include all non-rewritten candidates
|
||||
for the expression x == y that are rewrite targets with first operand x (see below)[.](#3.4.3.sentence-1)
|
||||
|
||||
* [(3.4.4)](#3.4.4)
|
||||
|
||||
For the equality operators,
|
||||
the rewritten candidates also include a synthesized candidate,
|
||||
with the order of the two parameters reversed,
|
||||
for each non-rewritten candidate
|
||||
for the expression y == x that is a rewrite target with first operand y[.](#3.4.4.sentence-1)
|
||||
|
||||
* [(3.4.5)](#3.4.5)
|
||||
|
||||
For all other operators, the rewritten candidate set is empty[.](#3.4.5.sentence-1)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
A candidate synthesized from a member candidate has its
|
||||
object parameter as the second parameter, thus implicit conversions
|
||||
are considered for the first, but not for the second, parameter[.](#3.4.sentence-2)
|
||||
â *end note*]
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L832)
|
||||
|
||||
A non-template function or function template F named operator== is a rewrite target with first operand o unless a search for the name operator!= in the scope S from the instantiation context of the operator expression
|
||||
finds a function or function template
|
||||
that would correspond ([[basic.scope.scope]](basic.scope.scope "6.4.1 General")) to F if its name were operator==,
|
||||
where S is the scope of the class type of o if F is a class member, and
|
||||
the namespace scope of which F is a member otherwise[.](#4.sentence-1)
|
||||
|
||||
A function template specialization named operator== is a rewrite target
|
||||
if its function template is a rewrite target[.](#4.sentence-2)
|
||||
|
||||
[*Example [2](#example-2)*: struct A {};template<typename T> bool operator==(A, T); // #1bool a1 = 0 == A(); // OK, calls reversed #1template<typename T> bool operator!=(A, T);bool a2 = 0 == A(); // error, #1 is not a rewrite targetstruct B {bool operator==(const B&); // #2};struct C : B { C();
|
||||
C(B); bool operator!=(const B&); // #3};bool c1 = B() == C(); // OK, calls #2; reversed #2 is not a candidate// because search for operator!= in C finds #3bool c2 = C() == B(); // error: ambiguous between #2 found when searching C and// reversed #2 found when searching Bstruct D {};template<typename T> bool operator==(D, T); // #4inline namespace N {template<typename T> bool operator!=(D, T); // #5}bool d1 = 0 == D(); // OK, calls reversed #4; #5 does not forbid #4 as a rewrite target â *end example*]
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L875)
|
||||
|
||||
For the first parameter of the built-in assignment operators,
|
||||
only standard conversion sequences ([[over.ics.scs]](over.ics.scs "12.2.4.2.2 Standard conversion sequences")) are considered[.](#5.sentence-1)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L879)
|
||||
|
||||
For all other operators, no such restrictions apply[.](#6.sentence-1)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L882)
|
||||
|
||||
The set of candidate functions for overload resolution
|
||||
for some operator @ is the
|
||||
union of
|
||||
the member candidates,
|
||||
the non-member candidates,
|
||||
the built-in candidates,
|
||||
and the rewritten candidates
|
||||
for that operator @[.](#7.sentence-1)
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L893)
|
||||
|
||||
The argument list contains all of the
|
||||
operands of the operator[.](#8.sentence-1)
|
||||
|
||||
The best function from the set of candidate functions is selected
|
||||
according to [[over.match.viable]](over.match.viable "12.2.3 Viable functions") and [[over.match.best]](over.match.best "12.2.4 Best viable function")[.](#8.sentence-2)[103](#footnote-103 "If the set of candidate functions is empty, overload resolution is unsuccessful.")
|
||||
|
||||
[*Example [3](#example-3)*: struct A {operator int();};
|
||||
A operator+(const A&, const A&);void m() { A a, b;
|
||||
a + b; // operator+(a, b) chosen over int(a) + int(b)} â *end example*]
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L916)
|
||||
|
||||
If a rewritten operator<=> candidate
|
||||
is selected by overload resolution
|
||||
for an operator @,x @ y is interpreted as0 @ (y <=> x) if the selected candidate is a synthesized candidate
|
||||
with reversed order of parameters,
|
||||
or (x <=> y) @ 0 otherwise,
|
||||
using the selected rewritten operator<=> candidate[.](#9.sentence-1)
|
||||
|
||||
Rewritten candidates for the operator @ are not considered in the context of the resulting expression[.](#9.sentence-2)
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L930)
|
||||
|
||||
If a rewritten operator== candidate
|
||||
is selected by overload resolution
|
||||
for an operator @,
|
||||
its return type shall be cv bool, andx @ y is interpreted as:
|
||||
|
||||
- [(10.1)](#10.1)
|
||||
|
||||
if @ is != and the selected candidate is a synthesized candidate
|
||||
with reversed order of parameters,!(y == x),
|
||||
|
||||
- [(10.2)](#10.2)
|
||||
|
||||
otherwise, if @ is !=,!(x == y),
|
||||
|
||||
- [(10.3)](#10.3)
|
||||
|
||||
otherwise (when @ is ==),y == x,
|
||||
|
||||
in each case using the selected rewritten operator== candidate[.](#10.sentence-1)
|
||||
|
||||
[11](#11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L951)
|
||||
|
||||
If a built-in candidate is selected by overload resolution, the
|
||||
operands of class type are converted to the types of the corresponding parameters
|
||||
of the selected operation function, except that the second standard conversion
|
||||
sequence of a [user-defined conversion sequence](over.ics.user "12.2.4.2.3 User-defined conversion sequences [over.ics.user]") is not applied[.](#11.sentence-1)
|
||||
|
||||
Then the operator is treated as the corresponding
|
||||
built-in operator and interpreted according to [[expr.compound]](expr.compound "7.6 Compound expressions")[.](#11.sentence-2)
|
||||
|
||||
[*Example [4](#example-4)*: struct X {operator double();};
|
||||
|
||||
struct Y {operator int*();};
|
||||
|
||||
int *a = Y() + 100.0; // error: pointer arithmetic requires integral operandint *b = Y() + X(); // error: pointer arithmetic requires integral operand â *end example*]
|
||||
|
||||
[12](#12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L973)
|
||||
|
||||
The second operand of operator-> is ignored in selecting anoperator-> function, and is not an argument when theoperator-> function is called[.](#12.sentence-1)
|
||||
|
||||
Whenoperator-> returns, the operator-> is applied to the value returned, with the original second
|
||||
operand[.](#12.sentence-2)[104](#footnote-104 "If the value returned by the operator-> function has class type, this can result in selecting and calling another operator-> function. The process repeats until an operator-> function returns a value of non-class type.")
|
||||
|
||||
[13](#13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L998)
|
||||
|
||||
If the operator is the operator,,
|
||||
the unary operator&,
|
||||
or the operator->,
|
||||
and there are no viable functions, then the operator is
|
||||
assumed to be the built-in operator and interpreted according to[[expr.compound]](expr.compound "7.6 Compound expressions")[.](#13.sentence-1)
|
||||
|
||||
[14](#14)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1009)
|
||||
|
||||
[*Note [3](#note-3)*:
|
||||
|
||||
The lookup rules for operators in expressions are different than
|
||||
the lookup
|
||||
rules for operator function names in a function call, as shown in the following
|
||||
example:struct A { };void operator + (A, A);
|
||||
|
||||
struct B {void operator + (B); void f ();};
|
||||
|
||||
A a;
|
||||
|
||||
void B::f() {operator+ (a,a); // error: global operator hidden by member a + a; // OK, calls global operator+}
|
||||
|
||||
â *end note*]
|
||||
|
||||
[103)](#footnote-103)[103)](#footnoteref-103)
|
||||
|
||||
If the set of candidate functions is empty,
|
||||
overload resolution is unsuccessful[.](#footnote-103.sentence-1)
|
||||
|
||||
[104)](#footnote-104)[104)](#footnoteref-104)
|
||||
|
||||
If the value returned by theoperator-> function has class type, this can result in selecting and calling anotheroperator-> function[.](#footnote-104.sentence-1)
|
||||
|
||||
The process repeats until anoperator-> function returns a value of non-class type[.](#footnote-104.sentence-2)
|
||||
59
cppdraft/over/match/ref.md
Normal file
59
cppdraft/over/match/ref.md
Normal file
@@ -0,0 +1,59 @@
|
||||
[over.match.ref]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#ref)
|
||||
|
||||
### 12.2.2 Candidate functions and argument lists [[over.match.funcs]](over.match.funcs#over.match.ref)
|
||||
|
||||
#### 12.2.2.7 Initialization by conversion function for direct reference binding [over.match.ref]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1143)
|
||||
|
||||
Under the conditions specified in [[dcl.init.ref]](dcl.init.ref "9.5.4 References"), a reference can be bound directly
|
||||
to the result of applying a conversion
|
||||
function to an initializer expression[.](#1.sentence-1)
|
||||
|
||||
Overload resolution is used to select the
|
||||
conversion function to be invoked[.](#1.sentence-2)
|
||||
|
||||
Assuming that âreference to *cv1* Tâ is the
|
||||
type of the reference being initialized,
|
||||
the candidate functions are selected as follows:
|
||||
|
||||
- [(1.1)](#1.1)
|
||||
|
||||
Let R be a set of types including
|
||||
* [(1.1.1)](#1.1.1)
|
||||
|
||||
âlvalue reference to *cv2* T2â
|
||||
(when converting to an lvalue) and
|
||||
|
||||
* [(1.1.2)](#1.1.2)
|
||||
|
||||
â*cv2* T2â
|
||||
and ârvalue reference to *cv2* T2â
|
||||
(when converting to an rvalue or an lvalue of function type)
|
||||
|
||||
for any T2[.](#1.sentence-3)
|
||||
The permissible types for non-explicit conversion functions are
|
||||
the members of R where â*cv1* Tâ is reference-compatible ([[dcl.init.ref]](dcl.init.ref "9.5.4 References"))
|
||||
with â*cv2* T2â[.](#1.1.sentence-2)
|
||||
For direct-initialization, the permissible types for explicit
|
||||
conversion functions are the members of R where T2 can be converted to type T with a (possibly trivial) qualification conversion ([[conv.qual]](conv.qual "7.3.6 Qualification conversions"));
|
||||
otherwise there are none[.](#1.1.sentence-3)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1176)
|
||||
|
||||
The argument list has one argument, which is the initializer expression[.](#2.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
This argument will be compared against
|
||||
the object parameter of the conversion functions[.](#2.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
107
cppdraft/over/match/viable.md
Normal file
107
cppdraft/over/match/viable.md
Normal file
@@ -0,0 +1,107 @@
|
||||
[over.match.viable]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.2 Overload resolution [[over.match]](over.match#viable)
|
||||
|
||||
### 12.2.3 Viable functions [over.match.viable]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1683)
|
||||
|
||||
From the set of candidate functions constructed for a given
|
||||
context ([[over.match.funcs]](over.match.funcs "12.2.2 Candidate functions and argument lists")), a set of viable functions is
|
||||
chosen, from which the best function will be selected by
|
||||
comparing argument conversion sequences
|
||||
and associated constraints ([[temp.constr.decl]](temp.constr.decl "13.5.3 Constrained declarations"))
|
||||
for the best fit ([[over.match.best]](over.match.best "12.2.4 Best viable function"))[.](#1.sentence-1)
|
||||
|
||||
The selection of viable functions considers
|
||||
associated constraints, if any, and
|
||||
relationships between arguments and function parameters other
|
||||
than the ranking of conversion sequences[.](#1.sentence-2)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1695)
|
||||
|
||||
First, to be a viable function, a candidate function shall have
|
||||
enough parameters to agree in number with the arguments in the
|
||||
list[.](#2.sentence-1)
|
||||
|
||||
- [(2.1)](#2.1)
|
||||
|
||||
If there are m arguments in the list,
|
||||
all candidate functions having exactly m parameters are viable[.](#2.1.sentence-1)
|
||||
|
||||
- [(2.2)](#2.2)
|
||||
|
||||
A candidate function having fewer than m parameters is viable
|
||||
only if it has an ellipsis in its parameter list ([[dcl.fct]](dcl.fct "9.3.4.6 Functions"))[.](#2.2.sentence-1)
|
||||
For the purposes of overload resolution,
|
||||
any argument for which there is no corresponding parameter is
|
||||
considered to âmatch the ellipsisâ ([[over.ics.ellipsis]](over.ics.ellipsis "12.2.4.2.4 Ellipsis conversion sequences"))[.](#2.2.sentence-2)
|
||||
|
||||
- [(2.3)](#2.3)
|
||||
|
||||
A candidate function C having more than m parameters is viable
|
||||
only if the set of scopes G, as defined below, is not empty[.](#2.3.sentence-1)
|
||||
G consists of every scope X that satisfies all of the following:
|
||||
* [(2.3.1)](#2.3.1)
|
||||
|
||||
There is a declaration of C, whose host scope is X,
|
||||
considered by the overload resolution[.](#2.3.1.sentence-1)
|
||||
|
||||
* [(2.3.2)](#2.3.2)
|
||||
|
||||
For every kth parameter P where k > m,
|
||||
there is a reachable declaration, whose host scope is X,
|
||||
that specifies a default argument ([[dcl.fct.default]](dcl.fct.default "9.3.4.7 Default arguments")) for P[.](#2.3.2.sentence-1)
|
||||
|
||||
If C is selected as the best viable function ([[over.match.best]](over.match.best "12.2.4 Best viable function")):
|
||||
* [(2.3.3)](#2.3.3)
|
||||
|
||||
G shall contain exactly one scope (call it S)[.](#2.3.3.sentence-1)
|
||||
|
||||
* [(2.3.4)](#2.3.4)
|
||||
|
||||
If the candidates are denoted by a [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]"),
|
||||
then S shall not be a block scope[.](#2.3.4.sentence-1)
|
||||
|
||||
* [(2.3.5)](#2.3.5)
|
||||
|
||||
The default arguments used in the call to C are
|
||||
the default arguments specified by
|
||||
the reachable declarations whose host scope is S[.](#2.3.5.sentence-1)
|
||||
|
||||
For the purposes of overload resolution,
|
||||
the parameter list is truncated on the right,
|
||||
so that there are exactly m parameters[.](#2.3.sentence-4)
|
||||
|
||||
[*Example [1](#example-1)*: namespace A {extern "C" void f(int, int = 5); extern "C" void f(int = 6, int);}namespace B {extern "C" void f(int, int = 7);}void use() {[:^^A::f:](3, 4); // OK, default argument was not used for viability[:^^A::f:](3); // error: default argument provided by declarations from two scopes[:^^A::f:](); // OK, default arguments provided by declarations in the scope of Ausing A::f; using B::f;
|
||||
f(3, 4); // OK, default argument was not used for viability f(3); // error: default argument provided by declaration from two scopes f(); // OK, default arguments provided by declarations in the scope of Avoid g(int = 8);
|
||||
g(); // OK[:^^g:](); // error: host scope is block scope}void h(int = 7);constexpr std::meta::info r = ^^h;void poison() {void h(int = 8);
|
||||
h(); // OK, calls h(8)[:^^h:](); // error: default argument provided by declarations from two scopes}void call_h() {[:^^h:](); // error: default argument provided by declarations from two scopes[:r:](); // error: default argument provided by declarations from two scopes}template<typename... Ts>int k(int = 3, Ts...);int i = k<int>(); // error: no default argument for the second parameterint j = k<>(); // OK â *end example*]
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1784)
|
||||
|
||||
Second, for a function to be viable, if it has associated constraints ([[temp.constr.decl]](temp.constr.decl "13.5.3 Constrained declarations")),
|
||||
those constraints shall be satisfied ([[temp.constr.constr]](temp.constr.constr "13.5.2 Constraints"))[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L1788)
|
||||
|
||||
Third, forF to be a viable function, there shall exist for each
|
||||
argument an[implicit conversion sequence](over.best.ics#def:conversion_sequence,implicit "12.2.4.2 Implicit conversion sequences [over.best.ics]") that
|
||||
converts that argument to the corresponding parameter ofF[.](#4.sentence-1)
|
||||
|
||||
If the parameter has reference type, the implicit conversion sequence
|
||||
includes the operation of binding the reference, and the fact that
|
||||
an lvalue reference to non-const cannot bind to an rvalue
|
||||
and that an rvalue reference cannot bind to an lvalue
|
||||
can affect
|
||||
the viability of the function (see [[over.ics.ref]](over.ics.ref "12.2.4.2.5 Reference binding"))[.](#4.sentence-2)
|
||||
420
cppdraft/over/oper.md
Normal file
420
cppdraft/over/oper.md
Normal file
@@ -0,0 +1,420 @@
|
||||
[over.oper]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.4 Overloaded operators [over.oper]
|
||||
|
||||
### [12.4.1](#general) General [[over.oper.general]](over.oper.general)
|
||||
|
||||
[1](#general-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3338)
|
||||
|
||||
A declaration
|
||||
whose [*declarator-id*](dcl.decl.general#nt:declarator-id "9.3.1 General [dcl.decl.general]") is an [*operator-function-id*](#nt:operator-function-id "12.4.1 General [over.oper.general]") shall declare a function or function template or
|
||||
an explicit instantiation or specialization of a function template[.](#general-1.sentence-1)
|
||||
|
||||
A function so declared is an [*operator function*](#def:function,operator "12.4.1 General [over.oper.general]")[.](#general-1.sentence-2)
|
||||
|
||||
A function template so declared is
|
||||
an [*operator function template*](#def:function,operator,template "12.4.1 General [over.oper.general]")[.](#general-1.sentence-3)
|
||||
|
||||
A specialization of an operator function template is also an operator function[.](#general-1.sentence-4)
|
||||
|
||||
An operator function is said to[*implement*](#def:operator,implementation "12.4.1 General [over.oper.general]") the operator named in its[*operator-function-id*](#nt:operator-function-id "12.4.1 General [over.oper.general]")[.](#general-1.sentence-5)
|
||||
|
||||
[operator-function-id:](#nt:operator-function-id "12.4.1 General [over.oper.general]")
|
||||
operator [*operator*](#nt:operator "12.4.1 General [over.oper.general]")
|
||||
|
||||
[operator:](#nt:operator "12.4.1 General [over.oper.general]") one of
|
||||
new delete new[] delete[] co_await ( ) [ ] -> ->*
|
||||
~ ! + - * / % ^ &
|
||||
| = += -= *= /= %= ^= &=
|
||||
|= == != < > <= >= <=> &&
|
||||
|| << >> <<= >>= ++ -- ,
|
||||
|
||||
[*Note [1](#general-note-1)*:
|
||||
|
||||
The operatorsnew[],delete[],(),
|
||||
and[] are formed from more than one token[.](#general-1.sentence-6)
|
||||
|
||||
The latter two operators are [function call](expr.call "7.6.1.3 Function call [expr.call]") and [subscripting](expr.sub "7.6.1.2 Subscripting [expr.sub]")[.](#general-1.sentence-7)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#general-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3382)
|
||||
|
||||
Both the unary and binary forms of
|
||||
|
||||
+ - * &
|
||||
|
||||
can be overloaded[.](#general-2.sentence-1)
|
||||
|
||||
[3](#general-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3389)
|
||||
|
||||
[*Note [2](#general-note-2)*:
|
||||
|
||||
The following operators cannot be overloaded:
|
||||
|
||||
. .* :: ?:
|
||||
|
||||
nor can the preprocessing symbols# ([[cpp.stringize]](cpp.stringize "15.7.3 The # operator"))
|
||||
and## ([[cpp.concat]](cpp.concat "15.7.4 The ## operator"))[.](#general-3.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[4](#general-4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3402)
|
||||
|
||||
Operator functions are usually not called directly; instead they are invoked
|
||||
to evaluate the operators they implement ([[over.unary]](#over.unary "12.4.2 Unary operators") â [[over.inc]](#over.inc "12.4.7 Increment and decrement"))[.](#general-4.sentence-1)
|
||||
|
||||
They can be explicitly called, however, using the[*operator-function-id*](#nt:operator-function-id "12.4.1 General [over.oper.general]") as the name of the function in the function call syntax ([[expr.call]](expr.call "7.6.1.3 Function call"))[.](#general-4.sentence-2)
|
||||
|
||||
[*Example [1](#general-example-1)*: complex z = a.operator+(b); // complex z = a+b;void* p = operator new(sizeof(int)*n); â *end example*]
|
||||
|
||||
[5](#general-5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3416)
|
||||
|
||||
The allocation and deallocation functions,operator new,operator new[],operator delete, andoperator delete[],
|
||||
are described completely in [[basic.stc.dynamic]](basic.stc.dynamic "6.8.6.5 Dynamic storage duration")[.](#general-5.sentence-1)
|
||||
|
||||
The attributes and restrictions
|
||||
found in the rest of [over.oper] do not apply to them unless explicitly
|
||||
stated in [[basic.stc.dynamic]](basic.stc.dynamic "6.8.6.5 Dynamic storage duration")[.](#general-5.sentence-2)
|
||||
|
||||
[6](#general-6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3427)
|
||||
|
||||
The co_await operator is described completely in [[expr.await]](expr.await "7.6.2.4 Await")[.](#general-6.sentence-1)
|
||||
|
||||
The attributes and restrictions
|
||||
found in the rest of [over.oper] do not apply to it unless explicitly
|
||||
stated in [[expr.await]](expr.await "7.6.2.4 Await")[.](#general-6.sentence-2)
|
||||
|
||||
[7](#general-7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3433)
|
||||
|
||||
An operator function
|
||||
shall have at least one
|
||||
function parameter or implicit object parameter whose type is
|
||||
a class, a reference to a class, an
|
||||
enumeration, or a reference to an enumeration[.](#general-7.sentence-1)
|
||||
|
||||
It is not possible to change the precedence, grouping, or number of operands
|
||||
of operators[.](#general-7.sentence-2)
|
||||
|
||||
The meaning of
|
||||
the operators =, (unary) &, and , (comma),
|
||||
predefined for each type, can be changed for specific class types by
|
||||
defining operator functions that implement these operators[.](#general-7.sentence-3)
|
||||
|
||||
Likewise, the meaning of the operators (unary) & and , (comma)
|
||||
can be changed for specific enumeration types[.](#general-7.sentence-4)
|
||||
|
||||
Operator functions are inherited in the same manner as other base class
|
||||
functions[.](#general-7.sentence-5)
|
||||
|
||||
[8](#general-8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3452)
|
||||
|
||||
An operator function shall be a
|
||||
prefix unary, binary, function call, subscripting, class member access, increment, or decrement
|
||||
operator function[.](#general-8.sentence-1)
|
||||
|
||||
[9](#general-9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3457)
|
||||
|
||||
[*Note [3](#general-note-3)*:
|
||||
|
||||
The identities among certain predefined operators applied to fundamental types
|
||||
(for example,++a ≡a+=1)
|
||||
need not hold for operator functions[.](#general-9.sentence-1)
|
||||
|
||||
Some predefined operators, such as+=,
|
||||
require an operand to be an lvalue when applied to fundamental types;
|
||||
this is not required by operator functions[.](#general-9.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[10](#general-10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3471)
|
||||
|
||||
An operator function cannot have [default arguments](dcl.fct.default "9.3.4.7 Default arguments [dcl.fct.default]"),
|
||||
except where explicitly stated below[.](#general-10.sentence-1)
|
||||
|
||||
Operator
|
||||
functions cannot have more or fewer parameters than the
|
||||
number required for the corresponding operator, as
|
||||
described in the rest of [over.oper][.](#general-10.sentence-2)
|
||||
|
||||
[11](#general-11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3480)
|
||||
|
||||
Operators not mentioned explicitly in subclauses [[over.assign]](#over.assign "12.4.3.2 Simple assignment") through [[over.inc]](#over.inc "12.4.7 Increment and decrement") act as ordinary unary and binary
|
||||
operators obeying the rules of [[over.unary]](#over.unary "12.4.2 Unary operators") or [[over.binary]](#over.binary "12.4.3 Binary operators")[.](#general-11.sentence-1)
|
||||
|
||||
### [12.4.2](#over.unary) Unary operators [[over.unary]](over.unary)
|
||||
|
||||
[1](#over.unary-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3491)
|
||||
|
||||
A [*prefix unary operator function*](#def:operator_function,prefix_unary "12.4.2 Unary operators [over.unary]") is a function named operator@ for a prefix [*unary-operator*](expr.unary.general#nt:unary-operator "7.6.2.1 General [expr.unary.general]") @ ([[expr.unary.op]](expr.unary.op "7.6.2.2 Unary operators"))
|
||||
that is either
|
||||
a non-static member function ([[class.mfct]](class.mfct "11.4.2 Member functions")) with no non-object parameters or
|
||||
a non-member function with one parameter[.](#over.unary-1.sentence-1)
|
||||
|
||||
For a [*unary-expression*](expr.unary.general#nt:unary-expression "7.6.2.1 General [expr.unary.general]") of the form @ [*cast-expression*](expr.cast#nt:cast-expression "7.6.3 Explicit type conversion (cast notation) [expr.cast]"),
|
||||
the operator function is selected by overload resolution ([[over.match.oper]](over.match.oper "12.2.2.3 Operators in expressions"))[.](#over.unary-1.sentence-2)
|
||||
|
||||
If a member function is selected,
|
||||
the expression is interpreted as
|
||||
|
||||
[*cast-expression*](expr.cast#nt:cast-expression "7.6.3 Explicit type conversion (cast notation) [expr.cast]") . operator @ ()
|
||||
|
||||
Otherwise, if a non-member function is selected,
|
||||
the expression is interpreted as
|
||||
|
||||
operator @ ( [*cast-expression*](expr.cast#nt:cast-expression "7.6.3 Explicit type conversion (cast notation) [expr.cast]") )
|
||||
|
||||
[*Note [1](#over.unary-note-1)*:
|
||||
|
||||
The operators ++ and -- ([[expr.pre.incr]](expr.pre.incr "7.6.2.3 Increment and decrement"))
|
||||
are described in [[over.inc]](#over.inc "12.4.7 Increment and decrement")[.](#over.unary-1.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#over.unary-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3517)
|
||||
|
||||
[*Note [2](#over.unary-note-2)*:
|
||||
|
||||
The unary and binary forms of the same operator have the same name[.](#over.unary-2.sentence-1)
|
||||
|
||||
Consequently, a unary operator can hide a binary
|
||||
operator from an enclosing scope, and vice versa[.](#over.unary-2.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
### [12.4.3](#over.binary) Binary operators [[over.binary]](over.binary)
|
||||
|
||||
#### [12.4.3.1](#over.binary.general) General [[over.binary.general]](over.binary.general)
|
||||
|
||||
[1](#over.binary.general-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3530)
|
||||
|
||||
A [*binary operator function*](#def:operator_function,binary "12.4.3.1 General [over.binary.general]") is a function named operator@ for a binary operator @ that is either
|
||||
a non-static member function ([[class.mfct]](class.mfct "11.4.2 Member functions")) with one non-object parameter or
|
||||
a non-member function with two parameters[.](#over.binary.general-1.sentence-1)
|
||||
|
||||
For an expression x @ y with subexpressions x and y,
|
||||
the operator function is selected by overload resolution ([[over.match.oper]](over.match.oper "12.2.2.3 Operators in expressions"))[.](#over.binary.general-1.sentence-2)
|
||||
|
||||
If a member function is selected,
|
||||
the expression is interpreted as
|
||||
|
||||
x . operator @ ( y )
|
||||
|
||||
Otherwise, if a non-member function is selected,
|
||||
the expression is interpreted as
|
||||
|
||||
operator @ ( x , y )
|
||||
|
||||
[2](#over.binary.general-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3550)
|
||||
|
||||
An [*equality operator function*](#def:operator_function,equality "12.4.3.1 General [over.binary.general]") is an operator function
|
||||
for an equality operator ([[expr.eq]](expr.eq "7.6.10 Equality operators"))[.](#over.binary.general-2.sentence-1)
|
||||
|
||||
A [*relational operator function*](#def:operator_function,relational "12.4.3.1 General [over.binary.general]") is an operator function
|
||||
for a relational operator ([[expr.rel]](expr.rel "7.6.9 Relational operators"))[.](#over.binary.general-2.sentence-2)
|
||||
|
||||
A [*three-way comparison operator function*](#def:operator_function,three-way_comparison "12.4.3.1 General [over.binary.general]") is an operator function
|
||||
for the three-way comparison operator ([[expr.spaceship]](expr.spaceship "7.6.8 Three-way comparison operator"))[.](#over.binary.general-2.sentence-3)
|
||||
|
||||
A [*comparison operator function*](#def:operator_function,comparison "12.4.3.1 General [over.binary.general]") is
|
||||
an equality operator function,
|
||||
a relational operator function, or
|
||||
a three-way comparison operator function[.](#over.binary.general-2.sentence-4)
|
||||
|
||||
#### [12.4.3.2](#over.assign) Simple assignment [[over.assign]](over.assign)
|
||||
|
||||
[1](#over.assign-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3566)
|
||||
|
||||
A [*simple assignment operator function*](#def:operator_function,simple_assignment "12.4.3.2 Simple assignment [over.assign]") is a binary operator function named operator=[.](#over.assign-1.sentence-1)
|
||||
|
||||
A simple assignment operator function shall be a non-static member function[.](#over.assign-1.sentence-2)
|
||||
|
||||
[*Note [1](#over.assign-note-1)*:
|
||||
|
||||
Because only standard conversion sequences are considered when converting
|
||||
to the left operand of an assignment operation ([[over.best.ics]](over.best.ics "12.2.4.2 Implicit conversion sequences")),
|
||||
an expression x = y with a subexpression x of class type
|
||||
is always interpreted as x.operator=(y)[.](#over.assign-1.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#over.assign-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3577)
|
||||
|
||||
[*Note [2](#over.assign-note-2)*:
|
||||
|
||||
Since a copy assignment operator is implicitly declared for a class
|
||||
if not declared by the user ([[class.copy.assign]](class.copy.assign "11.4.6 Copy/move assignment operator")),
|
||||
a base class assignment operator function is always hidden by
|
||||
the copy assignment operator function of the derived class[.](#over.assign-2.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[3](#over.assign-3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3585)
|
||||
|
||||
[*Note [3](#over.assign-note-3)*:
|
||||
|
||||
Any assignment operator function, even the copy and move assignment operators,
|
||||
can be virtual[.](#over.assign-3.sentence-1)
|
||||
|
||||
For a derived class D with a base class B for which a virtual copy/move assignment has been declared,
|
||||
the copy/move assignment operator in D does not overrideB's virtual copy/move assignment operator[.](#over.assign-3.sentence-2)
|
||||
|
||||
[*Example [1](#over.assign-example-1)*: struct B {virtual int operator= (int); virtual B& operator= (const B&);};struct D : B {virtual int operator= (int); virtual D& operator= (const B&);};
|
||||
|
||||
D dobj1;
|
||||
D dobj2;
|
||||
B* bptr = &dobj1;void f() { bptr->operator=(99); // calls D::operator=(int)*bptr = 99; // ditto bptr->operator=(dobj2); // calls D::operator=(const B&)*bptr = dobj2; // ditto dobj1 = dobj2; // calls implicitly-declared D::operator=(const D&)} â *end example*]
|
||||
|
||||
â *end note*]
|
||||
|
||||
### [12.4.4](#over.call) Function call [[over.call]](over.call)
|
||||
|
||||
[1](#over.call-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3622)
|
||||
|
||||
A [*function call operator function*](#def:operator_function,function_call "12.4.4 Function call [over.call]") is a function named operator() that is a member function with an arbitrary number of parameters[.](#over.call-1.sentence-1)
|
||||
|
||||
It may have default arguments[.](#over.call-1.sentence-2)
|
||||
|
||||
For an expression of the form
|
||||
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") ( [*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]")opt )
|
||||
|
||||
where the [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") is of class type,
|
||||
the operator function
|
||||
is selected by overload resolution ([[over.call.object]](over.call.object "12.2.2.2.3 Call to object of class type"))[.](#over.call-1.sentence-3)
|
||||
|
||||
If a surrogate call function is selected,
|
||||
let e be the result of invoking the corresponding conversion operator function on the [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]");
|
||||
|
||||
the expression is interpreted as
|
||||
|
||||
e ( [*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]")opt )
|
||||
|
||||
Otherwise, the expression is interpreted as
|
||||
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") . operator () ( [*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]")opt )
|
||||
|
||||
### [12.4.5](#over.sub) Subscripting [[over.sub]](over.sub)
|
||||
|
||||
[1](#over.sub-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3650)
|
||||
|
||||
A [*subscripting operator function*](#def:operator_function,subscripting "12.4.5 Subscripting [over.sub]") is a member function named operator[] with an arbitrary number of parameters[.](#over.sub-1.sentence-1)
|
||||
|
||||
It may have default arguments[.](#over.sub-1.sentence-2)
|
||||
|
||||
For an expression of the form
|
||||
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") [ [*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]")opt ]
|
||||
|
||||
the operator function
|
||||
is selected by overload resolution ([[over.match.oper]](over.match.oper "12.2.2.3 Operators in expressions"))[.](#over.sub-1.sentence-3)
|
||||
|
||||
If a member function is selected,
|
||||
the expression is interpreted as
|
||||
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") . operator [] ( [*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]")opt )
|
||||
|
||||
[2](#over.sub-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3667)
|
||||
|
||||
[*Example [1](#over.sub-example-1)*: struct X { Z operator[](std::initializer_list<int>);
|
||||
Z operator[](auto...);};
|
||||
X x;
|
||||
x[{1,2,3}] = 7; // OK, meaning x.operator[]({1,2,3}) x[1,2,3] = 7; // OK, meaning x.operator[](1,2,3)int a[10];
|
||||
a[{1,2,3}] = 7; // error: built-in subscript operator a[1,2,3] = 7; // error: built-in subscript operator â *end example*]
|
||||
|
||||
### [12.4.6](#over.ref) Class member access [[over.ref]](over.ref)
|
||||
|
||||
[1](#over.ref-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3687)
|
||||
|
||||
A [*class member access operator function*](#def:operator_function,class_member_access "12.4.6 Class member access [over.ref]") is a function named operator-> that is a non-static member function taking no non-object parameters[.](#over.ref-1.sentence-1)
|
||||
|
||||
For an expression of the form
|
||||
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") -> templateopt [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]")
|
||||
|
||||
the operator function
|
||||
is selected by overload resolution ([[over.match.oper]](over.match.oper "12.2.2.3 Operators in expressions")),
|
||||
and the expression is interpreted as
|
||||
|
||||
( [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") . operator -> () ) -> templateopt [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]")
|
||||
|
||||
### [12.4.7](#over.inc) Increment and decrement [[over.inc]](over.inc)
|
||||
|
||||
[1](#over.inc-1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3708)
|
||||
|
||||
An [*increment operator function*](#def:operator_function,increment "12.4.7 Increment and decrement [over.inc]") is a function named operator++[.](#over.inc-1.sentence-1)
|
||||
|
||||
If this function is a non-static member function with no non-object parameters, or a non-member
|
||||
function with one parameter,
|
||||
it defines the prefix increment operator++ for objects of that type[.](#over.inc-1.sentence-2)
|
||||
|
||||
If the function is a non-static member function with one non-object parameter (which shall be of typeint)
|
||||
or a non-member function with two parameters (the second of which shall be of typeint),
|
||||
it defines the postfix increment operator++ for objects of that type[.](#over.inc-1.sentence-3)
|
||||
|
||||
When the postfix increment is called as a result of using the++ operator, theint argument will have value zero[.](#over.inc-1.sentence-4)[107](#footnote-107 "Calling operator++ explicitly, as in expressions like a.operator++(2), has no special properties: The argument to operator++ is 2.")
|
||||
|
||||
[*Example [1](#over.inc-example-1)*: struct X { X& operator++(); // prefix ++a X operator++(int); // postfix a++};
|
||||
|
||||
struct Y { };
|
||||
Y& operator++(Y&); // prefix ++b Y operator++(Y&, int); // postfix b++void f(X a, Y b) {++a; // a.operator++(); a++; // a.operator++(0);++b; // operator++(b); b++; // operator++(b, 0); a.operator++(); // explicit call: like ++a; a.operator++(0); // explicit call: like a++;operator++(b); // explicit call: like ++b;operator++(b, 0); // explicit call: like b++;} â *end example*]
|
||||
|
||||
[2](#over.inc-2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3765)
|
||||
|
||||
A [*decrement operator function*](#def:operator_function,decrement "12.4.7 Increment and decrement [over.inc]") is a function named operator-- and is handled analogously to an increment operator function[.](#over.inc-2.sentence-1)
|
||||
|
||||
[107)](#footnote-107)[107)](#footnoteref-107)
|
||||
|
||||
Callingoperator++ explicitly, as in expressions likea.operator++(2),
|
||||
has no special properties:
|
||||
The argument tooperator++ is2[.](#footnote-107.sentence-1)
|
||||
167
cppdraft/over/oper/general.md
Normal file
167
cppdraft/over/oper/general.md
Normal file
@@ -0,0 +1,167 @@
|
||||
[over.oper.general]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.4 Overloaded operators [[over.oper]](over.oper#general)
|
||||
|
||||
### 12.4.1 General [over.oper.general]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3338)
|
||||
|
||||
A declaration
|
||||
whose [*declarator-id*](dcl.decl.general#nt:declarator-id "9.3.1 General [dcl.decl.general]") is an [*operator-function-id*](#nt:operator-function-id "12.4.1 General [over.oper.general]") shall declare a function or function template or
|
||||
an explicit instantiation or specialization of a function template[.](#1.sentence-1)
|
||||
|
||||
A function so declared is an [*operator function*](#def:function,operator "12.4.1 General [over.oper.general]")[.](#1.sentence-2)
|
||||
|
||||
A function template so declared is
|
||||
an [*operator function template*](#def:function,operator,template "12.4.1 General [over.oper.general]")[.](#1.sentence-3)
|
||||
|
||||
A specialization of an operator function template is also an operator function[.](#1.sentence-4)
|
||||
|
||||
An operator function is said to[*implement*](#def:operator,implementation "12.4.1 General [over.oper.general]") the operator named in its[*operator-function-id*](#nt:operator-function-id "12.4.1 General [over.oper.general]")[.](#1.sentence-5)
|
||||
|
||||
[operator-function-id:](#nt:operator-function-id "12.4.1 General [over.oper.general]")
|
||||
operator [*operator*](#nt:operator "12.4.1 General [over.oper.general]")
|
||||
|
||||
[operator:](#nt:operator "12.4.1 General [over.oper.general]") one of
|
||||
new delete new[] delete[] co_await ( ) [ ] -> ->*
|
||||
~ ! + - * / % ^ &
|
||||
| = += -= *= /= %= ^= &=
|
||||
|= == != < > <= >= <=> &&
|
||||
|| << >> <<= >>= ++ -- ,
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
The operatorsnew[],delete[],(),
|
||||
and[] are formed from more than one token[.](#1.sentence-6)
|
||||
|
||||
The latter two operators are [function call](expr.call "7.6.1.3 Function call [expr.call]") and [subscripting](expr.sub "7.6.1.2 Subscripting [expr.sub]")[.](#1.sentence-7)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3382)
|
||||
|
||||
Both the unary and binary forms of
|
||||
|
||||
+ - * &
|
||||
|
||||
can be overloaded[.](#2.sentence-1)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3389)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
The following operators cannot be overloaded:
|
||||
|
||||
. .* :: ?:
|
||||
|
||||
nor can the preprocessing symbols# ([[cpp.stringize]](cpp.stringize "15.7.3 The # operator"))
|
||||
and## ([[cpp.concat]](cpp.concat "15.7.4 The ## operator"))[.](#3.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3402)
|
||||
|
||||
Operator functions are usually not called directly; instead they are invoked
|
||||
to evaluate the operators they implement ([[over.unary]](over.unary "12.4.2 Unary operators") â [[over.inc]](over.inc "12.4.7 Increment and decrement"))[.](#4.sentence-1)
|
||||
|
||||
They can be explicitly called, however, using the[*operator-function-id*](#nt:operator-function-id "12.4.1 General [over.oper.general]") as the name of the function in the function call syntax ([[expr.call]](expr.call "7.6.1.3 Function call"))[.](#4.sentence-2)
|
||||
|
||||
[*Example [1](#example-1)*: complex z = a.operator+(b); // complex z = a+b;void* p = operator new(sizeof(int)*n); â *end example*]
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3416)
|
||||
|
||||
The allocation and deallocation functions,operator new,operator new[],operator delete, andoperator delete[],
|
||||
are described completely in [[basic.stc.dynamic]](basic.stc.dynamic "6.8.6.5 Dynamic storage duration")[.](#5.sentence-1)
|
||||
|
||||
The attributes and restrictions
|
||||
found in the rest of [[over.oper]](over.oper "12.4 Overloaded operators") do not apply to them unless explicitly
|
||||
stated in [[basic.stc.dynamic]](basic.stc.dynamic "6.8.6.5 Dynamic storage duration")[.](#5.sentence-2)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3427)
|
||||
|
||||
The co_await operator is described completely in [[expr.await]](expr.await "7.6.2.4 Await")[.](#6.sentence-1)
|
||||
|
||||
The attributes and restrictions
|
||||
found in the rest of [[over.oper]](over.oper "12.4 Overloaded operators") do not apply to it unless explicitly
|
||||
stated in [[expr.await]](expr.await "7.6.2.4 Await")[.](#6.sentence-2)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3433)
|
||||
|
||||
An operator function
|
||||
shall have at least one
|
||||
function parameter or implicit object parameter whose type is
|
||||
a class, a reference to a class, an
|
||||
enumeration, or a reference to an enumeration[.](#7.sentence-1)
|
||||
|
||||
It is not possible to change the precedence, grouping, or number of operands
|
||||
of operators[.](#7.sentence-2)
|
||||
|
||||
The meaning of
|
||||
the operators =, (unary) &, and , (comma),
|
||||
predefined for each type, can be changed for specific class types by
|
||||
defining operator functions that implement these operators[.](#7.sentence-3)
|
||||
|
||||
Likewise, the meaning of the operators (unary) & and , (comma)
|
||||
can be changed for specific enumeration types[.](#7.sentence-4)
|
||||
|
||||
Operator functions are inherited in the same manner as other base class
|
||||
functions[.](#7.sentence-5)
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3452)
|
||||
|
||||
An operator function shall be a
|
||||
prefix unary, binary, function call, subscripting, class member access, increment, or decrement
|
||||
operator function[.](#8.sentence-1)
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3457)
|
||||
|
||||
[*Note [3](#note-3)*:
|
||||
|
||||
The identities among certain predefined operators applied to fundamental types
|
||||
(for example,++a ≡a+=1)
|
||||
need not hold for operator functions[.](#9.sentence-1)
|
||||
|
||||
Some predefined operators, such as+=,
|
||||
require an operand to be an lvalue when applied to fundamental types;
|
||||
this is not required by operator functions[.](#9.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3471)
|
||||
|
||||
An operator function cannot have [default arguments](dcl.fct.default "9.3.4.7 Default arguments [dcl.fct.default]"),
|
||||
except where explicitly stated below[.](#10.sentence-1)
|
||||
|
||||
Operator
|
||||
functions cannot have more or fewer parameters than the
|
||||
number required for the corresponding operator, as
|
||||
described in the rest of [[over.oper]](over.oper "12.4 Overloaded operators")[.](#10.sentence-2)
|
||||
|
||||
[11](#11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3480)
|
||||
|
||||
Operators not mentioned explicitly in subclauses [[over.assign]](over.assign "12.4.3.2 Simple assignment") through [[over.inc]](over.inc "12.4.7 Increment and decrement") act as ordinary unary and binary
|
||||
operators obeying the rules of [[over.unary]](over.unary "12.4.2 Unary operators") or [[over.binary]](over.binary "12.4.3 Binary operators")[.](#11.sentence-1)
|
||||
178
cppdraft/over/over.md
Normal file
178
cppdraft/over/over.md
Normal file
@@ -0,0 +1,178 @@
|
||||
[over.over]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.3 Address of an overload set [over.over]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3155)
|
||||
|
||||
An expression
|
||||
that designates an overload set S and
|
||||
that appears without arguments
|
||||
is resolved to
|
||||
a function,
|
||||
a pointer to function, or
|
||||
a pointer to member function
|
||||
for a specific function
|
||||
that is chosen from a set of functions selected from S determined based on the target type required in the context (if any),
|
||||
as described below[.](#1.sentence-1)
|
||||
|
||||
The target can be
|
||||
|
||||
- [(1.1)](#1.1)
|
||||
|
||||
an object or reference being initialized ([[dcl.init]](dcl.init "9.5 Initializers"), [[dcl.init.ref]](dcl.init.ref "9.5.4 References"), [[dcl.init.list]](dcl.init.list "9.5.5 List-initialization")),
|
||||
|
||||
- [(1.2)](#1.2)
|
||||
|
||||
the left side of an assignment ([[expr.assign]](expr.assign "7.6.19 Assignment and compound assignment operators")),
|
||||
|
||||
- [(1.3)](#1.3)
|
||||
|
||||
a parameter of a function ([[expr.call]](expr.call "7.6.1.3 Function call")),
|
||||
|
||||
- [(1.4)](#1.4)
|
||||
|
||||
a parameter of a [user-defined operator](over.oper "12.4 Overloaded operators [over.oper]"),
|
||||
|
||||
- [(1.5)](#1.5)
|
||||
|
||||
the return value of a function, operator function, or conversion ([[stmt.return]](stmt.return "8.8.4 The return statement")),
|
||||
|
||||
- [(1.6)](#1.6)
|
||||
|
||||
an explicit type conversion ([[expr.type.conv]](expr.type.conv "7.6.1.4 Explicit type conversion (functional notation)"), [[expr.static.cast]](expr.static.cast "7.6.1.9 Static cast"), [[expr.cast]](expr.cast "7.6.3 Explicit type conversion (cast notation)")), or
|
||||
|
||||
- [(1.7)](#1.7)
|
||||
|
||||
a constant template parameter ([[temp.arg.nontype]](temp.arg.nontype "13.4.3 Constant template arguments"))[.](#1.sentence-2)
|
||||
|
||||
If the target type contains a placeholder type,
|
||||
placeholder type deduction is performed ([[dcl.type.auto.deduct]](dcl.type.auto.deduct "9.2.9.7.2 Placeholder type deduction")), and
|
||||
the remainder of this subclause uses the target type so deduced[.](#1.sentence-3)
|
||||
|
||||
The expression can be preceded by the & operator[.](#1.sentence-4)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
Any redundant set of parentheses surrounding the function name is
|
||||
ignored ([[expr.prim.paren]](expr.prim.paren "7.5.4 Parentheses"))[.](#1.sentence-5)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3193)
|
||||
|
||||
If there is no target, all non-template functions named are selected[.](#2.sentence-1)
|
||||
|
||||
Otherwise, a non-template function with type F is selected for the function type FT of the target type
|
||||
if F (after possibly applying the function pointer conversion ([[conv.fctptr]](conv.fctptr "7.3.14 Function pointer conversions")))
|
||||
is identical to FT[.](#2.sentence-2)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
That is, the class of which the function is a member is ignored when matching a
|
||||
pointer-to-member-function type[.](#2.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3205)
|
||||
|
||||
The specialization, if any, generated by template argument
|
||||
deduction ([[temp.over]](temp.over "13.10.4 Overload resolution"), [[temp.deduct.funcaddr]](temp.deduct.funcaddr "13.10.3.3 Deducing template arguments taking the address of a function template"), [[temp.arg.explicit]](temp.arg.explicit "13.10.2 Explicit template argument specification"))
|
||||
for each function template named
|
||||
is added to the set of selected functions considered[.](#3.sentence-1)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3211)
|
||||
|
||||
Non-member functions,
|
||||
static member functions, and
|
||||
explicit object member functions
|
||||
match targets of function pointer type or
|
||||
reference to function type[.](#4.sentence-1)
|
||||
|
||||
Implicit object member functions match targets of
|
||||
pointer-to-member-function type[.](#4.sentence-2)
|
||||
|
||||
[*Note [3](#note-3)*:
|
||||
|
||||
If an implicit object member function is chosen,
|
||||
the result can be used only to form a pointer to member ([[expr.unary.op]](expr.unary.op "7.6.2.2 Unary operators"))[.](#4.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3225)
|
||||
|
||||
All functions with
|
||||
associated constraints
|
||||
that are not satisfied ([[temp.constr.decl]](temp.constr.decl "13.5.3 Constrained declarations"))
|
||||
are eliminated from the set of selected functions[.](#5.sentence-1)
|
||||
|
||||
If more than one function in the set remains,
|
||||
all function template specializations
|
||||
in the set
|
||||
are eliminated if the set also contains a function that is not a
|
||||
function template specialization[.](#5.sentence-2)
|
||||
|
||||
Any given non-template functionF0 is eliminated if the set contains a second
|
||||
non-template function that
|
||||
is more partial-ordering-constrained thanF0 ([[temp.constr.order]](temp.constr.order "13.5.5 Partial ordering by constraints"))[.](#5.sentence-3)
|
||||
|
||||
Any given
|
||||
function template specializationF1 is eliminated if the set contains a second
|
||||
function template specialization whose function template
|
||||
is more specialized than the
|
||||
function template ofF1 according to
|
||||
the partial ordering rules of [[temp.func.order]](temp.func.order "13.7.7.3 Partial ordering of function templates")[.](#5.sentence-4)
|
||||
|
||||
After such eliminations,
|
||||
if any, there shall remain exactly one selected function[.](#5.sentence-5)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3254)
|
||||
|
||||
[*Example [1](#example-1)*: int f(double);int f(int);int (*pfd)(double) = &f; // selects f(double)int (*pfi)(int) = &f; // selects f(int)int (*pfe)(...) = &f; // error: type mismatchint (&rfi)(int) = f; // selects f(int)int (&rfd)(double) = f; // selects f(double)void g() {(int (*)(int))&f; // cast expression as selector}
|
||||
|
||||
The initialization ofpfe is ill-formed because nof() with typeint(...) has been declared, and not because of any ambiguity[.](#6.sentence-1)
|
||||
|
||||
â *end example*]
|
||||
|
||||
[*Example [2](#example-2)*: struct X {int f(int); static int f(long);};
|
||||
|
||||
int (X::*p1)(int) = &X::f; // OKint (*p2)(int) = &X::f; // error: mismatchint (*p3)(long) = &X::f; // OKint (X::*p4)(long) = &X::f; // error: mismatchint (X::*p5)(int) = &(X::f); // error: wrong syntax for// pointer to memberint (*p6)(long) = &(X::f); // OK â *end example*]
|
||||
|
||||
[*Example [3](#example-3)*: template<bool B> struct X {void f(short) requires B; void f(long); template<typename> void g(short) requires B; template<typename> void g(long);};void test() {&X<true>::f; // error: ambiguous; constraints are not considered&X<true>::g<int>; // error: ambiguous; constraints are not considered} â *end example*]
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3310)
|
||||
|
||||
[*Note [4](#note-4)*:
|
||||
|
||||
If f and g are both overload sets,
|
||||
the Cartesian product of possibilities is considered
|
||||
to resolve f(&g), or the equivalent expression f(g)[.](#7.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3317)
|
||||
|
||||
[*Note [5](#note-5)*:
|
||||
|
||||
Even if B is a public base of D,
|
||||
we haveD* f();
|
||||
B* (*p1)() = &f; // errorvoid g(D*);void (*p2)(B*) = &g; // error
|
||||
|
||||
â *end note*]
|
||||
44
cppdraft/over/pre.md
Normal file
44
cppdraft/over/pre.md
Normal file
@@ -0,0 +1,44 @@
|
||||
[over.pre]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.1 Preamble [over.pre]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L9)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
Each of two or more entities with the same name in the same scope,
|
||||
which must be functions or function templates,
|
||||
is commonly called an âoverloadâ[.](#1.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L18)
|
||||
|
||||
When a function is designated in a call, which function
|
||||
declaration is being referenced and the validity of the call
|
||||
are determined by comparing the types
|
||||
of the arguments at the point of use with the types of the parameters
|
||||
in the declarations in the overload set[.](#2.sentence-1)
|
||||
|
||||
This function selection process is called[*overload resolution*](#def:overload_resolution "12.1 Preamble [over.pre]") and is defined in [[over.match]](over.match "12.2 Overload resolution")[.](#2.sentence-2)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
Overload sets are formed by [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]")*s* naming functions and function templates and
|
||||
by [*splice-expression*](expr.prim.splice#nt:splice-expression "7.5.9 Expression splicing [expr.prim.splice]")*s* designating entities of the same kinds[.](#2.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[*Example [1](#example-1)*:
|
||||
|
||||
[ð](#:overloading,example_of)
|
||||
|
||||
double abs(double);int abs(int);
|
||||
|
||||
abs(1); // calls abs(int); abs(1.0); // calls abs(double); â *end example*]
|
||||
23
cppdraft/over/ref.md
Normal file
23
cppdraft/over/ref.md
Normal file
@@ -0,0 +1,23 @@
|
||||
[over.ref]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.4 Overloaded operators [[over.oper]](over.oper#over.ref)
|
||||
|
||||
### 12.4.6 Class member access [over.ref]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3687)
|
||||
|
||||
A [*class member access operator function*](#def:operator_function,class_member_access "12.4.6 Class member access [over.ref]") is a function named operator-> that is a non-static member function taking no non-object parameters[.](#1.sentence-1)
|
||||
|
||||
For an expression of the form
|
||||
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") -> templateopt [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]")
|
||||
|
||||
the operator function
|
||||
is selected by overload resolution ([[over.match.oper]](over.match.oper "12.2.2.3 Operators in expressions")),
|
||||
and the expression is interpreted as
|
||||
|
||||
( [*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") . operator -> () ) -> templateopt [*id-expression*](expr.prim.id.general#nt:id-expression "7.5.5.1 General [expr.prim.id.general]")
|
||||
37
cppdraft/over/sub.md
Normal file
37
cppdraft/over/sub.md
Normal file
@@ -0,0 +1,37 @@
|
||||
[over.sub]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.4 Overloaded operators [[over.oper]](over.oper#over.sub)
|
||||
|
||||
### 12.4.5 Subscripting [over.sub]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3650)
|
||||
|
||||
A [*subscripting operator function*](#def:operator_function,subscripting "12.4.5 Subscripting [over.sub]") is a member function named operator[] with an arbitrary number of parameters[.](#1.sentence-1)
|
||||
|
||||
It may have default arguments[.](#1.sentence-2)
|
||||
|
||||
For an expression of the form
|
||||
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") [ [*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]")opt ]
|
||||
|
||||
the operator function
|
||||
is selected by overload resolution ([[over.match.oper]](over.match.oper "12.2.2.3 Operators in expressions"))[.](#1.sentence-3)
|
||||
|
||||
If a member function is selected,
|
||||
the expression is interpreted as
|
||||
|
||||
[*postfix-expression*](expr.post.general#nt:postfix-expression "7.6.1.1 General [expr.post.general]") . operator [] ( [*expression-list*](expr.post.general#nt:expression-list "7.6.1.1 General [expr.post.general]")opt )
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3667)
|
||||
|
||||
[*Example [1](#example-1)*: struct X { Z operator[](std::initializer_list<int>);
|
||||
Z operator[](auto...);};
|
||||
X x;
|
||||
x[{1,2,3}] = 7; // OK, meaning x.operator[]({1,2,3}) x[1,2,3] = 7; // OK, meaning x.operator[](1,2,3)int a[10];
|
||||
a[{1,2,3}] = 7; // error: built-in subscript operator a[1,2,3] = 7; // error: built-in subscript operator â *end example*]
|
||||
49
cppdraft/over/unary.md
Normal file
49
cppdraft/over/unary.md
Normal file
@@ -0,0 +1,49 @@
|
||||
[over.unary]
|
||||
|
||||
# 12 Overloading [[over]](./#over)
|
||||
|
||||
## 12.4 Overloaded operators [[over.oper]](over.oper#over.unary)
|
||||
|
||||
### 12.4.2 Unary operators [over.unary]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3491)
|
||||
|
||||
A [*prefix unary operator function*](#def:operator_function,prefix_unary "12.4.2 Unary operators [over.unary]") is a function named operator@ for a prefix [*unary-operator*](expr.unary.general#nt:unary-operator "7.6.2.1 General [expr.unary.general]") @ ([[expr.unary.op]](expr.unary.op "7.6.2.2 Unary operators"))
|
||||
that is either
|
||||
a non-static member function ([[class.mfct]](class.mfct "11.4.2 Member functions")) with no non-object parameters or
|
||||
a non-member function with one parameter[.](#1.sentence-1)
|
||||
|
||||
For a [*unary-expression*](expr.unary.general#nt:unary-expression "7.6.2.1 General [expr.unary.general]") of the form @ [*cast-expression*](expr.cast#nt:cast-expression "7.6.3 Explicit type conversion (cast notation) [expr.cast]"),
|
||||
the operator function is selected by overload resolution ([[over.match.oper]](over.match.oper "12.2.2.3 Operators in expressions"))[.](#1.sentence-2)
|
||||
|
||||
If a member function is selected,
|
||||
the expression is interpreted as
|
||||
|
||||
[*cast-expression*](expr.cast#nt:cast-expression "7.6.3 Explicit type conversion (cast notation) [expr.cast]") . operator @ ()
|
||||
|
||||
Otherwise, if a non-member function is selected,
|
||||
the expression is interpreted as
|
||||
|
||||
operator @ ( [*cast-expression*](expr.cast#nt:cast-expression "7.6.3 Explicit type conversion (cast notation) [expr.cast]") )
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
The operators ++ and -- ([[expr.pre.incr]](expr.pre.incr "7.6.2.3 Increment and decrement"))
|
||||
are described in [[over.inc]](over.inc "12.4.7 Increment and decrement")[.](#1.sentence-3)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/overloading.tex#L3517)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
The unary and binary forms of the same operator have the same name[.](#2.sentence-1)
|
||||
|
||||
Consequently, a unary operator can hide a binary
|
||||
operator from an enclosing scope, and vice versa[.](#2.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
Reference in New Issue
Block a user