RFC on range design for D2
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Fri Jan 9 09:41:00 PST 2009
jq wrote:
> dsimcha Wrote:
>
>> == Quote from Andrei Alexandrescu (SeeWebsiteForEmail at erdani.org)'s article
>
>>> The idea is very simple: just use D's native append operation, but cache
>>> the capacity to avoid too many lookups (I understand that that's the
>>> bottleneck).
>>> I paste the code below, I'd be indebted if you guys grabbed it and
>>> tested it.
>>> Andrei
>>> struct ArrayAppender(T)
>>> {
>>> size_t capacity() const { return _capacity; }
>>> void putNext(T item)
>
> I have thoughts:
>
> 1) There should probably be a length/size call
> 2) How about add() or append() for a shorter name
> 3) What about using ~=? Maybe this is too short...
Length sounds good. The other two I'm more hesitant about because
ArrayAppender supports the interface of an output range. The output
range only allows putting one element and making a step simultaneously,
hence putNext. The ~= is also a bit of an unfortunate choice because
it's odd to define a type with ~= but no meaningful/desirable binary ~.
Andrei
More information about the Digitalmars-d-announce
mailing list