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

[std] Where template can be replaced with auto, or vice versa #4822

Open
JohelEGP opened this issue Aug 18, 2021 · 6 comments
Open

[std] Where template can be replaced with auto, or vice versa #4822

JohelEGP opened this issue Aug 18, 2021 · 6 comments

Comments

@JohelEGP
Copy link
Contributor

JohelEGP commented Aug 18, 2021

Following the discussion at #4817, I searched the WD for &&... and found some places where these could be swapped.

  • Use familiar template syntax for lambdas: [allocator.uses.construction], [allocator.adaptor.members], [range.utility.conv.to].
  • Remove redundant parameter pack:
    • [dcl.fct.def.coroutine]'s example.
    • [unique.ptr.creation]'s =deleted overloads. Perhaps useful for symmetry with the non-deleted overloads.
    • In containers: [deque.modifiers], [list.modifiers], [vector.modifiers], [vector.bool], [map.overview]'s emplace{,_hint}, [multimap.overview], [set.overview], [multiset.overview], [unord.map.overview]'s emplace{,_hint}, [unord.multimap.overview], [unord.set.overview], [unord.multiset.overview].
@jwakely
Copy link
Member

jwakely commented Aug 18, 2021

Following the discussion at #4817, I searched the WD for &&... and found some places where these could be swapped.

* Use familiar template syntax for lambdas: [allocator.uses.construction], [allocator.adaptor.members].

[&alloc]<class... Args1>(Args1&&... args1) would allow us to avoid decltype(args1) but I'm not sure it's significantly better, or worth changing.

* Remove redundant parameter pack:
  
  * [dcl.fct.def.coroutine]'s example.
  * [unique.ptr.creation]'s `=delete`d overloads. Perhaps useful for symmetry with the non-deleted overloads.

Keeping them symmetrical with the other overloads seems more useful than whatever benefit might come from using auto. We still need a template-head anyway for the non-deduced T template parameter.

  * In containers: [deque.modifiers], [list.modifiers], [vector.modifiers], [vector.bool], [map.overview]'s `emplace`{,`_hint`}, [multimap.overview], [set.overview], [multiset.overview], [unord.map.overview]'s `emplace`{,`_hint`}, [unord.multimap.overview], [unord.set.overview], [unord.multiset.overview].

Those names are used in the function bodies in actual implementations. I am not persuaded that changing them has any benefit.

@jwakely
Copy link
Member

jwakely commented Aug 18, 2021

Thanks for the survey though!

@jwakely
Copy link
Member

jwakely commented Aug 18, 2021

I think if we want a policy, then "a sink or catch-all where you don't care about the names or types of the parameters" seems like a good place to use auto&& or auto&&...

For other cases, I don't have a good suggestion (or preference). The survey here shows there aren't too many examples where it matters.

Maybe "if it's plausible that the specification, or just an implementation, would want to name the types, then use a < template-parameter-list > to give them names" makes sense, although it's a bit vague. I'd like to avoid changing things like list::emplace to use auto&&, only to have to change it back at a later date because we want to state a precondition or constraint in terms of the type. That guideline would suggest we should change [allocator.uses.construction] and [allocator.adaptor.members] to name the types, and maybe change the deleted make_unique overloads to:

template<class T> unspecified make_unique(auto&&...) = delete;

Now that I look at the line above, I think I do like it for make_unique. Only T matters here (for the Constraints: element) and the other arguments are "a catch-all where you don't care about the names or types of the parameters".

@JohelEGP
Copy link
Contributor Author

That does seem like an improved make_unique.

I'd refine the first suggestion for a policy to

-a sink or catch-all where you don't care about the names or types of the parameters
+a sink or catch-all where the names and types of the parameters don't matter

I think that's less subjective and might include (perhaps not clearly enough) the case where it does matter for an implementation.

As usual, I agree with your points.

@jwakely
Copy link
Member

jwakely commented Aug 18, 2021

That's much better phrasing, and I think it does nicely cover the "might need to refer to them in the spec or an impl" case as well as the "sink with unused/ignored arguments" case.

@jensmaurer jensmaurer added the decision-required A decision of the editorial group (or the Project Editor) is required. label Aug 19, 2021
@tkoeppe tkoeppe changed the title [std] Where template and function parameter pack can be swapped [std] Where template can be replaced with auto, or vice versa Jun 12, 2023
@tkoeppe
Copy link
Contributor

tkoeppe commented Jun 12, 2023

Editorial meeting consensus: The proposed policy #4822 (comment) sounds good, and we should adopt it. Only very few parts of the standard are affected.

We welcome pull requests to change make_unique accordingly.

We can also make the reverse change in individual cases where there is a clear benefit, without having a wider policy.

@jensmaurer jensmaurer removed the decision-required A decision of the editorial group (or the Project Editor) is required. label Jun 12, 2023
tkoeppe pushed a commit that referenced this issue Jul 21, 2023
See #4822 for the general policy on when to use abbreviated function
template syntax.
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

4 participants