Best practices for logical const

Steven Schveighoffer schveiguy at yahoo.com
Sat Feb 15 18:41:35 PST 2014


On Sat, 15 Feb 2014 21:36:43 -0500, Meta <jared771 at gmail.com> wrote:

> On Sunday, 16 February 2014 at 02:34:36 UTC, Steven Schveighoffer wrote:
>> On Sat, 15 Feb 2014 15:02:44 -0500, Meta <jared771 at gmail.com> wrote:
>>
>>> On Saturday, 15 February 2014 at 19:59:07 UTC, Meta wrote:
>>>> inout is *sort of* logical const, if the underlying type is immutable.
>>>
>>> I mean mutable, of course.
>>
>> No, it's not. It's not allowed to mutate with inout.
>>
>> -Steve
>
> Right, but inout can accept any of mutable, const, and mutable. The  
> compiler will statically disallow you from mutating an inout variable,  
> but if you know the underlying data is mutable, it's safe to cast inout  
> away and mutate. If the data is actually mutable, then inout is  
> effectively logical const. I guess the same is true of regular const.

inout does not know when the incoming data is mutable.

Effectively, inout is just like const, but has implications on the return  
value.

-Steve


More information about the Digitalmars-d mailing list