September 01

In order to make this work

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

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?

September 01

On Sunday, 1 September 2024 at 11:01:13 UTC, kdevel wrote:

>

In order to make this work

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

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?

Im pretty sure all solutions are imperfect, but id suggest combineing the overloadset

//myconv.d
import std.conv;
alias to=std.conv.to;
//template to(T) if cond(....){alias to(T)=std.conv.to!T;} if you need to mess with conditions
V to(V:vstring,T)(T t)=> cast(V) t.to!V;

spooky quantum shit will stop probably it from working on vstring[] without trail and error(were its a bug feature of dlang live editing the ast if it does work)