The Tree Container Library
A C++ generic tree container library which, not only works much like the STL, but is also compatible with the STL algorithms. The Tree Container Library is used worldwide in thousands of industries and organizations. It is completely free to use, and is licensed under the zlib/libpng license.
Versions 3.50 and later are compatible with the STL. What this means is that you can use STL container iterators in some operations in the TCL, and also use both TCL child iterators and descendant iterators with STL algorithms and containers. The following list shows just some of the operations you can perform between the STL and TCL.
- Copy elements from STL container to a TCL container node using an STL container iterator range.
- Copy child elements of a TCL container node to an STL container using a TCL child iterator range.
- Copy descendant elements of a TCL container node to an STL container using a TCL descendant iterator range.
- Perform STL algorithm operations on a TCL node's children, using a TCL child iterator range.
- Perform STL algorithm operations on a TCL node's descendants, using a TCL descendant iterator range.
STL compatibility is made possible by deriving the TCL iterators from the proper STL iterator type. Iterators derived from an appropriate STL iterator type, which also define the appropriate required set of operations, can be used in the STL algorithms. The list below, show how the various iterators are derived. Note that the iterators expose the underlying node's element as seen in all of the derivation declarations below. Since all iterators expose the element of the underlying node, any operations performed by STL algorithms will be on the element of the underlying node, not on the node itself. This is an important concept, and will be illustrated in the examples. The list below show how the various TCL iterators are derived.
child iterators and child const_iterators are derived from
sequential_tree child iterator and child const_iterator are derived from
The pre and post descendant iterators for all trees are derived from
The level order iterator for all trees are derived from
The ordered iterators for unique_tree are derived from
STL compatibility involves not only the TCL iterators, but the TCL containers as well. In order to be compatible with the STL, the TCL containers must define a required set of operations. These requirements differ between associative containers and sequential containers. Thus, there are different container requirements for the associative tree containers, and for sequential_tree. Furthermore, certain typdefs must be declared for both the STL containers and iterators for them to be compatible with the STL. The latest version of the TCL fulfills all these requirements, which make all the TCL containers and iterators compatible with the containers, iterators, and algorithms in the STL.
The following pages illustrate how you can use the TCL in conjunction with the STL. To see some live examples of how the TCL and STL work together, you can also download the TCL test suite, which provides tests on every facet of the TCL, including STL compatibility tests. Since this test suite is a work in progress, check back often to obtain the latest test cases within the suite.