title: How to create a hook on a std::function?
body: <p>I am trying to figure out how to decorate a <code>std::function</code> with "before" and "after" hooks.</p>
  
  <p>I have some trouble figuring out the right syntax. This is what I have so far:</p>
  
  <pre><code>// create a "before" hook
  template&lt;typename Functor, typename Hook&gt;
  Functor hook_before(const Functor &amp; original, Hook hook)
  {
      // not legal, but illustrates what I want to achieve
      template&lt;typename Args ...args&gt; 
      return [=](Args ...args)
      {
          hook();
          original(args...);
      };
  }
  </code></pre>
  
  <p>My sample application is on <a href="http://ideone.com/ZQCYi" rel="nofollow">Ideone</a>.</p>
  
  <p>Can anyone help me figure it out?</p>