OpenTTD Source: AlternatingIterator< Titer > Class Template Reference

OpenTTD Source 15.3

Public Types | Public Member Functions | Private Member Functions | Private Attributes
AlternatingIterator< Titer > Class Template Reference

Iterator that alternately takes from the "middle" of a range. More...

`#include <alternating_iterator.hpp>`

## Public Types
using | value_type = typename Titer::value_type
using | difference_type = std::ptrdiff_t
using | iterator_category = std::forward_iterator_tag
using | pointer = typename Titer::pointer
using | reference = typename Titer::reference

## Public Member Functions
| AlternatingIterator (Titer first, Titer last, Titer middle, bool begin)
| Construct an AlternatingIterator.
bool | operator== (const AlternatingIterator &rhs) const
std::strong_ordering | operator<=> (const AlternatingIterator &rhs) const
reference | operator* () const
AlternatingIterator & | operator++ ()
AlternatingIterator | operator++ (int)
Titer | Base () const

## Private Member Functions
void | Next ()

## Private Attributes
Titer | first
| Initial first iterator.
Titer | last
| Initial last iterator.
Titer | middle
| Initial middle iterator.
Titer | after
| Current iterator after the middle.
Titer | before
| Current iterator before the middle.
size_t | position
| Position within the entire range.
bool | next_state
| Next state for advancing iterator. If true take from after middle, otherwise take from before middle.
bool | state
| Current state for reading iterator. If true take from after middle, otherwise take from before middle.

## Detailed Description

template<typename Titer>
class AlternatingIterator< Titer >

Iterator that alternately takes from the "middle" of a range.

Template Parameters

  Titer | Type of iterator.

Definition at line 20 of file alternating_iterator.hpp.

## Member Typedef Documentation

## ◆ difference_type

template<typename Titer >

using AlternatingIterator< Titer >::difference_type = std::ptrdiff_t

Definition at line 23 of file alternating_iterator.hpp.

## ◆ iterator_category

template<typename Titer >

using AlternatingIterator< Titer >::iterator_category = std::forward_iterator_tag

Definition at line 24 of file alternating_iterator.hpp.

## ◆ pointer

template<typename Titer >

using AlternatingIterator< Titer >::pointer = typename Titer::pointer

Definition at line 25 of file alternating_iterator.hpp.

## ◆ reference

template<typename Titer >

using AlternatingIterator< Titer >::reference = typename Titer::reference

Definition at line 26 of file alternating_iterator.hpp.

## ◆ value_type

template<typename Titer >

using AlternatingIterator< Titer >::value_type = typename Titer::value_type

Definition at line 22 of file alternating_iterator.hpp.

## Constructor & Destructor Documentation

## ◆ AlternatingIterator()

template<typename Titer >

AlternatingIterator< Titer >::AlternatingIterator | ( | Titer | first,
|  | Titer | last,
|  | Titer | middle,
|  | bool | begin
| ) |  |
| inline

Construct an AlternatingIterator.

Parameters

  first | Iterator to first element.
  last | Iterator to last element.
  middle | Iterator to "middle" element, from where to start.
  begin | Whether this iterator points to the first or last elements.

Definition at line 37 of file alternating_iterator.hpp.

References AlternatingIterator< Titer >::after, AlternatingIterator< Titer >::before, AlternatingIterator< Titer >::first, AlternatingIterator< Titer >::last, AlternatingIterator< Titer >::middle, AlternatingIterator< Titer >::next_state, AlternatingIterator< Titer >::position, and AlternatingIterator< Titer >::state.

## Member Function Documentation

## ◆ Base()

template<typename Titer >

Titer AlternatingIterator< Titer >::Base | ( |  | ) | const
| inline

Definition at line 88 of file alternating_iterator.hpp.

## ◆ Next()

template<typename Titer >

void AlternatingIterator< Titer >::Next | ( |  | ) |
| inlineprivate

Definition at line 106 of file alternating_iterator.hpp.

## ◆ operator*()

template<typename Titer >

reference AlternatingIterator< Titer >::operator* | ( |  | ) | const
| inline

Definition at line 65 of file alternating_iterator.hpp.

## ◆ operator++() [1/2]

template<typename Titer >

AlternatingIterator & AlternatingIterator< Titer >::operator++ | ( |  | ) |
| inline

Definition at line 70 of file alternating_iterator.hpp.

## ◆ operator++() [2/2]

template<typename Titer >

AlternatingIterator AlternatingIterator< Titer >::operator++ | ( | int |  | ) |
| inline

Definition at line 81 of file alternating_iterator.hpp.

## ◆ operator<=>()

template<typename Titer >

std::strong_ordering AlternatingIterator< Titer >::operator<=> | ( | const AlternatingIterator< Titer > & | rhs | ) | const
| inline

Definition at line 57 of file alternating_iterator.hpp.

## ◆ operator==()

template<typename Titer >

bool AlternatingIterator< Titer >::operator== | ( | const AlternatingIterator< Titer > & | rhs | ) | const
| inline

Definition at line 49 of file alternating_iterator.hpp.

## Field Documentation

## ◆ after

template<typename Titer >

Titer AlternatingIterator< Titer >::after
| private

Current iterator after the middle.

Definition at line 98 of file alternating_iterator.hpp.

Referenced by AlternatingIterator< Titer >::AlternatingIterator().

## ◆ before

template<typename Titer >

Titer AlternatingIterator< Titer >::before
| private

Current iterator before the middle.

Definition at line 99 of file alternating_iterator.hpp.

Referenced by AlternatingIterator< Titer >::AlternatingIterator().

## ◆ first

template<typename Titer >

Titer AlternatingIterator< Titer >::first
| private

Initial first iterator.

Definition at line 94 of file alternating_iterator.hpp.

Referenced by AlternatingIterator< Titer >::AlternatingIterator().

## ◆ last

template<typename Titer >

Titer AlternatingIterator< Titer >::last
| private

Initial last iterator.

Definition at line 95 of file alternating_iterator.hpp.

Referenced by AlternatingIterator< Titer >::AlternatingIterator().

## ◆ middle

template<typename Titer >

Titer AlternatingIterator< Titer >::middle
| private

Initial middle iterator.

Definition at line 96 of file alternating_iterator.hpp.

Referenced by AlternatingIterator< Titer >::AlternatingIterator().

## ◆ next_state

template<typename Titer >

bool AlternatingIterator< Titer >::next_state
| private

Next state for advancing iterator. If true take from after middle, otherwise take from before middle.

Definition at line 103 of file alternating_iterator.hpp.

Referenced by AlternatingIterator< Titer >::AlternatingIterator().

## ◆ position

template<typename Titer >

size_t AlternatingIterator< Titer >::position
| private

Position within the entire range.

Definition at line 101 of file alternating_iterator.hpp.

Referenced by AlternatingIterator< Titer >::AlternatingIterator().

## ◆ state

template<typename Titer >

bool AlternatingIterator< Titer >::state
| private

Current state for reading iterator. If true take from after middle, otherwise take from before middle.

Definition at line 104 of file alternating_iterator.hpp.

Referenced by AlternatingIterator< Titer >::AlternatingIterator().

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

- src/misc/alternating_iterator.hpp