digitalmars.D.learn - constant expression
- Nicholas Wilson (18/18) Feb 22 2016 How is this not a constant expression ?
- =?UTF-8?Q?Ali_=c3=87ehreli?= (5/23) Feb 22 2016 Because it's mutable: :)
- Nicholas Wilson (3/29) Feb 22 2016 I've tried with both mutable and immutable a module scope. Scope
- =?UTF-8?Q?Ali_=c3=87ehreli?= (22/24) Feb 22 2016 Uncomment immutable if you want immutable and remove 'shared' if you
- Nicholas Wilson (3/29) Feb 23 2016 Thanks
- Steven Schveighoffer (6/40) Feb 23 2016 D cannot create associative arrays at compile time that can be used
- Marc =?UTF-8?B?U2Now7x0eg==?= (6/7) Feb 24 2016 Due to a problem with the implementation, associative arrays
How is this not a constant expression ? auto ctodtypes = [ "void" : "void", "uint32_t" : "uint", "uint64_t" : "ulong", "int32_t" : "int", "int64_t" : "long", "char" : "char", "uint8_t" : "ubyte", "size_t" : "size_t", "float" : "float" ]; dmd complains source/emit/registryemitter.d(7): Error: non-constant expression ["void":"void", "uint32_t":"uint", "uint64_t":"ulong", "int32_t":"int", "int64_t":"long", "char":"char", "uint8_t":"ubyte", "size_t":"size_t", "float":"float"]
Feb 22 2016
On 02/22/2016 09:52 PM, Nicholas Wilson wrote:How is this not a constant expression ? auto ctodtypes = [ "void" : "void", "uint32_t" : "uint", "uint64_t" : "ulong", "int32_t" : "int", "int64_t" : "long", "char" : "char", "uint8_t" : "ubyte", "size_t" : "size_t", "float" : "float" ]; dmd complains source/emit/registryemitter.d(7): Error: non-constant expression ["void":"void", "uint32_t":"uint", "uint64_t":"ulong", "int32_t":"int", "int64_t":"long", "char":"char", "uint8_t":"ubyte", "size_t":"size_t", "float":"float"]Because it's mutable: :) ctodtypes["hello"] = "world"; What context are you using it in? Ali
Feb 22 2016
On Tuesday, 23 February 2016 at 07:26:01 UTC, Ali Çehreli wrote:On 02/22/2016 09:52 PM, Nicholas Wilson wrote:I've tried with both mutable and immutable a module scope. Scope I want is global (don't care about mutability)How is this not a constant expression ? auto ctodtypes = [ "void" : "void", "uint32_t" : "uint", "uint64_t" : "ulong", "int32_t" : "int", "int64_t" : "long", "char" : "char", "uint8_t" : "ubyte", "size_t" : "size_t", "float" : "float" ]; dmd complains source/emit/registryemitter.d(7): Error: non-constant expression ["void":"void", "uint32_t":"uint", "uint64_t":"ulong", "int32_t":"int", "int64_t":"long", "char":"char", "uint8_t":"ubyte", "size_t":"size_t", "float":"float"]Because it's mutable: :) ctodtypes["hello"] = "world"; What context are you using it in? Ali
Feb 22 2016
On 02/22/2016 11:38 PM, Nicholas Wilson wrote:I've tried with both mutable and immutable a module scope. Scope I want is global (don't care about mutability)Uncomment immutable if you want immutable and remove 'shared' if you want multiple of this per thread (probably not). /* immutable */ string[string] ctodtypes; shared static this() { ctodtypes = [ "void" : "void", "uint32_t" : "uint", "uint64_t" : "ulong", "int32_t" : "int", "int64_t" : "long", "char" : "char", "uint8_t" : "ubyte", "size_t" : "size_t", "float" : "float" ]; } void main() { ctodtypes["hello"] = "world"; } Ali
Feb 22 2016
On Tuesday, 23 February 2016 at 07:43:37 UTC, Ali Çehreli wrote:On 02/22/2016 11:38 PM, Nicholas Wilson wrote:Thanks Silly question. Why is this necessary?I've tried with both mutable and immutable a module scope. Scope I want is global (don't care about mutability)Uncomment immutable if you want immutable and remove 'shared' if you want multiple of this per thread (probably not). /* immutable */ string[string] ctodtypes; shared static this() { ctodtypes = [ "void" : "void", "uint32_t" : "uint", "uint64_t" : "ulong", "int32_t" : "int", "int64_t" : "long", "char" : "char", "uint8_t" : "ubyte", "size_t" : "size_t", "float" : "float" ]; } void main() { ctodtypes["hello"] = "world"; } Ali
Feb 23 2016
On 2/23/16 3:00 AM, Nicholas Wilson wrote:On Tuesday, 23 February 2016 at 07:43:37 UTC, Ali Çehreli wrote:D cannot create associative arrays at compile time that can be used during runtime. You have to create them at runtime. It could probably do effectively what is done above, however. Just nobody has made that enhancement. -SteveOn 02/22/2016 11:38 PM, Nicholas Wilson wrote:Thanks Silly question. Why is this necessary?I've tried with both mutable and immutable a module scope. Scope I want is global (don't care about mutability)Uncomment immutable if you want immutable and remove 'shared' if you want multiple of this per thread (probably not). /* immutable */ string[string] ctodtypes; shared static this() { ctodtypes = [ "void" : "void", "uint32_t" : "uint", "uint64_t" : "ulong", "int32_t" : "int", "int64_t" : "long", "char" : "char", "uint8_t" : "ubyte", "size_t" : "size_t", "float" : "float" ]; } void main() { ctodtypes["hello"] = "world"; } Ali
Feb 23 2016
On Tuesday, 23 February 2016 at 08:00:24 UTC, Nicholas Wilson wrote:Silly question. Why is this necessary?Due to a problem with the implementation, associative arrays currently can't be initialized statically. We hope it will eventually get fixed, but until then, you have to use module constructors as a workaround.
Feb 24 2016