Mix struct types in the same array
Laeeth Isharc
Laeeth at laeeth.com
Fri Dec 20 17:47:35 UTC 2019
On Wednesday, 18 December 2019 at 22:17:21 UTC, tirithen wrote:
> On Wednesday, 18 December 2019 at 22:11:10 UTC, Sebastiaan
> Koppe wrote:
>>
>> If you know all types up front you can use the Sumtype library
>> on code.dlang.org
>
> Thanks, it's a good starting point, the best would be if I only
> needed to define that the struct would implement void
> applyTo(ref User user) so that could be run in the loop to
> update the User entity.
>
> But I'll try the Sumtype library, that takes me forward, thanks
> for the answer!
https://github.com/atilaneves/concepts
interface IFoo {
int foo(int i, string s) @safe;
double lefoo(string s) @safe;
}
@implements!(Foo, IFoo)
struct Foo {
int foo(int i, string s) @safe { return 0; }
double lefoo(string s) @safe { return 0; }
}
// doesn't compile
/*
@implements!(Oops, IFoo)
struct Oops {}
*/
More information about the Digitalmars-d-learn
mailing list