www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Forcing opDispatch error (not SFINAE?)

reply =?UTF-8?B?Ikx1w61z?= Marques" <luis luismarques.eu> writes:
Consider this:

     struct S
     {
         void opDispatch(string name, T)(T value)
         {
             alias AllowedTypes = SomeComplexTemplate!S;

             //static assert(is(T : AllowedTypes, "wrong type"));

              static if(!is(T : AllowedTypes))
             {
                 pragma(msg, "wrong type");
                 static assert(0);
             }

         }
     }

If the static assert fails, then the opDispatch instantiation 
fails, and so the relevant member is declared not found. Because 
of SFINAE, I assume (no?), the user/developer will never see the 
"wrong type" error message. So, instead, you have to use a 
pragma(msg), saying something like "hey, ignore the message 
bellow saying 'name' is not found; it's totally there, the 
problem is that you tried to assign a value of an invalid type".

Is there a way to improve this situation?

(BTW, the documentation for opDispatch is a bit thin on the 
details.)
Jun 17 2014
next sibling parent "deadalnix" <deadalnix gmail.com> writes:
On Tuesday, 17 June 2014 at 20:13:39 UTC, Luís Marques wrote:
 Consider this:

     struct S
     {
         void opDispatch(string name, T)(T value)
         {
             alias AllowedTypes = SomeComplexTemplate!S;

             //static assert(is(T : AllowedTypes, "wrong type"));

              static if(!is(T : AllowedTypes))
             {
                 pragma(msg, "wrong type");
                 static assert(0);
             }

         }
     }

 If the static assert fails, then the opDispatch instantiation 
 fails, and so the relevant member is declared not found. 
 Because of SFINAE, I assume (no?), the user/developer will 
 never see the "wrong type" error message. So, instead, you have 
 to use a pragma(msg), saying something like "hey, ignore the 
 message bellow saying 'name' is not found; it's totally there, 
 the problem is that you tried to assign a value of an invalid 
 type".

 Is there a way to improve this situation?

 (BTW, the documentation for opDispatch is a bit thin on the 
 details.)

No SFINAE please. That is an idiotic C++ idiom. use template constraints if you want to disable this template for some parameter sets. static assert is to statically assert. In this case it fails. As it should !
Jun 17 2014
prev sibling next sibling parent "Dicebot" <public dicebot.lv> writes:
On Tuesday, 17 June 2014 at 20:26:11 UTC, deadalnix wrote:
 No SFINAE please. That is an idiotic C++ idiom. use template
 constraints if you want to disable this template for some
 parameter sets. static assert is to statically assert. In this
 case it fails. As it should !

As far as I understand Luís wants exactly that, for static assert to trigger. Looks like some sort of error gagging hides it and "parent" error message gets printed instead. D does not support SFINAE in general as far as I know.
Jun 17 2014
prev sibling next sibling parent =?UTF-8?B?Ikx1w61z?= Marques" <luis luismarques.eu> writes:
On Tuesday, 17 June 2014 at 20:41:20 UTC, Dicebot wrote:
 As far as I understand Luís wants exactly that, for static 
 assert to trigger. Looks like some sort of error gagging hides 
 it and "parent" error message gets printed instead. D does not 
 support SFINAE in general as far as I know.

Yes, thanks for clarifying.
Jun 17 2014
prev sibling next sibling parent "deadalnix" <deadalnix gmail.com> writes:
On Tuesday, 17 June 2014 at 20:54:02 UTC, Luís Marques wrote:
 On Tuesday, 17 June 2014 at 20:41:20 UTC, Dicebot wrote:
 As far as I understand Luís wants exactly that, for static 
 assert to trigger. Looks like some sort of error gagging hides 
 it and "parent" error message gets printed instead. D does not 
 support SFINAE in general as far as I know.

Yes, thanks for clarifying.

OK I understood it the other way around, sorry. You are right.
Jun 17 2014
prev sibling next sibling parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Tuesday, 17 June 2014 at 20:54:02 UTC, Luís Marques wrote:
 On Tuesday, 17 June 2014 at 20:41:20 UTC, Dicebot wrote:
 As far as I understand Luís wants exactly that, for static 
 assert to trigger. Looks like some sort of error gagging hides 
 it and "parent" error message gets printed instead. D does not 
 support SFINAE in general as far as I know.

Yes, thanks for clarifying.

Aren't you just asking for template constraints? struct S { void opDispatch(string name, T)(T value) if (T : SomeComplexTemplate!S) { ... } } What am I missing?
Jun 17 2014
prev sibling parent "monarch_dodra" <monarchdodra gmail.com> writes:
On Tuesday, 17 June 2014 at 21:45:21 UTC, monarch_dodra wrote:
 What am I missing?

OK: I re-read the thread. Twice. Now I understand. Looks like a bug.
Jun 17 2014