diff --git a/include/xo/expression/Apply.hpp b/include/xo/expression/Apply.hpp index 1f2b9a8f..24f4849d 100644 --- a/include/xo/expression/Apply.hpp +++ b/include/xo/expression/Apply.hpp @@ -20,10 +20,11 @@ namespace xo { **/ class Apply : public Expression { public: - Apply(const ref::rp & fn, - const std::vector> & argv) - : Expression(exprtype::apply), fn_{fn}, argv_(argv) - {} + static ref::rp make(const ref::rp & fn, + const std::vector> & argv) + { + return new Apply(fn, argv); + } /** downcast from Expression **/ static ref::brw from(ref::brw x) { @@ -35,6 +36,12 @@ namespace xo { virtual void display(std::ostream & os) const; + private: + Apply(const ref::rp & fn, + const std::vector> & argv) + : Expression(exprtype::apply), fn_{fn}, argv_(argv) + {} + private: /** function to invoke **/ ref::rp fn_; @@ -42,13 +49,36 @@ namespace xo { std::vector> argv_; }; /*Apply*/ + namespace detail { + /** Use: + ** std::vector> + **/ + + template + struct apply_push_args; + + template <> + struct apply_push_args<> { + static void p9ush_all(std::vector> * /*p_argv*/) {} + }; + + template + struct apply_push_args { + static void push_all(std::vector> * p_argv, + const ref::rp & x, Rest... rest) + { + p_argv->push_back(x); + apply_push_args::push_all(p_argv, rest...); + }; + }; + } + + /* reminder: initializer-lists are compile-time only */ inline ref::rp make_apply(const ref::rp & fn, - const ref::rp & arg1) { - std::vector> argv; - argv.push_back(arg1); - - return new Apply(fn, argv); + const std::initializer_list> args) { + std::vector> argv(args); + return Apply::make(fn, argv); } /*make_apply*/ } /*namespace ast*/