Persistent list

Andrei Alexandrescu via Digitalmars-d digitalmars-d at puremagic.com
Sat Nov 14 07:44:24 PST 2015


On 11/13/2015 06:36 PM, Steven Schveighoffer wrote:
> On 11/13/15 6:10 PM, Andrei Alexandrescu wrote:
>> I created a simple persistent list with reference counting and custom
>> allocation at http://dpaste.dzfl.pl/0981640c2835. It's a good
>> illustration of a number of issues. In particular, each cast must be
>> properly explained.
>>
>> Here's my exegesis:
>>
>
>> * Lines 141-152: I couldn't make tail() work with inout. Generally I'm
>> very unhappy about inout. I don't know how to use it. Everything I read
>> about it is extremely complicated compared to its power. I wish we
>> removed it from the language and replaced it with an understandable
>> idiom.
>
> This seems to work for me:
>
>          inout(List) tail() inout
>      {
>          assert(root);
>          auto n = root.next;
>          incRef(n);
>          return inout(List)(n, allocator);
>      }

That doesn't work for me with my unittests, I get:

persistent_list.d(154): Error: None of the overloads of '__ctor' are 
callable using a inout object, candidates are:
persistent_list.d(93): 
persistent_list.List!(immutable(int)).List.this(const(Node*) n, 
IAllocator a)
persistent_list.d(264): Error: template instance 
persistent_list.List!(immutable(int)) error instantiating

154 is the last line in the function above.


Andrei




More information about the Digitalmars-d mailing list