Replace NumericTraits<T>::ZeroValue() with T{} or 0U#4460
Merged
dzenanz merged 3 commits intoInsightSoftwareConsortium:masterfrom Feb 14, 2024
Merged
Conversation
dzenanz
approved these changes
Feb 12, 2024
issakomi
reviewed
Feb 13, 2024
Modules/Numerics/Optimizersv4/include/itkGradientDescentLineSearchOptimizerv4.hxx
Outdated
Show resolved
Hide resolved
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{}`"
eba9c01 to
13ccff6
Compare
NumericTraits<T>::ZeroValue() with T{}NumericTraits<T>::ZeroValue() with T{} or 0U
NumericTraits<T>::ZeroValue() with T{} or 0UNumericTraits<T>::ZeroValue() with T{} or 0U
dzenanz
approved these changes
Feb 13, 2024
issakomi
approved these changes
Feb 13, 2024
N-Dekker
added a commit
to SuperElastix/elastix
that referenced
this pull request
Feb 14, 2024
Follow-up to ITK pull request InsightSoftwareConsortium/ITK#4460 commit InsightSoftwareConsortium/ITK@13ccff6
N-Dekker
added a commit
to SuperElastix/elastix
that referenced
this pull request
Feb 15, 2024
Follow-up to ITK pull request InsightSoftwareConsortium/ITK#4460 commit InsightSoftwareConsortium/ITK@13ccff6
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`"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For any type
Tthat is supported byNumericTraits<T>, the expressionNumericTraits<T>::ZeroValue()is just equivalent toT{}.T{}appears preferred, because it is more generic, and it may yield faster code than the correspondingNumericTraits<T>::ZeroValue()function call.Using Notepad++, Replace in Files:
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() }withT var{}"Also follows up to: