Thread overview | ||||||
---|---|---|---|---|---|---|
|
September 28, 2014 Non-const std.container.Array.opIndex and alikes blocks serialization | ||||
---|---|---|---|---|
| ||||
In my strive to add msgpacking support for std.container.Array I've been blocked by the fact that std.container.Array.opIndex only has one overload which is non-const probably because it returns a ref T. This doesn't place nicely with serialization. Shouldn't inout be used here? |
September 28, 2014 Re: Non-const std.container.Array.opIndex and alikes blocks serialization | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Sunday, 28 September 2014 at 08:58:27 UTC, Nordlöw wrote: > In my strive to add msgpacking support for std.container.Array I've been blocked by the fact that std.container.Array.opIndex only has one overload which is non-const probably because it returns a ref T. This doesn't place nicely with serialization. > > Shouldn't inout be used here? Further I've tried tagging all opIndex in array.d with inout as inout ref T opIndex(size_t i) inout but then I get another error array.d(479,30): Error: cast(string)this._data.refCountedPayload()._payload[i] is not an lvalue |
September 28, 2014 Re: Non-const std.container.Array.opIndex and alikes blocks serialization | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Sunday, 28 September 2014 at 09:04:42 UTC, Nordlöw wrote:
> On Sunday, 28 September 2014 at 08:58:27 UTC, Nordlöw wrote:
>> In my strive to add msgpacking support for std.container.Array I've been blocked by the fact that std.container.Array.opIndex only has one overload which is non-const probably because it returns a ref T. This doesn't place nicely with serialization.
>>
>> Shouldn't inout be used here?
>
> Further I've tried tagging all opIndex in array.d with inout as
>
> inout ref T opIndex(size_t i) inout
>
> but then I get another error
>
> array.d(479,30): Error: cast(string)this._data.refCountedPayload()._payload[i] is not an lvalue
Probably you want:
ref inout(T) opIndex(size_t i) inout
Instead. What you wrote was basically the same as:
ref T opIndex(size_t i) inout inout
While compiling, the "inout(T)" obtained from "_payload[i]" is "value-converted" into a "T" (makes it an lvalue), and then the return (which is "ref") fails.
This is the whole "function attributes on left side confusion" - fiasco thing...
|
September 30, 2014 Re: Non-const std.container.Array.opIndex and alikes blocks serialization | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarch_dodra | On Sunday, 28 September 2014 at 20:27:32 UTC, monarch_dodra wrote: > This is the whole "function attributes on left side confusion" - fiasco thing... https://github.com/D-Programming-Language/phobos/pull/2573 |
Copyright © 1999-2021 by the D Language Foundation