Persistent list
Steven Schveighoffer via Digitalmars-d
digitalmars-d at puremagic.com
Mon Nov 16 09:51:26 PST 2015
On 11/16/15 12:42 PM, Steven Schveighoffer wrote:
> On 11/16/15 12:35 PM, Steven Schveighoffer wrote:
>
>> I'm afraid without a working example, I can't figure out what's
>> *supposed* to work with inout/const.
>>
>
> Update, saw your other note. Working now, trying to figure out how to do
> this correctly without any duplication (or wrapping).
>
> -Steve
>
OK, I have figured it out.
inout isn't necessary here at all because everything is const internally.
For example, you had this:
List tail()
{
assert(root);
auto n = root.next;
incRef(n);
return List(n, allocator);
}
/// ditto
const(List) tail() const
{
assert(root);
auto n = root.next;
incRef(n);
return const(List)(n, allocator);
}
Which I was able to replace with this:
List tail() const
{
assert(root);
auto n = root.next;
incRef(n);
return List(n, allocator);
}
In any case, I think the choice between const and inout is confusing,
and warrants a more in-depth explanation (when should I choose const or
inout?)
-Steve
More information about the Digitalmars-d
mailing list