Код: Выделить всё
enum class E1 { a, b, c };
enum class E2 { p, Q, r, s, t };
enum class E3 { x, y, Q, z };
// ...
Код: Выделить всё
template bool constexpr has_Q() { return false; }
template bool constexpr has_Q { return true; }
template bool constexpr has_Q { return true; }
Код: Выделить всё
template T constexpr get_Q(); // not implemented
template E2 constexpr get_Q() { return E2::Q; }
template E3 constexpr get_Q() { return E3::Q; }
< /code>
Это позволяет шаблонам библиотечной функции делать такие вещи, как: < /p>
if constexpr(has_Q()) {
auto constexpr Q = get_Q();
// do something involving Q here
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... cular-name
Мобильная версия