const as default for variables

Zach the Mystic via Digitalmars-d digitalmars-d at puremagic.com
Mon Mar 16 18:34:21 PDT 2015


On Monday, 16 March 2015 at 19:52:00 UTC, deadalnix wrote:
> On Monday, 16 March 2015 at 14:40:51 UTC, Zach the Mystic wrote:
>> On Sunday, 15 March 2015 at 20:09:56 UTC, deadalnix wrote:
>>> On Sunday, 15 March 2015 at 07:44:50 UTC, Walter Bright wrote:
>>>> "const ref" can tell the optimizer that that path for a ref 
>>>> counted object cannot alter its ref count.
>>>
>>> That is not clear why. const ref is supposed to protect 
>>> against escaping when ref does not ?
>>
>> There are two cases here. One is when the reference is copied 
>> to new variable, which would actually break const because the 
>> reference count of the original data would have to be 
>> incremented (which is a separate issue).
>
> I think we should provide library solution for this kind of 
> things.

Changing the reference count is a very low-level operation. I'm 
not sure how to go about breaking the type system in order to 
support `const` variations on it.


More information about the Digitalmars-d mailing list