Skip to content

Commit

Permalink
STYLE: Prefer C++11 type alias over typedef
Browse files Browse the repository at this point in the history
== 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.
  • Loading branch information
hjmjohnson committed Feb 13, 2018
1 parent e8b997e commit 8c60e94
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 30 deletions.
20 changes: 10 additions & 10 deletions include/itkAdditiveGaussianNoiseMeshFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ public MeshToMeshFilter< TInput, TOutput >

public:

/** Standard class typedefs. */
typedef AdditiveGaussianNoiseMeshFilter Self;
typedef MeshToMeshFilter< TInput, TOutput > Superclass;
typedef SmartPointer< Self > Pointer;
typedef SmartPointer< const Self > ConstPointer;
/** Standard class type alias. */
using Self = AdditiveGaussianNoiseMeshFilter;
using Superclass = MeshToMeshFilter< TInput, TOutput >;
using Pointer = SmartPointer< Self >;
using ConstPointer = SmartPointer< const Self >;

typedef TInput InputMeshType;
typedef TOutput OutputMeshType;
typedef typename InputMeshType::Pointer InputMeshPointer;
typedef typename OutputMeshType::Pointer OutputMeshPointer;
using InputMeshType = TInput;
using OutputMeshType = TOutput;
using InputMeshPointer = typename InputMeshType::Pointer;
using OutputMeshPointer = typename OutputMeshType::Pointer;

/** Type for representing coordinates. */
typedef typename TInput::CoordRepType CoordRepType;
using CoordRepType = typename TInput::CoordRepType;

/** Method for creation through the object factory. */
itkNewMacro(Self);
Expand Down
10 changes: 5 additions & 5 deletions include/itkAdditiveGaussianNoiseMeshFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ void
AdditiveGaussianNoiseMeshFilter< TInputMesh, TOutputMesh >
::GenerateData(void)
{
typedef typename TInputMesh::PointsContainer InputPointsContainer;
typedef typename TOutputMesh::PointsContainer OutputPointsContainer;
using InputPointsContainer = typename TInputMesh::PointsContainer;
using OutputPointsContainer = typename TOutputMesh::PointsContainer;

typedef typename TInputMesh::PointsContainerConstPointer InputPointsContainerConstPointer;
typedef typename TOutputMesh::PointsContainerPointer OutputPointsContainerPointer;
using InputPointsContainerConstPointer = typename TInputMesh::PointsContainerConstPointer;
using OutputPointsContainerPointer = typename TOutputMesh::PointsContainerPointer;

const InputMeshType *inputMesh = this->GetInput();
OutputMeshPointer outputMesh = this->GetOutput();
Expand Down Expand Up @@ -82,7 +82,7 @@ AdditiveGaussianNoiseMeshFilter< TInputMesh, TOutputMesh >

unsigned int maxDimension = TInputMesh::MaxTopologicalDimension;

typedef itk::Statistics::NormalVariateGenerator GeneratorType;
using GeneratorType = itk::Statistics::NormalVariateGenerator;
GeneratorType::Pointer generator = GeneratorType::New();
generator->Initialize( this->m_Seed );

Expand Down
12 changes: 6 additions & 6 deletions include/itkAdditiveGaussianNoiseQuadEdgeMeshFilter.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ class AdditiveGaussianNoiseQuadEdgeMeshFilter:
public QuadEdgeMeshToQuadEdgeMeshFilter< TInputMesh, TOutputMesh >
{
public:
/** Standard class typedefs. */
typedef AdditiveGaussianNoiseQuadEdgeMeshFilter Self;
typedef QuadEdgeMeshToQuadEdgeMeshFilter< TInputMesh, TOutputMesh > Superclass;
typedef SmartPointer< Self > Pointer;
typedef SmartPointer< const Self > ConstPointer;
/** Standard class type alias. */
using Self = AdditiveGaussianNoiseQuadEdgeMeshFilter;
using Superclass = QuadEdgeMeshToQuadEdgeMeshFilter< TInputMesh, TOutputMesh >;
using Pointer = SmartPointer< Self >;
using ConstPointer = SmartPointer< const Self >;

/** Type for representing coordinates. */
typedef typename TInputMesh::CoordRepType CoordRepType;
using CoordRepType = typename TInputMesh::CoordRepType;

/** Method for creation through the object factory. */
itkNewMacro(Self);
Expand Down
2 changes: 1 addition & 1 deletion include/itkAdditiveGaussianNoiseQuadEdgeMeshFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ AdditiveGaussianNoiseQuadEdgeMeshFilter< TInputMesh, TOutputMesh >
typename TOutputMesh::PointsContainer::Iterator it =
outputMesh->GetPoints()->Begin();

typedef itk::Statistics::NormalVariateGenerator GeneratorType;
using GeneratorType = itk::Statistics::NormalVariateGenerator;
GeneratorType::Pointer generator = GeneratorType::New();
generator->Initialize( this->m_Seed );

Expand Down
8 changes: 4 additions & 4 deletions test/itkAdditiveGaussianNoiseMeshFilterTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ int
itkAdditiveGaussianNoiseMeshFilterTest(int itkNotUsed(argc), char * itkNotUsed(argv) [])
{

typedef double TPixel;
using TPixel = double;
const unsigned int Dimension = 3;

//////////////
// Typedefs //
//////////////

typedef itk::Mesh< TPixel, Dimension > TMesh;
typedef itk::RegularSphereMeshSource< TMesh > TSphere;
typedef itk::AdditiveGaussianNoiseMeshFilter< TMesh > TNoise;
using TMesh = itk::Mesh< TPixel, Dimension >;
using TSphere = itk::RegularSphereMeshSource< TMesh >;
using TNoise = itk::AdditiveGaussianNoiseMeshFilter< TMesh >;

////////////////
// Parameters //
Expand Down
8 changes: 4 additions & 4 deletions test/itkAdditiveGaussianNoiseQuadEdgeMeshFilterTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ int
itkAdditiveGaussianNoiseQuadEdgeMeshFilterTest(int itkNotUsed(argc), char * itkNotUsed(argv) [])
{

typedef double TPixel;
using TPixel = double;
const unsigned int Dimension = 3;

//////////////
// Typedefs //
//////////////

typedef itk::QuadEdgeMesh< TPixel, Dimension > TMesh;
typedef itk::RegularSphereMeshSource< TMesh > TSphere;
typedef itk::AdditiveGaussianNoiseQuadEdgeMeshFilter< TMesh > TNoise;
using TMesh = itk::QuadEdgeMesh< TPixel, Dimension >;
using TSphere = itk::RegularSphereMeshSource< TMesh >;
using TNoise = itk::AdditiveGaussianNoiseQuadEdgeMeshFilter< TMesh >;

////////////////
// Parameters //
Expand Down

0 comments on commit 8c60e94

Please sign in to comment.