Is all this Invarient **** er... stuff, premature optimisation?
Janice Caron
caron800 at googlemail.com
Mon Apr 28 11:00:43 PDT 2008
On 28/04/2008, Sean Kelly <sean at invisibleduck.org> wrote:
> Can you explain this in light of Steven's 'scoped const' proposal?
I meant that non-invariant versions would have to make a copy, but the
invariant version sometimes wouldn't. That means they can't share the
same code.
> string bufI = "HELLO";
> char[] bufM = "HELLO".dup;
> const(char)[] bufC = bufM;
>
> const(char)[] retC = toupper( bufC ); // return value is const - ok
>
> bufM[0] = 'J';
> assert( retC[0] == 'J' );
Why would that assert hold? I would expect toupper(char[]) to have to
return a copy precisely in order to /prevent/ that problem. What am I
missing?
More information about the Digitalmars-d
mailing list