Conditional Logic
std::conditional and if constexpr.
Choosing Types and Branches
Type-trait logic lets code pick types and code paths at compile time. The key tools are std::conditional and if constexpr.
std::conditional
std::conditional_t<cond, A, B> evaluates to A when cond is true, otherwise B.
#include <iostream>
#include <type_traits>
int main() {
using T = std::conditional_t<true, int, double>;
std::cout << std::is_same_v<T, int> << "\n";
return 0;
}All lessons in this course
- Querying Types
- Transforming Types
- Conditional Logic
- Writing Custom Traits