Next in Review Queue: The New std.path
Jonathan M Davis
jmdavisProg at gmx.com
Mon Jul 18 10:30:58 PDT 2011
On 2011-07-18 08:08, Lars T. Kyllingstad wrote:
> On Tue, 19 Jul 2011 00:57:44 +1000, Daniel Murphy wrote:
> > "Lars T. Kyllingstad" <public at kyllingen.NOSPAMnet> wrote in message
> > news:j01h2f$2ia$2 at digitalmars.com...
> >
> >> The specific cases in question are templated functions, where I don't
> >> know whether the array is immutable unless I specifically test it. I
> >> simply used arr.idup, assuming the compiler would optimise away the
> >> duplication when arr is immutable. But it's no big deal to change it
> >> to
> >>
> >> static if (!is(T == immutable)) return arr.idup;
> >>
> >> -Lars
> >
> > Doesn't std.conv.to do this for you?
>
> It probably does! I hadn't thought about that, but I'll check it out
> now. Thanks!
It does. That's why you should generally use std.conv.to instead of dup or
idup directly. Really, dup and idup should only be used if you definitely
_want_ a duplicate. Otherwise, std.conv.to will just (i)dup it when you
actually need to.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list