Skip to content

Commit 6464b88

Browse files
committed
ENH: Make default-constructors of RGBPixel and RGBAPixel constexpr
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.
1 parent d786f75 commit 6464b88

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

Modules/Core/Common/include/itkRGBAPixel.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ class ITK_TEMPLATE_EXPORT RGBAPixel : public FixedArray<TComponent, 4>
8181
#ifdef ITK_FUTURE_LEGACY_REMOVE
8282
RGBAPixel() = default;
8383
#else
84-
RGBAPixel() { this->Fill(0); }
84+
constexpr RGBAPixel()
85+
: Superclass()
86+
{}
8587
#endif
8688

8789
/** Pass-through constructor for the Array base class. */

Modules/Core/Common/include/itkRGBPixel.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ class ITK_TEMPLATE_EXPORT RGBPixel : public FixedArray<TComponent, 3>
8080
#ifdef ITK_FUTURE_LEGACY_REMOVE
8181
RGBPixel() = default;
8282
#else
83-
RGBPixel() { this->Fill(0); }
83+
constexpr RGBPixel()
84+
: Superclass()
85+
{}
8486
#endif
8587

8688
#if defined(ITK_LEGACY_REMOVE)

Modules/Core/Common/test/itkRGBAPixelGTest.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
#include <gtest/gtest.h>
2323

2424

25+
static_assert(itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::RGBAPixel<>>() &&
26+
itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::RGBAPixel<std::uint8_t>>() &&
27+
itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::RGBAPixel<float>>());
28+
29+
2530
// Tests that a RGBAPixel that is "value-initialized" (by empty braces, `{}`) is zero-filled.
2631
TEST(RGBAPixel, ValueInitializedIsZeroFilled)
2732
{

Modules/Core/Common/test/itkRGBPixelGTest.cxx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
#include <gtest/gtest.h>
2323

2424

25+
static_assert(itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::RGBPixel<>>() &&
26+
itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::RGBPixel<std::uint8_t>>() &&
27+
itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::RGBPixel<float>>());
28+
29+
2530
// Tests that a RGBPixel that is "value-initialized" (by empty braces, `{}`) is zero-filled.
2631
TEST(RGBPixel, ValueInitializedIsZeroFilled)
2732
{

0 commit comments

Comments
 (0)