|
1194 | 1194 |
|
1195 | 1195 | \pnum |
1196 | 1196 | \indextext{\idxcode{this}}% |
1197 | | -The keyword \keyword{this} names a pointer to the object for which a non-static member |
| 1197 | +The keyword \keyword{this} names a pointer to the object for which an implicit object member |
1198 | 1198 | function\iref{class.mfct.non-static} is invoked or a non-static data member's |
1199 | 1199 | initializer\iref{class.mem} is evaluated. |
1200 | 1200 |
|
|
1213 | 1213 | between the optional |
1214 | 1214 | \grammarterm{cv-qualifier-seq} and the end of the \grammarterm{function-definition}, |
1215 | 1215 | \grammarterm{member-declarator}, or \grammarterm{declarator}. It shall not appear within |
1216 | | -the declaration of a static member function of the current class (although its type and value category |
1217 | | -are defined within a static member function as they are within a non-static |
| 1216 | +the declaration of either |
| 1217 | +a static member function or an explicit object member function |
| 1218 | +of the current class (although its type and value category |
| 1219 | +are defined within such member functions as they are within an implicit object |
1218 | 1220 | member function). |
1219 | 1221 | \begin{note} |
1220 | 1222 | This is because declaration matching does not |
|
1450 | 1452 | the type of a class member access expression\iref{expr.ref} |
1451 | 1453 | naming the non-static data member |
1452 | 1454 | that would be declared for such a capture |
1453 | | -in the closure object of |
| 1455 | +in the object parameter\iref{dcl.fct} of the function call operator of |
1454 | 1456 | the innermost such intervening \grammarterm{lambda-expression}. |
1455 | 1457 | \begin{note} |
1456 | 1458 | If that \grammarterm{lambda-expression} is not declared \keyword{mutable}, |
|
1688 | 1690 | In the \grammarterm{decl-specifier-seq} of the \grammarterm{lambda-declarator}, |
1689 | 1691 | each \grammarterm{decl-specifier} |
1690 | 1692 | shall be one of \keyword{mutable}, \keyword{constexpr}, or \keyword{consteval}. |
| 1693 | +If the \grammarterm{lambda-declarator} contains |
| 1694 | +an explicit object parameter\iref{dcl.fct}, |
| 1695 | +then no \grammarterm{decl-specifier} in the \grammarterm{decl-specifier-seq} |
| 1696 | +shall be \keyword{mutable}. |
1691 | 1697 | \begin{note} |
1692 | 1698 | The trailing \grammarterm{requires-clause} is described in \ref{dcl.decl}. |
1693 | 1699 | \end{note} |
|
1792 | 1798 | { std::cout << v1 << v2 << v3; } ); |
1793 | 1799 | auto q = p(1, 'a', 3.14); // OK: outputs \tcode{1a3.14} |
1794 | 1800 | q(); // OK: outputs \tcode{1a3.14} |
| 1801 | + |
| 1802 | +auto fact = [](this auto self, int n) -> int { // OK: explicit object parameter |
| 1803 | + return (n <= 1) ? 1 : n * self(n-1); |
| 1804 | +}; |
| 1805 | +std::cout << fact(5); // OK: outputs 120 |
| 1806 | +\end{codeblock} |
| 1807 | +\end{example} |
| 1808 | + |
| 1809 | +\pnum |
| 1810 | +Given a lambda with a \grammarterm{lambda-capture}, |
| 1811 | +the type of the explicit object parameter, if any, |
| 1812 | +of the lambda's function call operator |
| 1813 | +(possibly instantiated from a function call operator template) |
| 1814 | +shall be either: |
| 1815 | +\begin{itemize} |
| 1816 | +\item |
| 1817 | +the closure type, |
| 1818 | +\item |
| 1819 | +a class type derived from the closure type, or |
| 1820 | +\item |
| 1821 | +a reference to a possibly cv-qualified such type. |
| 1822 | +\end{itemize} |
| 1823 | +\begin{example} |
| 1824 | +\begin{codeblock} |
| 1825 | +struct C { |
| 1826 | + template <typename T> |
| 1827 | + C(T); |
| 1828 | +}; |
| 1829 | + |
| 1830 | +void func(int i) { |
| 1831 | + int x = [=](this auto&&) { return i; }(); // OK |
| 1832 | + int y = [=](this C) { return i; }(); // error |
| 1833 | + int z = [](this C) { return 42; }(); // OK |
| 1834 | +} |
1795 | 1835 | \end{codeblock} |
1796 | 1836 | \end{example} |
1797 | 1837 |
|
1798 | 1838 | \pnum |
1799 | 1839 | The function call operator or operator template is declared |
1800 | 1840 | \keyword{const}~(\ref{class.mfct.non-static}) if and only if the |
1801 | 1841 | \grammarterm{lambda-expression}'s \grammarterm{parameter-declaration-clause} is not |
1802 | | -followed by \keyword{mutable}. It is neither virtual nor declared \tcode{volatile}. Any |
| 1842 | +followed by \keyword{mutable} and |
| 1843 | +the \grammarterm{lambda-declarator} does not contain |
| 1844 | +an explicit object parameter. |
| 1845 | +It is neither virtual nor declared \tcode{volatile}. Any |
1803 | 1846 | \grammarterm{noexcept-specifier} specified on a \grammarterm{lambda-expression} |
1804 | 1847 | applies to the corresponding function call operator or operator template. |
1805 | 1848 | An \grammarterm{attribute-specifier-seq} in a \grammarterm{lambda-declarator} appertains |
|
3082 | 3125 | When a function is called, each parameter\iref{dcl.fct} is |
3083 | 3126 | initialized~(\ref{dcl.init}, \ref{class.copy.ctor}) with |
3084 | 3127 | its corresponding argument. |
| 3128 | +If the function is an explicit object member function and |
| 3129 | +there is an implied object argument\iref{over.call.func}, |
| 3130 | +the list of provided arguments is preceded by the implied object argument |
| 3131 | +for the purposes of this correspondence. |
3085 | 3132 | If there is no corresponding argument, |
3086 | 3133 | the default argument for the parameter is used. |
3087 | 3134 | \begin{example} |
|
3090 | 3137 | int x = f<int>(); // error: no argument for second function parameter |
3091 | 3138 | \end{codeblock} |
3092 | 3139 | \end{example} |
3093 | | -If the function is a non-static member |
| 3140 | +If the function is an implicit object member |
3094 | 3141 | function, the \keyword{this} parameter of the function\iref{expr.prim.this} |
3095 | 3142 | is initialized with a pointer to the object of the call, converted |
3096 | 3143 | as if by an explicit type conversion\iref{expr.cast}. |
|
4337 | 4384 | \begin{itemize} |
4338 | 4385 | \item |
4339 | 4386 | If the operand is a \grammarterm{qualified-id} naming a non-static or variant member \tcode{m} |
4340 | | -of some class \tcode{C}, the result has type ``pointer to member |
| 4387 | +of some class \tcode{C}, other than an explicit object member function, the result has type ``pointer to member |
4341 | 4388 | of class \tcode{C} of type \tcode{T}'' and designates \tcode{C::m}. |
4342 | 4389 | \item |
4343 | 4390 | Otherwise, the result has type ``pointer to \tcode{T}'' and points to |
4344 | 4391 | the designated object\iref{intro.memory} or function\iref{basic.compound}. |
| 4392 | +If the operand names an explicit object member function\iref{dcl.fct}, |
| 4393 | +the operand shall be a \grammarterm{qualified-id}. |
4345 | 4394 | \begin{note} |
4346 | 4395 | In particular, taking the address of a variable of type ``\cv{}~\tcode{T}'' |
4347 | 4396 | yields a pointer of type ``pointer to \cv{}~\tcode{T}''. |
|
0 commit comments