lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] [lmi-commits] master 84cd25c 1/2: Remove stray spaces in templ


From: Vadim Zeitlin
Subject: Re: [lmi] [lmi-commits] master 84cd25c 1/2: Remove stray spaces in template declarations and specializations
Date: Fri, 3 Mar 2017 20:06:55 +0100

On Fri, 3 Mar 2017 15:42:15 +0000 Greg Chicares <address@hidden> wrote:

GC> But let me give the rationale from the guidelines I followed here
GC> (copyrighted, but a short quote is fair use):
GC> 
GC> C++ Coding Guidelines
GC> Copyright © 2001 David Abrahams and Nathan Myers
GC> 
GC> "Omit spaces in template instantiations. Spaces are allowed between 
arguments
GC> to template declarations. Unnecessary spaces in type names weaken their
GC> recognizability as a syntactic unit. Instantiations with names that are too
GC> unwieldy in this form should be typedef'ed."
GC> 
GC> Thus, they'd write
GC>   template<typename A, typename B> class C{};
GC> but
GC>   std::pair<A,B> a_b_pair;
GC> The difference between that and
GC>   std::make_pair(a0, b0);
GC> is that 'std::pair<A,B>' is a type, and I'm inclined to accept their
GC> suggestion that omitting spaces makes it easier to recognize as a
GC> single syntactic unit.

 Thanks, I see their point now. I admit I am still not swayed by it because
IMO C declaration syntax won't be made more (or less) clear by removing (or
adding) a single space, this is completely negligible compared to the other
sources of complexity in it. But this is subjective, of course.

 Objectively, I'd just like to note that:

1. I strongly prefer to use "auto" instead of longer type names, which
   definitely includes any templates with more than one parameter, so
   I'm never going to use std::pair<A,B> for a local variable anyhow.
2. I do almost always define aliases for any template instantiations, so 
   the only place the type is going to appear in my code is on the RHS of
   "using ab_pair = std::pair<A, B>" where it's already easily recognized
   as a single syntax unit.

 I'm not sure what's the lmi policy about these 2 points however, it might
be worth it to add a few words to style.html when you have a moment.

 Thanks in advance,
VZ


reply via email to

[Prev in Thread] Current Thread [Next in Thread]