29 #include <type_traits>
42 template <
typename T, T MinVal, T MaxVal >
45 static_assert( MinVal <= MaxVal,
"MinVal must be less than or equal to MaxVal" );
48 constexpr
explicit bounded( T val )
60 template <
typename U, U OtherMin, U OtherMax >
62 std::is_integral_v< U > && std::is_integral_v< T > &&
min_val <=
OtherMin &&
65 : val_( static_cast< T >( *
other ) )
80 template <
typename U >
81 static std::optional< bounded< T, min_val, max_val > >
make( U val )
83 if (
static_cast< T
>( val ) <
min_val )
85 if (
static_cast< T
>( val ) >
max_val )
87 return bounded{
static_cast< T
>( val ) };
110 explicit operator T()
const
131 template <
typename U >
138 template < T FromOther, T ToOther >
145 template <
typename U, U FromOther, U ToOther >
150 template < std::
size_t N >
155 template <
typename T, T MinVal, T MaxVal >
163 template <
typename T >
166 #ifdef EMLABCPP_USE_OSTREAM
167 template <
typename T, T MinVal, T MaxVal >
168 std::ostream&
operator<<( std::ostream& os, bounded< T, MinVal, MaxVal >
const& b )
The bounded class represents a wrapper over type T constrained between MinVal and MaxVal as compile-t...
Definition: bounded.h:44
static bounded< T, min_val, max_val > min()
Definition: bounded.h:90
static bounded< T, min_val, max_val > max()
Definition: bounded.h:95
void rotate_right(T step)
Rotation to the right increases the internal value by step modulo the range it is in.
Definition: bounded.h:116
static constexpr bool has_single_element
Definition: bounded.h:57
constexpr friend auto operator<=>(bounded const &, bounded const &)=default
static std::optional< bounded< T, min_val, max_val > > make(U val)
Creates an optional bounded value if the input value is within the allowed range.
Definition: bounded.h:81
constexpr T operator*() const
Definition: bounded.h:105
requires(std::is_integral_v< U > &&std::is_integral_v< T > &&min_val<=OtherMin &&OtherMax<=max_val) const expr bounded(bounded< U
Constructor that allows conversion from another bounded type with compatible bounds.
static constexpr T min_val
Definition: bounded.h:54
OtherMin
Definition: bounded.h:64
constexpr friend auto operator<=>(bounded const &b, U const &val)
Definition: bounded.h:132
void rotate_left(T step)
Rotation to the left decreases the internal value by step modulo the range it is in.
Definition: bounded.h:123
static constexpr T max_val
Definition: bounded.h:55
OtherMax other
Definition: bounded.h:74
constexpr bounded< T, MinVal+FromOther, MaxVal+ToOther > operator+(bounded< T, FromOther, ToOther > const &other) const
Sum of two bounded types of same base type is bounded within appropiate ranges.
Definition: bounded.h:140
constexpr bounded()
Definition: bounded.h:100
return bounded
Definition: bounded.h:75
static constexpr T interval_range
Definition: bounded.h:56
constexpr bool bounded_derived_test(bounded< T, MinVal, MaxVal > const &)
Definition: bounded.h:156
MIT License.
Definition: impl.h:31
constexpr auto bounded_constant
Simple type alias for bounded index constants.
Definition: bounded.h:151
requires(!range_container< Container >) const expr std
Returns index of an element in tuple 't', for which call to predicate f(x) holds true,...
Definition: algorithm.h:127
concept bounded_derived
Concept that matchestype deriving from bounded.
Definition: bounded.h:164
std::ostream & operator<<(std::ostream &os, string_buffer< N > const &sb)
Definition: string_buffer.h:112