template<class Derived>
struct Base {
void name() {
(static_cast<Derived*>(this))->impl();
}
};
struct D1 : public Base<D1> {
void impl() {
std::cout << "D1::impl()\n";
}
};
struct D2 : public Base<D2> {
void impl() {
std::cout << "D2::impl()\n";
}
};
struct D3 {
void impl() {
std::cout << "D3::impl()\n";
}
};
template <class T>
void myFunction(T value) {
if constexpr (std::is_same_v<T, D1>) {
// Code for float case
std::cout << "D1 constexpr" << std::endl;
value.name();
}
else {
std::cout << "no D1 constexpr" << std::endl;
// Code for general case
}
}