On 01/31/2013 08:33 AM, d coder wrote:
To be honest deque can be implemented far better if random access as in
indexing, removal and such is dropped.
As other people too pointed out, Deque is indeed a random access
range, so indexing operator is a must. Insert/Remove too are good to
have. Array implementation in the std.container too implements remove
and insert.
Another small issue is that this Deque implementation is a Class.
std.container provides all the containers as structs. So for sake of
consistency, we should implement Deque too as a struct.
Thats not totally correct. The Rb tree is a class. But the real reason
for the Deque being a class
is that it holds two value members. And if you pass the Deque around you
need to do this as ref.
Otherwise you shall not call any method that modifies this value
members, because this will only be
visible at the calling site. See this tiny example:
struct F {
size_t a;
}
void foo(F f) {
f.a = 10;
}
void main() {
F a;
a.a = 9;
foo(a);
assert(a.a == 10);
}
So I think leaving it a class is valid. But I could create a static
opCall method that creates a Deque or a
convince Function similar to that of the Rb tree
Regards
- Puneet