Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy std::bind can't be param of parameters pack?
    primarykey
    data
    text
    <p>I'd like to use parameters pack, but find the problem. Some code:</p> <pre><code>template &lt;typename Function, typename... Args&gt; auto f(Function func, Args... args) -&gt; decltype(func(args...)) { auto f11 = std::bind(func, args...); f11(); } void print(const char* string) { std::cout &lt;&lt; string &lt;&lt; std::endl; } </code></pre> <p>All of this works well:</p> <pre><code> f([] (const char* additional, const char* more) { std::cout &lt;&lt; "hello ( " &lt;&lt; additional &lt;&lt; ", " &lt;&lt; more &lt;&lt; " )" &lt;&lt; std::endl; }, "additional text", "and one more"); auto printFunction = std::bind(&amp;print, std::placeholders::_1); printFunction("hello from print bind"); f(print, "hello from print directly"); </code></pre> <p>but if i would like to give std::function to parameters pack:</p> <pre><code>f([] (std::function&lt;void(const char*)&gt; printParamFunc) { printParamFunc("hello from print from std::function"); }, printFunction); </code></pre> <p>application no more compiles. </p> <p>So, what the problem to use function as parameter in pack?</p> <p>Thanks.</p> <p><strong>UPDATE:</strong> if change code of f to:</p> <pre><code>template &lt;typename Function, typename... Args&gt; auto f(Function func, Args... args) -&gt; decltype(func(args...)) { func(args...); } </code></pre> <p>it works well, but i wouldn't like to execute this function here, i wanna create function and pass it like param.</p> <p><strong>UPDATE2:</strong> Code execution example: <a href="http://ideone.com/gDjnPq" rel="nofollow">http://ideone.com/gDjnPq</a></p> <p><strong>UPDATE3:</strong> Clear code with compilation error: <a href="http://ideone.com/50z7IN" rel="nofollow">http://ideone.com/50z7IN</a></p>
    singulars
    1. This table or related slice is empty.
    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.
 

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