// Copyright (C) 2023 johannst enum Kind { kPrimary, kTT, kIntBool, kIntInt, }; // (1) Primary template. template struct pair { static constexpr Kind kind = kPrimary; }; // (2) Partial template specialization. template struct pair { static constexpr Kind kind = kTT; }; // (3) Template specialization. template<> struct pair { static constexpr Kind kind = kIntBool; }; // (4) Template specialization. template<> struct pair { static constexpr Kind kind = kIntInt; }; int main() { static_assert(pair::kind == kIntBool, ""); // * Compare template arg list with primary template, we only supplied one // arg, the second one will be defaulted as // pair // * Compare template arg list against available specializations, this will // try to match the pattern against the patterns defined in the // partial specializations. // * (2) pattern does not match // * (3) pattern does match // * (4) pattern does not match // * Pick the most specialized version -> (3) static_assert(pair::kind == kTT, ""); // * Compare template arg list against available specializations, this will // try to match the pattern against the patterns defined in the // partial specializations. // * (2) pattern does match // * (3) pattern does not match // * (4) pattern does not match // * Pick the most specialized version -> (2) static_assert(pair::kind == kIntInt, ""); // * Compare template arg list against available specializations, this will // try to match the pattern against the patterns defined in the // partial specializations. // * (2) pattern does match // * (3) pattern does match // * (4) pattern does not match // * Pick the most specialized version -> (3) static_assert(pair::kind == kPrimary, ""); // * Compare template arg list against available specializations, this will // try to match the pattern against the patterns defined in the // partial specializations. // * (2) pattern does not match // * (3) pattern does not match // * (4) pattern does not match // * No specialization matches, take the primary template. }