|
6853 | 6853 | or obtained from default
|
6854 | 6854 | \grammarterm{template-argument}{s}.
|
6855 | 6855 | \begin{example}
|
6856 |
| - |
6857 | 6856 | \begin{codeblock}
|
6858 | 6857 | void f(Array<dcomplex>& cv, Array<int>& ci) {
|
6859 | 6858 | sort(cv); // calls \tcode{sort(Array<dcomplex>\&)}
|
6860 | 6859 | sort(ci); // calls \tcode{sort(Array<int>\&)}
|
6861 | 6860 | }
|
6862 | 6861 | \end{codeblock}
|
6863 |
| - |
6864 | 6862 | and
|
6865 |
| - |
6866 | 6863 | \begin{codeblock}
|
6867 | 6864 | void g(double d) {
|
6868 | 6865 | int i = convert<int>(d); // calls \tcode{convert<int,double>(double)}
|
|
6878 | 6875 | deduction fails. Specifically, the following steps are performed when
|
6879 | 6876 | evaluating an explicitly specified template argument list with respect
|
6880 | 6877 | to a given function template:
|
6881 |
| - |
6882 | 6878 | \begin{itemize}
|
6883 | 6879 | \item The specified template arguments must match the template parameters in
|
6884 | 6880 | kind (i.e., type, non-type, template). There
|
|
6908 | 6904 | variable within the function.
|
6909 | 6905 | \end{note}
|
6910 | 6906 | \begin{example}
|
6911 |
| - |
6912 | 6907 | \begin{codeblock}
|
6913 | 6908 | template <class T> void f(T t);
|
6914 | 6909 | template <class X> void g(const X x);
|
|
6962 | 6957 | }
|
6963 | 6958 | \end{codeblock}
|
6964 | 6959 | \end{example}
|
6965 |
| - |
6966 | 6960 | When all template arguments have been deduced or obtained from
|
6967 | 6961 | default template arguments, all uses of template parameters in
|
6968 | 6962 | the template parameter list of the template and the function type
|
|
6989 | 6983 | template arguments but also general expressions (i.e., non-constant expressions)
|
6990 | 6984 | inside \tcode{sizeof}, \tcode{decltype}, and other contexts that allow non-constant
|
6991 | 6985 | expressions. The substitution proceeds in lexical order and stops when
|
6992 |
| -a condition that causes deduction to fail is encountered. \begin{note} The equivalent substitution in exception specifications is |
6993 |
| -done only when the \grammarterm{noexcept-specifier} is instantiated, at which point a program is ill-formed |
6994 |
| -if the substitution results in an invalid type or |
6995 |
| -expression. \end{note} |
| 6986 | +a condition that causes deduction to fail is encountered. |
| 6987 | +\begin{note} |
| 6988 | +The equivalent substitution in exception specifications is |
| 6989 | +done only when the \grammarterm{noexcept-specifier} is instantiated, |
| 6990 | +at which point a program is ill-formed |
| 6991 | +if the substitution results in an invalid type or expression. |
| 6992 | +\end{note} |
6996 | 6993 | \begin{example}
|
6997 | 6994 | \begin{codeblock}
|
6998 | 6995 | template <class T> struct A { using X = typename T::X; };
|
|
7011 | 7008 | \pnum
|
7012 | 7009 | If a substitution results in an invalid type or expression, type deduction fails. An
|
7013 | 7010 | invalid type or expression is one that would be ill-formed, with a diagnostic
|
7014 |
| -required, if written using the substituted arguments. \begin{note} If no |
| 7011 | +required, if written using the substituted arguments. |
| 7012 | +\begin{note} |
| 7013 | +If no |
7015 | 7014 | diagnostic is required, the program is still ill-formed. Access checking is done
|
7016 | 7015 | as part of the substitution
|
7017 |
| -process. \end{note} Only invalid types and expressions in the immediate |
| 7016 | +process. |
| 7017 | +\end{note} |
| 7018 | +Only invalid types and expressions in the immediate |
7018 | 7019 | context of the function type and its template parameter types can result in a deduction
|
7019 |
| -failure. \begin{note} The substitution into types and expressions can result |
| 7020 | +failure. |
| 7021 | +\begin{note} |
| 7022 | +The substitution into types and expressions can result |
7020 | 7023 | in effects such as the instantiation of class template specializations and/or
|
7021 | 7024 | function template specializations, the generation of implicitly-defined functions,
|
7022 | 7025 | etc. Such effects are not in the ``immediate context'' and can result in the
|
7023 |
| -program being ill-formed.\end{note} |
| 7026 | +program being ill-formed. |
| 7027 | +\end{note} |
7024 | 7028 |
|
| 7029 | +\pnum |
7025 | 7030 | \begin{example}
|
7026 | 7031 | \begin{codeblock}
|
7027 | 7032 | struct X { };
|
|
7036 | 7041 | X x3 = f(x1, x2); // deduction fails on \#1 (cannot add \tcode{X+X}), calls \#2\end{codeblock}
|
7037 | 7042 | \end{example}
|
7038 | 7043 |
|
7039 |
| -\begin{note} Type deduction may fail for |
7040 |
| -the following reasons: |
7041 |
| - |
| 7044 | +\pnum |
| 7045 | +\begin{note} |
| 7046 | +Type deduction may fail for the following reasons: |
7042 | 7047 | \begin{itemize}
|
7043 | 7048 | \item Attempting to instantiate a pack expansion containing multiple parameter packs of differing lengths.
|
7044 | 7049 | \item
|
7045 | 7050 | Attempting to create an array with an element type that is \tcode{void}, a
|
7046 | 7051 | function type, a reference type, or an abstract class type, or attempting
|
7047 | 7052 | to create an array with a size that is zero or negative.
|
7048 | 7053 | \begin{example}
|
7049 |
| - |
7050 | 7054 | \begin{codeblock}
|
7051 | 7055 | template <class T> int f(T[5]);
|
7052 | 7056 | int I = f<int>(0);
|
|
7056 | 7060 | \item
|
7057 | 7061 | Attempting to use a type that is not a class or enumeration type in a qualified name.
|
7058 | 7062 | \begin{example}
|
7059 |
| - |
7060 | 7063 | \begin{codeblock}
|
7061 | 7064 | template <class T> int f(typename T::B*);
|
7062 | 7065 | int i = f<int>(0);
|
|
7075 | 7078 | the specified member is not a non-type where a non-type is required.
|
7076 | 7079 | \end{itemize}
|
7077 | 7080 | \begin{example}
|
7078 |
| - |
7079 | 7081 | \begin{codeblock}
|
7080 | 7082 | template <int I> struct X { };
|
7081 | 7083 | template <template <class T> class> struct Z { };
|
|
7108 | 7110 | Attempting to create ``pointer to member of \tcode{T}'' when \tcode{T} is not a
|
7109 | 7111 | class type.
|
7110 | 7112 | \begin{example}
|
7111 |
| - |
7112 | 7113 | \begin{codeblock}
|
7113 | 7114 | template <class T> int f(int T::*);
|
7114 | 7115 | int i = f<int>(0);
|
|
0 commit comments