RFR: 8189088: Add intrusive doubly-linked list utility [v3]
Daniel D. Daugherty
dcubed at openjdk.org
Mon Oct 9 13:20:00 UTC 2023
On Mon, 9 Oct 2023 06:22:48 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:
>> That rewrite isn't correct.
>>
>> You _can_ add const values to a non-const list. In fact, you can only add
>> values (const or not) to a non-const list. A const list has type `const
>> IntrusiveList<T, accessor>`, while a non-const list is similar but without the
>> `const` qualifier.
>>
>> What you can't do is add a const value to a (necessarily non-const) list of
>> non-const elements. So if T is an unqualified class type, then you can add
>> const values to an `IntrusiveList<const T, accessor>` but not to an
>> `IntrusiveList<T, accessor>`.
>
> Is something like this more clear? In my experience, non-intrusive collections
> with const-qualified elements are uncommon, so I found the implications here
> not immediately obvious.
>
>
> * A const iterator has a const-qualified element type, and provides const
> * access to the elements of the associated list. A non-const iterator has an
> * unqualified element type, and provides mutable element access. A non-const
> * iterator is implicitly convertible to a corresponding const iterator.
> *
> * A const list provides const iterators and access to const-qualified
> * elements, and cannot be used to modify the sequence of elements. Only a
> * non-const list can be used to modify the sequence of elements.
> *
> * A list can have a const-qualified element type, providing const iterators
> * and access to const-qualified elements. A const object cannot be added to
> * a list with an unqualified element type, as that wuold be an implicit
> * casting away of the const qualifier.
Nit typo: s/wuold/would/
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/15896#discussion_r1350296773
More information about the hotspot-dev
mailing list