Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2019-07 CWG Motion 11] P1816R0 Wording for class template argument deduction for aggregates #2990

Closed
jensmaurer opened this issue Jul 21, 2019 · 1 comment · Fixed by #3085
Assignees
Milestone

Comments

@jensmaurer
Copy link
Member

No description provided.

@zygoloid zygoloid self-assigned this Jul 21, 2019
@timuraudio
Copy link

Dear editors:
This paper is written in cppdraft-compatible LaTeX, so I copypasted the wording below, in case it helps. Also, I just noticed that, in the code example, my comments are somewhat inconsistent with the existing rest of the example: I use // OK, X deduced, while the existing code instead uses // OK, deduces X. Perhaps this inconsistency can be removed editorially.

In addition, if \tcode{C} satisfies the conditions for an aggregate class with the assumption that any dependent base class has no virtual functions and no virtual base classes, and the initializer is a non-empty \grammarterm{braced-init-list} or parenthesized \grammarterm{expression-list}, the set contains an additional function template, called the \grammarterm{aggregate deduction candidate}, defined as follows. Let $x_1, ..., x_n$ be the elements of the \grammarterm{initializer-list} or \grammarterm{designated-initializer-list} of the \grammarterm{braced-init-list}, or of the \grammarterm{expression-list}. For each $x_i$, let $e_i$ be the corresponding element of \tcode{C} or of one of its (possibly recursive) subaggregates that would be initialized by $x_i$ ([dcl.init.aggr]) if brace elision is not considered for any subaggregate that has a dependent type. If there is no such element $e_i$, the program is ill-formed. The aggregate deduction candidate is derived as above from a hypothetical constructor $\tcode{C}(\tcode{T}_1, ..., \tcode{T}_n)$, where $\tcode{T}_i$ is the declared type of the element $e_i$.
\begin{codeblock}
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, \tcode{C<int>} deduced

D d1 = {1, 2};         // error: deduction failed
D d2 = {1, 2, 3};      // OK, braces elided, \tcode{D<int>} deduced

template <typename T>
struct I {
    using type = T;
};

template <typename T>
struct E {
    typename I<T>::type i;
    T t;
};

E e1 = {1, 2};         // OK, \tcode{E<int>} deduced
    
\end{codeblock}

@jensmaurer jensmaurer added this to the post-2019-07 milestone Jul 23, 2019
@zygoloid zygoloid removed their assignment Jul 24, 2019
@jensmaurer jensmaurer self-assigned this Jul 26, 2019
zygoloid added a commit that referenced this issue Aug 2, 2019
P1816R0 Class template argument deduction for aggregates

Fixes #2990.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants