diff --git a/src/tint/resolver/resolver_test_helper.h b/src/tint/resolver/resolver_test_helper.h index 68a70178a9..fe33c265d0 100644 --- a/src/tint/resolver/resolver_test_helper.h +++ b/src/tint/resolver/resolver_test_helper.h @@ -31,6 +31,7 @@ #include "src/tint/sem/expression.h" #include "src/tint/sem/statement.h" #include "src/tint/sem/variable.h" +#include "src/tint/traits.h" #include "src/tint/utils/vector.h" namespace tint::resolver { @@ -793,6 +794,7 @@ constexpr bool IsValue = std::is_same_v; /// Creates a Value of DataType from a scalar `v` template Value Val(T v) { + static_assert(traits::IsTypeIn, "v must be a Number of bool"); return Value::Create(utils::Vector{v}); } diff --git a/src/tint/traits.h b/src/tint/traits.h index 8dcc65b3d6..441067e6cc 100644 --- a/src/tint/traits.h +++ b/src/tint/traits.h @@ -160,6 +160,22 @@ template using SliceTuple = std::remove_pointer_t(Range()))>; +namespace detail { +/// Base template for IsTypeIn +template +struct IsTypeIn; + +/// Specialization for IsTypeIn +template class TypeContainer, class... Ts> +struct IsTypeIn> : std::disjunction...> {}; +} // namespace detail + +/// Evaluates to true if T is one of the types in the TypeContainer's template arguments. +/// Works for std::variant, std::tuple, std::pair, or any class template where all parameters are +/// types. +template +static constexpr bool IsTypeIn = detail::IsTypeIn::value; + } // namespace tint::traits #endif // SRC_TINT_TRAITS_H_