Re: Question about @nogc in D 2.066

2014-07-11 Thread Dicebot via Digitalmars-d-learn
On Friday, 11 July 2014 at 21:02:30 UTC, Timon Gehr wrote: He is allocating an immutable(int)[] here. There is no reason why it should allocate unless providing different addresses for different runs of the code is considered a feature, as the literal has a compile-time known value. It's just t

Re: Question about @nogc in D 2.066

2014-07-11 Thread Trass3r via Digitalmars-d-learn
http://forum.dlang.org/thread/pxotrowaqcenrpnnw...@forum.dlang.org

Re: Question about @nogc in D 2.066

2014-07-11 Thread Timon Gehr via Digitalmars-d-learn
On 07/11/2014 10:39 PM, Dicebot wrote: Key difference is that type of string literal is immutable(char)[] so it is perfectly legal to keep it in binary text segment. Type of array literal is just T[] (int[] here) and you can possibly mutate their elements. Because of this each assignment of array

Re: Question about @nogc in D 2.066

2014-07-11 Thread Dicebot via Digitalmars-d-learn
Key difference is that type of string literal is immutable(char)[] so it is perfectly legal to keep it in binary text segment. Type of array literal is just T[] (int[] here) and you can possibly mutate their elements. Because of this each assignment of array literal needs to allocate a new copy

Re: Question about @nogc in D 2.066

2014-07-11 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 11 July 2014 at 20:02:32 UTC, Weasel wrote: Why does the s1 not throw an error, but the a1 does? Strings don't allocate upon use whereas all other arrays do unless you specifically mark it as static - immutability isn't considered here (I think because the part of the compiler that

Question about @nogc in D 2.066

2014-07-11 Thread Weasel via Digitalmars-d-learn
@nogc void main(string[] args) { immutable(char)[] s1 = "hello"; immutable(int)[] a1 = [1, 2]; } Why does the s1 not throw an error, but the a1 does? As far as I can tell, they're both immutable arrays. Error is: "Error: array literal @nogc function main may cause GC allocation" It

Re: Question about @nogc

2014-05-20 Thread anonymous via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 21:48:08 UTC, Timon Gehr wrote: Wtf. Is this really the point you are trying to make? :o) This achieves the same: template lookupTable(alias fn,uint max=255){ static assert(maxenum ReturnType!fn[max+1] lookupTable=iota(0,max+1).map!fn.array; } Ha! That's .

Re: Question about @nogc

2014-05-20 Thread Timon Gehr via Digitalmars-d-learn
On 05/20/2014 11:48 PM, Timon Gehr wrote: This achieves the same: template lookupTable(alias fn,uint max=255){ static assert(max (Though I'd never actually do template argument checking in a static assert within the template body.)

Re: Question about @nogc

2014-05-20 Thread Timon Gehr via Digitalmars-d-learn
On 05/20/2014 11:04 PM, anonymous wrote: On Tuesday, 20 May 2014 at 20:15:09 UTC, Dominikus Dittes Scherkl wrote: /// create a fixed size array with the given name and with *max* entries max + 1 entries /// of immutable values of the same type as the return value of the /// given function. /

Re: Question about @nogc

2014-05-20 Thread anonymous via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 21:16:26 UTC, monarch_dodra wrote: enum ReturnType!fn[length] lookupTable = [elements]; Depending on what the usecase is, you might want to change that to static immutable instead: static immutable ReturnType!fn[length] lookupTable = [elements]; Remember that

Re: Question about @nogc

2014-05-20 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 21:04:37 UTC, anonymous wrote: On Tuesday, 20 May 2014 at 20:15:09 UTC, Dominikus Dittes Scherkl wrote: /// create a fixed size array with the given name and with *max* entries max + 1 entries /// of immutable values of the same type as the return value of the //

Re: Question about @nogc

2014-05-20 Thread anonymous via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 20:15:09 UTC, Dominikus Dittes Scherkl wrote: /// create a fixed size array with the given name and with *max* entries max + 1 entries /// of immutable values of the same type as the return value of the /// given function. /// it contains the values of that functio

Re: Question about @nogc

2014-05-20 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 17:14:31 UTC, John Colvin wrote: On Tuesday, 20 May 2014 at 12:25:11 UTC, Dominikus Dittes Scherkl wrote: Did I understand correct that a function can only be @nogc if also all functions that it calls are @nogc too (and of course it doesn't use the GC itself)? If so

Re: Question about @nogc

2014-05-20 Thread John Colvin via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 12:25:11 UTC, Dominikus Dittes Scherkl wrote: Did I understand correct that a function can only be @nogc if also all functions that it calls are @nogc too (and of course it doesn't use the GC itself)? If so, should this be possible: string foo() { // use GC to al

Re: Question about @nogc

2014-05-20 Thread monarch_dodra via Digitalmars-d-learn
On Tuesday, 20 May 2014 at 12:25:11 UTC, Dominikus Dittes Scherkl wrote: Did I understand correct that a function can only be @nogc if also all functions that it calls are @nogc too (and of course it doesn't use the GC itself)? If so, should this be possible: string foo() { // use GC to al

Question about @nogc

2014-05-20 Thread Dominikus Dittes Scherkl via Digitalmars-d-learn
Did I understand correct that a function can only be @nogc if also all functions that it calls are @nogc too (and of course it doesn't use the GC itself)? If so, should this be possible: string foo() { // use GC to allocate some string } bar @nogc { mixin(foo()); } Because, bar() didn'