Skip to content

Inconsistent spacing between "template" and "<" #53

Closed

Description

@sdutoit

From an email to cxxeditor@:

template<typename T>

or

template <typename T>

The standard as-is has 1494 instances of 'template<' that I can find trivially, and 2053 instances of 'template <'.

Activity

  1. sdutoit commented on Apr 15, 2013

    @sdutoit
    ContributorAuthor

    I intend to use template <typename T> throughout - if only because there are more instances of that style existing, and the choice is arbitrary.

  2. lichray commented on Aug 29, 2013

    @lichray
    Contributor

    I +1 for using typename in place of class in template parameter list wherever possible.

  3. PeterSommerlad commented on Aug 30, 2013

    @PeterSommerlad

    My +100 template is so "last millenium" :-)
    On 29.08.2013, at 23:42, Zhihao Yuan notifications@github.com wrote:

    I +1 for using typename in place of class in template parameter list wherever possible.

    —
    Reply to this email directly or view it on GitHub.

  4. PeterSommerlad commented on Aug 30, 2013

    @PeterSommerlad

    Or were you only talking about the space between template and < ???

  5. lichray commented on Aug 30, 2013

    @lichray
    Contributor

    The thread itself is talking about the spacing. I seldom see <typename T>'s usage in the standard, so I suddenly felt too excited...

  6. zygoloid commented on Jun 18, 2014

    @zygoloid
    Member

    Editorial meeting consensus: use template< not template < (41% vs 59%, but we prefer the former).
    Use class not typename unless the example is demonstrating that typename can be used, since class is 2-3 orders of magnitude more common.

  7. self-assigned this
    on Jun 18, 2014
  8. AlisdairM commented on Jul 6, 2016

    @AlisdairM
    Contributor

    Can we confirm the preference is:

    template<class T, template class<class U>>
    and not
    template <typename T,template class <typename U> >

    (space and keyword choice)

    I will perform a sweep of all library clauses after the Oulu papers land, and apply the preferred rule.
    Understood that this may miss the CD, but should be easily landed before ballot resolutions arrive.

    My preference would be template <typename T, template typename<typename U>> so it is a good job that I don't get to pick ;)

  9. tkoeppe commented on Jul 6, 2016

    @tkoeppe
    Contributor

    @AlisdairM: My understanding is that "space after comma" and "closing >>" are uncontroversial and desirable. On the other hand, both openings template< and template < appear in roughly equal numbers and should not be changed at this point.

    It's probably best to wait until all the motions have been merged unless you're happy to rebase.

  10. AlisdairM commented on Jul 6, 2016

    @AlisdairM
    Contributor

    I want to do whatever is required to close the issue - the legwork seems easy, but repetitive :)
    Yes, I definitely plan to wait till all the motions have landed, so that I am looking at the full text.

    I would prefer guidance to resolve one way or the other on the 'template <' vs. 'template<', but if the conclusion is that both are acceptable, I will look for local consistency in each clause, and leave it at that.

  11. FrankHB commented on Jul 11, 2016

    @FrankHB
    Contributor

    I don't like the idea to choose a style merely according to the amount of instances, unless there are no other reasons.

    Personally I prefer template< as we usually don't have any whitespace between identifier and lparen of function parameter list in a function declaration. Spaces are also rarely occurred before ( or < of function/template argument lists. This results a simpler rule: just avoid any space before the first token of function/template parameter/argument lists. The current preference of space fits to my flavor:)

    BTW, I've ever searched for some tools to format code in this style, but failed. Notably, clang-format had implemented the needed functionality about whitespace after template, but eventually rejected. The reviewer also mentioned the style in the standard. Perhaps they should reconsider it this time.
    See also http://stackoverflow.com/questions/34423615/cpp-template-spacing-using-clang-format-3-6-not-working-as-expected.

    Note I still prefer typename to ease some refactoring work, as template<typename T, template<typename> class C>. Some more tips:

    • Order is significant. Please note the phrase template class is not well-formed here...
    • I prefer >> because it looks tightly.
    • I don't keep optional parameter names in any parameter list, unless they are necessary (esp. for documentation). Proper naming is difficult.
    • I use class only when it should be a "class". For a template template-parameter, it must be a "class" rather than "typename" since ordinary types have no way to be higher-rank polymorphic in C++. Choosing permissive requirements of grammar is an effort to simplify the parser of a conforming implementation rather than direct encouragement to prefer class over typename.
  12. jwakely commented on Jul 11, 2016

    @jwakely
    Member

    I have a weak preference for template< without a space, just because it's slightly more compact and so gives us one more character spare. That way we might be able to fit something on one line that needed breaking (or ran into the margin) otherwise.

  13. added
    decision-requiredA decision of the editorial group (or the Project Editor) is required.
    on Nov 18, 2016
  14. added 2 commits that reference this issue on Dec 20, 2016
    b8195fd
    44266bf
  15. self-assigned this
    on Dec 20, 2016
  16. removed
    decision-requiredA decision of the editorial group (or the Project Editor) is required.
    on Dec 20, 2016
  17. jensmaurer commented on Mar 2, 2017

    @jensmaurer
    Member

    Editorial meeting consensus: Don't apply for C++17.

  18. added this to the milestone on Mar 2, 2017
  19. added 2 commits that reference this issue on Mar 5, 2017
    52fdab7
    d343e77
  20. burblebee commented on Mar 8, 2019

    @burblebee
    Contributor

    I'm reopening this because I ran into this while reviewing PR #2719, applied from P1458R1. I would like to see a consistent form for this, with guidance added to our Specification-Style-Guidelines.

  21. added
    decision-requiredA decision of the editorial group (or the Project Editor) is required.
    on Mar 8, 2019
  22. CaseyCarter commented on Mar 8, 2019

    @CaseyCarter
    Contributor

    FWIW, we use template< in the specification of the Library, but allow template < in some examples (IIRC) as a nod to the validity of both styles. I suspect it would simplify the editorial team's job if you instituted a blanket ban on template < so the CI could validate it.

  23. tkoeppe commented on Mar 9, 2019

    @tkoeppe
    Contributor

    @burblebee: Thanks for finding this. The guidance is clear (see above); I have finally updated the wiki to reflect this. Please apply the intended (no-space) formatting to this and all future wording changes.

  24. removed
    decision-requiredA decision of the editorial group (or the Project Editor) is required.
    on Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions