15 auto compare = [](TYPE a, TYPE b) {
return a < b ? -1 : (a == b) ? 0 : 1; };
19 auto count = values.size();
24 for (std::size_t i = 0; i < count; ++i) {
25 int current = compare(values[i], values[i + offset]);
30 if (current != previous && previous != 0) {
54 throw std::invalid_argument(
"Values must be strict monotonic.");
60 std::size_t
size() const noexcept {
return data_.size(); }
65 const TYPE &
at(std::size_t index)
const {
return data_.at(index); }
70 TYPE &
operator[](std::size_t index) {
return data_.at(index); }
75 const TYPE &
operator[](std::size_t index)
const {
return data_.at(index); }
102 std::vector<TYPE> data_;
Defines a monotonic vector container type.
Definition: monotonic_vector.h:42
typename std::vector< TYPE >::iterator IteratorType
Element iterator.
Definition: monotonic_vector.h:45
std::size_t size() const noexcept
Gets the number of elements.
Definition: monotonic_vector.h:60
TYPE & operator[](std::size_t index)
Gets a specified element with bounds checking.
Definition: monotonic_vector.h:70
ConstIteratorType begin() const noexcept
Gets an read-only iterator to the beginning of the elements.
Definition: monotonic_vector.h:87
ConstIteratorType cend() const noexcept
Gets an read-only iterator to the element following the element of the vector.
Definition: monotonic_vector.h:99
ConstIteratorType cbegin() const noexcept
Gets an read-only iterator to the beginning of the elements.
Definition: monotonic_vector.h:95
const TYPE & operator[](std::size_t index) const
Gets a specified read-only element with bounds checking.
Definition: monotonic_vector.h:75
IteratorType begin() noexcept
Gets an iterator to the beginning of the elements.
Definition: monotonic_vector.h:79
typename std::vector< TYPE >::const_iterator ConstIteratorType
Read-only element iterator.
Definition: monotonic_vector.h:47
IteratorType end() noexcept
Gets an iterator to the element following the element of the vector.
Definition: monotonic_vector.h:83
const TYPE & at(std::size_t index) const
Gets a specified element with bounds checking.
Definition: monotonic_vector.h:65
MonotonicVector(std::vector< TYPE > &values)
Initialises a new instance of the MonotonicVector class.
Definition: monotonic_vector.h:52
ConstIteratorType end() const noexcept
Gets an read-only iterator to the element following the element of the vector.
Definition: monotonic_vector.h:91
Top-level namespace for Health-GPS C++ API.
Definition: analysis_definition.h:8
bool is_strict_monotonic(const std::vector< TYPE > &values) noexcept
Determine whether a vector data is strict monotonic.
Definition: monotonic_vector.h:14