Const sucks
Walter Bright
newshound1 at digitalmars.com
Mon Sep 10 19:25:06 PDT 2007
Bruno Medeiros wrote:
> Walter Bright wrote:
>> What, exactly, is the use case that needs a solution?
>
> Before hand, let me just say that by broken, I didn't mean subvertable,
> but rather that using const/invariant with classes would be impractical
> and unmanageable.
>
> Simple example: Let's say you have a class Foo that is comparable. How
> do you sort an array of const(Foo)'s ?
>
> const(Foo)[] sort(const(Foo)[] arr) {
> ... ?
> The sorting algorithm doesn't matter, what matters is: how would one
> swap two elements in the array?
You can't sort an (array of)(const T). You can sort an (array
of)(something of)(const T).
More information about the Digitalmars-d
mailing list