Note that there are some explanatory texts on larger screens.

plurals
  1. POAmbiguous template arguments not excluded by enable_if
    primarykey
    data
    text
    <p>I want to automatically choose the right pointer-to-member among overloaded ones based on the "type" of the member, by removing specializations that accept unconcerned members (via enable_if).</p> <p>I have the following code:</p> <pre><code>class test; enum Type { INT_1, FLOAT_1, UINT_1, CHAR_1, BOOL_1, INT_2, FLOAT_2, UINT_2, CHAR_2, BOOL_2 }; template&lt;typename T, Type Et, typename func&gt; struct SetterOk { static const bool value = false; }; template&lt;typename T&gt; struct SetterOk&lt;T,INT_1,void (T::*)(int)&gt; { static const bool value = true; }; template&lt;typename T&gt; struct SetterOk&lt;T,FLOAT_1,void (T::*)(float)&gt; { static const bool value = true; }; template&lt;typename T&gt; struct SetterOk&lt;T,UINT_1,void (T::*)(unsigned int)&gt; { static const bool value = true; }; template&lt;typename T&gt; struct SetterOk&lt;T,CHAR_1,void (T::*)(char)&gt; { static const bool value = true; }; template&lt;typename T&gt; struct SetterOk&lt;T,BOOL_1,void (T::*)(bool)&gt; { static const bool value = true; }; template&lt;typename T&gt; struct SetterOk&lt;T,INT_2,void (T::*)(int,int)&gt; { static const bool value = true; }; template&lt;typename T&gt; struct SetterOk&lt;T,FLOAT_2,void (T::*)(float,float)&gt; { static const bool value = true; }; template&lt;typename T&gt; struct SetterOk&lt;T,UINT_2,void (T::*)(unsigned int, unsigned int)&gt; { static const bool value = true; }; template&lt;typename T&gt; struct SetterOk&lt;T,CHAR_2,void (T::*)(char,char)&gt; { static const bool value = true; }; template&lt;typename T&gt; struct SetterOk&lt;T,BOOL_2,void (T::*)(bool,bool)&gt; { static const bool value = true; }; template &lt;bool, class T = void&gt; struct enable_if {}; template &lt;class T&gt; struct enable_if&lt;true, T&gt; { typedef T type; }; template&lt;typename T, Type Et&gt; struct Helper { template&lt;typename U&gt; static void func(U method, typename enable_if&lt;SetterOk&lt;T,Et,U&gt;::value&gt;::type* dummy = 0) { } }; class test { public: void init() { Helper&lt;test,INT_2&gt;::func(&amp;test::set); } void set2(int); void set(int); void set(int,int); void set(float,float); }; int main() { test t; t.init(); return 0; } </code></pre> <p>I'm expecting it to choose the right function between all possible. The problem is that the compiler says "cannot deduce template argument as function argument is ambiguous".</p> <p>It seems I don't know how to use enable_if, because if so the compiler would only allow the specialization if the specified function has the right type...</p> <p>Note that I want to have C++03 solutions (if possible) - my code must compile on some old compilers.</p> <p>Thanks in advance</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload