Add type checking to find_child()

Ensure that find_child() with impossible child nodes will now error
at compile time.
This commit is contained in:
ridiculousfish 2018-01-22 11:09:29 -08:00
parent 020fe5ccdf
commit 3b64a256b6

View File

@ -161,6 +161,7 @@ class tnode_t {
/// Find the first direct child of the given node of the given type. asserts on failure.
template <class ChildType>
tnode_t<ChildType> find_child() const {
static_assert(child_type_possible<Type, ChildType>(), "Cannot have that type as a child");
assert(nodeptr && "receiver is missing in find_child()");
tnode_t<ChildType> result{tree, &tree->find_child(*nodeptr, ChildType::token)};
assert(result && "cannot find child");