RangeExtra
Denis Koroskin
2korden at gmail.com
Thu Apr 23 12:07:10 PDT 2009
On Thu, 23 Apr 2009 22:37:37 +0400, Andrei Alexandrescu <SeeWebsiteForEmail at erdani.org> wrote:
> dsimcha wrote:
>> I'm loving the new Phobos, and have been playing around with ranges,
>> alias
>> this, etc. I've compiled a list of a few range types that I have at
>> least
>> partial implementations of for personal use that were overlooked by
>> Andrei, et
>> al. in the initial release of the new Phobos. Please tell me which of
>> these
>> are generally useful and should be cleaned up and released, which ones
>> are too
>> niche to belong in Phobos, which ones std.range can already do by some
>> slightly non-obvious idiom, and which ones, if any, are already in the
>> works.
>
> I think these are fantastic. Some comments within.
>
>> CapacityArray: A range that covers a builtin array and gives it a
>> capacity
>> field. All operations that don't have to do with appending are
>> forwarded to
>> the underlying array via alias this (modulo a few compiler bugs),
>> meaning that
>> a CapacityArray has an identical compile time interface to a builtin
>> array,
>> and is implicitly convertible to one.
>
> Upon more thinking, I think we'll have to bit the bullet and define
> Array!T and Slice!T. Then dmd rewrites:
>
> [ a, b, c ] -> .Array!(typeof(a))(a, b, c)
> T[new] -> .Array!(T)
> new T[n] -> .Array!(T)(n)
> T[] -> .Slice!(T)
>
> It seems increasingly clear that slices alone can't quite cut the
> mustard.
>
> So your CapacityArray will essentially be the basis of Array.
>
Now that there is a consideration about putting built-in types into a library...
... how about introducing struct MaybeNull(T) { ... } among them (and NonNull-by-default)?
Oh, and Object.d deserves a better name, IMHO.
More information about the Digitalmars-d
mailing list