From 03a883356bd3aba53b2dfadb424d53b1db04a842 Mon Sep 17 00:00:00 2001 From: Ryoga Date: Wed, 10 Jul 2019 06:50:06 +0900 Subject: Allows multiple arguments to be passed to PassRunner::add() (#2208) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit struct FooPass : public wasm::Pass { FooPass(int a, int b); }; PassRunner runner {module}; runner.add(1, 2); // To allow this This change avoids unnecessary copying and allows us to pass the reference without reference_wrapper. struct BarPass : public wasm::Pass { BarPass(std::ostream& s); }; runner.add(std::cout); // Error (cout is uncopyable) runner.add(std::ref(std::cout)); // OK ↓ runner.add(std::cout); // OK (passed by reference) runner.add(std::ref(std::cout)); // OK --- src/pass.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/pass.h b/src/pass.h index 0a9cc251f..5c1315844 100644 --- a/src/pass.h +++ b/src/pass.h @@ -171,9 +171,9 @@ struct PassRunner { doAdd(pass); } - template void add() { doAdd(new P()); } - - template void add(Arg arg) { doAdd(new P(arg)); } + template void add(Args&&... args) { + doAdd(new P(std::forward(args)...)); + } // Adds the default set of optimization passes; this is // what -O does. -- cgit v1.2.3