Skip to content

Commit

Permalink
ENH: Make default-constructors of RGBPixel and RGBAPixel constexpr
Browse files Browse the repository at this point in the history
Tested by means of `CheckConstexprBeginAndEndOfContainer()`. Note that these
default-constructors were already `constexpr` _implicitly_, as implied by
`= default`, when `ITK_FUTURE_LEGACY_REMOVE` would be enabled.
  • Loading branch information
N-Dekker committed Dec 17, 2024
1 parent d786f75 commit 6464b88
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Modules/Core/Common/include/itkRGBAPixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ class ITK_TEMPLATE_EXPORT RGBAPixel : public FixedArray<TComponent, 4>
#ifdef ITK_FUTURE_LEGACY_REMOVE
RGBAPixel() = default;
#else
RGBAPixel() { this->Fill(0); }
constexpr RGBAPixel()
: Superclass()
{}
#endif

/** Pass-through constructor for the Array base class. */
Expand Down
4 changes: 3 additions & 1 deletion Modules/Core/Common/include/itkRGBPixel.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ class ITK_TEMPLATE_EXPORT RGBPixel : public FixedArray<TComponent, 3>
#ifdef ITK_FUTURE_LEGACY_REMOVE
RGBPixel() = default;
#else
RGBPixel() { this->Fill(0); }
constexpr RGBPixel()
: Superclass()
{}
#endif

#if defined(ITK_LEGACY_REMOVE)
Expand Down
5 changes: 5 additions & 0 deletions Modules/Core/Common/test/itkRGBAPixelGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#include <gtest/gtest.h>


static_assert(itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::RGBAPixel<>>() &&
itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::RGBAPixel<std::uint8_t>>() &&
itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::RGBAPixel<float>>());


// Tests that a RGBAPixel that is "value-initialized" (by empty braces, `{}`) is zero-filled.
TEST(RGBAPixel, ValueInitializedIsZeroFilled)
{
Expand Down
5 changes: 5 additions & 0 deletions Modules/Core/Common/test/itkRGBPixelGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
#include <gtest/gtest.h>


static_assert(itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::RGBPixel<>>() &&
itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::RGBPixel<std::uint8_t>>() &&
itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::RGBPixel<float>>());


// Tests that a RGBPixel that is "value-initialized" (by empty braces, `{}`) is zero-filled.
TEST(RGBPixel, ValueInitializedIsZeroFilled)
{
Expand Down

0 comments on commit 6464b88

Please sign in to comment.