Remove use of deprecated std::iterator

This commit is contained in:
Howard Hinnant
2022-08-18 20:29:36 -04:00
committed by Nik Bougalis
parent 47dec467ea
commit f5af42a640
5 changed files with 69 additions and 90 deletions

View File

@@ -30,23 +30,21 @@ class aged_ordered_container;
namespace detail { namespace detail {
// Idea for Base template argument to prevent having to repeat
// the base class declaration comes from newbiz on ##c++/Freenode
//
// If Iterator is SCARY then this iterator will be as well. // If Iterator is SCARY then this iterator will be as well.
template < template <bool is_const, class Iterator>
bool is_const, class aged_container_iterator
class Iterator,
class Base = std::iterator<
typename std::iterator_traits<Iterator>::iterator_category,
typename std::conditional<
is_const,
typename Iterator::value_type::stashed::value_type const,
typename Iterator::value_type::stashed::value_type>::type,
typename std::iterator_traits<Iterator>::difference_type>>
class aged_container_iterator : public Base
{ {
public: public:
using iterator_category =
typename std::iterator_traits<Iterator>::iterator_category;
using value_type = typename std::conditional<
is_const,
typename Iterator::value_type::stashed::value_type const,
typename Iterator::value_type::stashed::value_type>::type;
using difference_type =
typename std::iterator_traits<Iterator>::difference_type;
using pointer = value_type*;
using reference = value_type&;
using time_point = typename Iterator::value_type::stashed::time_point; using time_point = typename Iterator::value_type::stashed::time_point;
aged_container_iterator() = default; aged_container_iterator() = default;
@@ -56,13 +54,11 @@ public:
template < template <
bool other_is_const, bool other_is_const,
class OtherIterator, class OtherIterator,
class OtherBase,
class = typename std::enable_if< class = typename std::enable_if<
(other_is_const == false || is_const == true) && (other_is_const == false || is_const == true) &&
std::is_same<Iterator, OtherIterator>::value == false>::type> std::is_same<Iterator, OtherIterator>::value == false>::type>
explicit aged_container_iterator( explicit aged_container_iterator(
aged_container_iterator<other_is_const, OtherIterator, OtherBase> const& aged_container_iterator<other_is_const, OtherIterator> const& other)
other)
: m_iter(other.m_iter) : m_iter(other.m_iter)
{ {
} }
@@ -70,22 +66,19 @@ public:
// Disable constructing a const_iterator from a non-const_iterator. // Disable constructing a const_iterator from a non-const_iterator.
template < template <
bool other_is_const, bool other_is_const,
class OtherBase,
class = typename std::enable_if< class = typename std::enable_if<
other_is_const == false || is_const == true>::type> other_is_const == false || is_const == true>::type>
aged_container_iterator( aged_container_iterator(
aged_container_iterator<other_is_const, Iterator, OtherBase> const& aged_container_iterator<other_is_const, Iterator> const& other)
other)
: m_iter(other.m_iter) : m_iter(other.m_iter)
{ {
} }
// Disable assigning a const_iterator to a non-const iterator // Disable assigning a const_iterator to a non-const iterator
template <bool other_is_const, class OtherIterator, class OtherBase> template <bool other_is_const, class OtherIterator>
auto auto
operator=( operator=(
aged_container_iterator<other_is_const, OtherIterator, OtherBase> const& aged_container_iterator<other_is_const, OtherIterator> const& other) ->
other) ->
typename std::enable_if< typename std::enable_if<
other_is_const == false || is_const == true, other_is_const == false || is_const == true,
aged_container_iterator&>::type aged_container_iterator&>::type
@@ -94,20 +87,18 @@ public:
return *this; return *this;
} }
template <bool other_is_const, class OtherIterator, class OtherBase> template <bool other_is_const, class OtherIterator>
bool bool
operator==( operator==(aged_container_iterator<other_is_const, OtherIterator> const&
aged_container_iterator<other_is_const, OtherIterator, OtherBase> const& other) const
other) const
{ {
return m_iter == other.m_iter; return m_iter == other.m_iter;
} }
template <bool other_is_const, class OtherIterator, class OtherBase> template <bool other_is_const, class OtherIterator>
bool bool
operator!=( operator!=(aged_container_iterator<other_is_const, OtherIterator> const&
aged_container_iterator<other_is_const, OtherIterator, OtherBase> const& other) const
other) const
{ {
return m_iter != other.m_iter; return m_iter != other.m_iter;
} }
@@ -142,13 +133,13 @@ public:
return prev; return prev;
} }
typename Base::reference reference
operator*() const operator*() const
{ {
return m_iter->value; return m_iter->value;
} }
typename Base::pointer pointer
operator->() const operator->() const
{ {
return &m_iter->value; return &m_iter->value;
@@ -167,7 +158,7 @@ private:
template <bool, bool, class, class, class, class, class, class> template <bool, bool, class, class, class, class, class, class>
friend class aged_unordered_container; friend class aged_unordered_container;
template <bool, class, class> template <bool, class>
friend class aged_container_iterator; friend class aged_container_iterator;
template <class OtherIterator> template <class OtherIterator>

View File

@@ -989,22 +989,20 @@ public:
template < template <
bool is_const, bool is_const,
class Iterator, class Iterator,
class Base,
class = std::enable_if_t<!is_boost_reverse_iterator<Iterator>::value>> class = std::enable_if_t<!is_boost_reverse_iterator<Iterator>::value>>
beast::detail::aged_container_iterator<false, Iterator, Base> beast::detail::aged_container_iterator<false, Iterator>
erase(beast::detail::aged_container_iterator<is_const, Iterator, Base> pos); erase(beast::detail::aged_container_iterator<is_const, Iterator> pos);
// enable_if prevents erase (reverse_iterator first, reverse_iterator last) // enable_if prevents erase (reverse_iterator first, reverse_iterator last)
// from compiling // from compiling
template < template <
bool is_const, bool is_const,
class Iterator, class Iterator,
class Base,
class = std::enable_if_t<!is_boost_reverse_iterator<Iterator>::value>> class = std::enable_if_t<!is_boost_reverse_iterator<Iterator>::value>>
beast::detail::aged_container_iterator<false, Iterator, Base> beast::detail::aged_container_iterator<false, Iterator>
erase( erase(
beast::detail::aged_container_iterator<is_const, Iterator, Base> first, beast::detail::aged_container_iterator<is_const, Iterator> first,
beast::detail::aged_container_iterator<is_const, Iterator, Base> last); beast::detail::aged_container_iterator<is_const, Iterator> last);
template <class K> template <class K>
auto auto
@@ -1019,10 +1017,9 @@ public:
template < template <
bool is_const, bool is_const,
class Iterator, class Iterator,
class Base,
class = std::enable_if_t<!is_boost_reverse_iterator<Iterator>::value>> class = std::enable_if_t<!is_boost_reverse_iterator<Iterator>::value>>
void void
touch(beast::detail::aged_container_iterator<is_const, Iterator, Base> pos) touch(beast::detail::aged_container_iterator<is_const, Iterator> pos)
{ {
touch(pos, clock().now()); touch(pos, clock().now());
} }
@@ -1264,11 +1261,10 @@ private:
template < template <
bool is_const, bool is_const,
class Iterator, class Iterator,
class Base,
class = std::enable_if_t<!is_boost_reverse_iterator<Iterator>::value>> class = std::enable_if_t<!is_boost_reverse_iterator<Iterator>::value>>
void void
touch( touch(
beast::detail::aged_container_iterator<is_const, Iterator, Base> pos, beast::detail::aged_container_iterator<is_const, Iterator> pos,
typename clock_type::time_point const& now); typename clock_type::time_point const& now);
template < template <
@@ -2010,13 +2006,13 @@ template <
class Clock, class Clock,
class Compare, class Compare,
class Allocator> class Allocator>
template <bool is_const, class Iterator, class Base, class> template <bool is_const, class Iterator, class>
beast::detail::aged_container_iterator<false, Iterator, Base> beast::detail::aged_container_iterator<false, Iterator>
aged_ordered_container<IsMulti, IsMap, Key, T, Clock, Compare, Allocator>:: aged_ordered_container<IsMulti, IsMap, Key, T, Clock, Compare, Allocator>::
erase(beast::detail::aged_container_iterator<is_const, Iterator, Base> pos) erase(beast::detail::aged_container_iterator<is_const, Iterator> pos)
{ {
unlink_and_delete_element(&*((pos++).iterator())); unlink_and_delete_element(&*((pos++).iterator()));
return beast::detail::aged_container_iterator<false, Iterator, Base>( return beast::detail::aged_container_iterator<false, Iterator>(
pos.iterator()); pos.iterator());
} }
@@ -2028,17 +2024,17 @@ template <
class Clock, class Clock,
class Compare, class Compare,
class Allocator> class Allocator>
template <bool is_const, class Iterator, class Base, class> template <bool is_const, class Iterator, class>
beast::detail::aged_container_iterator<false, Iterator, Base> beast::detail::aged_container_iterator<false, Iterator>
aged_ordered_container<IsMulti, IsMap, Key, T, Clock, Compare, Allocator>:: aged_ordered_container<IsMulti, IsMap, Key, T, Clock, Compare, Allocator>::
erase( erase(
beast::detail::aged_container_iterator<is_const, Iterator, Base> first, beast::detail::aged_container_iterator<is_const, Iterator> first,
beast::detail::aged_container_iterator<is_const, Iterator, Base> last) beast::detail::aged_container_iterator<is_const, Iterator> last)
{ {
for (; first != last;) for (; first != last;)
unlink_and_delete_element(&*((first++).iterator())); unlink_and_delete_element(&*((first++).iterator()));
return beast::detail::aged_container_iterator<false, Iterator, Base>( return beast::detail::aged_container_iterator<false, Iterator>(
first.iterator()); first.iterator());
} }
@@ -2173,11 +2169,11 @@ template <
class Clock, class Clock,
class Compare, class Compare,
class Allocator> class Allocator>
template <bool is_const, class Iterator, class Base, class> template <bool is_const, class Iterator, class>
void void
aged_ordered_container<IsMulti, IsMap, Key, T, Clock, Compare, Allocator>:: aged_ordered_container<IsMulti, IsMap, Key, T, Clock, Compare, Allocator>::
touch( touch(
beast::detail::aged_container_iterator<is_const, Iterator, Base> pos, beast::detail::aged_container_iterator<is_const, Iterator> pos,
typename clock_type::time_point const& now) typename clock_type::time_point const& now)
{ {
auto& e(*pos.iterator()); auto& e(*pos.iterator());

View File

@@ -1205,15 +1205,15 @@ public:
return emplace<maybe_multi>(std::forward<Args>(args)...); return emplace<maybe_multi>(std::forward<Args>(args)...);
} }
template <bool is_const, class Iterator, class Base> template <bool is_const, class Iterator>
beast::detail::aged_container_iterator<false, Iterator, Base> beast::detail::aged_container_iterator<false, Iterator>
erase(beast::detail::aged_container_iterator<is_const, Iterator, Base> pos); erase(beast::detail::aged_container_iterator<is_const, Iterator> pos);
template <bool is_const, class Iterator, class Base> template <bool is_const, class Iterator>
beast::detail::aged_container_iterator<false, Iterator, Base> beast::detail::aged_container_iterator<false, Iterator>
erase( erase(
beast::detail::aged_container_iterator<is_const, Iterator, Base> first, beast::detail::aged_container_iterator<is_const, Iterator> first,
beast::detail::aged_container_iterator<is_const, Iterator, Base> last); beast::detail::aged_container_iterator<is_const, Iterator> last);
template <class K> template <class K>
auto auto
@@ -1222,9 +1222,9 @@ public:
void void
swap(aged_unordered_container& other) noexcept; swap(aged_unordered_container& other) noexcept;
template <bool is_const, class Iterator, class Base> template <bool is_const, class Iterator>
void void
touch(beast::detail::aged_container_iterator<is_const, Iterator, Base> pos) touch(beast::detail::aged_container_iterator<is_const, Iterator> pos)
{ {
touch(pos, clock().now()); touch(pos, clock().now());
} }
@@ -1541,10 +1541,10 @@ private:
insert_unchecked(first, last); insert_unchecked(first, last);
} }
template <bool is_const, class Iterator, class Base> template <bool is_const, class Iterator>
void void
touch( touch(
beast::detail::aged_container_iterator<is_const, Iterator, Base> pos, beast::detail::aged_container_iterator<is_const, Iterator> pos,
typename clock_type::time_point const& now) typename clock_type::time_point const& now)
{ {
auto& e(*pos.iterator()); auto& e(*pos.iterator());
@@ -3044,8 +3044,8 @@ template <
class Hash, class Hash,
class KeyEqual, class KeyEqual,
class Allocator> class Allocator>
template <bool is_const, class Iterator, class Base> template <bool is_const, class Iterator>
beast::detail::aged_container_iterator<false, Iterator, Base> beast::detail::aged_container_iterator<false, Iterator>
aged_unordered_container< aged_unordered_container<
IsMulti, IsMulti,
IsMap, IsMap,
@@ -3054,11 +3054,11 @@ aged_unordered_container<
Clock, Clock,
Hash, Hash,
KeyEqual, KeyEqual,
Allocator>:: Allocator>::erase(beast::detail::aged_container_iterator<is_const, Iterator>
erase(beast::detail::aged_container_iterator<is_const, Iterator, Base> pos) pos)
{ {
unlink_and_delete_element(&*((pos++).iterator())); unlink_and_delete_element(&*((pos++).iterator()));
return beast::detail::aged_container_iterator<false, Iterator, Base>( return beast::detail::aged_container_iterator<false, Iterator>(
pos.iterator()); pos.iterator());
} }
@@ -3071,8 +3071,8 @@ template <
class Hash, class Hash,
class KeyEqual, class KeyEqual,
class Allocator> class Allocator>
template <bool is_const, class Iterator, class Base> template <bool is_const, class Iterator>
beast::detail::aged_container_iterator<false, Iterator, Base> beast::detail::aged_container_iterator<false, Iterator>
aged_unordered_container< aged_unordered_container<
IsMulti, IsMulti,
IsMap, IsMap,
@@ -3083,13 +3083,13 @@ aged_unordered_container<
KeyEqual, KeyEqual,
Allocator>:: Allocator>::
erase( erase(
beast::detail::aged_container_iterator<is_const, Iterator, Base> first, beast::detail::aged_container_iterator<is_const, Iterator> first,
beast::detail::aged_container_iterator<is_const, Iterator, Base> last) beast::detail::aged_container_iterator<is_const, Iterator> last)
{ {
for (; first != last;) for (; first != last;)
unlink_and_delete_element(&*((first++).iterator())); unlink_and_delete_element(&*((first++).iterator()));
return beast::detail::aged_container_iterator<false, Iterator, Base>( return beast::detail::aged_container_iterator<false, Iterator>(
first.iterator()); first.iterator());
} }

View File

@@ -72,11 +72,12 @@ private:
template <typename N> template <typename N>
class ListIterator class ListIterator
: public std::iterator<std::bidirectional_iterator_tag, std::size_t>
{ {
public: public:
using iterator_category = std::bidirectional_iterator_tag;
using value_type = using value_type =
typename beast::detail::CopyConst<N, typename N::value_type>::type; typename beast::detail::CopyConst<N, typename N::value_type>::type;
using difference_type = std::ptrdiff_t;
using pointer = value_type*; using pointer = value_type*;
using reference = value_type&; using reference = value_type&;
using size_type = std::size_t; using size_type = std::size_t;

View File

@@ -29,18 +29,7 @@ namespace beast {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
template <class Container, bool IsConst> template <class Container, bool IsConst>
class LockFreeStackIterator : public std::iterator< class LockFreeStackIterator
std::forward_iterator_tag,
typename Container::value_type,
typename Container::difference_type,
typename std::conditional<
IsConst,
typename Container::const_pointer,
typename Container::pointer>::type,
typename std::conditional<
IsConst,
typename Container::const_reference,
typename Container::reference>::type>
{ {
protected: protected:
using Node = typename Container::Node; using Node = typename Container::Node;
@@ -48,7 +37,9 @@ protected:
typename std::conditional<IsConst, Node const*, Node*>::type; typename std::conditional<IsConst, Node const*, Node*>::type;
public: public:
using iterator_category = std::forward_iterator_tag;
using value_type = typename Container::value_type; using value_type = typename Container::value_type;
using difference_type = typename Container::difference_type;
using pointer = typename std::conditional< using pointer = typename std::conditional<
IsConst, IsConst,
typename Container::const_pointer, typename Container::const_pointer,