Namespaces
Variants
Actions

Talk:cpp/language/template parameters

From cppreference.com

Contents

[edit] DR 150

Clang appears to intend to apply it retroactively all the way back to C++98: "This is the resolution to a Defect Report, so will be applied to all language versions." T. Canens (talk) 13:52, 15 December 2016 (PST)

cool, maybe it shouldn't be revboxed at all then.. The DR table could use a bit of rewording too, to stress that fix applies to all previous standards. --Cubbi (talk) 14:23, 15 December 2016 (PST)

[edit] Default arguments and template members

The page says:

> Default parameters are not allowed in the out-of-class definition of a member template (they have to be provided in the declaration inside the class body)

This does not appear to be justified by the standard, which instead says (http://eel.is/c++draft/temp.param#12.sentence-4) only: "A default template-argument shall not be specified in the template-parameter-lists of the definition of a member of a class template that appears outside of the member's class."

In particular, member templates of non-template classes *are* permitted to have default template arguments added after their declaration in the class, per the standard's rule.

Clang implements the rule as written in the standard, GCC and ICC implement the rule as written here. How is such implementation divergence usually documented?

Good catch. Looks like [User:Jwakely] spotted it in gcc back here bug 53856, but it was then fixed only for member types, not member functions as I just tested. I'll update this page to say member of class template. As far as notable implementation divergences, we put them under Notes heading, or write a little (note: see gcc bug 12346) when unobtrusive. --Cubbi (talk) 13:19, 1 December 2017 (PST)

[edit] Different template parameter name in different declarations

Is it allowed to redeclare a template with its parameters differently named? For example:

template <typename A> class Foo;
//...
template <typename B> class Foo { Foo() = default; }

My opinion is that it should be allowed. Another person thinks it should not. (See our discussion [1]) I think we should explicitly mention this whether or not it is allowed, since it is confusing. -- LittleFlower (talk) 22:50, 1 August 2018 (PDT)

[edit] Constant destruction?

The page says:
A template parameter object shall have constant destruction.

Does it mean that it obeys the rules of constant initialization and therefore it must be destroyed correspondingly? First time I see the term "constant destruction"
ticotico (talk) 12:31, 25 May 2020 (PDT)

https://eel.is/c++draft/expr.const#def:destruction,constant seems to be relevant. — Radix (talk) 13:09, 25 May 2020 (PDT)
An anchor added for "constant destruction". --Fruderica (talk) 22:56, 25 May 2020 (PDT)

[edit] "Constant" is far more readable than "non-type"

By "non-type" we can't immediately know what they are. I think we should applied the new terms thoroughly. --Fruderica (talk) 20:57, 16 April 2025 (PDT)

Managed to spot this talk edit before mass reverting, phew. I personally think we should keep the non-type naming because that's how existing literature works, and I don't think there will be any confusion with concept or variable template parameters, the same way that there's never been any confusion with template template parameters. I feel quite strongly about this, but I'm willing to accept being outvoted, so I will hold off on mass reverts myself until the start of next week (unless consensus says otherwise). --Ybab321 (talk) 04:10, 17 April 2025 (PDT)
I don't think confusion would be an argument, because I think a large portion of readers that comprehend non-type template parameter/argument treat "non-type" as some kind of prefix of proper nouns (cf. std::nontype). But after all, "non-type" is not literally descriptive, and thus I do believe that changing to "constant" would be an improvement for comprehensibility and new revisions of literature should adopt it. Also, I kept non-type in some places (e.g. cpp/language/acronyms), which should be sufficient, IMO. --Fruderica (talk) 05:41, 17 April 2025 (PDT)
That's a bold one, but that's their new name in the standard (btw I'd link directly to the paper, http://wg21.link/p2841r5 , not the editorial pull request) -- and I think it is a rare case where language-lawyerism improved terminology. --Cubbi (talk) 15:08, 17 April 2025 (PDT)
After the previous revert, I discussed with Xmcgcg, and my view is that since the standard had changed its name, users would eventually accept it over time, although it might be premature to modify the wiki now. --YexuanXiao (talk) 20:21, 17 April 2025 (PDT)
I think the counter-arguments made here are terribly weak, but I'm going to roll with the consensus --Ybab321 (talk) 03:44, 21 April 2025 (PDT)