GSoC-2011 project:: Containers

Lutger Blijdestijn lutger.blijdestijn at gmail.com
Sun Mar 27 10:22:08 PDT 2011


Ishan Thilina wrote:

> As to my understanding algorithms are seperated from the containers so
> that the code is maintainable. But in std.container I can see that all the
> algorithms are in the container method definitions. Why is this? Have I
> got the things incorrectly?

Slightly, D ranges use the same basic principles as the STL so any 
documentation on that can be used to understand the big picture. 

You'll see that no container implements all of std.algorithm, in fact 
containers have a very small interface. Normally algorithms work with 
different kinds of ranges and containers can  provide one or more ranges, 
thus achieving very loose coupling and reuse. If a container provides a 
certain range then *all* algorithms which operate on that kind of range will 
work with the container. For example, any container that can be accessed 
with a random access range can be used by std.sort. 

However, containers usually have more to offer than what can be expressed by 
ranges. std.container documents a large set of methods that particular 
containers can implement as they see fit, as a convention. These methods are 
usually specific to a particular container implementation and necessary to 
use a container or take advantage of it's specific properties. 


More information about the Digitalmars-d mailing list