Using decltype to declare the entire function type itself (not pointer!) : <p>So I have a function with a specific signature in a header file, and I want to declare another function with the exact same signature inside a class <strong>without</strong> typing the parameters again, and of course, hopefully without a macro... The member function should also have an extra hidden parameter obviously, the <code>this</code> pointer (since it's not a static member function).</p>

<p>Now, I'm actually surprised that the following hack/trick <em>works</em> in both GCC and ICC, but I'm not sure if it's "legal" C++. I'm not particularly concerned with legality <em>if it's a supported extension</em>, but unfortunately I do not want it to break on a compiler version update because some people decided to <em>arbitrarily block</em> this useful feature since the standard says "no" (that kind of stuff really annoys me to be honest).</p>

<p>Here's what I mean:</p>

<pre><code>// test.hpp
int func(int x) { return x; }

struct foo
{
  decltype(func) fn;  // &lt;-- legal?
};

int test()
{
  return foo().fn(6);
}


// then in test.cpp
int foo::fn(int x) { return x + 42; }
</code></pre>

<p>This <em>works</em> (with GCC and ICC), but I don't know if it's "legal" in the standard. I'm asking just to be assured that it is legal and it won't suddenly stop working in the future.</p>

<p>(if it's not legal and you want to report it as a bug, please mark it as a suggestion to make it a legal compiler extension instead of killing it...)</p>

<p>Basically, it's the same as declaring <code>int fn(int x);</code> in the struct, and that's how it works currently.</p>

<p>If you ask me for a use case: it's to declare a wrapper member function for the other free function which does something with the <code>this</code> pointer before passing it to the free function. Its parameters must match exactly, obviously. Again, I don't want to type the parameters again.</p>
