#pragma once #include #include namespace midi_parsing { template class adjacent_iterator { public: adjacent_iterator(FwdIt first, FwdIt last) : m_first(first), m_next(first == last ? first : std::next(first)) { } bool operator!=(const adjacent_iterator& other) const { return m_next != other.m_next; } adjacent_iterator& operator++() { ++m_first; ++m_next; return *this; } typedef typename std::iterator_traits::reference Ref; typedef std::pair Pair; Pair operator*() const { return Pair(*m_first, *m_next); } private: FwdIt m_first; FwdIt m_next; }; template class adjacent_range { public: adjacent_range(FwdIt first, FwdIt last) : m_first(first), m_last(last) { } adjacent_iterator begin() const { return adjacent_iterator(m_first, m_last); } adjacent_iterator end() const { return adjacent_iterator(m_last, m_last); } private: FwdIt m_first; FwdIt m_last; }; template auto make_adjacent_range(C& c) -> adjacent_range { return adjacent_range(c.begin(), c.end()); } }