3 ms·
Static If [1]. Would simplify a lot of template code, like generic data structures with optional features. template <class Entry, bool useParents> struct AvlTr
by ambrop7 14y ago
Static If [1]. Would simplify a lot of template code, like generic data structures with optional features.
template <class Entry, bool useParents>
struct AvlTreeHelper {
int balance;
Entry \child[2];
static if (useParents) {
Entry \parent;
}
};
template <...., bool useParents>
void ...::insert (...)
{
...
static if (useParents) {
// fixup parent pointers
}
...
}
Such optional behavior can be achieved with existing C++ features by inheriting specialized template classes, but it makes code very unreadable, especially when you have big functions with small conditional parts inside, or when you have more than one boolean condition.
[1] http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3329.pdf http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n332...