Best practices for logical const

Steven Schveighoffer schveiguy at yahoo.com
Sat Feb 15 20:46:34 PST 2014


On Sat, 15 Feb 2014 23:35:52 -0500, Meta <jared771 at gmail.com> wrote:

> On Sunday, 16 February 2014 at 03:26:42 UTC, Steven Schveighoffer wrote:
>> I'm not sure what you are asking, because the answer I want to give is  
>> so trivial :)
>
> Then I don't know what we're arguing about. I'm saying that if you pass  
> mutable data to an inout function, inout effectively acts as logical  
> const within that function, as the compiler doesn't allow you to modify  
> the inout function argument but it is safe to cast away inout. Do you  
> agree or disagree with this?

It is safe if you can guarantee the input is ultimately mutable. But there  
is no way to enforce such a guarantee. It is on the caller to make sure  
that is true.

I don't see why inout should be identified as any different from const in  
this respect. You could just as easily say the same thing about const.

-Steve


More information about the Digitalmars-d mailing list