45#ifndef LASS_GUARDIAN_OF_INCLUSION_NUM_MODULO_INL
46#define LASS_GUARDIAN_OF_INCLUSION_NUM_MODULO_INL
61template <
unsigned N,
typename T>
62constexpr Modulo<N, T>::Modulo():
69template <
unsigned N,
typename T>
70constexpr Modulo<N, T>::Modulo(TParam value):
71 value_(static_cast<TValue>(mod(value, N)))
77template <
unsigned N,
typename T>
inline
78constexpr Modulo<N, T> Modulo<N, T>::operator+()
const
85template <
unsigned N,
typename T>
86constexpr Modulo<N, T> Modulo<N, T>::operator-()
const
89 value_ == 0 ? 0 :
static_cast<T
>(N) - value_,
95template <
unsigned N,
typename T>
96constexpr Modulo<N, T>& Modulo<N, T>::operator++()
98 value_ = value_ + 1 ==
static_cast<T
>(N) ? 0 : value_ + 1;
99 LASS_ASSERT(isInRange(value_));
105template <
unsigned N,
typename T>
106constexpr Modulo<N, T>& Modulo<N, T>::operator--()
108 value_ = value_ == 0 ?
static_cast<T
>(N) - 1 : value_ - 1;
109 LASS_ASSERT(isInRange(value_));
115template <
unsigned N,
typename T>
116constexpr Modulo<N, T> Modulo<N, T>::operator++(
int)
118 Modulo<N, T> result(*
this);
125template <
unsigned N,
typename T>
126constexpr Modulo<N, T> Modulo<N, T>::operator--(
int)
128 Modulo<N, T> result(*
this);
135template <
unsigned N,
typename T>
136constexpr Modulo<N, T>& Modulo<N, T>::operator+=(
const Modulo<N, T>& other)
138 value_ += other.value_;
139 if (value_ >=
static_cast<T
>(N))
143 LASS_ASSERT(isInRange(value_));
149template <
unsigned N,
typename T>
150constexpr Modulo<N, T>& Modulo<N, T>::operator-=(
const Modulo<N, T>& other)
152 value_ -= other.value_;
157 LASS_ASSERT(isInRange(value_));
163template <
unsigned N,
typename T>
164constexpr Modulo<N, T>& Modulo<N, T>::operator*=(
const Modulo<N, T>& other)
166 *
this = TSelf(value_ * other.value_);
192template <
unsigned N,
typename T>
193constexpr Modulo<N, T>::Modulo(TParam value,
bool):
196 LASS_ASSERT(isInRange(value));
201template <
unsigned N,
typename T>
202constexpr bool Modulo<N, T>::isInRange(TParam value)
const
204 return value >= 0 && value < static_cast<T>(N);
211template <
unsigned N,
typename T>
212constexpr bool operator==(
const Modulo<N, T>& a,
const Modulo<N, T>& b)
214 return a.value() == b.value();
219template <
unsigned N,
typename T>
220constexpr bool operator!=(
const Modulo<N, T>& a,
const Modulo<N, T>& b)
227template <
unsigned N,
typename T>
228constexpr bool operator<(
const Modulo<N, T>& a,
const Modulo<N, T>& b)
230 return a.value() < b.value();
235template <
unsigned N,
typename T>
236constexpr bool operator>(
const Modulo<N, T>& a,
const Modulo<N, T>& b)
243template <
unsigned N,
typename T>
244constexpr bool operator<=(
const Modulo<N, T>& a,
const Modulo<N, T>& b)
251template <
unsigned N,
typename T>
252constexpr bool operator>=(
const Modulo<N, T>& a,
const Modulo<N, T>& b)
259template <
unsigned N,
typename T>
260std::ostream& operator<<(std::ostream& stream,
const Modulo<N, T>& a)
268template <
unsigned N,
typename T>
269std::istream& operator>>(std::istream& stream, Modulo<N, T>& a)
272 LASS_ENFORCE(stream) >> result;
273 a = Modulo<N, T>(result);
numeric types and traits.
Library for Assembled Shared Sources.