Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Modules/Core/Common/include/itkFixedArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,37 +322,37 @@ class ITK_TEMPLATE_EXPORT FixedArray

itkLegacyMacro(ConstReverseIterator rEnd() const);

const_iterator
constexpr const_iterator
cbegin() const noexcept
{
return m_InternalArray;
}

iterator
constexpr iterator
begin() noexcept
{
return m_InternalArray;
}

const_iterator
constexpr const_iterator
begin() const noexcept
{
return this->cbegin();
}

const_iterator
constexpr const_iterator
cend() const noexcept
{
return m_InternalArray + VLength;
}

iterator
constexpr iterator
end() noexcept
{
return m_InternalArray + VLength;
}

const_iterator
constexpr const_iterator
end() const noexcept
{
return this->cend();
Expand Down
28 changes: 20 additions & 8 deletions Modules/Core/Common/include/itkIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -346,28 +346,40 @@ struct ITK_TEMPLATE_EXPORT Index final
std::swap(m_InternalArray, other.m_InternalArray);
}

iterator
constexpr const_iterator
cbegin() const
{
return &m_InternalArray[0];
}

constexpr iterator
begin()
{
return iterator(&m_InternalArray[0]);
return &m_InternalArray[0];
}

const_iterator
constexpr const_iterator
begin() const
{
return const_iterator(&m_InternalArray[0]);
return &m_InternalArray[0];
}

constexpr const_iterator
cend() const
{
return &m_InternalArray[VDimension];
}

iterator
constexpr iterator
end()
{
return iterator(&m_InternalArray[VDimension]);
return &m_InternalArray[VDimension];
}

const_iterator
constexpr const_iterator
end() const
{
return const_iterator(&m_InternalArray[VDimension]);
return &m_InternalArray[VDimension];
}

reverse_iterator
Expand Down
28 changes: 20 additions & 8 deletions Modules/Core/Common/include/itkOffset.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,28 +299,40 @@ struct ITK_TEMPLATE_EXPORT Offset final
std::swap(m_InternalArray, other.m_InternalArray);
}

iterator
constexpr const_iterator
cbegin() const
{
return &m_InternalArray[0];
}

constexpr iterator
begin()
{
return iterator(&m_InternalArray[0]);
return &m_InternalArray[0];
}

const_iterator
constexpr const_iterator
begin() const
{
return const_iterator(&m_InternalArray[0]);
return &m_InternalArray[0];
}

constexpr const_iterator
cend() const
{
return &m_InternalArray[VDimension];
}

iterator
constexpr iterator
end()
{
return iterator(&m_InternalArray[VDimension]);
return &m_InternalArray[VDimension];
}

const_iterator
constexpr const_iterator
end() const
{
return const_iterator(&m_InternalArray[VDimension]);
return &m_InternalArray[VDimension];
}

reverse_iterator
Expand Down
28 changes: 20 additions & 8 deletions Modules/Core/Common/include/itkSize.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,28 +258,40 @@ struct ITK_TEMPLATE_EXPORT Size final
std::swap(m_InternalArray, other.m_InternalArray);
}

iterator
constexpr const_iterator
cbegin() const
{
return &m_InternalArray[0];
}

constexpr iterator
begin()
{
return iterator(&m_InternalArray[0]);
return &m_InternalArray[0];
}

const_iterator
constexpr const_iterator
begin() const
{
return const_iterator(&m_InternalArray[0]);
return &m_InternalArray[0];
}

constexpr const_iterator
cend() const
{
return &m_InternalArray[VDimension];
}

iterator
constexpr iterator
end()
{
return iterator(&m_InternalArray[VDimension]);
return &m_InternalArray[VDimension];
}

const_iterator
constexpr const_iterator
end() const
{
return const_iterator(&m_InternalArray[VDimension]);
return &m_InternalArray[VDimension];
}

