|
706 | 706 | The type of the \grammarterm{lambda-expression} (which is also the type of the
|
707 | 707 | closure object) is a unique, unnamed non-union class type
|
708 | 708 | --- called the \defn{closure type} ---
|
709 |
| -whose properties are described below. |
710 |
| -This class type is not an aggregate type~(\ref{dcl.init.aggr}). |
| 709 | +whose properties are described in section~\ref{expr.prim.lambda.closure}. |
| 710 | + |
| 711 | +\pnum |
| 712 | +If a \grammarterm{lambda-expression} does not include a |
| 713 | +\grammarterm{lambda-declarator}, it is as if the \grammarterm{lambda-declarator} were |
| 714 | +\tcode{()}. |
| 715 | +The lambda return type is \tcode{auto}, which is replaced by the |
| 716 | +type specified by the |
| 717 | +\grammarterm{trailing-return-type} if provided and/or deduced from |
| 718 | +\tcode{return} statements as described in~\ref{dcl.spec.auto}. |
| 719 | +\begin{example} |
| 720 | +\begin{codeblock} |
| 721 | +auto x1 = [](int i){ return i; }; // OK: return type is \tcode{int} |
| 722 | +auto x2 = []{ return { 1, 2 }; }; // error: deducing return type from \grammarterm{braced-init-list} |
| 723 | +int j; |
| 724 | +auto x3 = []()->auto&& { return j; }; // OK: return type is \tcode{int\&} |
| 725 | +\end{codeblock} |
| 726 | +\end{example} |
| 727 | + |
| 728 | +\rSec3[expr.prim.lambda.closure]{Closure types}% |
| 729 | + |
| 730 | +\pnum |
711 | 731 | The closure type is declared in the smallest block
|
712 | 732 | scope, class scope, or namespace scope that contains the corresponding
|
713 | 733 | \grammarterm{lambda-expression}. \begin{note} This determines the set of namespaces and
|
714 | 734 | classes associated with the closure type~(\ref{basic.lookup.argdep}). The parameter
|
715 | 735 | types of a \grammarterm{lambda-declarator} do not affect these associated namespaces and
|
716 |
| -classes. \end{note} An implementation may define the closure type differently from what |
| 736 | +classes. \end{note} The closure type is not an aggregate type~(\ref{dcl.init.aggr}). |
| 737 | +An implementation may define the closure type differently from what |
717 | 738 | is described below provided this does not alter the observable behavior of the program
|
718 | 739 | other than by changing:
|
719 | 740 |
|
|
731 | 752 | An implementation shall not add members of rvalue reference type to the closure
|
732 | 753 | type.
|
733 | 754 |
|
734 |
| -\pnum |
735 |
| -If a \grammarterm{lambda-expression} does not include a |
736 |
| -\grammarterm{lambda-declarator}, it is as if the \grammarterm{lambda-declarator} were |
737 |
| -\tcode{()}. |
738 |
| -The lambda return type is \tcode{auto}, which is replaced by the |
739 |
| -type specified by the |
740 |
| -\grammarterm{trailing-return-type} if provided and/or deduced from |
741 |
| -\tcode{return} statements as described in~\ref{dcl.spec.auto}. |
742 |
| -\begin{example} |
743 |
| -\begin{codeblock} |
744 |
| -auto x1 = [](int i){ return i; }; // OK: return type is \tcode{int} |
745 |
| -auto x2 = []{ return { 1, 2 }; }; // error: deducing return type from \grammarterm{braced-init-list} |
746 |
| -int j; |
747 |
| -auto x3 = []()->auto&& { return j; }; // OK: return type is \tcode{int\&} |
748 |
| -\end{codeblock} |
749 |
| -\end{example} |
750 |
| - |
751 | 755 | \pnum
|
752 | 756 | The closure type for a non-generic \grammarterm{lambda-expression} has a public
|
753 | 757 | inline function call operator~(\ref{over.call}) whose parameters and return type
|
|
788 | 792 | q(); // OK: outputs \tcode{1a3.14}
|
789 | 793 | \end{codeblock}
|
790 | 794 | \end{example}
|
791 |
| -This function call operator or operator template is declared |
| 795 | + |
| 796 | +\pnum |
| 797 | +The function call operator or operator template is declared |
792 | 798 | \tcode{const}~(\ref{class.mfct.non-static}) if and only if the
|
793 | 799 | \grammarterm{lambda-expression}'s \grammarterm{parameter-declaration-clause} is not
|
794 | 800 | followed by \tcode{mutable}. It is neither virtual nor declared \tcode{volatile}. Any
|
|
839 | 845 | the pointer to function shall behave as if it were a
|
840 | 846 | \grammarterm{decltype-specifier} denoting the return type of the corresponding
|
841 | 847 | function call operator template specialization.
|
| 848 | + |
| 849 | +\pnum |
842 | 850 | \begin{note}
|
843 | 851 | If the generic lambda has no \grammarterm{trailing-return-type} or
|
844 | 852 | the \grammarterm{trailing-return-type} contains a placeholder type, return type
|
|
889 | 897 | \end{codeblock}
|
890 | 898 | \end{example}
|
891 | 899 |
|
| 900 | +\pnum |
892 | 901 | The value returned by any given specialization of this conversion function
|
893 | 902 | template is the address of a function \tcode{F} that, when invoked, has the same
|
894 | 903 | effect as invoking the generic lambda's corresponding function call operator
|
|
908 | 917 | \end{codeblock}
|
909 | 918 | \end{example}
|
910 | 919 |
|
| 920 | +\pnum |
911 | 921 | The conversion function or conversion function template is public,
|
912 | 922 | constexpr, non-virtual, non-explicit, const, and has a non-throwing exception
|
913 | 923 | specification~(\ref{except.spec}).
|
|
950 | 960 | the \grammarterm{compound-statement} of the \grammarterm{lambda-expression},
|
951 | 961 | with semantics as described in~\ref{dcl.fct.def.general}.
|
952 | 962 |
|
| 963 | +\pnum |
| 964 | +The closure type associated with a \grammarterm{lambda-expression} has no |
| 965 | +default constructor and a deleted copy assignment operator. It has a |
| 966 | +defaulted copy constructor and a defaulted move constructor~(\ref{class.copy}). |
| 967 | +\begin{note} These special member functions are implicitly defined as |
| 968 | +usual, and might therefore be defined as deleted. \end{note} |
| 969 | + |
| 970 | +\pnum |
| 971 | +The closure type associated with a \grammarterm{lambda-expression} has an |
| 972 | +implicitly-declared destructor~(\ref{class.dtor}). |
| 973 | + |
| 974 | +\pnum |
| 975 | +A member of a closure type shall not be |
| 976 | +explicitly instantiated~(\ref{temp.explicit}), |
| 977 | +explicitly specialized~(\ref{temp.expl.spec}), or |
| 978 | +named in a \tcode{friend} declaration~(\ref{class.friend}). |
| 979 | + |
| 980 | +\rSec3[expr.prim.lambda.capture]{Captures}% |
| 981 | + |
953 | 982 | \pnum
|
954 | 983 | If a \grammarterm{lambda-capture} includes a \grammarterm{capture-default} that
|
955 | 984 | is \tcode{\&}, no identifier in a \grammarterm{simple-capture} of that
|
|
1263 | 1292 | \end{codeblock}
|
1264 | 1293 | \end{example}
|
1265 | 1294 |
|
1266 |
| -\pnum |
1267 |
| -The closure type associated with a \grammarterm{lambda-expression} has no |
1268 |
| -default constructor and a deleted copy assignment operator. It has a |
1269 |
| -defaulted copy constructor and a defaulted move constructor~(\ref{class.copy}). |
1270 |
| -\begin{note} These special member functions are implicitly defined as |
1271 |
| -usual, and might therefore be defined as deleted. \end{note} |
1272 |
| - |
1273 |
| -\pnum |
1274 |
| -The closure type associated with a \grammarterm{lambda-expression} has an |
1275 |
| -implicitly-declared destructor~(\ref{class.dtor}). |
1276 |
| - |
1277 |
| -\pnum |
1278 |
| -A member of a closure type shall not be |
1279 |
| -explicitly instantiated~(\ref{temp.explicit}), |
1280 |
| -explicitly specialized~(\ref{temp.expl.spec}), or |
1281 |
| -named in a \tcode{friend} declaration~(\ref{class.friend}). |
1282 |
| - |
1283 | 1295 | \pnum
|
1284 | 1296 | When the \grammarterm{lambda-expression} is evaluated, the entities that are
|
1285 | 1297 | captured by copy are used to direct-initialize each corresponding non-static data member
|
|
0 commit comments