www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Today's weird D edge case

reply Ethan <gooberman gmail.com> writes:
https://run.dlang.io/is/l5Vyn4

Using an is statement inside a template constraint doesn't 
propagate the is results in to a function. You have to static if 
with the same is statement to make it work.
Jul 13 2019
next sibling parent reply Ethan <gooberman gmail.com> writes:
On Sunday, 14 July 2019 at 00:22:10 UTC, Ethan wrote:
 https://run.dlang.io/is/l5Vyn4

 Using an is statement inside a template constraint doesn't 
 propagate the is results in to a function. You have to static 
 if with the same is statement to make it work.
https://run.dlang.io/is/rR5UCA And now with the full example. Derp.
Jul 13 2019
parent reply Les De Ridder <les lesderid.net> writes:
On Sunday, 14 July 2019 at 00:23:49 UTC, Ethan wrote:
 On Sunday, 14 July 2019 at 00:22:10 UTC, Ethan wrote:
 https://run.dlang.io/is/l5Vyn4

 Using an is statement inside a template constraint doesn't 
 propagate the is results in to a function. You have to static 
 if with the same is statement to make it work.
https://run.dlang.io/is/rR5UCA And now with the full example. Derp.
I realise this doesn't work for all template constraints, but for some cases there's a workaround using normal type specialisation. ... and as I was about to show it, I hit an ICE (goes away when you uncomment the second line in the !compiles): https://run.dlang.io/is/aWkOOo
Jul 14 2019
parent Basile B. <b2.temp gmx.com> writes:
On Sunday, 14 July 2019 at 19:58:20 UTC, Les De Ridder wrote:
 On Sunday, 14 July 2019 at 00:23:49 UTC, Ethan wrote:
 On Sunday, 14 July 2019 at 00:22:10 UTC, Ethan wrote:
 https://run.dlang.io/is/l5Vyn4

 Using an is statement inside a template constraint doesn't 
 propagate the is results in to a function. You have to static 
 if with the same is statement to make it work.
https://run.dlang.io/is/rR5UCA And now with the full example. Derp.
I realise this doesn't work for all template constraints, but for some cases there's a workaround using normal type specialisation. ... and as I was about to show it, I hit an ICE (goes away when you uncomment the second line in the !compiles): https://run.dlang.io/is/aWkOOo
took note of the ICE : https://issues.dlang.org/show_bug.cgi?id=20051
Jul 14 2019
prev sibling next sibling parent Petar Kirov [ZombineDev] <petar.p.kirov gmail.com> writes:
On Sunday, 14 July 2019 at 00:22:10 UTC, Ethan wrote:
 https://run.dlang.io/is/l5Vyn4

 Using an is statement inside a template constraint doesn't 
 propagate the is results in to a function. You have to static 
 if with the same is statement to make it work.
I hit the exact same limitation yesterday. It turns out it is a known thing from 2011: https://issues.dlang.org/show_bug.cgi?id=6269
Jul 14 2019
prev sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 7/13/2019 5:22 PM, Ethan wrote:
 https://run.dlang.io/is/l5Vyn4
 
 Using an is statement inside a template constraint doesn't propagate the is 
 results in to a function. You have to static if with the same is statement to 
 make it work.
URLs to those sand boxes tend to be ephemeral. Much better to just quote the text in the email, like this: import std.stdio; string SomeFunc( T )() if( is( T : AT[], AT ) ) { return AT.stringof; } void main() { writeln(SomeFunc!( int[] )); }
Jul 14 2019
parent reply bauss <jj_1337 live.dk> writes:
On Sunday, 14 July 2019 at 23:10:33 UTC, Walter Bright wrote:
 On 7/13/2019 5:22 PM, Ethan wrote:
 https://run.dlang.io/is/l5Vyn4
 
 Using an is statement inside a template constraint doesn't 
 propagate the is results in to a function. You have to static 
 if with the same is statement to make it work.
URLs to those sand boxes tend to be ephemeral. Much better to just quote the text in the email, like this: import std.stdio; string SomeFunc( T )() if( is( T : AT[], AT ) ) { return AT.stringof; } void main() { writeln(SomeFunc!( int[] )); }
I think that's an opinion. Since I use the web interface mainly then it's much more convenient to me at least that there is a link I can just click and run the example instead of having to copy-paste it.
Jul 16 2019
parent Ethan <gooberman gmail.com> writes:
On Tuesday, 16 July 2019 at 14:09:05 UTC, bauss wrote:
 I think that's an opinion. Since I use the web interface mainly 
 then it's much more convenient to me at least that there is a 
 link I can just click and run the example instead of having to 
 copy-paste it.
That's not at all what Walter meant by saying it's ephemeral. His point is that when reading this thread in a year, the link may have expired. Thus, the correct solution is to paste the code and provide the link for convenience.
Jul 17 2019