Best practices for logical const

Meta jared771 at gmail.com
Sat Feb 15 18:36:43 PST 2014


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.


More information about the Digitalmars-d mailing list