digitalmars.D - Forcing opDispatch error (not SFINAE?)
- =?UTF-8?B?Ikx1w61z?= Marques" (24/24) Jun 17 2014 Consider this:
- deadalnix (5/30) Jun 17 2014 No SFINAE please. That is an idiotic C++ idiom. use template
- Dicebot (5/9) Jun 17 2014 As far as I understand Luís wants exactly that, for static assert
- =?UTF-8?B?Ikx1w61z?= Marques" (2/6) Jun 17 2014 Yes, thanks for clarifying.
- deadalnix (2/8) Jun 17 2014 OK I understood it the other way around, sorry. You are right.
- monarch_dodra (11/17) Jun 17 2014 Aren't you just asking for template constraints?
- monarch_dodra (3/4) Jun 17 2014 OK: I re-read the thread. Twice. Now I understand.
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
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
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
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
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:OK I understood it the other way around, sorry. You are right.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
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: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?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
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