3.8.0
Freundlich's C++ toolkit
Classes | Public Types | Public Member Functions
fcppt::container::tree::pre_order< Tree > Class Template Reference

Detailed Description

template<typename Tree>
class fcppt::container::tree::pre_order< Tree >

Wraps a tree to make it iterable in a pre-order fashion.

Internally, this class manages a stack, losely imitating the runtime stack in a recursive implementation.

Example:

// Create a tree, insert 5 elements below the root
string_tree tree(FCPPT_TEXT("hello"));
tree.push_back(FCPPT_TEXT("foo"));
tree.push_back(FCPPT_TEXT("bar"));
tree.push_back(FCPPT_TEXT("baz"));
tree.front().get_unsafe().get().push_back(FCPPT_TEXT("qux"));
// Create a traversal and "attach" it to the tree in the ctor
// Then use it like a forward-iterable container!
// This outputs:
//
// hello, foo, qux, bar, baz
for (string_tree const &item : fcppt::container::tree::pre_order<string_tree const>(tree))
{
fcppt::io::cout() << item.value() << std::endl;
}

Classes

class  iterator
 

Public Types

using const_iterator = iterator
 

Public Member Functions

 pre_order (Tree &_tree)
 Construct a pre-order traversal from a tree (which can be const or nonconst) More...
 
iterator begin () const
 Return an iterator to the first tree in the traversal. More...
 
iterator end () const
 Return a dummy iterator to stop the traversal. More...
 

Member Typedef Documentation

◆ const_iterator

template<typename Tree >
using fcppt::container::tree::pre_order< Tree >::const_iterator = iterator

Constructor & Destructor Documentation

◆ pre_order()

template<typename Tree >
fcppt::container::tree::pre_order< Tree >::pre_order ( Tree &  _tree)
inlineexplicit

Construct a pre-order traversal from a tree (which can be const or nonconst)

Member Function Documentation

◆ begin()

template<typename Tree >
iterator fcppt::container::tree::pre_order< Tree >::begin ( ) const
inline

Return an iterator to the first tree in the traversal.

◆ end()

template<typename Tree >
iterator fcppt::container::tree::pre_order< Tree >::end ( ) const
inline

Return a dummy iterator to stop the traversal.