I am going through Alexandrescu's book and it demonstrates the useful concept of typifying integral values to allow for compile-time dispatch:
template <int Val>
struct Elastic
{
enum {V = Val};
};
template <class Object, bool isElastic>
class ImpactMomentum
{
double calc_momentum(double v_in, Elastic<true> /* */)
{
// compute elastic ...
}
double calc_momentum(double v_in, Elastic<false> /* */)
{
// compute rigid ...
}
public:
double calc_momentum(double v_in)
{
calc_velocity(v_in, Elastic<isElastic>());
}
};
Is there a modern C++ implementation which supersedes this idiom? Something which scales well when there are multiple flags to toggle in the function's argument list.
if constexpr
can be used if the code differences between makes that more suitable