negative_index_semantics.cpp
Go to the documentation of this file.
2 
3 #include <algorithm>
4 
5 
7 {
8  const size_t max = size > 0 ? size - 1 : 0;
9  if (index >= 0)
10  {
11  return std::clamp<size_t>(static_cast<size_t>(index), 0, max);
12  }
13  else
14  {
15  return static_cast<size_t>(std::clamp<long>(static_cast<long>(size) + index, 0, static_cast<long>(max)));
16  }
17 }
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::armem::base::detail::negativeIndexSemantics
size_t negativeIndexSemantics(long index, size_t size)
Definition: negative_index_semantics.cpp:6
max
T max(T t1, T t2)
Definition: gdiam.h:48
negative_index_semantics.h