Eliminate redundancy of dup/idup

kenji hara k.hara.pg at gmail.com
Sun Sep 9 08:44:47 PDT 2012


2012/9/10 Adam D. Ruppe <destructionator at gmail.com>:
> On Sunday, 9 September 2012 at 15:32:01 UTC, kenji hara wrote:
>>
>> Then returned value can be implicitly convertible to immutable(E[]).
>
>
> What about rebindable with auto? For example:
>
> void main() {
>         char[] a = "cool".dup;
>         string b = a.idup; // explicitly immutable(char)[]
>         auto c = a.idup; // automatically typeof(c) == immutable(char)[]

Yes. In this case, you should write:
          immutable c = a.dup(); // explicit immutable conversion

>         c = "another"; // so this compiles
> }
>
> I do this in a few places in my code. If I want it to be immutable(char[]),
> I'll write immutable instead of auto.

Kenji Hara


More information about the Digitalmars-d mailing list