C++ wrap a generic std::tr1::function with another function
<p>How can I wrap a <em>generic</em> C++ std::tr1::function object with another function such that this function executes first followed by the wrapped function? I've tried:</p>

<pre><code>#include &lt;tr1/functional&gt;

template &lt;typename T&gt;
int wrapped(const std::tr1::function&lt;int(T)&gt;&amp; f, T t)
{
  return f(t);
}

template &lt;typename T&gt;
std::tr1::function&lt;int(T)&gt; wrap(const std::tr1::function&lt;int(T)&gt;&amp; f)
{
  return std::tr1::bind(&amp;wrapped, f, std::tr1::placeholders::_1);
}

int foo(int i) { return i; }

int main(int argc, char** argv)
{
  std::tr1::function&lt;int(int)&gt; f =
    wrap(std::tr1::bind(&amp;foo, std::tr1::placeholders::_1));
  f(1);
  return 0;
}
</code></pre>

<p>But this returns with the compiler error (g++):</p>

<pre><code>wrap.cpp: In function ‘int main(int, char**)’:
wrap.cpp:22: error: no matching function for call to ‘wrap(std::tr1::_Bind&lt;int (* ()(std::tr1::_Placeholder&lt;1&gt;))(int)&gt;)’
</code></pre>
