Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with upstream. #10

Closed
wants to merge 4 commits into from
Closed

Sync with upstream. #10

wants to merge 4 commits into from

Conversation

jhlegarreta
Copy link
Member

Pull upstream changes.

@jhlegarreta jhlegarreta mentioned this pull request Oct 20, 2018
hjmjohnson pushed a commit that referenced this pull request Nov 4, 2018
ENH: Providing ITKv5 updates for C++11
An ITK-v4 branch was created to clarify that from this point the master relies on ITK-v5 (mostly because of the c++11 requirements)
STYLE: Use auto for variable creation

This check is responsible for using the auto type specifier for variable
declarations to improve code readability and maintainability.

The auto type specifier will only be introduced in situations where the
variable type matches the type of the initializer expression. In other words
auto should deduce the same type that was originally spelled in the source

cd /Users/johnsonhj/Dashboard/src/ITK-clangtidy/
run-clang-tidy.py -checks=-*,modernize-use-auto  -header-filter=.* -fix

use auto when declaring iterators
use auto when initializing with a cast to avoid duplicating the type name
use auto when initializing with a template cast to avoid duplicating the type name
use auto when initializing with new to avoid duplicating the type name

SRCDIR=/Users/johnsonhj/Dashboard/src/ITK #My local SRC
BLDDIR=/Users/johnsonhj/Dashboard/src/ITK-clangtidy/ #My local BLD

PERF: Replace explicit return calls of constructor

Replaces explicit calls to the constructor in a return with a braced
initializer list. This way the return type is not needlessly duplicated in the
function definition and the return statement.

SRCDIR=/Users/johnsonhj/Dashboard/src/ITK #My local SRC
BLDDIR=/Users/johnsonhj/Dashboard/src/ITK-clangtidy/ #My local BLD

cd /Users/johnsonhj/Dashboard/src/ITK-clangtidy/
run-clang-tidy.py -checks=-*,modernize-return-braced-init-list  -header-filter=.* -fix

PERF: Allow compiler to choose best way to construct a copy

With move semantics added to the language and the standard library updated with
move constructors added for many types it is now interesting to take an
argument directly by value, instead of by const-reference, and then copy. This
check allows the compiler to take care of choosing the best way to construct
the copy.

The transformation is usually beneficial when the calling code passes an rvalue
and assumes the move construction is a cheap operation. This short example
illustrates how the construction of the value happens:

class Foo {
 public:
-  Foo(const std::string &Copied, const std::string &ReadOnly)
-    : Copied(Copied), ReadOnly(ReadOnly) {}
+  Foo(std::string Moved, const std::string &ReadOnly)
+    : Copied(std::move(Moved)), ReadOnly(ReadOnly) {}
 private:
   private:
   std::string Copied;
   const std::string &ReadOnly;
};

SRCDIR=/Users/johnsonhj/Dashboard/src/ITK #My local SRC
BLDDIR=/Users/johnsonhj/Dashboard/src/ITK-clangtidy/ #My local BLD

cd /Users/johnsonhj/Dashboard/src/ITK-clangtidy/
run-clang-tidy.py -checks=-*,modernize-pass-by-value  -header-filter=.* -fix

STYLE: Use range-based loops from C++11

Used as a more readable equivalent to the traditional for loop operating
over a range of values, such as all elements in a container, in the
forward direction.

====
Range based loopes are more explicit for only computing the
end location once for containers.

for ( ImageIORegion::IndexType::const_iterator i = this->GetIndex().begin();
  i != this->GetIndex().end(); //<- NOTE: Compute end every loop iteration
  ++i )

for (long i : this->GetIndex()) //<- NOTE: Implicitly only compute end once

====
Explicitly reduce the amount of index computations: (The compiler
probably does this too)

for(int i = 0; i < 11; i++)
  {
  pos[0] = testPoints[i][0];
  pos[1] = testPoints[i][1];
                    ^^^^

for(auto & testPoint : testPoints)
  {
  pos[0] = testPoint[0];
  pos[1] = testPoint[1];

====

SRCDIR=/Users/johnsonhj/Dashboard/src/ITK #My local SRC
BLDDIR=/Users/johnsonhj/Dashboard/src/ITK-clangtidy/ #My local BLD

cd /Users/johnsonhj/Dashboard/src/ITK-clangtidy/
run-clang-tidy.py -checks=-*,modernize-loop-convert  -header-filter=.* -fix
Use static constexpr directly now that C++11 conformance
is required by all compilers.

:%s/itkStaticConstMacro *( *\([^,]*\),[ \_s]*\([^,]*\),\_s*\([^)]*\)) */static constexpr \2 \1 = \3/ge
== http://en.cppreference.com/w/cpp/language/type_alias ==

Type alias is a name that refers to a previously defined type (similar
to typedef).

A type alias declaration introduces a name which can be used as a
synonym for the type denoted by type-id. It does not introduce a new
type and it cannot change the meaning of an existing type name. There is
no difference between a type alias declaration and typedef declaration.
This declaration may appear in block scope, class scope, or namespace
scope.

== https://www.quora.com/Is-using-typedef-in-C++-considered-a-bad-practice ==

While typedef is still available for backward compatibility, the new
Type Alias syntax 'using Alias = ExistingLongName;' is more consistent
with the flow of C++ than the old typedef syntax 'typedef
ExistingLongName Alias;', and it also works for templates (Type alias,
alias template (since C++11)), so leftover 'typedef' aliases will differ
in style from any alias templates.
Use constexpr for constant numeric literals.
{
public:
ITK_DISALLOW_COPY_AND_ASSIGN(GPUSmoothingRecursiveYvvGaussianImageFilterKernel);
ITK_DISALLOW_COPY_AND_ASSIGN(GPUSmoothingRecursiveYvvGaussianImageFilter);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is also being fixed in this PR.

@jhlegarreta
Copy link
Member Author

Closing this and submitting a new PR since while trying to rebase on master to pull the new commits things messed up

@jhlegarreta jhlegarreta closed this Nov 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants