diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h index 5396cdd0c5..4dac010736 100644 --- a/src/tint/program_builder.h +++ b/src/tint/program_builder.h @@ -149,6 +149,10 @@ struct IsVectorLike> { }; } // namespace detail +// Forward declare metafunction that evaluates to true iff T can be wrapped in a statement. +template +struct CanWrapInStatement; + /// ProgramBuilder is a mutable builder for a Program. /// To construct a Program, populate the builder and then `std::move` it to a /// Program. @@ -3326,12 +3330,13 @@ class ProgramBuilder { /// by the Resolver. /// @param args a mix of ast::Expression, ast::Statement, ast::Variables. /// @returns the function - template + template ::value && ...)>> const ast::Function* WrapInFunction(ARGS&&... args) { utils::Vector stmts{ WrapInStatement(std::forward(args))..., }; - return WrapInFunction(utils::VectorRef{std::move(stmts)}); + return WrapInFunction(std::move(stmts)); } /// @param stmts a list of ast::Statement that will be wrapped by a function, /// so that each statement is reachable by the Resolver. @@ -3411,6 +3416,17 @@ inline ProgramID ProgramIDOf(const ProgramBuilder* builder) { return builder->ID(); } +// Primary template for metafunction that evaluates to true iff T can be wrapped in a statement. +template +struct CanWrapInStatement : std::false_type {}; + +// Specialization of CanWrapInStatement +template +struct CanWrapInStatement< + T, + std::void_t().WrapInStatement(std::declval()))>> + : std::true_type {}; + } // namespace tint #endif // SRC_TINT_PROGRAM_BUILDER_H_