Frustrations with const

Timon Gehr timon.gehr at gmx.ch
Fri Mar 9 02:24:46 PST 2012


On 03/08/2012 09:06 PM, H. S. Teoh wrote:
> On Thu, Mar 08, 2012 at 02:50:50PM -0500, Steven Schveighoffer wrote:
>> On Thu, 08 Mar 2012 14:49:12 -0500, H. S. Teoh
>> <hsteoh at quickfur.ath.cx>  wrote:
>>
>>> On Thu, Mar 08, 2012 at 08:22:05PM +0100, Timon Gehr wrote:
> [...]
>>>> inout(Slot)* findSlot(Key key) inout { ... }
>>>
>>> Ahhh. Thanks!
>>>
>>> But that still doesn't solve the problem:
>>>
>>> 	inout(Slot)* findSlot(Key key) inout {
>>> 		auto slot = slots[hash(key)];
>>
>> What is type slot, and how is it constructed?  This snippit isn't
>> enough to provide help.
> [...]
>
> Slot is a struct, and slots is Slots*[].  But anyway, I found the
> problem.  I needed to explicitly declare slot as:
>
> 	inout(Slot)* slot = ...
>
> because for whatever reason, auto turns it into inout(Slot*) which
> cannot be modified.

Probably it does not. What is the type of the "slots" hashtable?


>
> I think inout is one of those things that really needs more thorough
> treatment for newbies, because coming from a C/C++ background I had no
> idea what was wrong. Now that I get it, it makes so much more sense.
>
>
> T
>

This is a general issue with how auto infers types. It would often be 
useful to get the head-mutable type out of the type deduction instead of 
the actual type.


More information about the Digitalmars-d-learn mailing list