4.6.0
Freundlich's C++ toolkit
Loading...
Searching...
No Matches
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{"hello"};
tree.push_back("foo");
tree.push_back("bar");
tree.push_back("baz");
tree.front().get_unsafe().get().push_back("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))
{
std::cout << item.value() << '\n';
}

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)
 
iterator begin () const
 Return an iterator to the first tree in the traversal.
 
iterator end () const
 Return a dummy iterator to stop the traversal.
 

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
inlinenodiscard

Return an iterator to the first tree in the traversal.

◆ end()

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

Return a dummy iterator to stop the traversal.