#pragma once #include #include #include namespace beast { template class aged_ordered_container; namespace detail { // If Iterator is SCARY then this iterator will be as well. template class aged_container_iterator { public: using iterator_category = typename std::iterator_traits::iterator_category; using value_type = std::conditional_t< is_const, typename Iterator::value_type::stashed::value_type const, typename Iterator::value_type::stashed::value_type>; using difference_type = typename std::iterator_traits::difference_type; using pointer = value_type*; using reference = value_type&; using time_point = typename Iterator::value_type::stashed::time_point; aged_container_iterator() = default; // Disable constructing a const_iterator from a non-const_iterator. // Converting between reverse and non-reverse iterators should be explicit. template < bool other_is_const, class OtherIterator, class = std::enable_if_t< (!other_is_const || is_const) && !static_cast(std::is_same_v)>> explicit aged_container_iterator( aged_container_iterator const& other) : m_iter(other.m_iter) { } // Disable constructing a const_iterator from a non-const_iterator. template > aged_container_iterator(aged_container_iterator const& other) : m_iter(other.m_iter) { } // Disable assigning a const_iterator to a non-const iterator template auto operator=(aged_container_iterator const& other) -> std::enable_if_t { m_iter = other.m_iter; return *this; } template bool operator==(aged_container_iterator const& other) const { return m_iter == other.m_iter; } template bool operator!=(aged_container_iterator const& other) const { return m_iter != other.m_iter; } aged_container_iterator& operator++() { ++m_iter; return *this; } aged_container_iterator operator++(int) { aged_container_iterator const prev(*this); ++m_iter; return prev; } aged_container_iterator& operator--() { --m_iter; return *this; } aged_container_iterator operator--(int) { aged_container_iterator const prev(*this); --m_iter; return prev; } reference operator*() const { return m_iter->value; } pointer operator->() const { return &m_iter->value; } [[nodiscard]] time_point const& when() const { return m_iter->when; } private: template friend class aged_ordered_container; template friend class aged_unordered_container; template friend class aged_container_iterator; template aged_container_iterator(OtherIterator iter) : m_iter(std::move(iter)) { } [[nodiscard]] Iterator const& iterator() const { return m_iter; } Iterator m_iter; }; } // namespace detail } // namespace beast