IDS peak ICV v1.2.0
Loading...
Searching...
No Matches
peak_common_range.hpp
Go to the documentation of this file.
1
11#pragma once
12
15#include <peak_common_c/detail/peak_common_defines.h>
16
17#include <type_traits>
18
19namespace peak
20{
21namespace common
22{
23
24namespace detail
25{
26
42template <typename T>
43class RangeT : public detail::IntervalT<T>
44{
45
46public:
47 static_assert(std::is_arithmetic<T>::value, "Template argument of Interval must be arithmetic.");
48
49 using type = T;
50
63 constexpr RangeT(T minimum, T maximum, T increment)
64 : detail::IntervalT<T>(minimum, maximum)
65 , m_increment{ increment }
66 {
67 if (increment > maximum - minimum)
68 {
69 throw peak::common::InvalidParameterException("The given increment is larger than the total range!");
70 }
71 }
72
80 PEAK_COMMON_NO_DISCARD constexpr T GetIncrement() const
81 {
82 return m_increment;
83 }
84
95 constexpr bool operator==(const RangeT& rhs) const
96 {
97 return detail::IntervalT<T>::operator==(rhs) && m_increment == rhs.m_increment;
98 }
99
108 constexpr bool operator!=(const RangeT& rhs) const
109 {
110 return !(rhs == *this);
111 }
112
113private:
114 T m_increment;
115};
116
117} // namespace detail
118
133
148
163
178
179
180} // namespace common
181} // namespace peak
Thrown when a function receives an invalid parameter.
Represents a continuous numeric interval with inclusive lower and upper bounds.
constexpr bool operator==(const IntervalT< H > &rhs) const
Compares two intervals for equality (integral types).
Represents a numeric range with defined boundaries and a fixed increment.
constexpr bool operator==(const RangeT &rhs) const
Compares this range with another for equality.
constexpr T GetIncrement() const
Retrieves the increment value associated with this range.
constexpr RangeT(T minimum, T maximum, T increment)
Constructs a range with specified minimum, maximum, and increment values.
constexpr bool operator!=(const RangeT &rhs) const
Compares this range with another for inequality.