Manipulating variables without evaluating them
Salih Dincer
salihdb at hotmail.com
Mon May 8 11:06:59 UTC 2023
On Sunday, 7 May 2023 at 17:11:52 UTC, Dadoum wrote:
> Hello,
>
> I am currently making a wrapper around libplist in D, and to
> get a good syntax I first thought about making a `pl` function
> with bunch of overloads allowing to convert strings, integers,
> booleans into the corresponding `Plist` type. It is working but
> the problem here is that associative array literals are not
> preserving order (they are immediately hashed, and so all the
> keys are in a random order).
It's hard to figure out what you want but there are errors in
your code. This works:
```d
auto plistDict(alias AA)()
{
auto dict = new string[AA.length];
foreach (key, value; AA)
{
dict[key] = value;
}
return dict;
}
import std.stdio;
void main()
{
auto plist = plistDict!([0: "zero",
1: "one",
2: "two"]);
plist.writeln; // ["zero", "one", "two"]
}
```
And yes, the data is not converted at compile time.
SDB at 79
More information about the Digitalmars-d
mailing list