On Sun, 27 Nov 2011 16:52:56 -0500, Matthias Walter <xa...@xammy.homelinux.net> wrote:

Hi,

Recently, I realized that several "dup" methods in D2's phobos are
declared like the one for BitArray:

@property BitArray dup()

My question is why it is declared without "const"? Is it a bug or is
there a reason for it? I can think of a case where one only has
implemented a shallow copy and wants to omit the const due to the
involved transitivity, but this shouldn't be the case for BitArray (the
underlying array is dup'ed). Is there a general rule/recommendation when
to make a dup method const and when not? My problem arises in a copy
constructor for a struct S which takes a const(S) instance. But as S has
a BitArray member, duping is not allowed, so I need a way to duplicate a
const(BitArray) object.

dup should be const. There is no compiler limitation as to why this isn't const. You should file a bug.

-Steve

Reply via email to