libwordring
公開型 | 公開メンバ関数 | フレンド | 全メンバ一覧
wordring::basic_tree_iterator< Iterator, Container, Allocator > クラステンプレート

プレ・オーダーあるいはレベル・オーダーで木を走査するイテレータ・アダプター [詳解]

#include <wordring/tree/tree_iterator.hpp>

公開型

using base_type = Iterator
 
using container = Container
 
using allocator_type = Allocator
 
using value_type = typename std::iterator_traits< base_type >::value_type
 
using difference_type = typename std::iterator_traits< base_type >::difference_type
 
using reference = typename std::iterator_traits< base_type >::reference
 
using pointer = typename std::iterator_traits< base_type >::pointer
 
using iterator_category = std::input_iterator_tag
 

公開メンバ関数

 basic_tree_iterator (allocator_type const &alloc=allocator_type())
 
 basic_tree_iterator (base_type const &it, allocator_type const &alloc=allocator_type())
 親を指すイテレータを指定して構築する [詳解]
 
 basic_tree_iterator (base_type const &first, base_type const &last, allocator_type const &alloc=allocator_type())
 
 basic_tree_iterator (basic_tree_iterator const &)=default
 
 basic_tree_iterator (basic_tree_iterator &&)=default
 
basic_tree_iteratoroperator= (basic_tree_iterator const &rhs)=default
 
basic_tree_iteratoroperator= (basic_tree_iterator &&rhs)=default
 
base_type base () const
 現在の位置を指す、元となる木のイテレータを返す
 
reference operator* () const
 要素の逆参照を返す
 
pointer operator-> () const
 要素の参照を返す
 
basic_tree_iteratoroperator++ ()
 イテレータを進める [詳解]
 
base_type operator++ (int)
 イテレータを進める [詳解]
 

フレンド

template<typename Iterator1 , typename Container1 , typename Allocator1 >
bool operator== (basic_tree_iterator< Iterator1, Container1, Allocator1 > const &, basic_tree_iterator< Iterator1, Container1, Allocator1 > const &)
 
template<typename Iterator1 , typename Container1 , typename Allocator1 >
bool operator!= (basic_tree_iterator< Iterator1, Container1, Allocator1 > const &, basic_tree_iterator< Iterator1, Container1, Allocator1 > const &)
 

詳解

template<typename Iterator, typename Container, typename Allocator>
class wordring::basic_tree_iterator< Iterator, Container, Allocator >

プレ・オーダーあるいはレベル・オーダーで木を走査するイテレータ・アダプター

テンプレート引数
Iteratorベースとなる木のイテレータ
Containerdetail::tree_iterator_stack あるいは detail::tree_iterator_queue
Allocatorアロケータ

プレ・オーダー走査用の tree_iterator とレベル・オーダー走査用の level_order_tree_iterator が事前に定義されている。

template <typename Iterator, typename Allocator = std::allocator<Iterator>>
using tree_iterator = basic_tree_iterator<Iterator, detail::tree_iterator_stack<Iterator, Allocator>, Allocator>;
template <typename Iterator, typename Allocator = std::allocator<Iterator>>
using level_order_tree_iterator = basic_tree_iterator<Iterator, detail::tree_iterator_queue<Iterator, Allocator>, Allocator>;

このクラスは、道順の調査に、スタックあるいはキューを使う。 従って、コピーのコストは相応に高い。

operator++() によって、走査順に従い次の要素へ移動する。 operator*() によって、指している要素の逆参照を得る。 元となる木のイテレータを得るには、 base() を使う。

走査順のイメージを以下に示す。
※要素についている番号は移動順を示す。

プレ・オーダー
レベル・オーダー

構築子と解体子

◆ basic_tree_iterator()

template<typename Iterator , typename Container , typename Allocator >
wordring::basic_tree_iterator< Iterator, Container, Allocator >::basic_tree_iterator ( base_type const &  it,
allocator_type const &  alloc = allocator_type() 
)
inlineexplicit

親を指すイテレータを指定して構築する

引数
it親を指すイテレータ
alloc内部コンテナ用のアロケータ

親は任意の要素で十分であり、木の根である必要はない。

関数詳解

◆ operator++() [1/2]

template<typename Iterator , typename Container , typename Allocator >
basic_tree_iterator& wordring::basic_tree_iterator< Iterator, Container, Allocator >::operator++ ( )
inline

イテレータを進める

戻り値
*this

◆ operator++() [2/2]

template<typename Iterator , typename Container , typename Allocator >
base_type wordring::basic_tree_iterator< Iterator, Container, Allocator >::operator++ ( int  )
inline

イテレータを進める

戻り値
進める前の位置を指す元となる木のイテレータ

この関数は、コピーのコストを避けるため basic_tree_iterator ではなく元となる木のイテレータを返す。


このクラス詳解は次のファイルから抽出されました: