How to move from Unique(someClass) to Unique(someInterface)?

Konstantin kostya.hm2 at gmail.com
Sat May 16 17:45:56 UTC 2020


import std.stdio;
import automem;
import std.experimental.allocator.mallocator : Mallocator;

interface IGetInt
{
     @nogc int GetInt();
}

class Foo : IGetInt
{
     @nogc int GetInt()
     {
         return 42;
     }
}

@nogc void main()
{
     auto foo = Unique!(Foo, Mallocator).construct;

     printf("Value is %d!\n", foo.GetInt());

//     Unique!(IGetInt, Mallocator) ifoo = Unique!(Foo, 
Mallocator).construct;
//     printf("Value is %d!\n", ifoo.GetInt());
}

How to cast from a class to an interface in such situation? Is it 
possible?

And one more question: Where can i find actual status(or plans) 
of @nogc support for Phobos and language constructs?


More information about the Digitalmars-d-learn mailing list