Repository: carbon-language/carbon-lang
File: toolchain/sem_ir/id_kind.h (C/C++)

Code before:
  }

 private:
  // Translates a type to its enum value, or `Invalid`.
  template <typename IdT, bool AllowInvalid>
  static constexpr auto ForImpl() -> TypeEnum {
    // A bool for each type saying whether it matches. The result is the index
    // of the first `true` in this list. If none matches, then the result is the
    // length of the list, which is mapped to `Invalid`.
    constexpr bool TypeMatches[] = {std::same_as<IdT, Types>...};
    constexpr int Index =
        std::find(TypeMatches, TypeMatches + NumTypes, true) - TypeMatches;
    static_assert(Index != NumTypes || AllowInvalid,
                  "Unexpected type passed to TypeEnum::For<...>");
    return TypeEnum(static_cast<RawEnumType>(Index));
  }

  RawEnumType value_;
};

// An enum of all the ID types used as instruction operands.
//
// As instruction operands, the types listed here can appear as fields of typed
// instructions (`toolchain/sem_ir/typed_insts.h`) and must implement the
// `FromRaw` and `ToRaw` protocol in `Inst`. In most cases this is done
// by inheriting from `IdBase` or `IndexBase`.
//
// clang-format off: We want one per line.
using IdKind = TypeEnum<
    // From base/value_store.h.
    FloatId,
    IntId,
    RealId,
    StringLiteralValueId,
    // From sem_ir/ids.h.
    AbsoluteInstBlockId,
    AbsoluteInstId,
    AnyRawId,
    AssociatedConstantId,
    BoolValue,
    CallParamIndex,
    ClassId,
    CompileTimeBindIndex,
    ConstantId,
    DeclInstBlockId,
    DestInstId,
    ElementIndex,
    EntityNameId,
    ExprRegionId,
    FacetTypeId,
    FloatKind,

Review comment (suggestion):
```suggestion
// `FromRaw` and `ToRaw` protocol in `Inst`. In most cases this is done by
// inheriting from `IdBase` or `IndexBase`.
```

Code after:
  }

 private:
  // Translates a type to its enum value, or `Invalid`.
  template <typename IdT, bool AllowInvalid>
  static constexpr auto ForImpl() -> TypeEnum {
    // A bool for each type saying whether it matches. The result is the index
    // of the first `true` in this list. If none matches, then the result is the
    // length of the list, which is mapped to `Invalid`.
    constexpr bool TypeMatches[] = {std::same_as<IdT, Types>...};
    constexpr int Index =
        std::find(TypeMatches, TypeMatches + NumTypes, true) - TypeMatches;
    static_assert(Index != NumTypes || AllowInvalid,
                  "Unexpected type passed to TypeEnum::For<...>");
    return TypeEnum(static_cast<RawEnumType>(Index));
  }

  RawEnumType value_;
};

// An enum of all the ID types used as instruction operands.
//
// As instruction operands, the types listed here can appear as fields of typed
// instructions (`toolchain/sem_ir/typed_insts.h`) and must implement the
// `FromRaw` and `ToRaw` protocol in `Inst`. In most cases this is done by
// inheriting from `IdBase` or `IndexBase`.
//
// clang-format off: We want one per line.
using IdKind = TypeEnum<
    // From base/value_store.h.
    FloatId,
    IntId,
    RealId,
    StringLiteralValueId,
    // From sem_ir/ids.h.
    AbsoluteInstBlockId,
    AbsoluteInstId,
    AnyRawId,
    AssociatedConstantId,
    BoolValue,
    CallParamIndex,
    ClassId,
    CompileTimeBindIndex,
    ConstantId,
    DeclInstBlockId,
    DestInstId,
    ElementIndex,
    EntityNameId,
    ExprRegionId,
    FacetTypeId,
    FloatKind,