On 11/16/15 2:37 PM, Andrei Alexandrescu wrote:
On 11/16/2015 01:55 PM, Steven Schveighoffer wrote:
On 11/16/15 1:37 PM, Andrei Alexandrescu wrote:
On 11/16/2015 12:51 PM, Steven Schveighoffer wrote:
     List tail() const

I'd like tail to be qualifier-idempotent, i.e. return const for const
and non-const for non-const. -- Andrei

Why? const(int)[] isn't const, why should List!(const(int)) be?

I'm keeping an eye toward other containers and also more general use.
It's a common need. -- Andrei

Anywhere const can work, inout should work as well. The one exception as I've described is when you create and build a (im)mutable result, then converting it to const. In this case, you have to build it at once. Otherwise, the compiler can't tell whether this mutable thing you are constructing is safe to cast to inout (and whatever flavor it needs to cast to upon exit).

In this case, it appears to work only because of your cast of _allocator to mutable whenever you access it via allocator. Other than that, the only other member is the node pointer, which is const. Effectively, A list's data is always const, so there is no reason to make the struct itself const.

-Steve

Reply via email to