Explain the concept of Type Traits. How does the compiler use them to make decisions at compile time?
Last updated
Type traits are template structs exposing compile-time facts about a type (
::value, e.g.std::is_integral_v) or transforming it (::type, e.g.std::remove_const_t).They work via specialization: a primary template gives the default answer and specializations override it, so the compiler picks the match during instantiation.
Their results drive
if constexpr,static_assert,std::enable_if, and concepts, so dispatch happens at compile time with no runtime cost.