create fixed length string of characters
IchorDev
zxinsworld at gmail.com
Fri Aug 16 17:59:55 UTC 2024
On Friday, 16 August 2024 at 15:58:31 UTC, Nick Treleaven wrote:
> On Friday, 16 August 2024 at 13:30:53 UTC, IchorDev wrote:
>> On Friday, 16 August 2024 at 11:37:08 UTC, Nick Treleaven
>> wrote:
>>> On Friday, 16 August 2024 at 06:15:18 UTC, Bruce wrote:
>>> ```d
>>> string s = a.dup; // copy to heap, assuming you need the data
>>> to escape (use a[] otherwise)
>>> s.writeln();
>>> ```
>>
>> I think you meant `idup`? `dup` will make it mutable.
>
> `dup` actually works. I tested the code before posting. It
> should be that `dup` is a template function which gets inferred
> as strongly `pure`, so the result is known to the compiler to
> be unique.
Oh, that’s awesome I didn’t know pure stuff can do that.
> https://dlang.org/spec/function.html#pure-factory-functions
>
> So perhaps `idup` is no longer needed.
It’s more explicit so I think still generally preferable.
More information about the Digitalmars-d-learn
mailing list