![]() |
Arene Base
Fundamental Utilities For Safety Critical C++
|
A metaprogramming facility for selecting a branch statically without evaluating both branches apriori. More...
A metaprogramming facility for selecting a branch statically without evaluating both branches apriori.
This has uses similar to std::conditional except that it allows for lazily evaluated metafunctions. Usage can lead to fewer template instantiations, which can have significant impact on compile times in low level facilities.
std::conditional .The principle that's followed is that instantiations of type templates are costly in terms of resource usage during compilation and have a tendency to add up surprisingly quickly, however, template aliases are close to free (you only pay for the substitution process of the template arguments). static_if minimizes resource usage at compile-time because regardless of how many times a developer uses static_if , with any combination of arguments, there are only two types: static_if<true> and static_if<false> . All branching is done with nested templates aliases.
In order to handle a variety of branch kinds, there are 4 different forms of "then else" corresponding to when none, one, or both branches take a lazily-evaluated metafunction. The naming convention used is that apply in the name corresponds to a parameter that is a metafunction. In other words:
then_else // No metafunctions then_apply_else // The "then" branch is a metafunction then_else_apply // The "else" branch is a metafunction then_apply_else_apply // Both "then" and "else" branches are metafunctions
Usage Example: