Previous Entry Share Next Entry
Improving std.typecons.wrap to support structs

The goal behind 'wrap' is to provide a means to "cast" a type based on structual conformance. If the type provides all the functionality needed then it can be wrapped as the desired type.

In D it is more common to utilize a struct instead of a class. Structs don't provide inheritance so it is not possible to wrap a type into a struct, similarly a final classes prevent wrapping as that type.

What can be done is to take a struct and wrap it into a class. I'm attempting to make this possible.

What I noticed from the implementation was this supporting interface:

// Internal class to support dynamic cross-casting
private interface Structural
    inout(Object) _wrap_getSource() inout @safe pure nothrow;

This is utilized during unwrapping. And I thought a good modification would be:

private interface Structural(T)
    inout(T) _wrap_getSource() inout @safe pure nothrow;

This hit a compiler bug which took some time to minimize. But now that the unittests are running, there's a broken test to look into.


Log in