reverse_iterator
Expand Down
1 change: 1 addition & 0 deletions Modules/Core/Common/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ set(ITKCommonGTests
itkMersenneTwisterRandomVariateGeneratorGTest.cxx
itkNeighborhoodAllocatorGTest.cxx
itkNumberToStringGTest.cxx
itkOffsetGTest.cxx
itkOptimizerParametersGTest.cxx
itkPointGTest.cxx
itkShapedImageNeighborhoodRangeGTest.cxx
Expand Down
5 changes: 5 additions & 0 deletions Modules/Core/Common/test/itkFixedArrayGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

// First include the header file to be tested:
#include "itkFixedArray.h"
#include "itkRangeGTestUtilities.h"
#include <gtest/gtest.h>

#include <array>
Expand Down Expand Up @@ -248,6 +249,10 @@ static_assert(Is_Filled_FixedArray_correctly_filled<0>() && Is_Filled_FixedArray
Is_Filled_FixedArray_correctly_filled<std::numeric_limits<int>::max()>(),
"itk::FixedArray::Filled(value) should be correctly filled at compile-time");

static_assert(itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::FixedArray<int>>() &&
itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::FixedArray<double, 1>>(),
"Check constexpr begin() and end() of FixedArray.");


// Tests that the values of a FixedArray (either const or non-const) can be retrieved by a
// range-based for-loop.
Expand Down
5 changes: 5 additions & 0 deletions Modules/Core/Common/test/itkIndexGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

// First include the header file to be tested:
#include "itkIndex.h"
#include "itkRangeGTestUtilities.h"
#include <gtest/gtest.h>
#include <initializer_list>
#include <limits>
Expand Down Expand Up @@ -70,6 +71,10 @@ static_assert(Is_Filled_Index_correctly_filled<0>() && Is_Filled_Index_correctly
Is_Filled_Index_correctly_filled<std::numeric_limits<itk::IndexValueType>::max()>(),
"itk::Index::Filled(value) should be correctly filled at compile-time");

static_assert(itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::Index<>>() &&
itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::Index<1>>(),
"Check constexpr begin() and end() of Index.");


// Tests that itk::Index::Filled(value) returns an itk::Index with the
// specified value for each element.
Expand Down
26 changes: 26 additions & 0 deletions Modules/Core/Common/test/itkOffsetGTest.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/

// First include the header file to be tested:
#include "itkOffset.h"
#include "itkRangeGTestUtilities.h"


static_assert(itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::Offset<>>() &&
itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::Offset<1>>(),
"Check constexpr begin() and end() of Offset.");
34 changes: 34 additions & 0 deletions Modules/Core/Common/test/itkRangeGTestUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,40 @@ class RangeGTestUtilities
ExpectRangesHaveEqualBeginAndEnd(moveAssignedRange, originalRangeBeforeMove);
}


// Checks the `constexpr` member functions begin() and end() of a container like FixedArray, Index, Offset and Size.
template <typename TContainer>
static constexpr bool
CheckConstexprBeginAndEndOfContainer()
{
using ConstContainerType = const TContainer;
using ValueType = std::remove_reference_t<decltype(*(TContainer().begin()))>;

static_assert(std::is_same<decltype(*(TContainer().begin())), ValueType &>::value,
"For a non-const container, begin() should return a non-const reference");
static_assert(std::is_same<decltype(*(ConstContainerType().begin())), const ValueType &>::value,
"For a const container, begin() should return a const reference");
static_assert(std::is_same<decltype(*(TContainer().cbegin())), const ValueType &>::value &&
std::is_same<decltype(*(ConstContainerType().cbegin())), const ValueType &>::value,
"For any container, cbegin() should return a const reference");

static_assert(std::is_same<decltype(*(TContainer().end())), ValueType &>::value,
"For a non-const container, end() should return a non-const reference");
static_assert(std::is_same<decltype(*(ConstContainerType().end())), const ValueType &>::value,
"For a const container, end() should return a const reference");
static_assert(std::is_same<decltype(*(TContainer().cend())), const ValueType &>::value &&
std::is_same<decltype(*(ConstContainerType().cend())), const ValueType &>::value,
"For any container, cend() should return a const reference");

constexpr TContainer container{};

static_assert(container.cbegin() == container.begin(), "cbegin() should return the same iterator as begin().");
static_assert(container.cend() == container.end(), "cend() should return the same iterator as end().");

// Just return true to ease calling this function inside a static_assert.
return true;
}

private:
template <typename TRange>
static void
Expand Down
5 changes: 5 additions & 0 deletions Modules/Core/Common/test/itkSizeGTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

// First include the header file to be tested:
#include "itkSize.h"
#include "itkRangeGTestUtilities.h"
#include <gtest/gtest.h>
#include <limits>
#include <type_traits> // For integral_constant.
Expand Down Expand Up @@ -75,6 +76,10 @@ static_assert(Is_Filled_Size_correctly_filled<0>() && Is_Filled_Size_correctly_f
Is_Filled_Size_correctly_filled<std::numeric_limits<itk::IndexValueType>::max()>(),
"itk::Size::Filled(value) should be correctly filled at compile-time");

static_assert(itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::Size<>>() &&
itk::RangeGTestUtilities::CheckConstexprBeginAndEndOfContainer<itk::Size<1>>(),
"Check constexpr begin() and end() of Size.");


// Tests that itk::Size::Filled(value) returns an itk::Size with the
// specified value for each element.
Expand Down