Persistent list

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Mon Nov 16 15:34:51 PST 2015


On 11/16/15 5:35 PM, Andrei Alexandrescu wrote:
> On 11/16/2015 05:30 PM, Steven Schveighoffer wrote:
>> I'll reiterate what I said elsewhere: inout is better, safer, and easier
>> to maintain than the template solution.
>
> Do you have a working solution in dpaste? No change to the return types
> please. -- Andrei

Ah, where it breaks down is emplace uses an internal struct with a T, 
which is inout(const(Node)*).

So you *are* hitting one of the limitations of inout, one that Dmitry 
brought up. I stand corrected.

I think it can be fixed, we need to make structs that contain inout 
member variables legal as long as they only exist on inout function 
stacks. It may be possible to fix emplace for inout by changing the ctor 
of the internal struct to inout instead of typing T as inout, but I'm 
not sure.

In this case, in order to work around, you have to cast when you use 
emplace, somewhat defeating the safety of emplace :(

http://dpaste.dzfl.pl/182e2ac5da2d

The only other weird part is where you see inout(const(Node)*) in the 
fixed ctor. This is because it's a different type than inout(Node*), 
it's like const(immutable(Node)*), the pointer itself is const, but the 
data it points at is still immutable.

-Steve


More information about the Digitalmars-d mailing list