Skip to content

Commit

Permalink
STYLE: Use std::next in LabelMap::GetNthLabelObject
Browse files Browse the repository at this point in the history
Somewhat simplified their implementations.
  • Loading branch information
N-Dekker committed Jan 18, 2024
1 parent 1deea1e commit f844df9
Showing 1 changed file with 8 additions and 22 deletions.
30 changes: 8 additions & 22 deletions Modules/Filtering/LabelMap/include/itkLabelMap.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -183,39 +183,25 @@ template <typename TLabelObject>
auto
LabelMap<TLabelObject>::GetNthLabelObject(const LabelMap::SizeValueType & pos) -> LabelObjectType *
{
SizeValueType i = 0;

for (auto it = m_LabelObjectContainer.begin(); it != m_LabelObjectContainer.end(); ++it)
if (const auto numberOfLabelObjects = m_LabelObjectContainer.size(); numberOfLabelObjects <= pos)
{
if (i == pos)
{
return it->second;
}
++i;
itkExceptionMacro("Can't access label object at position " << pos << ". The label map has only "
<< numberOfLabelObjects << " label objects registered.");
}
itkExceptionMacro("Can't access to label object at position " << pos << ". The label map has only "
<< this->GetNumberOfLabelObjects()
<< " label objects registered.");
return std::next(m_LabelObjectContainer.cbegin(), pos)->second;
}


template <typename TLabelObject>
auto
LabelMap<TLabelObject>::GetNthLabelObject(const LabelMap::SizeValueType & pos) const -> const LabelObjectType *
{
SizeValueType i = 0;

for (LabelObjectContainerConstIterator it = m_LabelObjectContainer.begin(); it != m_LabelObjectContainer.end(); ++it)
if (const auto numberOfLabelObjects = m_LabelObjectContainer.size(); numberOfLabelObjects <= pos)
{
if (i == pos)
{
return it->second;
}
++i;
itkExceptionMacro("Can't access label object at position " << pos << ". The label map has only "
<< numberOfLabelObjects << " label objects registered.");
}
itkExceptionMacro("Can't access to label object at position " << pos << ". The label map has only "
<< this->GetNumberOfLabelObjects()
<< " label objects registered.");
return std::next(m_LabelObjectContainer.cbegin(), pos)->second;
}


Expand Down

0 comments on commit f844df9

Please sign in to comment.