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
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
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 ?
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
> 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
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")
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
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
> 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];
spir:
> void f () {
> static string[string] map = ["1":"un", "2":"du", "3":"tri"];
> }
> ==>
> Error: non-constant expression ["1":"un","2":"du","3":"tri&quo
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
11 matches
Mail list logo