Skip to content

Commit d66197a

Browse files
authored
Merge pull request #5703 from N-Dekker/FixedArray-empty
ENH: Add `FixedArray::empty()`, which always just returns false
2 parents 403982d + ee00825 commit d66197a

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

Modules/Core/Common/include/itkFixedArray.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,12 @@ class ITK_TEMPLATE_EXPORT FixedArray
448448
return VLength;
449449
}
450450

451+
[[nodiscard]] constexpr bool
452+
empty() const noexcept
453+
{
454+
return false;
455+
}
456+
451457
/** Set all the elements of the container to the input value. */
452458
void
453459
Fill(const ValueType &);

Modules/Core/Common/test/itkFixedArrayGTest.cxx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,15 @@ TEST(FixedArray, ValueInitialized)
356356
expectEachElementValueInitialized(itk::FixedArray<float, 3>{});
357357
expectEachElementValueInitialized(itk::FixedArray<void *, 3>{});
358358
}
359+
360+
361+
// Tests that empty() always returns false for FixedArray.
362+
TEST(FixedArray, EmptyIsFalse)
363+
{
364+
static_assert(!itk::FixedArray<int>{}.empty());
365+
static_assert(!itk::FixedArray<float, 1>{}.empty());
366+
static_assert(!itk::FixedArray<void *, 2>{}.empty());
367+
static_assert(!itk::FixedArray<double>::Filled(1.0).empty());
368+
369+
EXPECT_FALSE(itk::FixedArray<int>({ 0, 1, 2 }).empty());
370+
}

0 commit comments

Comments
 (0)