2

Named template arguments would arguably be a very important feature in C++. Namely, given a class template that has many template parameters with default arguments, this feature would allow the user to provide arguments for an arbitrary subset of these parameters. "C++ Templates: the Complete Guide" by Vandervoorde and Josuttis spends the whole Section 16.1 on achieving the effect of named template arguments.

Section 13.9 of the same book lists named template arguments as one of the features that are likely to be added to the language. Given both the fact that this estimation dates 12 years ago and the great utility of this feature, I would like to find out: have named template arguments made it into the newest Standard and/or been implemented in a contemporary compiler?

If the answer to the first question is negative, then I would like to understand what I am missing, that is: why is the need for this feature not as bad as I perceive it?

AlwaysLearning
  • 7,257
  • 4
  • 33
  • 68
  • They said "At this point there is no reason to believe named template arguments will ever make it into the language." I'm not sure how you deduced "likely to be added to the language" from that. EWG has repeatedly rejected named function arguments, most recently [last November](http://wg21.link/ewg150); there's no reason to believe that named template arguments would be treated any more favorably. – T.C. Sep 15 '15 at 10:56
  • @T.C. You are correct. I missed this. – AlwaysLearning Sep 15 '15 at 20:53

1 Answers1

6

1) No.

2) Nobody has made any statement about "the need for this feature". The fact that it doesn't exist doesn't mean that it's not badly needed; it just means that nobody has successfully proposed it and convinced the committee of it.

Kerrek SB
  • 464,522
  • 92
  • 875
  • 1,084
  • How can this be? Both authors of the book that I mentioned in the question are members of the C++ Standards committee! – AlwaysLearning Sep 09 '15 at 11:59
  • 4
    @MeirGoldenberg: Did they also write/promise that they were going to write and defend a proposal? – Kerrek SB Sep 09 '15 at 12:00
  • Not that I know of... What about the second part of the first question? I am not a compiler specialist, but this feature would seem to be not hard to implement. So, how come it was never provided by any compiler? (especially an open-source compiler like gcc) – AlwaysLearning Sep 09 '15 at 12:09
  • @MeirGoldenberg Are you aware of the Dunning-Kruger effect? Extensions not only have to work, they cannot interfere with both any current language feature, nor any future language feature. On top of that, current C++ developers are leery about using compiler language extensions (as they tend only to be stable over short terms in practice), so the yield will be low. On top of that, you'd only be talking about the rare code base where huge numbers of non-uniform template arguments make sense, which is a low yield on a rare situation. – Yakk - Adam Nevraumont Sep 10 '15 at 14:06
  • 1) What does Dunning-Kruger effect imply with respect to the particular feature we are talking about? 2) Consider an example: the Concepts Lite implemented in `gcc`. Why did they do it? Because it is a test bed for an important feature: experience will be gained by people using it and this will give serious support to the proposal. 3) Is it rare that one has four policies for a host class? Why have the user specify three policies when he wants to use a non-default one for the third policy only? This situation does not seem rare to me at all. – AlwaysLearning Sep 11 '15 at 08:27
  • @MeirGoldenberg: Concepts (Lite) is an acutal, written up standards proposal that has been heavily worked on by 20+ people in the last five committee meetings. That's quite different from some hypothetical feature someone once mentioned as "wouldn't this be nice". – Kerrek SB Sep 11 '15 at 08:51
  • @KerrekSB "someone once mentioned"? This sounds like "most people do well without it". Am I missing something then? Is it not a great inconvenience to have to specify all these policies or to pollute libraries with the work-around suggested in the book that I cited in the original question? – AlwaysLearning Sep 11 '15 at 09:43
  • @MeirGoldenberg: There are thousands of books. A compiler isn't going to implement every idea from every book randomly. If the idea is good and you want it in the language, write a standard proposal, come to the meetings, and convince people that it belongs in the language. I have absolutely no idea if "most people do well without it"; all I can see is that nobody has proposed this yet for standardization, unlike Concepts. – Kerrek SB Sep 11 '15 at 09:46