You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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 ;)
@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.
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.
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:)
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.
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.
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.
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.
@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.
Activity
sdutoit commentedon Apr 15, 2013
I intend to use
template <typename T>
throughout - if only because there are more instances of that style existing, and the choice is arbitrary.lichray commentedon Aug 29, 2013
I +1 for using
typename
in place ofclass
in template parameter list wherever possible.PeterSommerlad commentedon Aug 30, 2013
My +100 template is so "last millenium" :-)
On 29.08.2013, at 23:42, Zhihao Yuan notifications@github.com wrote:
PeterSommerlad commentedon Aug 30, 2013
Or were you only talking about the space between template and < ???
lichray commentedon Aug 30, 2013
The thread itself is talking about the spacing. I seldom see
<typename T>
's usage in the standard, so I suddenly felt too excited...zygoloid commentedon Jun 18, 2014
Editorial meeting consensus: use
template<
nottemplate <
(41% vs 59%, but we prefer the former).Use
class
nottypename
unless the example is demonstrating thattypename
can be used, sinceclass
is 2-3 orders of magnitude more common.AlisdairM commentedon Jul 6, 2016
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 ;)
tkoeppe commentedon Jul 6, 2016
@AlisdairM: My understanding is that "space after comma" and "closing
>>
" are uncontroversial and desirable. On the other hand, both openingstemplate<
andtemplate <
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.
AlisdairM commentedon Jul 6, 2016
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.
FrankHB commentedon Jul 11, 2016
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 aftertemplate
, 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, astemplate<typename T, template<typename> class C>
. Some more tips:template class
is not well-formed here...>>
because it looks tightly.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 preferclass
overtypename
.jwakely commentedon Jul 11, 2016
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.2 remaining items
jensmaurer commentedon Mar 2, 2017
Editorial meeting consensus: Don't apply for C++17.
Harmonize spacing for template headers.
Harmonize spacing for template headers.
burblebee commentedon Mar 8, 2019
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.
CaseyCarter commentedon Mar 8, 2019
FWIW, we use
template<
in the specification of the Library, but allowtemplate <
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 ontemplate <
so the CI could validate it.tkoeppe commentedon Mar 9, 2019
@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.