Skip to content

Commit 03a8833

Browse files
Ryoooooogakripken
authored andcommitted
Allows multiple arguments to be passed to PassRunner::add<T>() (#2208)
struct FooPass : public wasm::Pass { FooPass(int a, int b); }; PassRunner runner {module}; runner.add<FooPass>(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<BarPass>(std::cout); // Error (cout is uncopyable) runner.add<BarPass>(std::ref(std::cout)); // OK ↓ runner.add<BarPass>(std::cout); // OK (passed by reference) runner.add<BarPass>(std::ref(std::cout)); // OK
1 parent cbca5a2 commit 03a8833

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/pass.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ struct PassRunner {
171171
doAdd(pass);
172172
}
173173

174-
template<class P> void add() { doAdd(new P()); }
175-
176-
template<class P, class Arg> void add(Arg arg) { doAdd(new P(arg)); }
174+
template<class P, class... Args> void add(Args&&... args) {
175+
doAdd(new P(std::forward<Args>(args)...));
176+
}
177177

178178
// Adds the default set of optimization passes; this is
179179
// what -O does.

0 commit comments

Comments
 (0)