www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 14098] New: std.typecons.wrap should allow wrapping a struct

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 puremagic.com
          Reporter: Jesse.K.Phillips+D 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);
}

--
Jan 31 2015