Hmm - about manifest/enum

Janice Caron caron800 at googlemail.com
Mon Dec 31 12:21:58 PST 2007


On 12/31/07, Steven Schveighoffer <schveiguy at yahoo.com> wrote:
> How about doing an in-place sort of an array of const classes?
>
> const(C)[] myarray;

How would you even /create/ such a thing in the first place? How could
you populate it?

In any case, the obvious solution is to just do things a different
way. There are plenty of alternative strategies. The most obvious one
which springs to my mind is just to use pointers:

    const(C)*[] myarray;


> // swap two items i and j
> auto tmp = myarray[i];
> myarray[i] = myarray[j]; // error
> myarray[j] = tmp; // error

...and that would work now.


> This
> feature of being able to swap two references to const data is a very common
> algorithmic requirement.

Neither C nor C++ lets you do this. C doesn't even /have/ references.
C++ has references, but they are always const. For both of these
languages, you have to use pointers if you want to do this sort of
thing. It's not a big deal. We can live without it.



More information about the Digitalmars-d mailing list