Skip to content

Commit 2e1b8ff

Browse files
N-Dekkerdzenanz
authored andcommitted
STYLE: Use C++17 "constexpr if" in ImageRegionRange
Replaced its two cases of `true_type`/`false_type` tag dispatching by using "constexpr if", within the implementation of its internal (private) member functions `Increment` and `Decrement`.
1 parent e287d81 commit 2e1b8ff

File tree

1 file changed

+30
-32
lines changed

1 file changed

+30
-32
lines changed

Modules/Core/Common/include/itkImageRegionRange.h

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -146,52 +146,50 @@ class ImageRegionRange final
146146
{}
147147

148148
template <size_t VIndex>
149-
void Increment(std::true_type) noexcept
149+
void
150+
Increment() noexcept
150151
{
151-
static_assert(VIndex < (ImageDimension - 1), "For a larger index value, the other overload should be picked");
152-
153152
m_BufferIterator += m_OffsetTable[VIndex];
154153

155-
if (static_cast<SizeValueType>(++m_IterationOffset[VIndex]) >= m_IterationRegionSize[VIndex])
154+
if constexpr (VIndex < (ImageDimension - 1))
156155
{
157-
m_IterationOffset[VIndex] = 0;
158-
m_BufferIterator -= m_OffsetTable[VIndex] * m_IterationRegionSize[VIndex];
159-
this->Increment<VIndex + 1>(std::integral_constant<bool, (VIndex + 1) < (ImageDimension - 1)>{});
156+
if (static_cast<SizeValueType>(++m_IterationOffset[VIndex]) >= m_IterationRegionSize[VIndex])
157+
{
158+
m_IterationOffset[VIndex] = 0;
159+
m_BufferIterator -= m_OffsetTable[VIndex] * m_IterationRegionSize[VIndex];
160+
this->Increment<VIndex + 1>();
161+
}
160162
}
161-
}
162-
163-
template <size_t VIndex>
164-
void Increment(std::false_type) noexcept
165-
{
166-
static_assert(VIndex == (ImageDimension - 1), "For a smaller index value, the other overload should be picked");
163+
else
164+
{
165+
static_assert(VIndex == (ImageDimension - 1));
167166

168-
++m_IterationOffset[VIndex];
169-
m_BufferIterator += m_OffsetTable[VIndex];
167+
++m_IterationOffset[VIndex];
168+
}
170169
}
171170

172171

173172
template <size_t VIndex>
174-
void Decrement(std::true_type) noexcept
173+
void
174+
Decrement() noexcept
175175
{
176-
static_assert(VIndex < (ImageDimension - 1), "For a larger index value, the other overload should be picked");
177-
178176
m_BufferIterator -= m_OffsetTable[VIndex];
179177

180-
if (--m_IterationOffset[VIndex] < 0)
178+
if constexpr (VIndex < (ImageDimension - 1))
181179
{
182-
m_IterationOffset[VIndex] = m_IterationRegionSize[VIndex] - 1;
183-
m_BufferIterator += m_OffsetTable[VIndex] * m_IterationRegionSize[VIndex];
184-
this->Decrement<VIndex + 1>(std::integral_constant<bool, (VIndex + 1) < (ImageDimension - 1)>{});
180+
if (--m_IterationOffset[VIndex] < 0)
181+
{
182+
m_IterationOffset[VIndex] = m_IterationRegionSize[VIndex] - 1;
183+
m_BufferIterator += m_OffsetTable[VIndex] * m_IterationRegionSize[VIndex];
184+
this->Decrement<VIndex + 1>();
185+
}
185186
}
186-
}
187-
188-
template <size_t VIndex>
189-
void Decrement(std::false_type) noexcept
190-
{
191-
static_assert(VIndex == (ImageDimension - 1), "For a smaller index value, the other overload should be picked");
187+
else
188+
{
189+
static_assert(VIndex == (ImageDimension - 1));
192190

193-
--m_IterationOffset[VIndex];
194-
m_BufferIterator -= m_OffsetTable[VIndex];
191+
--m_IterationOffset[VIndex];
192+
}
195193
}
196194

197195

@@ -230,7 +228,7 @@ class ImageRegionRange final
230228
QualifiedIterator &
231229
operator++() noexcept
232230
{
233-
this->Increment<0>(std::integral_constant<bool, (ImageDimension > 1)>{});
231+
this->Increment<0>();
234232
return *this;
235233
}
236234

@@ -250,7 +248,7 @@ class ImageRegionRange final
250248
QualifiedIterator &
251249
operator--() noexcept
252250
{
253-
this->Decrement<0>(std::integral_constant<bool, (ImageDimension > 1)>{});
251+
this->Decrement<0>();
254252
return *this;
255253
}
256254

0 commit comments

Comments
 (0)