negative_index_semantics.cpp
Go to the documentation of this file.
2
3#include <algorithm>
4
5size_t
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>(
16 std::clamp<long>(static_cast<long>(size) + index, 0, static_cast<long>(max)));
17 }
18}
size_t negativeIndexSemantics(long index, size_t size)
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)