[Issue 14098] New: std.typecons.wrap should allow wrapping a struct

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sat Jan 31 19:42:30 PST 2015


https://issues.dlang.org/show_bug.cgi?id=14098

          Issue ID: 14098
           Summary: std.typecons.wrap should allow wrapping a struct
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody at puremagic.com
          Reporter: Jesse.K.Phillips+D at gmail.com

The current implementation of wrap only allows for other classes to be wrapped
into another interface. Structures are much more common in D so there is great
value in supporting the ability to wrap a struct into a specified interface.

This is similar to request #10404 but doesn't require a concrete type to be
produced.

For example:

interface iRange {
    pure nothrow @nogc @property @safe int front();
    void popFront();
    pure nothrow @nogc @property @safe bool empty();
}

void main()
{
    import std.algorithm;
    import std.range;
    // Create a range type.
    auto squares = map!"a * a"(iota(10));

    import std.typecons;
    // Wrap it in an interface.
    iRange squaresWrapped = squares.wrap!(iRange);
}

--


More information about the Digitalmars-d-bugs mailing list