How to restrict template functor return and parameter types
<p>My code looks like this:</p>

<pre><code>template&lt;typename F&gt;
void printHello(F f)
{
    f("Hello!");
}

int main() {
    std::string buf;
    printHello([&amp;buf](const char*msg) { buf += msg; });
    printHello([&amp;buf]() { });
}
</code></pre>

<p>The question is - how can I restrict the <code>F</code> type to accept only lambdas that have a signature <code>void(const char*)</code>, so that the second call to <code>printHello</code> doesn't fail at some obscure place inside <code>printHello</code> but instead on the line that calls <code>printHello</code> incorrectly?</p>

<p><strong>==EDIT==</strong></p>

<p>I <em>know</em> that <code>std::function</code> can solve it in this particular case (is what I'd use if I really wanted to print 'hello'). But <code>std::function</code> is really something else and comes at a cost (however small that cost is, as of today, April 2016, GCC and MSVC <em>cannot</em> optimize away the virtual call). So my question can be seen as purely academic - is there a "template" way to solve it?</p>