What should array() return for const/immutable ElementTypes?

David Nadlinger see at klickverbot.at
Sat May 5 09:57:05 PDT 2012


The title says it all – currently, std.array.array() is broken 
for (some) ranges of const/immutable elements. Fixing it is not 
hard, but the question is: Should it always return an array of 
(head-)mutable elements (since it allocates a copy anyway), or 
should it preserve constness of the element type?

The latter is maybe be the more »consistent« behavior, as the 
return type would always just be ElementType!Range[], but has the 
disadvantage that if you actually wanted to construct a mutable 
array from an immutable range, you'd have to cast away immutable 
(with unclear semantics), whereas getting an immutable array with 
the first implementation would just require assumeUnique() (for 
most ranges, array() is not going to be strongly pure).

I have a fix ready, but will hold back the pull request until it 
is clear which semantics we want.

Thanks,
David


More information about the Digitalmars-d mailing list