Skip to content

Conversation

@N-Dekker
Copy link
Contributor

@N-Dekker N-Dekker commented Nov 4, 2024

Suggests evaluating its value at compile-time, rather than at runtime.

Found by regular expressions:

^( [ ]+)(auto \w+[ ]+= MakeFilled<.+>\(-?\d+\);)
^( [ ]+)(auto \w+[ ]+= MakeFilled<.+>\(\d.0\);)
^( [ ]+)(auto \w+[ ]+= MakeFilled<.+>\(false\);)
^( [ ]+)(auto \w+[ ]+= MakeFilled<.+>\(true\);)

Inspired by a comment by Hans Johnson (@hjmjohnson) at
#4924 (comment)

Suggests evaluating its value at compile-time, rather than at runtime.

Found by regular expressions:

    ^( [ ]+)(auto \w+[ ]+= MakeFilled<.+>\(-?\d+\);)
    ^( [ ]+)(auto \w+[ ]+= MakeFilled<.+>\(\d.0\);)
    ^( [ ]+)(auto \w+[ ]+= MakeFilled<.+>\(false\);)
    ^( [ ]+)(auto \w+[ ]+= MakeFilled<.+>\(true\);)

Inspired by a comment by Hans Johnson at
InsightSoftwareConsortium#4924 (comment)
@github-actions github-actions bot added area:Core Issues affecting the Core module area:Filtering Issues affecting the Filtering module area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module type:Style Style changes: no logic impact (indentation, comments, naming) area:Numerics Issues affecting the Numerics module labels Nov 4, 2024
Copy link
Member

@hjmjohnson hjmjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love It !!!


// Build and setup the neighborhood iterator
auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
constexpr auto radius = MakeFilled<typename NeighborhoodIteratorType::RadiusType>(1);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could even declare those variables static constexpr, instead of just non-static constexpr. I don't know if it matters much, in these cases 🤷 Some people prefer to always declare local variables static constexpr if possible.

@N-Dekker
Copy link
Contributor Author

N-Dekker commented Nov 4, 2024

FYI This PR has excluded variables that could not be declared constexpr, either because they are modified later on, or because their MakeFilled call cannot be evaluated at compile-time.

@N-Dekker N-Dekker marked this pull request as ready for review November 4, 2024 20:47
@N-Dekker
Copy link
Contributor Author

N-Dekker commented Nov 4, 2024

/azp run ITK.Linux

@hjmjohnson hjmjohnson merged commit fd14482 into InsightSoftwareConsortium:master Nov 5, 2024
15 checks passed
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Nov 9, 2024
Found by the regular expression `^( [ ]+)(auto \w+[ ]+= .+::Filled\(\d+\);)`

Manually excluded cases that did not compile, in

    itkLabelMapContourOverlayImageFilter.hxx
    itkBSplineControlPointImageFilter.hxx
    itkBSplineScatteredDataPointSetToImageFilter.hxx
    itkTileImageFilter.hxx
    itkFFTDiscreteGaussianImageFilter.hxx
    itkSLICImageFilter.hxx

 - Follow-up to pull request InsightSoftwareConsortium#4930
commit fd14482
"STYLE: Add constexpr to variables initialized by MakeFilled"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Nov 9, 2024
Found by the regular expression `^( [ ]+)(auto \w+[ ]+= .+::Filled\(\d+\);)`

Manually excluded cases that did not compile, in

    itkLabelMapContourOverlayImageFilter.hxx
    itkBSplineControlPointImageFilter.hxx
    itkBSplineScatteredDataPointSetToImageFilter.hxx
    itkTileImageFilter.hxx
    itkFFTDiscreteGaussianImageFilter.hxx
    itkSLICImageFilter.hxx

 - Follow-up to pull request InsightSoftwareConsortium#4930
commit fd14482
"STYLE: Add constexpr to variables initialized by MakeFilled"
N-Dekker added a commit to N-Dekker/ITK that referenced this pull request Nov 9, 2024
Using Notepad++, Replace in Files, doing:

    Find what: ^( [ ]+)(auto \w+[ ]+= .+::Filled\(\d+\);)
    Replace with: $1constexpr $2
    Filters: itk*.* !+\test
    Directory: D:\src\ITK\Modules
    [v] Match case
    (*) Regular expression

Manually excluded cases that did not compile, in

    itkLabelMapContourOverlayImageFilter.hxx
    itkBSplineControlPointImageFilter.hxx
    itkBSplineScatteredDataPointSetToImageFilter.hxx
    itkTileImageFilter.hxx
    itkFFTDiscreteGaussianImageFilter.hxx
    itkSLICImageFilter.hxx

 - Follow-up to pull request InsightSoftwareConsortium#4930
commit fd14482
"STYLE: Add constexpr to variables initialized by MakeFilled"
hjmjohnson pushed a commit that referenced this pull request Nov 11, 2024
Using Notepad++, Replace in Files, doing:

    Find what: ^( [ ]+)(auto \w+[ ]+= .+::Filled\(\d+\);)
    Replace with: $1constexpr $2
    Filters: itk*.* !+\test
    Directory: D:\src\ITK\Modules
    [v] Match case
    (*) Regular expression

Manually excluded cases that did not compile, in

    itkLabelMapContourOverlayImageFilter.hxx
    itkBSplineControlPointImageFilter.hxx
    itkBSplineScatteredDataPointSetToImageFilter.hxx
    itkTileImageFilter.hxx
    itkFFTDiscreteGaussianImageFilter.hxx
    itkSLICImageFilter.hxx

 - Follow-up to pull request #4930
commit fd14482
"STYLE: Add constexpr to variables initialized by MakeFilled"
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:Numerics Issues affecting the Numerics module area:Registration Issues affecting the Registration module area:Segmentation Issues affecting the Segmentation module type:Style Style changes: no logic impact (indentation, comments, naming)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants