Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Scott Snyder
coding-rules
Commits
80b80d85
Commit
80b80d85
authored
Nov 21, 2017
by
scott snyder
Browse files
recommend range-based for. Bump version to 0.5.
parent
ef2608f4
Changes
1
Hide whitespace changes
Inline
Side-by-side
rules.org
View file @
80b80d85
#+
MACRO
:
version
0.
4
#+
LaTeX_HEADER
:
\
def
\
rulesversion
{
0.
4
}
#+
MACRO
:
version
0.
5
#+
LaTeX_HEADER
:
\
def
\
rulesversion
{
0.
5
}
#+
TITLE
:
ATLAS
C
++
coding
guidelines
,
version
{{{
version
}}}
#+
AUTHOR
:
Shaun
Roe
(
CERN
),
Scott
Snyder
(
BNL
),
and
the
former
ATLAS
Quality
Control
group
#+
EMAIL
:
Correspondence
to
snyder
@
bnl
.
gov
.
...
...
@@ -433,6 +433,34 @@ vector<int> x; // Missing std!
change
the
loop
variable
within
the
loop
body
rather
than
inside
the
expression
executed
after
each
iteration
.
-
*
Prefer
range
-
based
for
loops
.*
[<<
prefer
-
range
-
based
-
for
>>]
C
++
11
introduced
the
`
range
-
based
for
'. Prefer using this to a loop
with explicit iterators; that is, prefer:
#+BEGIN_EXAMPLE
std::vector<int> v = ...;
for (int x : v) {
doSomething (x);
}
#+END_EXAMPLE
to
#+BEGIN_EXAMPLE
std::vector<int> v = ...;
for (std::vector<int>::const_iterator it = v.begin();
it != v.end();
++it)
{
doSomething (*it);
}
#+END_EXAMPLE
In some cases you can'
t
make
this
replacement
;
for
example
,
if
you
need
to
call
methods
on
the
iterator
itself
,
or
you
need
to
manage
multiple
iterators
within
the
loop
.
But
most
simple
loops
over
STL
ranges
are
most
simply
written
with
a
range
-
based
for
.
-
*
All
switch
statements
must
have
a
default
clause
.*
[<<
switch
-
default
>>]
In
some
cases
the
default
clause
can
never
be
reached
because
there
...
...
@@ -2848,6 +2876,7 @@ The comment includes the fact that it is the perpendicular distance.
** Version 0.5
- Add an initial set of guidelines for AthenaMT.
- Add recommendation to prefer range-based for.
** Version 0.4
- Minor updates: we'
re
now
using
c
++
14.
Add
note
about
implicit
fallthrough
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment