dChar Error

Salih Dincer salihdb at hotmail.com
Sat Dec 31 00:42:50 UTC 2022


On Friday, 30 December 2022 at 22:02:41 UTC, Ali Çehreli wrote:
> > But I couldn't find if the target will be mutable, but I
> think it will
> > be,
>
> The target will always be the type the programmer specifies 
> explicitly. (dchar[] in this case.)

I have one more little question! Is it possible to infer the 
string without the type the programmer specifies explicitly in 
the template below?

```d

template Fun(dstring str)/*
template Fun(T)(T str)/* like this */
{
   import std.traits : Unconst;
   alias T = Unconst!(typeof(str[0]));

   auto Fun()
   {
     import std.conv : to;

     auto result = Result();
     result.data = str.to!(T[]);

     return result;
   }
   
   struct Result
   {
     union
     {
       T[str.length] data;
       ubyte[T.sizeof * str.length] bytes;
     }
     string toString()
     {
       import std.format;
       return format("%s: %(%02X-%)", data, bytes);
     }
   }
}

void main()
{
   import std.stdio : writeln;
   Fun!"β€Ş"w.writeln; // type1: wstring
   Fun!"β€Ş"d.writeln; // type2: dstring
}
```
That is, the compiler can/must infer between type 1-2 or type 
3(string) that it knows at compile time, right?

SDB at 79


More information about the Digitalmars-d-learn mailing list