Commit 80b80d85 authored by scott snyder's avatar scott snyder
Browse files

recommend range-based for. Bump version to 0.5.

parent ef2608f4
#+MACRO: version 0.4 #+MACRO: version 0.5
#+LaTeX_HEADER: \def\rulesversion{0.4} #+LaTeX_HEADER: \def\rulesversion{0.5}
#+TITLE: ATLAS C++ coding guidelines, version {{{version}}} #+TITLE: ATLAS C++ coding guidelines, version {{{version}}}
#+AUTHOR: Shaun Roe (CERN), Scott Snyder (BNL), and the former ATLAS Quality Control group #+AUTHOR: Shaun Roe (CERN), Scott Snyder (BNL), and the former ATLAS Quality Control group
#+EMAIL: Correspondence to snyder@bnl.gov. #+EMAIL: Correspondence to snyder@bnl.gov.
...@@ -433,6 +433,34 @@ vector<int> x; // Missing std! ...@@ -433,6 +433,34 @@ vector<int> x; // Missing std!
change the loop variable within the loop body rather than inside the change the loop variable within the loop body rather than inside the
expression executed after each iteration. 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>>] - *All switch statements must have a default clause.* [<<switch-default>>]
In some cases the default clause can never be reached because there 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. ...@@ -2848,6 +2876,7 @@ The comment includes the fact that it is the perpendicular distance.
** Version 0.5 ** Version 0.5
- Add an initial set of guidelines for AthenaMT. - Add an initial set of guidelines for AthenaMT.
- Add recommendation to prefer range-based for.
** Version 0.4 ** Version 0.4
- Minor updates: we're now using c++14. Add note about implicit fallthrough - Minor updates: we're now using c++14. Add note about implicit fallthrough
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment