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@79
  • Re: dChar Error Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
    • Re: dChar E... Salih Dincer via Digitalmars-d-learn
      • Re: dCh... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
  • Re: dChar Error novice2 via Digitalmars-d-learn
    • Re: dChar E... Salih Dincer via Digitalmars-d-learn
      • Re: dCh... matheus via Digitalmars-d-learn
        • Re:... Salih Dincer via Digitalmars-d-learn
          • ... matheus via Digitalmars-d-learn
            • ... Ali Çehreli via Digitalmars-d-learn
              • ... matheus via Digitalmars-d-learn
              • ... Salih Dincer via Digitalmars-d-learn
              • ... Salih Dincer via Digitalmars-d-learn
              • ... Ali Çehreli via Digitalmars-d-learn
              • ... Salih Dincer via Digitalmars-d-learn

Reply via email to