Should .idup simply do nothing for arrays that are already immutable?

Michel Fortin michel.fortin at michelf.com
Sat Jan 9 10:12:16 PST 2010


On 2010-01-08 16:07:16 -0500, dsimcha <dsimcha at yahoo.com> said:

> Should we define .idup on an already-immutable array to simply do nothing?  It
> seems that there is never any good reason to copy an immutable array, and it
> would avoid the need to either needlessly copy an array or explicitly check
> for immutability in metaprogramming situations.

I think it should indeed return the same immutable array. One goal of 
immutable is to avoid having to make unnecessary copies. If you call 
idup it means you want an immutable version of the array, so it 
shouldn't matter if it's a copy or if it's the same, as long as it's 
immutable (as in guarantied to never change) and it contains the right 
data.

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list