Eliminate redundancy of dup/idup

kenji hara k.hara.pg at gmail.com
Sun Sep 9 09:26:07 PDT 2012


Yes, This works just as expected.

import std.stdio;
void main()
{
    char[] a = dup("Hello");
    string b = dup(a);
    writeln(a);  // prints "Hello"
    writeln(b);  // prints "Hello"
    assert(cast(void*)a.ptr !is cast(void*)b.ptr);  // elements are duplicated
}

Kenji Hara

2012/9/10 Jesse Phillips <jessekphillips+D at gmail.com>:
> On Sunday, 9 September 2012 at 15:32:01 UTC, kenji hara wrote:
>>
>> Finally, built-in dup and idup are merged into library dup(). Destroy!
>>
>> Kenji Hara
>
>
> Well, that is pretty awesome. I didn't see an example which says this would
> work, but I expect it would?
>
> char[] a = dup("Hello");
> string b = dup(a);
>
> I'm not as familiar with the pure to immutable but I believe to
> immutable(char)[] is or should be valid right?


More information about the Digitalmars-d mailing list