--- a/sources/range.h Tue Dec 16 23:50:56 2014 +0200 +++ b/sources/range.h Mon May 04 15:51:03 2015 +0300 @@ -48,161 +48,102 @@ { T value; T step; - inline METHOD operator*() -> T&; - inline METHOD operator== (const Iterator& other) const -> bool; - inline METHOD operator!= (const Iterator& other) const -> bool; - inline METHOD operator++() -> Iterator&; + + Iterator (T value, T step) : + value (value), + step (step) {} + + T& operator*() + { + return value; + } + + bool operator== (const Iterator& other) const + { + return value == other.value; + } + + bool operator!= (const Iterator& other) const + { + return value != other.value; + } + + Iterator& operator++() + { + value += step; return *this; + } }; - Range (const T& a, const T& b, const T& step = 1); - Range(); - - METHOD begin() const -> Iterator; - METHOD end() const -> Iterator; - METHOD min() const -> T; - METHOD max() const -> T; - METHOD check_bounds() -> void; - METHOD contains (const T& c) const -> bool; - METHOD contains_exclusively (const T& c) const -> bool; - METHOD overlaps (Range<T> const& other) const -> bool; - METHOD operator== (Range<T> const& other) const -> bool; - METHOD operator!= (Range<T> const& other) const -> bool; -}; + Range (T a, T b, T step = 1) : + m_a (a), + m_b (b), + m_step (step) + { + check_bounds(); + } -// ------------------------------------------------------------------------------------------------- -// -template<typename T> -Range<T>::Range (const T& a, const T& b, const T& step) : - m_a (a), - m_b (b), - m_step (step) -{ - check_bounds(); -} - -// ------------------------------------------------------------------------------------------------- -// -template<typename T> -Range<T>::Range() : - m_a (T()), - m_b (T()) {} + Range() : + m_a (T()), + m_b (T()) {} -// ------------------------------------------------------------------------------------------------- -// -template<typename T> inline METHOD -Range<T>::Iterator::operator*() -> T& -{ - return value; -} - -// ------------------------------------------------------------------------------------------------- -// -template<typename T> inline METHOD -Range<T>::Iterator::operator== (const Iterator& other) const -> bool -{ - return value == other.value; -} + Iterator begin() const + { + Iterator it; + it.value = min(); + it.step = m_step; + return it; + } -// ------------------------------------------------------------------------------------------------- -// -template<typename T> inline METHOD -Range<T>::Iterator::operator!= (const Iterator& other) const -> bool -{ - return value != other.value; -} + Iterator end() const + { + Iterator it; + it.value = max() + 1; + it.step = m_step; + return it; + } -// ------------------------------------------------------------------------------------------------- -// -template<typename T> inline METHOD -Range<T>::Iterator::operator++() -> Iterator& -{ - value += step; - return *this; -} - -// ------------------------------------------------------------------------------------------------- -// -template<typename T> METHOD -Range<T>::check_bounds() -> void -{ - if (m_b < m_a) - std::swap (m_a, m_b); -} + T min() const + { + return m_a; + } -// ------------------------------------------------------------------------------------------------- -// -template<typename T> METHOD -Range<T>::contains (const T& c) const -> bool -{ - return (c >= m_a) and (c <= m_b); -} - -// ------------------------------------------------------------------------------------------------- -// -template<typename T> METHOD -Range<T>::contains_exclusively (const T& c) const -> bool -{ - return (c > m_a) and (c < m_b); -} + T max() const + { + return m_b; + } -// ------------------------------------------------------------------------------------------------- -// -template<typename T> METHOD -Range<T>::overlaps (Range<T> const& other) const -> bool -{ - return contains (other.m_a) or contains (other.m_b); -} + void check_bounds() + { + if (m_b < m_a) + std::swap (m_a, m_b); + } -// ------------------------------------------------------------------------------------------------- -// -template<typename T> METHOD -Range<T>::operator== (Range<T> const& other) const -> bool -{ - return m_a == other.m_a and m_b == other.m_b; -} + bool contains (T c) const + { + return c >= m_a + and c <= m_b; + } -// ------------------------------------------------------------------------------------------------- -// -template<typename T> METHOD -Range<T>::operator!= (Range<T> const& other) const -> bool -{ - return not operator== (other); -} + bool contains_exclusively (T c) const + { + return c > m_a + and c < m_b; + } -// ------------------------------------------------------------------------------------------------- -// -template<typename T> METHOD -Range<T>::min() const -> T -{ - return m_a; -} + bool overlaps (Range<T> const& other) const + { + return contains (other.m_a) + or contains (other.m_b); + } -// ------------------------------------------------------------------------------------------------- -// -template<typename T> METHOD -Range<T>::max() const -> T -{ - return m_b; -} + bool operator== (Range<T> const& other) const + { + return m_a == other.m_a + and m_b == other.m_b; + } -// ------------------------------------------------------------------------------------------------- -// -template<typename T> METHOD -Range<T>::begin() const -> Iterator -{ - Iterator it; - it.value = min(); - it.step = m_step; - return it; -} - -// ------------------------------------------------------------------------------------------------- -// -template<typename T> METHOD -Range<T>::end() const -> Iterator -{ - Iterator it; - it.value = max() + 1; - it.step = m_step; - return it; -} + bool operator!= (Range<T> const& other) const + { + return not operator== (other); + } +}; \ No newline at end of file