Skip to content

Commit 0c6c3a9

Browse files
N-Dekkerhjmjohnson
authored andcommitted
STYLE: Avoid T var = elementValue syntax to initialize a filled array
The C++ copy-initialization syntax `T var = value` suggests that the value at the right side is implicitly converted to the target type `T`. When the target type `T` is a `FixedArray<TValue, VLength>`, or one of its derived types, `T var = elementValue` _fills_ the variable with the specified `elementValue`, by assigning the `elementValue` to each of its elements. In this case, the C++ direct-initialization syntax `T var(elementValue)` appears more appropriate. Occurrences of `T var = elementValue` were found by locally temporarily declaring the corresponding constructors `explicit`.
1 parent 5b71d63 commit 0c6c3a9

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

Modules/Core/SpatialObjects/test/itkEllipseSpatialObjectTest.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ itkEllipseSpatialObjectTest(int, char *[])
4444

4545
ITK_TEST_SET_GET_VALUE(radii, myEllipse->GetRadiusInObjectSpace());
4646

47-
EllipseType::ArrayType objectSpaceRadius = 3;
47+
EllipseType::ArrayType objectSpaceRadius(3);
4848
myEllipse->SetRadiusInObjectSpace(objectSpaceRadius);
4949
myEllipse->Update();
5050

Modules/Filtering/ImageFeature/test/itkCannyEdgeDetectionImageFilterTest.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ itkCannyEdgeDetectionImageFilterTest(int argc, char * argv[])
6363
filter->SetLowerThreshold(lowerThreshold);
6464
ITK_TEST_SET_GET_VALUE(lowerThreshold, filter->GetLowerThreshold());
6565

66-
CannyEdgeDetectionImageFilterType::ArrayType variance = 1.0f;
66+
CannyEdgeDetectionImageFilterType::ArrayType variance(1.0f);
6767
filter->SetVariance(variance);
6868
ITK_TEST_SET_GET_VALUE(variance, filter->GetVariance());
6969

70-
CannyEdgeDetectionImageFilterType::ArrayType maximumError = .01f;
70+
CannyEdgeDetectionImageFilterType::ArrayType maximumError(.01f);
7171
filter->SetMaximumError(maximumError);
7272
ITK_TEST_SET_GET_VALUE(maximumError, filter->GetMaximumError());
7373

Modules/Filtering/ImageFeature/test/itkCannyEdgeDetectionImageFilterTest2.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,11 @@ itkCannyEdgeDetectionImageFilterTest2(int argc, char * argv[])
6060
filter->SetLowerThreshold(lowerThreshold);
6161
ITK_TEST_SET_GET_VALUE(lowerThreshold, filter->GetLowerThreshold());
6262

63-
CannyEdgeDetectionImageFilterType::ArrayType variance = 1.0f;
63+
CannyEdgeDetectionImageFilterType::ArrayType variance(1.0f);
6464
filter->SetVariance(variance);
6565
ITK_TEST_SET_GET_VALUE(variance, filter->GetVariance());
6666

67-
CannyEdgeDetectionImageFilterType::ArrayType maximumError = .01f;
67+
CannyEdgeDetectionImageFilterType::ArrayType maximumError(.01f);
6868
filter->SetMaximumError(maximumError);
6969
ITK_TEST_SET_GET_VALUE(maximumError, filter->GetMaximumError());
7070

Modules/Filtering/ImageGrid/test/itkBSplineControlPointImageFilterTest.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ BSpline(int argc, char * argv[])
6565
bspliner->SetCloseDimension(closeDimension);
6666
ITK_TEST_SET_GET_VALUE(closeDimension, bspliner->GetCloseDimension());
6767

68-
typename BSplinerType::ArrayType splineOrder = 3;
68+
typename BSplinerType::ArrayType splineOrder(3);
6969
bspliner->SetSplineOrder(splineOrder);
7070
ITK_TEST_SET_GET_VALUE(splineOrder, bspliner->GetSplineOrder());
7171

Modules/Filtering/ImageSources/test/itkGaborImageSourceTest.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ itkGaborImageSourceTestHelper(char * outputFilename, bool calculcateImaginaryPar
5454
gaborImage->SetSigma(sigma);
5555
ITK_TEST_SET_GET_VALUE(sigma, gaborImage->GetSigma());
5656

57-
typename GaborSourceType::ArrayType mean = 0.1;
57+
typename GaborSourceType::ArrayType mean(0.1);
5858
gaborImage->SetMean(mean);
5959
ITK_TEST_SET_GET_VALUE(mean, gaborImage->GetMean());
6060

0 commit comments

Comments
 (0)