Re: Error: non-constant expression

2013-12-26 Thread Jakob Ovrum
On Thursday, 26 December 2013 at 08:35:58 UTC, Ali Çehreli wrote: Are those at module scope (i.e. outside of any function)? Although it can be argued that it should be possible to produce the initial value of b at compile time, it is currently not possible. To elaborate: the problem is not wi

Re: Error: non-constant expression

2013-12-26 Thread Ali Çehreli
b = init_b(); } void main() { import std.stdio; writefln("%(%s -> %s\n%)", b); } > When add "const": > > const auto a = [["test", "1"]]; > const auto b = a.map!(x=>tuple(x[1],x[0])).assocArray; > > Gives another error: > Er

Error: non-constant expression

2013-12-25 Thread Dfr
uot;test", "1"]]; const auto b = a.map!(x=>tuple(x[1],x[0])).assocArray; Gives another error: Error: non-constant expression ["1":"test"] Any idea what is wrong ?

Re: Error: non-constant expression...

2010-11-27 Thread Jérôme M. Berger
bearophile wrote: > Jonathan M Davis: > >> At present, I don't believe that associative arrays are valid CTFE > > You are wrong, the current situation with AAs is not so simple :-) > > > string foo(string k) { > string[string] map = ["bar" : "spam"]; > return map[k]; > } > enum string v

Re: Error: non-constant expression...

2010-11-26 Thread bearophile
> I may add something about this in bugzilla (the problem with enum AAs is > already present there). http://d.puremagic.com/issues/show_bug.cgi?id=5279

Re: Error: non-constant expression...

2010-11-26 Thread bearophile
Jonathan M Davis: > At present, I don't believe that associative arrays are valid CTFE You are wrong, the current situation with AAs is not so simple :-) string foo(string k) { string[string] map = ["bar" : "spam"]; return map[k]; } enum string v = foo("bar"); static assert(v == "spam")

Re: Error: non-constant expression...

2010-11-26 Thread Jonathan M Davis
On Friday 26 November 2010 11:16:08 spir wrote: > Hello, > > void f () { > static string[string] map = ["1":"un", "2":"du", "3":"tri"]; > } > ==> > Error: non-constant expression ["1":"u

Re: Error: non-constant expression...

2010-11-26 Thread spir
On Fri, 26 Nov 2010 16:17:10 -0500 bearophile wrote: > spir: > > > void f () { > > static string[string] map = ["1":"un", "2":"du", "3":"tri"]; > > } > > ==> > > Error: non-constant expres

Re: Error: non-constant expression...

2010-11-26 Thread bearophile
> In my mind there is some confusion about all this. Other people may give you > better answers. A solution in such situations is to take a look at the asm, that has confirmed my ideas: string first_function(string k) { immutable string[string] map1 = ["bar" : "spam"]; return map1[k];

Re: Error: non-constant expression...

2010-11-26 Thread bearophile
spir: > void f () { > static string[string] map = ["1":"un", "2":"du", "3":"tri"]; > } > ==> > Error: non-constant expression ["1":"un","2":"du","3":"tri&quo

Error: non-constant expression...

2010-11-26 Thread spir
Hello, void f () { static string[string] map = ["1":"un", "2":"du", "3":"tri"]; } ==> Error: non-constant expression ["1":"un","2":"du","3":"tri"] I do not understand w