Skip to content

TreeData rewritten, using forEachNode. Copy assignment operator corrected and move operations added

Summary

I have rewritten the TreeData structure, using the copy-and-swap ideom and forEachNode loops.

Motivation

In TreeData there is a bug in the copy assignment operator: If tree_ is already set, it is destroyed first, but not initialized afterwards, so that the CopyVisitor would produce a segfault. Simple solution:

TreeData& operator=(const TreeData& other)
{
  if (tree_) {
    TypeTree::applyToTree(*tree_, DestroyVisitor(data_));
    TypeTree::applyToTree(*tree_, InitVisitor(data_));
  }
  tree_ = other.tree_;
  TypeTree::applyToTree(*tree_, CopyVisitor(*this, other));
  return *this;
}

However, this implementation seems not so very clean. So, I have rewritten the TreeData structure. Additionally, I have added move-operations and a small test for all the functions.

Edited by Carsten Gräser

Merge request reports

Loading