Perhaps you are thinking of something like:
#include <iostream>
#include <map>
template <typename Key, typename Value>
struct Tree
{
typedef std::map<Key, Tree> Children;
Tree& operator=(const Value& value) { value_ = value; return *this; }
Tree& operator[](const Key& key) { return children_[key]; }
Children children_;
Value value_;
friend std::ostream& operator<<(std::ostream& os, const Tree& tree)
{
os << tree.value_ << " { ";
for (typename Children::const_iterator i = tree.children_.begin();
i != tree.children_.end(); ++i)
os << i->first << " -> " << i->second << " | ";
return os << '}';
}
};
int main()
{
Tree<int, std::string> t;
t[1].children_[1] = "one,one";
t[1].children_[9] = "one,nine";
t[1] = "hmmm";
std::cout << t << '\n';
}
I would not recommend it.
source
share