Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The short answer is "templates are not string substitution". <code>void f(void)</code> has meaning only so far as it is an alias for <code>void f()</code> in C++, in order to be backwards compatible with C.</p> <p>The first step is to use variadics, as noted elsewhere.</p> <p>The second step is figuring out how to map <code>void</code> returning functions to ... well, maybe something like <code>std::function&lt;void()&gt;</code>, or maybe something else. I say maybe something else because unlike the other cases, you cannot call <code>std::function&lt;void()&gt; foo; foo( []()-&gt;void {} );</code> -- it isn't a true continuation.</p> <p>Something like this maybe:</p> <pre><code>template&lt;typename T&gt; struct Continuation { typedef std::function&lt;void(T)&gt; type; }; template&lt;&gt; struct Continuation&lt;void&gt; { typedef std::function&lt;void()&gt; type; }; </code></pre> <p>then use it like this:</p> <pre><code>auto someFunc = []()-&gt;void {}; Continuation&lt;decltype(someFunc())&gt;::type c; </code></pre> <p>which gives you the type you want. You could even add in an apply to continuation:</p> <pre><code>template&lt;typename T&gt; struct Continuation { typedef std::function&lt;void(T)&gt; type; template&lt;typename func, typename... Args&gt; static void Apply( type const&amp; cont, func&amp;&amp; f, Args... args) { cont( f(args...) ); } }; template&lt;&gt; struct Continuation&lt;void&gt; { typedef std::function&lt;void()&gt; type; template&lt;typename func, typename... Args&gt; static void Apply( type const&amp; cont, func&amp;&amp; f, Args... args) { f(args...); cont(); } }; </code></pre> <p>which lets you apply a continuation to an execution of a function uniformly if the incoming type is a void or if it is a non-void type.</p> <p>However, I would ask "why would you want to do this"?</p>
 

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