JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers — header-only, RTTI-free, and concurrency-friendly.
Loading...
Searching...
No Matches
jh::avl::tree_map< K, V, Alloc >::const_iterator Struct Referencefinal

Const bidirectional iterator for in-order traversal. More...

#include <jh/core/ordered_map.h>

Public Types

using base_type = tree_map
 Owning tree type.
using node_type = detail::node_t<K, V>
 Canonical node type used internally.
using stored_type = detail::base_t<K, V>
 Stored value type (key for set, pair<const K,V> for map).
using iterator_concept = std::bidirectional_iterator_tag
 Iterator concept tag (bidirectional).
using value_type = stored_type
 Value type produced when dereferenced.
using reference = const stored_type &
 Reference type for dereferencing.
using pointer = const stored_type *
 Pointer type for dereferencing.
using difference_type = std::int64_t
 Difference type used for iterator arithmetic.

Public Member Functions

 const_iterator ()=default
 Construct a singular iterator.
 const_iterator (const base_type *t, std::size_t i)
 Construct an iterator referring to the given node index.
 const_iterator (const iterator &it)
 Construct a const_iterator from a non-const iterator.
reference operator* () const
 Dereference the iterator.
pointer operator-> () const
 Access the referenced element via pointer.
const node_type::key_typekey () const
 Obtain the key of the referenced element.
const_iteratoroperator++ ()
 Advance to the in-order successor.
const_iterator operator++ (int)
 Post-increment.
const_iteratoroperator-- ()
 Move to the in-order predecessor.
const_iterator operator-- (int)
 Post-decrement.
bool operator== (const const_iterator &other) const
 Compare two const_iterators for equality.
bool operator!= (const const_iterator &other) const
 Compare two const_iterators for inequality.

Public Attributes

const base_typetree = nullptr
 Associated tree instance; nullptr indicates a singular iterator.
std::size_t idx = static_cast<std::size_t>(-1)
 Index of the referenced node, or -1 for end().

Detailed Description

template<typename K, typename V, typename Alloc = std::allocator<detail::value_t<K, V>>>
struct jh::avl::tree_map< K, V, Alloc >::const_iterator

Const bidirectional iterator for in-order traversal.

Unlike iterator, this type provides a strictly read-only view of the underlying elements. All dereference operations yield const access, and mutation through the iterator is not permitted. This mirrors the behavior of standard associative-container const_iterator.

Conversion from iterator to const_iterator is supported, but not the reverse. Aside from const-qualification, traversal semantics (increment, decrement, ordering) match those of iterator.

Constructor & Destructor Documentation

◆ const_iterator() [1/3]

template<typename K, typename V, typename Alloc = std::allocator<detail::value_t<K, V>>>
jh::avl::tree_map< K, V, Alloc >::const_iterator::const_iterator ( )
default

Construct a singular iterator.

A default-constructed const_iterator does not refer to any tree and is therefore singular. It must not be incremented, decremented, or dereferenced. Only assignment or destruction is permitted.

This state is distinct from end(): an end iterator is bound to a specific container and supports valid bidirectional traversal (e.g., end()), while a singular iterator does not.

◆ const_iterator() [2/3]

template<typename K, typename V, typename Alloc = std::allocator<detail::value_t<K, V>>>
jh::avl::tree_map< K, V, Alloc >::const_iterator::const_iterator ( const base_type * t,
std::size_t i )
inline

Construct an iterator referring to the given node index.

Parameters
tPointer to the owning tree.
iNode index, or -1 to represent end().

This constructor is typically used internally to form begin/end iterators. Users generally obtain iterators through member functions.

◆ const_iterator() [3/3]

template<typename K, typename V, typename Alloc = std::allocator<detail::value_t<K, V>>>
jh::avl::tree_map< K, V, Alloc >::const_iterator::const_iterator ( const iterator & it)
inlineexplicit

Construct a const_iterator from a non-const iterator.

Parameters
itThe iterator to convert.

Enables implicit promotion from iterator to const_iterator, matching standard iterator behavior for associative containers.

Member Function Documentation

◆ key()

template<typename K, typename V, typename Alloc = std::allocator<detail::value_t<K, V>>>
const node_type::key_type & jh::avl::tree_map< K, V, Alloc >::const_iterator::key ( ) const
inlinenodiscard

Obtain the key of the referenced element.

Returns
Constant reference to the key.

Undefined behavior if the iterator is singular or equals end().

◆ operator!=()

template<typename K, typename V, typename Alloc = std::allocator<detail::value_t<K, V>>>
bool jh::avl::tree_map< K, V, Alloc >::const_iterator::operator!= ( const const_iterator & other) const
inline

Compare two const_iterators for inequality.

Equivalent to !(a == b).

Returns
true if the iterators are not equal.

◆ operator*()

template<typename K, typename V, typename Alloc = std::allocator<detail::value_t<K, V>>>
reference jh::avl::tree_map< K, V, Alloc >::const_iterator::operator* ( ) const
inline

Dereference the iterator.

Returns
Reference to the element.

Undefined behavior if the iterator is singular or equals end().

◆ operator++() [1/2]

template<typename K, typename V, typename Alloc = std::allocator<detail::value_t<K, V>>>
const_iterator & jh::avl::tree_map< K, V, Alloc >::const_iterator::operator++ ( )
inline

Advance to the in-order successor.

Bidirectional-iterator semantics apply:

  • If the iterator is end(), incrementing leaves it unchanged.
  • Otherwise moves to the next element in sorted order.
  • Undefined behavior if the iterator is singular.
Returns
Reference to *this.

◆ operator++() [2/2]

template<typename K, typename V, typename Alloc = std::allocator<detail::value_t<K, V>>>
const_iterator jh::avl::tree_map< K, V, Alloc >::const_iterator::operator++ ( int )
inline

Post-increment.

Returns the prior iterator value, then advances using operator++().

Returns
Copy of the iterator before incrementing.

◆ operator--() [1/2]

template<typename K, typename V, typename Alloc = std::allocator<detail::value_t<K, V>>>
const_iterator & jh::avl::tree_map< K, V, Alloc >::const_iterator::operator-- ( )
inline

Move to the in-order predecessor.

Bidirectional-iterator semantics apply:

  • If the iterator is end(), decrementing moves it to the last element, or leaves it unchanged if the container is empty.
  • If the iterator refers to begin(), decrementing moves it to end().
  • Otherwise moves to the previous element in sorted order.
  • Undefined behavior if the iterator is singular.
Returns
Reference to *this.

◆ operator--() [2/2]

template<typename K, typename V, typename Alloc = std::allocator<detail::value_t<K, V>>>
const_iterator jh::avl::tree_map< K, V, Alloc >::const_iterator::operator-- ( int )
inline

Post-decrement.

Returns the prior iterator value, then decrements using operator--().

Returns
Copy of the iterator before decrementing.

◆ operator->()

template<typename K, typename V, typename Alloc = std::allocator<detail::value_t<K, V>>>
pointer jh::avl::tree_map< K, V, Alloc >::const_iterator::operator-> ( ) const
inline

Access the referenced element via pointer.

Returns
Pointer to the element.

Undefined behavior if the iterator is singular or equals end().

◆ operator==()

template<typename K, typename V, typename Alloc = std::allocator<detail::value_t<K, V>>>
bool jh::avl::tree_map< K, V, Alloc >::const_iterator::operator== ( const const_iterator & other) const
inline

Compare two const_iterators for equality.

Parameters
otherThe iterator to compare with.

Two const_iterators are equal only if they refer to the same container and the same logical position.


The documentation for this struct was generated from the following file: