Kinds of containers

Jonathan M Davis via Digitalmars-d digitalmars-d at puremagic.com
Sun Oct 25 02:05:45 PDT 2015


On Sunday, 25 October 2015 at 05:37:02 UTC, deadalnix wrote:
> On Saturday, 24 October 2015 at 19:33:03 UTC, David Nadlinger 
> wrote:
>> On Friday, 23 October 2015 at 17:44:55 UTC, deadalnix wrote:
>>> Collection!T and Collection!const(T) are 2 completely 
>>> different types.
>>
>> Isn't this also required anyway because of covariance vs. 
>> contravariance considerations?
>>
>>  — David
>
> It is close, but not exactly the same. 
> Covariance/contravariance can be emutalted via alias this 
> without too much trouble for a container (however, it is hard 
> to ensure correctness, but I'd assume not too hard). On the 
> other hand, the qualifier thing turtle from the collection to 
> the element in the collection, which is not that easy to 
> achieve.

The bigger problem is probably ranges rather than containers. We 
get tail-const slices from arrays all the time, but opSlice with 
no arguments isn't really a range operation (none of the range 
traits require it), and it's pretty painful to get it to make 
tail-const work with opSlice anyway (though I know that the EMSI 
guys were jumping through all kinds of hoops to make it work, so 
their containers make actually handle it reasonably well). Plus 
there's the fun problem of how declaring opSlice on a range 
causes foreach to call it, which essentially means that your 
range can get saved accidentally, which can be problematic 
(especially for ranges like RefRange).

It's been a while since I sat down and worked through the various 
issues that we have here. I should probably do that soon and see 
if I can distill them down well enough to come up with a DIP to 
resolve them - or at least to clearly present them so that they 
can be discussed. What we have right now mostly works, but it 
falls apart in some corner cases - especially if you want to be 
able to operate on a range like you would an array.

- Jonathan M Davis


More information about the Digitalmars-d mailing list