invariant/const class storage class

Simen Kjaeraas simen.kjaras at gmail.com
Wed Oct 1 18:50:40 PDT 2008


On Thu, 02 Oct 2008 03:46:00 +0200, Andrei Alexandrescu  
<SeeWebsiteForEmail at erdani.org> wrote:

> Simen Kjaeraas wrote:
>> On Wed, 01 Oct 2008 16:23:32 +0200, Yigal Chripun <yigal100 at gmail.com>  
>> wrote:
>>
>>> Andrei Alexandrescu wrote:
>>>> Yigal Chripun wrote:
>>>>> Walter Bright wrote:
>>>>>> Simen Kjaeraas wrote:
>>>>>>> Is this really correct behavior? How then are we supposed to
>>>>>>> initialize our
>>>>>>> invariant objects?
>>>>>> Currently, create them as mutable ones, then cast them to invariant.
>>>>>
>>>>> I understand casting as breaking the type system. shouldn't there be  
>>>>> a
>>>>> way to create invariant objects without the cast?
>>>>> an invariant constructor seems a good way to solve this. any plans on
>>>>> adding such a feature to D2?
>>>>
>>>> There are plans.
>>>>
>>>>> I think it can work like this:
>>>>>
>>>>> class A {
>>>>>   this(params) {}   // [1]
>>>>>   invariant this(params) {}  // [2]
>>>>> }
>>>>>
>>>>> // create a mutable object - will use type [1] c-tors.
>>>>> auto a = new A(params);
>>>>>
>>>>> // create an invariant object - will use type [2] c-tors.
>>>>> invariant a = new A(params);
>>>>>
>>>>> // create a const object - will use type [1] or [2] c-tors.
>>>>> const a = new A(params);
>>>>>
>>>>> in the const case, if there are two c-tors which only differ by
>>>>> invariant-ness of the c-tor using either will create ambiguity and
>>>>> therefore should be a compile-time error.
>>>>
>>>> Way, way, way more complicated than this.
>>>>
>>>> Andrei
>>>
>>> May I ask what are the complications?
>>  "Mortis Portalis Tackulatum - and he's still breathing"...
>
> Tackulatum? Was that tacitum?
>
> Andrei
>

 From Terry Pratchett's 'Pyramids'.

Doctor: "Fairly straightforward. A case of mortis portalis tackulatum with  
complications."
Chidder: "What's that mean?"
Doctor: "In laymen's terms, he's as dead as a doornail."
Chidder: "What are the complications?"
Doctor: "He's still breathing."

-- 
Simen



More information about the Digitalmars-d mailing list