Adding a partial specialization of std.conv.to for Typedef!string

kdevel kdevel at vogtner.de
Sun Sep 1 11:01:13 UTC 2024


In order to make this work

```d
import std.typecons;

alias vstring = Typedef!string;

void main ()
{
    import std.stdio;
    import std.conv;

    auto v = 3.to!vstring; // ain't work out of the box
    writeln (v);

    auto w = 3.to!string;
    writeln (w);

    long l = 3.to!long;
    writeln (l);
}
```

I ended up adding

```d
V to (V, T) (T t)
{
    static import std.conv;
    return std.conv.to!V (t);
}

V to (V : vstring, T) (T t)
{
    static import std.conv;
    auto s = std.conv.to!(TypedefType!V) (t);
    return cast (V) s;
}
```

to the code. Is there a way to add only a partial specialization 
of std.conv.to?


More information about the Digitalmars-d-learn mailing list