One way before C ++ 17 is to use partial template specializations, as here:
template <template T, bool AorB> struct dummy; template <typename T, true> struct dummy { static void MyFunc() { FunctionA<T>(); } } template <typename T, false> struct dummy { static void MyFunc() { FunctionB<T>(); } } template <typename T> void Facade() { dummy<T, MeetsConditions<T>::value>::MyFunc(); }
If you need more than two specializations, you can use an enumeration or an integer value and create specializations for all necessary enumerations.
Another way is to use std :: enable_if:
template <typename T> std::enable_if<MeetsConditions<T>::value, void>::type MyFunc() { FunctionA<T>(); } template <typename T> std::enable_if<!MeetsConditions<T>::value, void>::type MyFunc() { FunctionB<T>(); }
source share