cannot interpret `cast(void)0` at compile time?
Salih Dincer
salihdb at hotmail.com
Tue May 9 23:27:07 UTC 2023
On Tuesday, 9 May 2023 at 09:54:21 UTC, Dadoum wrote:
> Hello,
>
> I am making a libplist wrapper and I am currently writing a
> template to handle associative arrays and preserve the order of
> the keys in the conversion process. (I already talked a bit
> about that
> [here](https://forum.dlang.org/post/pxevvegnaqueprwrkfos@forum.dlang.org))
>
> I have `plistConvert` which is a function with a lot of
> overloads to convert any other type to its plist counterpart
> already, and I want to have a template `pl` to convert
> associative arrays to PlistDict.
To tell the truth, I'm a little confused. 😀
So I can't understand why we should use the delegate. Below I
will share a similar example and it includes a wrapper (Bar),
your class (PlistDict) and it works:
```d
alias AA = Bar[string];
struct Bar // Wrapper
{
int value;
}
class Foo // PlistDict
{
void opIndexAssign(Bar element, string key)
{
import std.stdio;
key.writeln(" added, value: ", element.value);
}
}
template PL(alias R) // pl
{
static if(is(typeof(R) == AA))
{
auto PL()
{
auto dict = new Foo();
static foreach (K, V; R)
{
dict[K] = V;
}
return dict;
}
} else static if(is(typeof(R) == int)) {
enum PL = Bar(R);
} else {
enum PL = Bar();
}
}
void main()
{
enum two = 2;
auto request = PL!(
[
"one": PL!1,
"two": PL!two,
"zero": PL!"zero"
]
);
} /*
one added, value: 1
two added, value: 2
zero added, value: 0
*/
```
SDB at 79
More information about the Digitalmars-d
mailing list