You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve behaviour of tree creation and Tree::root_id().
`Tree` is now non-empty by default, and `Tree::root_id()` will no longer modify the tree when it is empty. To create an empty tree now it is necessary to use the capacity constructor with a capacity of zero:
```c++
// default-constructed tree is now non-empty
Tree tree;
assert(!tree.empty()); // MODIFIED! was empty on previous version
id_type root = tree.root_id(); // OK. default-constructed tree is now non-empty
// to create an empty tree:
Tree tree(0); // pass capacity of zero
assert(tree.empty()); // as expected
// but watchout, this is no longer possible:
//id_type root = tree.root_id(); // ERROR: cannot get root of empty tree.
```
This changeset also enables the python library to call `root_id()` on a default-constructed tree
re #556
Copy file name to clipboardExpand all lines: changelog/current.md
+14Lines changed: 14 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,3 +6,17 @@
6
6
---
7
7
more data here
8
8
```
9
+
-[PR#557](https://github.com/biojppm/rapidyaml/pull/557) - `Tree` is now non-empty by default, and `Tree::root_id()` will no longer modify the tree when it is empty. To create an empty tree now it is necessary to use the capacity constructor with a capacity of zero:
10
+
```c++
11
+
// default-constructed tree is now non-empty
12
+
Tree tree;
13
+
assert(!tree.empty()); // MODIFIED! was empty on previous version
14
+
id_type root = tree.root_id(); // OK. default-constructed tree is now non-empty
15
+
16
+
// to create an empty tree:
17
+
Tree tree(0); // pass capacity of zero
18
+
assert(tree.empty()); // as expected
19
+
// but watchout, this is no longer possible:
20
+
//id_type root = tree.root_id(); // ERROR: cannot get root of empty tree.
21
+
```
22
+
This changeset also enables the python library to call `root_id()` on a default-constructed tree (fixes [#556](https://github.com/biojppm/rapidyaml/issues/556)).
0 commit comments