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

[temp.deduct.type] p4 values vs parameters #4884

Open
xmh0511 opened this issue Sep 9, 2021 · 5 comments
Open

[temp.deduct.type] p4 values vs parameters #4884

xmh0511 opened this issue Sep 9, 2021 · 5 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Sep 9, 2021

In most cases, the types, templates, and non-type values that are used to compose P participate in template argument deduction.

Isn't that it should be phrased as the following

In most cases, the type, template, and non-type template parameters that are used to compose P participate in template argument deduction.

This keeps consistent with [temp.deduct.type] p1

Template arguments can be deduced in several different contexts, but in each case a type that is specified in terms of template parameters (call it P) is compared with an actual type (call it A)

The same issue is in the below sentence

In certain contexts, however, the value template parameter does not participate in type template argument deduction, but instead uses the values of template arguments that were either deduced elsewhere or explicitly specified. If a template parameter is used only in non-deduced contexts and is not explicitly specified, template argument deduction fails.

It is the template parameter that participates in template argument deduction rather than the value. Furthermore, should we specifically say which case does not the template parameter participate in template argument deduction? At least, we should say the template parameter within a non-deduced context does not participate in the template argument deduction, which can associate it with the latter sentence "If a template parameter is used only in non-deduced contexts...".

@jensmaurer
Copy link
Member

[temp.deduct.type] p3 uses the same phrasing "A given type P can be composed from a number of other types, templates, and non-type values:" Note that p3 does a recursive decomposition here, and looks through nested types etc, not all of which are (directly) template parameters. So, this part looks sane.

I agree with the concerns about "In certain contexts, however, the value does not participate in type deduction, "

@xmh0511
Copy link
Contributor Author

xmh0511 commented Sep 10, 2021

For the first concern, my opinion is, given P C<std::tuple<int>,std::tuple,0>, there is no template argument to be deduced, even though the nested such things(i.e. types, templates, non-type values) compose that P. I think only these P and the nested things thereof that contain at least one template parameter need to participate in deduction whatever the number of nest levels, which is recursive. For instance, D<std::tuple<T, T*>, N, int>, where the type std::tuple<T, T*>, T, T* need to participate in deduction, the non-type template parameter N as well, conversely, type int does not participate in template argument deduction since it does not contain template parameter.

Maybe it will be more clear

In most cases, the types, templates, and non-type values containing at least one template parameter, which are used to compose P, participate in template argument deduction.

Incidentally, [temp.deduct.type] p3 just specify what things can form the P, however, it didn't mention template argument deduction, I just think we should restrict which P actually needs to participate in template argument deduction. The following sentence has proved that

That is, they may be used to determine the value of a template argument

Whatever how degree are these template parameters nested, the template arguments always correspond to these template parameters, that is, template parameters are ultimately participated in deduction to deduce the corresponding template arguments for them.

@jensmaurer
Copy link
Member

"For the first concern": I think this describes the contexts in which deduction is possible, in a general fashion. I don't think it's strictly necessary to talk about template parameters for that description to work.

I'm not sure we consistently say "value of a template parameter" vs. "value of a template argument". The first is my preference.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Sep 10, 2021

[temp.deduct.call] p1 restricts that which P can participate in template argument deduction.

Template argument deduction is done by comparing each function template parameter type (call it P) that contains template-parameters that participate in template argument deduction with the type of the corresponding argument of the call (call it A) as described below.

Also notes the note following [temp.deduct.type] p4

[Note 1: Under [temp.deduct.call], if P contains no template-parameters that appear in deduced contexts, no deduction is done, so P and A need not have the same form. — end note]

So, in [temp.deduct.type] p4, we should specify which template parameters participate in template argument deduction and which do not.

For "value of a template parameter" vs. "value of a template argument", why not we directly say

That is, they may be used to determine the template argument.

After all, the subject is "template argument deduction", hence the result of the deduction produces the corresponding template argument for the template parameter.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Sep 10, 2021

Ah, a special case for [temp.deduct.type] is the partial ordering. Consider the example mentioned by CWG2235

template <class T> T f(int);        // #1
template <class T, class U> T f(U); // #2

During the partial ordering, when P = int while A = U, the deduction still performs and eventually fails. Hence, [temp.deduct.type] should cover this, However, this would make [temp.deduct.type] p1 not be fine anymore.

Template arguments can be deduced in several different contexts, but in each case a type that is specified in terms of template parameters (call it P) is compared with an actual type (call it A)


we should specify which template parameters participate in template argument deduction and which do not.

it should be covered in the second concern.

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

No branches or pull requests

2 participants