Skip to content

Commit 66e5d6b

Browse files
committed
STYLE: Prefer C++11 type alias over typedef
== 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. ======= First pass regex manual changes ================== cat > /tmp/typdef_vim_script.vim << EOF :%s/typedef *\(.*<\_s*.*[>,]\_s*.*[><,]\_s*.*[><,]\_s*.*[><,]\_s*.*[><,]\_s*.*[^>]>\)\_s *\([A-Za-z0-9][A-Za-z0-9]*\);\{-};/using \2 = \1;/ge :%s/typedef *\(.*<\_s*.*[><,]\_s*.*[><,]\_s*.*[><,]\_s*.*[><,]\_s*.*[^>]>\)\_s *\([A-Za-z0-9][A-Za-z0-9]*\);\{-};/using \2 = \1;/ge :%s/typedef *\(.*<\_s*.*[><,]\_s*.*[><,]\_s*.*[><,]\_s*.*[^>]>\)\_s *\([A-Za-z0-9][A-Za-z0-9]*\);\{-};/using \2 = \1;/ge :%s/typedef *\(.*<\_s*.*[><,]\_s*.*[><,]\_s*.*[^>]>\)\_s *\([A-Za-z0-9][A-Za-z0-9]*\);\{-};/using \2 = \1;/ge :%s/typedef *\(.*<\_s*.*[><,]\_s*.*[^>]>\)\_s *\([A-Za-z0-9][A-Za-z0-9]*\);\{-};/using \2 = \1;/ge :%s/typedef *\(.*<\_s*.*[^>]>\)\_s *\([A-Za-z0-9][A-Za-z0-9]*\);\{-};/using \2 = \1;/ge :%s/\*\(.*\) typedef\(s*\)\(.*\)\*/*\1 type alias\3*/ge :%s/\*\*\(.*\) typedef\(s*\)\(.*\)/**\1 type alias\3/ge :%s/\/\/\(.*\)typedefs/\/\/\1type alias/ge :%s/typedef *\(.*<\_s*.*,\_s*.*,\_s*[^>]*>\) *\([A-Za-z0-9][A-Za-z0-9]*\);\{-};/using \2 = \1;/ge :%s/\/\/\(.*\)typedefs/\/\/\1type alias/ge :%s/typedef *\(.*<\_s*.*[>,]\_s.*[^>]>\)\_s *\([A-Za-z0-9][A-Za-z0-9]*\);\{-};/using \2 = \1;/ge :%s/\*\(.*\) typedef\(s*\)\(.*\)\*/*\1 type alias\3*/ge :%s/\*\*\(.*\) typedef\(s*\)\(.*\)/**\1 type alias\3/ge :%s/typedef *\(.*[><,]*\_s*.*[><,]\_s.*[^>]>\)\_s *\([A-Za-z0-9][A-Za-z0-9]*\);\{-};/using \2 = \1;/ge :%s/typedef *\(.*<\_s*.*[>,]\_s*.*[><,]\_s*.*[><,]\_s*.*[^>]>\)\_s *\([A-Za-z0-9][A-Za-z0-9]*\);\{-};/using \2 = \1;/ge :%s/typedef *\(.*<\_s*.*[>,]\_s*.*[><,]\_s*.*[><,]\_s*.*[><,]\_s*.*[><,]\_s*.*[^>]>\)\_s *\([A-Za-z0-9][A-Za-z0-9]*\);\{-};/using \2 = \1;/ge :%s/typedef  *\(.*\) * \([a-zA-Z0-9]*\);/using \2 = \1;/g :%s/typedef *\(.*<\_s*.*,\n[^>]*>\) *\([A-Za-z0-9][A-Za-z0-9]*\);\{-};/using \2 = \1;/ge :%s/typedef *\(.*<\_s*.*,.*>\{-}>\) *\([A-Za-z0-9][A-Za-z0-9]*\);\{-};/using \2 = \1;/ge :%s/\( *\)typedef *\(.*<.*>\)\_s\( *\)\([A-Za-z0-9][A-Za-z0-9]*\);\{-};/\1using \4 =\r\1 \2;/ge :%s/typedef support\(\.*\)/type alias support/ge :%s/ *;/;/ge :w :q EOF for ff in $(git grep -l "typedef" |fgrep -v ThirdParty |head -n 1500); do vim -S /tmp/typdef_vim_script.vim $ff; done clang-tidy -header-filter=.* \ -checks=-*,modernize-use-using \ -fix -p=~/Dashboard/src/ITK-clangtidy \ $(git grep -l typedef |fgrep -v ThirdParty|fgrep "cxx") Change-Id: I7d121a71b220e74337ec7626c6b4f53b61c64c53
1 parent d0610e3 commit 66e5d6b

4,144 files changed

Lines changed: 49924 additions & 51120 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Documentation/Doxygen/NeighborhoodIterators.dox

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ have been omitted for clarity. )
6565

6666

6767
\code
68-
1 typedef itk::Image<float, 2> ImageType;
69-
2 typedef itk::SmartNeighborhoodIterator<ImageType> NeighborhoodIterator;
70-
3 typedef itk::ImageRegionIterator<ImageType> ImageIterator;
68+
1 using ImageType = itk::Image<float, 2>;
69+
2 using NeighborhoodIterator = itk::SmartNeighborhoodIterator<ImageType>;
70+
3 using ImageIterator = itk::ImageRegionIterator<ImageType>;
7171
4
7272
5 ImageType::Pointer input_image = GetImageSomehow();
7373
6 ImageType::Pointer output_image = GetImageSomehow();
@@ -98,7 +98,7 @@ Note that the computational work is confined to lines 18-26. The code is also
9898
completely generalized for multiple dimensions. For example, changing line 1
9999
to:
100100
\code
101-
1 typedef itk::Image<float, 5> ImageType;
101+
1 using ImageType = itk::Image<float, 5>;
102102
\endcode
103103
produces an averaging filter for five-dimensional images.
104104

@@ -185,7 +185,7 @@ Rewriting the inner product code using this approach looks like the following.
185185
omitting some template parameters for simplicity.)
186186

187187
\code
188-
typedef NeighborhoodAlgorithm::ImageBoundaryFacesCalculator RegionFinderType;
188+
using RegionFinderType = NeighborhoodAlgorithm::ImageBoundaryFacesCalculator;
189189

190190
LaPlacianOperator<double, InputImageType::ImageDimension> OP;
191191

Examples/DataRepresentation/Containers/TreeContainer.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ int main(int, char* [])
6363

6464

6565
// Software Guide : BeginCodeSnippet
66-
typedef int NodeType;
67-
typedef itk::TreeContainer<NodeType> TreeType;
66+
using NodeType = int;
67+
using TreeType = itk::TreeContainer<NodeType>;
6868
TreeType::Pointer tree = TreeType::New();
6969
// Software Guide : EndCodeSnippet
7070

@@ -262,8 +262,8 @@ int main(int, char* [])
262262

263263

264264
// Software Guide : BeginCodeSnippet
265-
typedef itk::TreeIteratorBase<TreeType> IteratorType;
266-
typedef itk::TreeIteratorClone<IteratorType> IteratorCloneType;
265+
using IteratorType = itk::TreeIteratorBase<TreeType>;
266+
using IteratorCloneType = itk::TreeIteratorClone<IteratorType>;
267267
IteratorCloneType anotherChildItClone = childIt;
268268
// Software Guide : EndCodeSnippet
269269

Examples/DataRepresentation/Image/Image1.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ int main(int, char *[])
4545
// Software Guide : EndLatex
4646
//
4747
// Software Guide : BeginCodeSnippet
48-
typedef itk::Image< unsigned short, 3 > ImageType;
48+
using ImageType = itk::Image< unsigned short, 3 >;
4949
// Software Guide : EndCodeSnippet
5050

5151

Examples/DataRepresentation/Image/Image2.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ int main( int , char * argv[])
3939
// Software Guide : EndLatex
4040

4141
// Software Guide : BeginCodeSnippet
42-
typedef unsigned char PixelType;
42+
using PixelType = unsigned char;
4343
const unsigned int Dimension = 3;
4444

45-
typedef itk::Image< PixelType, Dimension > ImageType;
45+
using ImageType = itk::Image< PixelType, Dimension >;
4646
// Software Guide : EndCodeSnippet
4747

4848
// Software Guide : BeginLatex
@@ -64,7 +64,7 @@ int main( int , char * argv[])
6464
// Software Guide : EndLatex
6565

6666
// Software Guide : BeginCodeSnippet
67-
typedef itk::ImageFileReader< ImageType > ReaderType;
67+
using ReaderType = itk::ImageFileReader< ImageType >;
6868
// Software Guide : EndCodeSnippet
6969

7070
// Software Guide : BeginLatex

Examples/DataRepresentation/Image/Image3.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
int main(int, char *[])
3737
{
3838
// First the image type should be declared
39-
typedef itk::Image< unsigned short, 3 > ImageType;
39+
using ImageType = itk::Image< unsigned short, 3 >;
4040

4141
// Then the image object can be created
4242
ImageType::Pointer image = ImageType::New();

Examples/DataRepresentation/Image/Image4.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ static itk::Image< unsigned short, 3 >::IndexType GetIndexFromMouseClick()
7979
int main(int, char *[])
8080
{
8181
const unsigned int Dimension=3;
82-
typedef itk::Image< unsigned short, Dimension > ImageType;
82+
using ImageType = itk::Image< unsigned short, Dimension >;
8383
ImageType::Pointer image = ImageType::New();
8484

8585
const ImageType::SizeType size = {{ 200, 200, 200}}; //Size along {X,Y,Z}
@@ -255,7 +255,7 @@ int main(int, char *[])
255255
// Software Guide : EndLatex
256256

257257
// Software Guide : BeginCodeSnippet
258-
typedef itk::Point< double, ImageType::ImageDimension > PointType;
258+
using PointType = itk::Point< double, ImageType::ImageDimension >;
259259
// Software Guide : EndCodeSnippet
260260

261261
// Software Guide : BeginLatex
@@ -383,7 +383,7 @@ int main(int, char *[])
383383
// SoftwareGuide : EndLatex
384384

385385
// Software Guide : BeginCodeSnippet
386-
typedef itk::Matrix<double, Dimension, Dimension> MatrixType;
386+
using MatrixType = itk::Matrix<double, Dimension, Dimension>;
387387
MatrixType SpacingMatrix;
388388
SpacingMatrix.Fill( 0.0F );
389389

@@ -396,7 +396,7 @@ int main(int, char *[])
396396
image->GetDirection();
397397
const ImageType::PointType &ImageOrigin = image->GetOrigin();
398398

399-
typedef itk::Vector< double, Dimension > VectorType;
399+
using VectorType = itk::Vector< double, Dimension >;
400400
VectorType LeftEyeIndexVector;
401401
LeftEyeIndexVector[0]= LeftEyeIndex[0];
402402
LeftEyeIndexVector[1]= LeftEyeIndex[1];

Examples/DataRepresentation/Image/Image5.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ int main(int argc, char * argv[])
6363
// Software Guide : EndLatex
6464

6565
// Software Guide : BeginCodeSnippet
66-
typedef unsigned char PixelType;
66+
using PixelType = unsigned char;
6767
const unsigned int Dimension = 3;
6868

69-
typedef itk::Image< PixelType, Dimension > ImageType;
69+
using ImageType = itk::Image< PixelType, Dimension >;
7070
// Software Guide : EndCodeSnippet
7171

7272
// Software Guide : BeginLatex
@@ -79,7 +79,7 @@ int main(int argc, char * argv[])
7979
// Software Guide : EndLatex
8080

8181
// Software Guide : BeginCodeSnippet
82-
typedef itk::ImportImageFilter< PixelType, Dimension > ImportFilterType;
82+
using ImportFilterType = itk::ImportImageFilter< PixelType, Dimension >;
8383
// Software Guide : EndCodeSnippet
8484

8585
// Software Guide : BeginLatex
@@ -237,7 +237,7 @@ int main(int argc, char * argv[])
237237
// Software Guide : EndLatex
238238

239239
// Software Guide : BeginCodeSnippet
240-
typedef itk::ImageFileWriter< ImageType > WriterType;
240+
using WriterType = itk::ImageFileWriter< ImageType >;
241241
WriterType::Pointer writer = WriterType::New();
242242

243243
writer->SetFileName( argv[1] );

Examples/DataRepresentation/Image/ImageAdaptor1.cxx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
class CastPixelAccessor
6060
{
6161
public:
62-
typedef unsigned char InternalType;
63-
typedef float ExternalType;
62+
using InternalType = unsigned char;
63+
using ExternalType = float;
6464

6565
static void Set(InternalType & output, const ExternalType & input)
6666
{
@@ -102,11 +102,11 @@ int main( int argc, char *argv[] )
102102

103103

104104
// Software Guide : BeginCodeSnippet
105-
typedef unsigned char InputPixelType;
105+
using InputPixelType = unsigned char;
106106
const unsigned int Dimension = 2;
107-
typedef itk::Image< InputPixelType, Dimension > ImageType;
107+
using ImageType = itk::Image< InputPixelType, Dimension >;
108108

109-
typedef itk::ImageAdaptor< ImageType, CastPixelAccessor > ImageAdaptorType;
109+
using ImageAdaptorType = itk::ImageAdaptor< ImageType, CastPixelAccessor >;
110110
ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
111111
// Software Guide : EndCodeSnippet
112112

@@ -119,7 +119,7 @@ int main( int argc, char *argv[] )
119119

120120

121121
// Software Guide : BeginCodeSnippet
122-
typedef itk::ImageFileReader< ImageType > ReaderType;
122+
using ReaderType = itk::ImageFileReader< ImageType >;
123123
ReaderType::Pointer reader = ReaderType::New();
124124
// Software Guide : EndCodeSnippet
125125

@@ -151,7 +151,7 @@ int main( int argc, char *argv[] )
151151

152152

153153
// Software Guide : BeginCodeSnippet
154-
typedef itk::ImageRegionIteratorWithIndex< ImageAdaptorType > IteratorType;
154+
using IteratorType = itk::ImageRegionIteratorWithIndex< ImageAdaptorType >;
155155
IteratorType it( adaptor, adaptor->GetBufferedRegion() );
156156

157157
double sum = 0.0;

Examples/DataRepresentation/Image/ImageAdaptor2.cxx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
class RedChannelPixelAccessor
5353
{
5454
public:
55-
typedef itk::RGBPixel<float> InternalType;
56-
typedef float ExternalType;
55+
using InternalType = itk::RGBPixel<float>;
56+
using ExternalType = float;
5757

5858
static ExternalType Get( const InternalType & input )
5959
{
@@ -100,12 +100,12 @@ int main( int argc, char *argv[] )
100100

101101

102102
// Software Guide : BeginCodeSnippet
103-
typedef RedChannelPixelAccessor::InternalType InputPixelType;
103+
using InputPixelType = RedChannelPixelAccessor::InternalType;
104104
const unsigned int Dimension = 2;
105-
typedef itk::Image< InputPixelType, Dimension > ImageType;
105+
using ImageType = itk::Image< InputPixelType, Dimension >;
106106

107-
typedef itk::ImageAdaptor< ImageType,
108-
RedChannelPixelAccessor > ImageAdaptorType;
107+
using ImageAdaptorType = itk::ImageAdaptor< ImageType,
108+
RedChannelPixelAccessor >;
109109

110110
ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
111111
// Software Guide : EndCodeSnippet
@@ -120,7 +120,7 @@ int main( int argc, char *argv[] )
120120

121121

122122
// Software Guide : BeginCodeSnippet
123-
typedef itk::ImageFileReader< ImageType > ReaderType;
123+
using ReaderType = itk::ImageFileReader< ImageType >;
124124
ReaderType::Pointer reader = ReaderType::New();
125125
// Software Guide : EndCodeSnippet
126126

@@ -144,13 +144,13 @@ int main( int argc, char *argv[] )
144144

145145

146146
// Software Guide : BeginCodeSnippet
147-
typedef itk::Image< unsigned char, Dimension > OutputImageType;
148-
typedef itk::RescaleIntensityImageFilter< ImageAdaptorType,
149-
OutputImageType
150-
> RescalerType;
147+
using OutputImageType = itk::Image< unsigned char, Dimension >;
148+
using RescalerType = itk::RescaleIntensityImageFilter<
149+
ImageAdaptorType,
150+
OutputImageType >;
151151

152152
RescalerType::Pointer rescaler = RescalerType::New();
153-
typedef itk::ImageFileWriter< OutputImageType > WriterType;
153+
using WriterType = itk::ImageFileWriter< OutputImageType >;
154154
WriterType::Pointer writer = WriterType::New();
155155
// Software Guide : EndCodeSnippet
156156

@@ -213,8 +213,8 @@ int main( int argc, char *argv[] )
213213
class GreenChannelPixelAccessor
214214
{
215215
public:
216-
typedef itk::RGBPixel<float> InternalType;
217-
typedef float ExternalType;
216+
using InternalType = itk::RGBPixel<float>;
217+
using ExternalType = float;
218218

219219
static ExternalType Get( const InternalType & input )
220220
{
@@ -237,8 +237,8 @@ int main( int argc, char *argv[] )
237237
class BlueChannelPixelAccessor
238238
{
239239
public:
240-
typedef itk::RGBPixel<float> InternalType;
241-
typedef float ExternalType;
240+
using InternalType = itk::RGBPixel<float>;
241+
using ExternalType = float;
242242

243243
static ExternalType Get( const InternalType & input )
244244
{

Examples/DataRepresentation/Image/ImageAdaptor3.cxx

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ namespace itk
6666
class VectorPixelAccessor
6767
{
6868
public:
69-
typedef itk::CovariantVector<float,2> InternalType;
70-
typedef float ExternalType;
69+
using InternalType = itk::CovariantVector<float,2>;
70+
using ExternalType = float;
7171

7272
VectorPixelAccessor() : m_Index(0) {}
7373

@@ -130,13 +130,13 @@ int main( int argc, char *argv[] )
130130

131131

132132
// Software Guide : BeginCodeSnippet
133-
typedef unsigned char InputPixelType;
133+
using InputPixelType = unsigned char;
134134
const unsigned int Dimension = 2;
135-
typedef itk::Image< InputPixelType, Dimension > InputImageType;
136-
typedef itk::CovariantVector< float, Dimension > VectorPixelType;
137-
typedef itk::Image< VectorPixelType, Dimension > VectorImageType;
138-
typedef itk::GradientRecursiveGaussianImageFilter< InputImageType,
139-
VectorImageType> GradientFilterType;
135+
using InputImageType = itk::Image< InputPixelType, Dimension >;
136+
using VectorPixelType = itk::CovariantVector< float, Dimension >;
137+
using VectorImageType = itk::Image< VectorPixelType, Dimension >;
138+
using GradientFilterType = itk::GradientRecursiveGaussianImageFilter< InputImageType,
139+
VectorImageType>;
140140

141141
GradientFilterType::Pointer gradient = GradientFilterType::New();
142142
// Software Guide : EndCodeSnippet
@@ -151,8 +151,8 @@ int main( int argc, char *argv[] )
151151
// Software Guide : EndLatex
152152

153153
// Software Guide : BeginCodeSnippet
154-
typedef itk::ImageAdaptor< VectorImageType,
155-
itk::VectorPixelAccessor > ImageAdaptorType;
154+
using ImageAdaptorType = itk::ImageAdaptor< VectorImageType,
155+
itk::VectorPixelAccessor >;
156156

157157
ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
158158
// Software Guide : EndCodeSnippet
@@ -184,7 +184,7 @@ int main( int argc, char *argv[] )
184184

185185

186186
// Software Guide : BeginCodeSnippet
187-
typedef itk::ImageFileReader< InputImageType > ReaderType;
187+
using ReaderType = itk::ImageFileReader< InputImageType >;
188188
ReaderType::Pointer reader = ReaderType::New();
189189
gradient->SetInput( reader->GetOutput() );
190190

@@ -207,11 +207,11 @@ int main( int argc, char *argv[] )
207207
// Software Guide : EndCodeSnippet
208208

209209

210-
typedef itk::Image< unsigned char, Dimension > OutputImageType;
211-
typedef itk::RescaleIntensityImageFilter< ImageAdaptorType, OutputImageType>
212-
RescalerType;
210+
using OutputImageType = itk::Image< unsigned char, Dimension >;
211+
using RescalerType = itk::RescaleIntensityImageFilter< ImageAdaptorType,
212+
OutputImageType>;
213213
RescalerType::Pointer rescaler = RescalerType::New();
214-
typedef itk::ImageFileWriter< OutputImageType > WriterType;
214+
using WriterType = itk::ImageFileWriter< OutputImageType >;
215215
WriterType::Pointer writer = WriterType::New();
216216

217217
writer->SetFileName( argv[2] );

0 commit comments

Comments
 (0)