-
Steffen Müthing authored
This patch introduces two new functions to obtain the degree of a tree node: degree(node) is a normal, freestanding function that will in theory even work for nodes where the number of children is determined at run time. StaticDegree<Node> and staticDegree<Node> obtain the degree as a compile time constant and are thus only usable for nodes where the degree is fixed at compile time. staticDegree<Node> is a variable template and thus creates a hard dependency on C++14. Internally, both functions dispatch to the following function signature: template<typename Node, typename NodeTag> constexpr std::size_t degree(const Node* node, NodeTag nodeTag); Note that this signature uses a pointer to the node; this is necessary to make it usable in the constexpr context, where the node parameter has to be constexpr - manufacturing a constexpr reference is not possible in general. The default implementation of this function calls the static member function Node::degree(). If your node implementation requires different behavior, you can provide an overload for your custom node tag that will be found via ADL. staticDegree<Node> will only work if this function is constexpr (it is thus important to make Node::degree() constexpr in your implementation iff the degree is a compile time constant).
2a1f33b9