diff -r 202e74157de5 -r eb4c25284a19 sources/range.h --- 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 const& other) const -> bool; - METHOD operator== (Range const& other) const -> bool; - METHOD operator!= (Range const& other) const -> bool; -}; + Range (T a, T b, T step = 1) : + m_a (a), + m_b (b), + m_step (step) + { + check_bounds(); + } -// ------------------------------------------------------------------------------------------------- -// -template -Range::Range (const T& a, const T& b, const T& step) : - m_a (a), - m_b (b), - m_step (step) -{ - check_bounds(); -} - -// ------------------------------------------------------------------------------------------------- -// -template -Range::Range() : - m_a (T()), - m_b (T()) {} + Range() : + m_a (T()), + m_b (T()) {} -// ------------------------------------------------------------------------------------------------- -// -template inline METHOD -Range::Iterator::operator*() -> T& -{ - return value; -} - -// ------------------------------------------------------------------------------------------------- -// -template inline METHOD -Range::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 inline METHOD -Range::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 inline METHOD -Range::Iterator::operator++() -> Iterator& -{ - value += step; - return *this; -} - -// ------------------------------------------------------------------------------------------------- -// -template METHOD -Range::check_bounds() -> void -{ - if (m_b < m_a) - std::swap (m_a, m_b); -} + T min() const + { + return m_a; + } -// ------------------------------------------------------------------------------------------------- -// -template METHOD -Range::contains (const T& c) const -> bool -{ - return (c >= m_a) and (c <= m_b); -} - -// ------------------------------------------------------------------------------------------------- -// -template METHOD -Range::contains_exclusively (const T& c) const -> bool -{ - return (c > m_a) and (c < m_b); -} + T max() const + { + return m_b; + } -// ------------------------------------------------------------------------------------------------- -// -template METHOD -Range::overlaps (Range 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 METHOD -Range::operator== (Range 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 METHOD -Range::operator!= (Range const& other) const -> bool -{ - return not operator== (other); -} + bool contains_exclusively (T c) const + { + return c > m_a + and c < m_b; + } -// ------------------------------------------------------------------------------------------------- -// -template METHOD -Range::min() const -> T -{ - return m_a; -} + bool overlaps (Range const& other) const + { + return contains (other.m_a) + or contains (other.m_b); + } -// ------------------------------------------------------------------------------------------------- -// -template METHOD -Range::max() const -> T -{ - return m_b; -} + bool operator== (Range const& other) const + { + return m_a == other.m_a + and m_b == other.m_b; + } -// ------------------------------------------------------------------------------------------------- -// -template METHOD -Range::begin() const -> Iterator -{ - Iterator it; - it.value = min(); - it.step = m_step; - return it; -} - -// ------------------------------------------------------------------------------------------------- -// -template METHOD -Range::end() const -> Iterator -{ - Iterator it; - it.value = max() + 1; - it.step = m_step; - return it; -} + bool operator!= (Range const& other) const + { + return not operator== (other); + } +}; \ No newline at end of file