mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Add a SameAsOneOf helper (#5490)
Trying to make repeated `std::same_as` easier to write. Calling it "concepts.h" because I figure we'll maybe have a couple more things like this. Was looking at this because I may add a couple more similar constructs.
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#include <utility>
|
||||
#include <variant>
|
||||
|
||||
#include "common/concepts.h"
|
||||
#include "common/ostream.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
@@ -298,18 +299,15 @@ struct Worklist {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires(std::same_as<T, BoolValue> ||
|
||||
std::same_as<T, CompileTimeBindIndex> ||
|
||||
std::same_as<T, ElementIndex> || std::same_as<T, FloatKind> ||
|
||||
std::same_as<T, IntKind> || std::same_as<T, CallParamIndex>)
|
||||
requires(SameAsOneOf<T, BoolValue, CompileTimeBindIndex, ElementIndex,
|
||||
FloatKind, IntKind, CallParamIndex>)
|
||||
auto Add(T arg) -> void {
|
||||
// Index-like ID: just include the value directly.
|
||||
contents.push_back(arg.index);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
requires(std::same_as<T, AnyRawId> || std::same_as<T, ExprRegionId> ||
|
||||
std::same_as<T, LocId> || std::same_as<T, RealId>)
|
||||
requires(SameAsOneOf<T, AnyRawId, ExprRegionId, LocId, RealId>)
|
||||
auto Add(T /*arg*/) -> void {
|
||||
CARBON_FATAL("Unexpected instruction operand kind {0}", typeid(T).name());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user