Skip to content

Is it possible to make the library work with templates? #8

@ghost

Description

Consider the following snippet, which attempts to recreate (a better, extensible) to:

import openmethods;
mixin(registerMethods);

interface BaseWrapper { }

class Wrapper(T): BaseWrapper
{
    T value;
    this(T v) { value = v; }
}

T
to(T)(virtual!BaseWrapper);

@method
Wrapper!T
_to(T)(Wrapper!string w)
{
    import std.conv;
    return new Wrapper!T(std.conv.to!T(w.value));
}

void 
main()
{
    updateMethods;

    auto s = new Wrapper!string("12");
    assert(s.to!int == 12);
}

This doesn't compile because, it seems, the open methods mechanism doesn't kick in for to and the compiler doesn't see Wrapper!string as a possible stand-in for virtual!BaseWrapper. The error message is

function app.to!int.to (virtual!(BaseWrapper)) is not callable using argument types (Wrapper!string)

Is it possible to enable the library to work with templates? This would add a considerable layer of cool and useful to it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions