dup method const or not?
Matthias Walter
xammy at xammy.homelinux.net
Sun Nov 27 13:52:56 PST 2011
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.
Matthias
More information about the Digitalmars-d-learn
mailing list