Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Hm. I think I got something nasty. The code is not very pretty or good, but you probably get the idea. You should be able to use templates to recursively store objects of any type, and also recurse through them when calling the function.</p> <pre><code>#include &lt;iostream&gt; template&lt;typename first_arg, typename... args&gt; class Event { public: Event(void (*fn)(first_arg, args...), first_arg first, args... in) : m_func(fn), var(first, in...) {} void operator()() { var(m_func); } private: void (*m_func)(first_arg, args...); template &lt;typename t_arg, typename... t_args&gt; struct storage; template &lt;typename t_arg&gt; struct storage&lt;t_arg&gt; { storage(t_arg t) : m_var(t) {} template&lt;typename t_func, typename... tt_args&gt; void operator()(t_func fn, tt_args... p) { fn(p..., m_var); } t_arg m_var; }; template &lt;typename t_arg, typename t_arg2, typename... t_args&gt; struct storage&lt;t_arg, t_arg2, t_args...&gt; { storage(t_arg t, t_arg2 t2, t_args... p) : m_var(t), m_storage(t2, p...) {} template&lt;typename t_func, typename... tt_args&gt; void operator()(t_func fn, tt_args... p) { m_storage(fn, p..., m_var); } t_arg m_var; storage&lt;t_arg2, t_args...&gt; m_storage; }; storage&lt;first_arg, args...&gt; var; }; void test(int a, float b) { std::cout &lt;&lt; a &lt;&lt; std::endl &lt;&lt; b &lt;&lt; std::endl; } int main() { Event&lt;int, float&gt; event(test, 10, 100.0); event(); } </code></pre> <p>Also, I think std::bind does something similar, but not sure :D</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload