Is it possible to conditionally disable a global function definition using template metaprogramming?
<p>Say I have a simple nullary template function templated on a single parameter, with two specializations, one for <code>unsigned long</code>, and one for <code>size_t</code> (contents not important):</p>

<pre><code>template&lt;typename T&gt; T f(void);
template&lt;&gt; unsigned long f&lt;unsigned long&gt;(void) { return 1; }
template&lt;&gt; size_t f&lt;size_t&gt;(void) { return 2; }
</code></pre>

<p>My understanding is that the exact definition of the type <code>size_t</code> is platform-dependent, and so it may or may not be equivalent to <code>unsigned long</code>. On my current platform (Cygwin g++ 5.2.0 on Windows 10 64-bit compiling with <code>-std=gnu++1y</code>) these two types appear to be equivalent, so the above code fails to compile:</p>

<pre><code>../test.cpp:51:19: error: redefinition of ‘T f() [with T = long unsigned int]’
 template&lt;&gt; size_t f&lt;size_t&gt;(void) { return 2; }
                   ^
../test.cpp:50:26: note: ‘T f() [with T = long unsigned int]’ previously declared here
 template&lt;&gt; unsigned long f&lt;unsigned long&gt;(void) { return 1; }
                          ^
</code></pre>

<p>From my thinking, this problem could be solved by simply disabling the <code>size_t</code> function definition, since any code that attempted to call <code>f&lt;size_t&gt;()</code> would automatically resolve to <code>f&lt;unsigned long&gt;()</code>. But the function should be enabled for platforms that define <code>size_t</code> to be different from <code>unsigned long</code>.</p>

<p>I've read a little bit about template metaprogramming and SFINAE, and I've been playing with things like this:</p>

<pre><code>std::enable_if&lt;(sizeof(size_t) &gt; sizeof(unsigned long))&gt;::type 
</code></pre>

<p>But I'm unsure how to use such a fragment to disable a global function definition, if that's possible at all.</p>

<p>So, is there any way to conditionally disable a global function definition using template metaprogramming? Or, more generally, am I on the right track, or heading down a wrong path?</p>