Skip to content

Replace NumericTraits<T>::ZeroValue() with T{} or 0U#4460

Merged
dzenanz merged 3 commits intoInsightSoftwareConsortium:masterfrom
N-Dekker:Replace-NumericTraits-ZeroValue
Feb 14, 2024
Merged

Replace NumericTraits<T>::ZeroValue() with T{} or 0U#4460
dzenanz merged 3 commits intoInsightSoftwareConsortium:masterfrom
N-Dekker:Replace-NumericTraits-ZeroValue

Conversation

@N-Dekker
Copy link
Copy Markdown
Contributor

@N-Dekker N-Dekker commented Feb 12, 2024

For any type T that is supported by NumericTraits<T>, the expression NumericTraits<T>::ZeroValue() is just equivalent to T{}. T{} appears preferred, because it is more generic, and it may yield faster code than the corresponding NumericTraits<T>::ZeroValue() function call.

Using Notepad++, Replace in Files:

Find what: itk::NumericTraits<(\w+)>::ZeroValue\(\)
Find what: NumericTraits<(\w+)>::ZeroValue\(\)
Replace with: $1{}
Filters: itk*.hxx;itk*.h;itk*.cxx
Directory: ITK\Modules
[v] Match case
(*) Regular expression

Excluded "itkNumericTraitsTest.cxx", because it purposely calls NumericTraits::ZeroValue() as part of the test.

Follow-up to pull request #4017 commit 5ac803e "STYLE: Replace T var{ NumericTraits<T>::ZeroValue() } with T var{}"

Also follows up to:

@github-actions github-actions bot added type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots area:Python wrapping Python bindings for a class type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:IO Issues affecting the IO module area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module area:Video Issues affecting the Video module type:Style Style changes: no logic impact (indentation, comments, naming) area:Numerics Issues affecting the Numerics module labels Feb 12, 2024
@N-Dekker N-Dekker marked this pull request as ready for review February 12, 2024 19:57
@N-Dekker N-Dekker marked this pull request as draft February 13, 2024 07:58
The last parameter of its member functions `WritePoints(T*, std::ofstream&, T)`
and `WriteCells(T*, std::ofstream&, T)` already has zero as default argument.

Style improvement inspired by remarks from Mihail Isakov about replacing
`NumericTraits::ZeroValue()` calls.
Style improvement within the default-constructor of
`GradientDescentLineSearchOptimizer`, suggested by Mihail Isakov.
For any type `T` that is supported by `NumericTraits<T>`, the expression
`NumericTraits<T>::ZeroValue()` is just equivalent to `T{}`. `T{}` appears
preferable, because it is more generic, and it may yield faster code than the
corresponding `NumericTraits<T>::ZeroValue()` function call.

Using Notepad++, Replace in Files:

    Find what:
      itk::NumericTraits<(\w+)>::ZeroValue\(\)
      NumericTraits<(\w+)>::ZeroValue\(\)
      itk::NumericTraits<([^ <>]+)>::ZeroValue\(\)
      NumericTraits<([^ <>]+)>::ZeroValue\(\)
      itk::NumericTraits<(typename [^ <>]+)>::ZeroValue\(\)
      NumericTraits<(typename [^ <>]+)>::ZeroValue\(\)
      itk::NumericTraits<(itk::NumericTraits<[^ ]+>::ValueType)>::ZeroValue\(\)
      itk::NumericTraits<(typename itk::NumericTraits<[^ ]+>::ValueType)>::ZeroValue\(\)
      NumericTraits<(typename NumericTraits<[^ ]+>::ValueType)>::ZeroValue\(\)
      itk::NumericTraits<(typename .+)>::ZeroValue\(\)
      NumericTraits<(typename .+)>::ZeroValue\(\)
    Replace with: $1{}
    Filters: itk*.hxx;itk*.h;itk*.cxx
    Directory: ITK\Modules
    [v] Match case
    (*) Regular expression

Excluded "itkNumericTraitsTest.cxx", because it purposely calls
`NumericTraits::ZeroValue()` as part of the test.

Follow-up to pull request InsightSoftwareConsortium#4017
commit 5ac803e
"STYLE: Replace `T var{ NumericTraits<T>::ZeroValue() }` with `T var{}`"
@N-Dekker N-Dekker force-pushed the Replace-NumericTraits-ZeroValue branch from eba9c01 to 13ccff6 Compare February 13, 2024 12:44
@N-Dekker N-Dekker changed the title STYLE: Replace NumericTraits<T>::ZeroValue() with T{} Replace NumericTraits<T>::ZeroValue() with T{} or 0U Feb 13, 2024
@N-Dekker N-Dekker changed the title Replace NumericTraits<T>::ZeroValue() with T{} or 0U Replace NumericTraits<T>::ZeroValue() with T{} or 0U Feb 13, 2024
@N-Dekker N-Dekker marked this pull request as ready for review February 13, 2024 13:47
@dzenanz dzenanz merged commit 45ca040 into InsightSoftwareConsortium:master Feb 14, 2024
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Feb 14, 2024
N-Dekker added a commit to SuperElastix/elastix that referenced this pull request Feb 15, 2024
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Feb 16, 2024
Follow-up to pull request InsightSoftwareConsortium#4460
commit 5d746cc
"STYLE: Replace `NumericTraits<unsigned int>::ZeroValue()` with `0U`"
hjmjohnson pushed a commit that referenced this pull request Feb 16, 2024
Follow-up to pull request #4460
commit 5d746cc
"STYLE: Replace `NumericTraits<unsigned int>::ZeroValue()` with `0U`"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:IO Issues affecting the IO module area:Numerics Issues affecting the Numerics module area:Python wrapping Python bindings for a class area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module area:Video Issues affecting the Video module type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots type:Style Style changes: no logic impact (indentation, comments, naming) type:Testing Ensure that the purpose of a class is met/the results on a wide set of test cases are correct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants