41 #include <boost/container/stable_vector.hpp> 42 #include <boost/noncopyable.hpp> 80 template <
typename T>
class Tree 97 void print_impl(std::ostream&
os,
const TreeNode<T> *node,
int indent )
const;
99 std::unique_ptr<TreeNode<T>>
_root;
105 template <
typename T>
inline 106 std::ostream& operator<<(std::ostream &os, const std::pair<const TreeNode<T>*,
const TreeNode<T>* >& tail_head )
111 if( !head )
return os;
115 array[index++] = head;
117 while( !head || head != tail)
120 array[index++] = head;
122 array[index] =
nullptr;
130 if( index >0 )
os <<
".";
136 template <
typename T>
inline 139 for (
int i=0;
i<indent;
i++) os <<
" ";
140 os << node->
value() << std::endl;
144 print_impl(os, &
child, indent+3);
148 template <
typename T>
inline 155 template <
typename T>
inline TreeNode< T > * root()
Mutable pointer to the root of the tree.
const ChildrenVector & children() const
const TreeNode * parent() const
TreeNode * child(size_t index)
const TreeNode * child(size_t index) const
std::vector< TreeNode > ChildrenVector
std::unique_ptr< TreeNode< T > > _root
ChildrenVector & children()
TreeNode * addChild(const T &child)
Element of the tree. it has a single parent and N >= 0 children.
#define assert(condition)
friend std::ostream & operator<<(std::ostream &os, const Tree &_this)
void setValue(const T &value)
TreeNode(const TreeNode *parent)
void print_impl(std::ostream &os, const TreeNode< T > *node, int indent) const
const TreeNode< T > * root() const