Re: How to initialize a associative array?

2016-12-25 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 25 December 2016 at 03:12:09 UTC, Carl Vogel wrote: Does anyone know if compile-time initialization of AAs is something that will be fixed? I do intend to fix this. The method is rather simple, Given the aa implantation in d-runtime is made ctfe-able everything that causes trouble c

Re: How to initialize a associative array?

2016-12-25 Thread Stefan Koch via Digitalmars-d-learn
On Sunday, 25 December 2016 at 05:45:14 UTC, Era Scarecrow wrote: On Saturday, 24 December 2016 at 11:21:11 UTC, Stefan Koch wrote: On Saturday, 24 December 2016 at 00:55:01 UTC, Yuxuan Shui wrote: What's the correct way? You cannot initialize an AA at compile-time. Because AA's are provided

Re: How to initialize a associative array?

2016-12-25 Thread Jack Applegame via Digitalmars-d-learn
On Saturday, 24 December 2016 at 00:55:01 UTC, Yuxuan Shui wrote: I tried this: immutable int[char] xx = ['Q':0, 'B':1, 'N':2, 'R':3, 'P':4]; And got a "non-constant expression" error (with or without 'immutable'). What's the correct way? This works: void main() { immutable int[

Re: How to initialize a associative array?

2016-12-24 Thread Era Scarecrow via Digitalmars-d-learn
On Saturday, 24 December 2016 at 11:21:11 UTC, Stefan Koch wrote: On Saturday, 24 December 2016 at 00:55:01 UTC, Yuxuan Shui wrote: What's the correct way? You cannot initialize an AA at compile-time. Because AA's are provided by druntime and the ABI is not stable. For fun I'm throwing toge

Re: How to initialize a associative array?

2016-12-24 Thread Carl Vogel via Digitalmars-d-learn
On Saturday, 24 December 2016 at 11:21:11 UTC, Stefan Koch wrote: You cannot initialize an AA at compile-time. Because AA's are provided by druntime and the ABI is not stable. This bit me when I was first starting out as well. I feel like there's really very little documentation on this, and

Re: How to initialize a associative array?

2016-12-24 Thread Stefan Koch via Digitalmars-d-learn
On Saturday, 24 December 2016 at 00:55:01 UTC, Yuxuan Shui wrote: I tried this: immutable int[char] xx = ['Q':0, 'B':1, 'N':2, 'R':3, 'P':4]; And got a "non-constant expression" error (with or without 'immutable'). What's the correct way? You cannot initialize an AA at compile-time.

Re: How to initialize a associative array?

2016-12-23 Thread Nicholas Wilson via Digitalmars-d-learn
On Saturday, 24 December 2016 at 00:57:04 UTC, Yuxuan Shui wrote: On Saturday, 24 December 2016 at 00:55:01 UTC, Yuxuan Shui wrote: I tried this: immutable int[char] xx = ['Q':0, 'B':1, 'N':2, 'R':3, 'P':4]; And got a "non-constant expression" error (with or without 'immutable'). What

How to initialize a associative array?

2016-12-23 Thread Yuxuan Shui via Digitalmars-d-learn
I tried this: immutable int[char] xx = ['Q':0, 'B':1, 'N':2, 'R':3, 'P':4]; And got a "non-constant expression" error (with or without 'immutable'). What's the correct way?

Re: How to initialize a associative array?

2016-12-23 Thread Yuxuan Shui via Digitalmars-d-learn
On Saturday, 24 December 2016 at 00:55:01 UTC, Yuxuan Shui wrote: I tried this: immutable int[char] xx = ['Q':0, 'B':1, 'N':2, 'R':3, 'P':4]; And got a "non-constant expression" error (with or without 'immutable'). What's the correct way? This example here: https://dlang.org/spec/has