Frustrations with const
H. S. Teoh
hsteoh at quickfur.ath.cx
Fri Mar 9 07:32:31 PST 2012
On Fri, Mar 09, 2012 at 11:24:46AM +0100, Timon Gehr wrote:
> On 03/08/2012 09:06 PM, H. S. Teoh wrote:
> >On Thu, Mar 08, 2012 at 02:50:50PM -0500, Steven Schveighoffer wrote:
[...]
> >>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?
Here are the relevant declarations:
struct Slot
{
Slot *next;
hash_t hash;
Key key;
Value value;
this(hash_t h, Key k, Value v)
{
hash = h;
key = k;
value = v;
}
}
struct Impl
{
Slot*[] slots;
size_t nodes;
// Prevent extra allocations for very small AA's.
Slot*[4] binit;
}
[...]
> >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.
[...]
> 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.
Yeah, that would be very useful.
T
--
Tech-savvy: euphemism for nerdy.
More information about the Digitalmars-d-learn
mailing list