Skip to content

Instantly share code, notes, and snippets.

@njlr
Created May 25, 2017 13:59
Show Gist options
  • Save njlr/c9ab184c80c93cb7e3c440dafc1ac630 to your computer and use it in GitHub Desktop.
Save njlr/c9ab184c80c93cb7e3c440dafc1ac630 to your computer and use it in GitHub Desktop.
struct Tree {
string const name;
value_ptr<Tree> left;
value_ptr<Tree> right;
Tree(
string const& name,
value_ptr<Tree> const& left = value_ptr<Tree>{},
value_ptr<Tree> const& right = value_ptr<Tree>{})
: name{name}
, left{left}
, right{right}
{}
};
int main() {
Tree root = Tree{
"root",
Tree{"l0"}
Tree{"r0"}
};
root.left = root; // Copy of root assigned to left
root.right = root; // and we don't have cyclic references
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment