Repository: carbon-language/carbon-lang
File: toolchain/base/kind_switch.h (C/C++)

Code before:
[[maybe_unused]] static constexpr bool IsStdVariantValue = false;

template <typename... Ts>
[[maybe_unused]] static constexpr bool IsStdVariantValue<std::variant<Ts...>> =
    true;

template <typename T>
concept IsStdVariant = IsStdVariantValue<std::decay_t<T>>;

#define CARBON_INTERNAL_IDENTIFIER(name) T##name
// Turns a list of numbers into a list `T0, T1, ...`.
#define CARBON_INTERNAL_IDENTIFIERS(...)                             \
  CARBON_FOR_EACH(CARBON_INTERNAL_IDENTIFIER, CARBON_FOR_EACH_COMMA, \
                  __VA_ARGS__)

#define CARBON_INTERNAL_TYPENAME(name) typename CARBON_INTERNAL_IDENTIFIER(name)
// Turns a list of numbers into a list `typename T0, typename T1, ...`.
#define CARBON_INTERNAL_TYPENAMES(...) \
  CARBON_FOR_EACH(CARBON_INTERNAL_TYPENAME, CARBON_FOR_EACH_COMMA, __VA_ARGS__)

#define CARBON_INTERNAL_ENUM_NAME(n) VariantType##n##NotHandledInSwitch
// Turns a list of numbers into a list `VariantType0NotHandledInSwitch, ...`.
#define CARBON_INTERNAL_TYPES_TO_ENUM_NAMES(...) \
  CARBON_FOR_EACH(CARBON_INTERNAL_ENUM_NAME, CARBON_FOR_EACH_COMMA, __VA_ARGS__)

// Turns a list of numbers into a set to template specializations of the
// variable `EnumType EnumValue`, with each specialization having the Nth value
// in the EnumType (as defined by CARBON_INTERNAL_TYPES_TO_ENUM_NAMES).
#define CARBON_INTERNAL_TYPE_TO_ENUM_NAME(n)                    \
  template <>                                                   \
  constexpr EnumType EnumValue<CARBON_INTERNAL_IDENTIFIER(n)> = \
      EnumType::CARBON_INTERNAL_ENUM_NAME(n)

template <class T>
concept TypeFoundInVariant = false;

template <class T, class StdVariant>
  requires TypeFoundInVariant<T>
struct ValidCaseType;

template <typename T>
struct StdVariantTypeMap;

#define CARBON_INTERNAL_TYPE_MAP(...)                                          \
  template <CARBON_INTERNAL_TYPENAMES(__VA_ARGS__)>                            \
  struct StdVariantTypeMap<                                                    \
      std::variant<CARBON_INTERNAL_IDENTIFIERS(__VA_ARGS__)>> {                \
    /* An enum with a value for each type in the std::variant. The switch will \
     * be on this enum so that we get a warning if one of the enum values is   \
     * not handled. They are named in a way to help explain the warning, that  \
     * it means a type in the std::variant<...> type list does not have a      \

Review comment (suggestion):
```suggestion
// Turns a list of numbers into a set of template specializations of the
```

Code after:
constexpr bool IsStdVariantValue = false;

template <typename... Ts>
constexpr bool IsStdVariantValue<std::variant<Ts...>> = true;

template <typename T>
concept IsStdVariant = IsStdVariantValue<std::decay_t<T>>;

#define CARBON_INTERNAL_KIND_IDENTIFIER(name) T##name
// Turns a list of numbers into a list `T0, T1, ...`.
#define CARBON_INTERNAL_KIND_IDENTIFIERS(...)                             \
  CARBON_FOR_EACH(CARBON_INTERNAL_KIND_IDENTIFIER, CARBON_FOR_EACH_COMMA, \
                  __VA_ARGS__)

#define CARBON_INTERNAL_KIND_TYPENAME(name) \
  typename CARBON_INTERNAL_KIND_IDENTIFIER(name)
// Turns a list of numbers into a list `typename T0, typename T1, ...`.
#define CARBON_INTERNAL_KIND_TYPENAMES(...)                             \
  CARBON_FOR_EACH(CARBON_INTERNAL_KIND_TYPENAME, CARBON_FOR_EACH_COMMA, \
                  __VA_ARGS__)

#define CARBON_INTERNAL_KIND_ENUM_NAME(n) VariantType##n##NotHandledInSwitch
// Turns a list of numbers into a list `VariantType0NotHandledInSwitch, ...`.
#define CARBON_INTERNAL_KIND_TYPES_TO_ENUM_NAMES(...)                    \
  CARBON_FOR_EACH(CARBON_INTERNAL_KIND_ENUM_NAME, CARBON_FOR_EACH_COMMA, \
                  __VA_ARGS__)

// Turns a list of numbers into a set of template specializations of the
// variable `EnumType EnumValue`, with each specialization having the Nth value
// in the EnumType (as defined by CARBON_INTERNAL_KIND_TYPES_TO_ENUM_NAMES).
#define CARBON_INTERNAL_KIND_TYPE_TO_ENUM_NAME(n)                    \
  template <>                                                        \
  constexpr EnumType EnumValue<CARBON_INTERNAL_KIND_IDENTIFIER(n)> = \
      EnumType::CARBON_INTERNAL_KIND_ENUM_NAME(n)

// Used to provide a reason in the compiler error from `ValidCaseType`, which
// will state that "T does not satisfy TypeFoundInVariant".
template <class T>
concept TypeFoundInVariant = false;

// Used to cause a compler error, which will state that "ValidCaseType was not
// satisfied" for T and std::variant<...>.
template <class T, class StdVariant>
  requires TypeFoundInVariant<T>
struct ValidCaseType;

template <typename T>
struct StdVariantTypeMap;

#define CARBON_INTERNAL_KIND_TYPE_MAP(...)                                     \
  template <CARBON_INTERNAL_KIND_TYPENAMES(__VA_ARGS__)>                       \