Idea to ease tail-const class reference woes

Steven Schveighoffer schveiguy at yahoo.com
Mon Mar 24 08:04:37 PDT 2008


My apologies, you are correct :)  I meant to say what you said.  My point 
was that with the current template, you cannot do this, because 
Rebindable!(C) becomes a struct with only a small number of member 
functions, which does not pass method calls to C.  If there is a plan for 
this to be fixed, then I will accept this as a less than ideal, but 
functional solution.

-Steve

"Simen Kjaeraas" wrote
On Sat, 22 Mar 2008 00:08:55 +0100, Steven Schveighoffer  wrote:
> "Janice Caron" wrote
>> Oops. Typo. Let's try that again...
>>
>> Sounds more work than
>>
>>    import std.typecons;
>>    Rebindable!(C) myClass = new C;
>>
>> which is planned for the future. (See D2.012 change log)
>
> One further question on this...
>
> If I have:
>
> class C
> {
>    void foo() {};
> }
>
> Rebindable!(const(C)) myC = new C;
>
> myC.foo();
>
> Is the plan for this to compile (I know it doesn't today)? If not, then 
> this
> is not an acceptable solution.
>
> -Steve

Why should that compile? It clearly says that myC is const, and hence
non-const methods should not be callable on it.
Had it been:

class C
{
     const void constFunc() {}
     void nonConstFunc() {}
}

Rebindable!(const(C)) myC = new C;

myC.constFunc(); // should work, both myC and constFunc are const.
myC.nonConstFunc(); // should not work, might change myC's internal state.


--Simen 





More information about the Digitalmars-d mailing list