std.allocator ready for some abuse

Dmitry Olshansky dmitry.olsh at gmail.com
Sat Oct 26 09:10:39 PDT 2013


26-Oct-2013 20:01, Joseph Rushton Wakeling пишет:
> On 25/10/13 20:41, Namespace wrote:
>> Did you mean to get rid of built-in arrays / kill int[] and replace it
>> with
>> Array!T?
>
> Array!T is problematic as things stand -- e.g. you can't foreach over
> one.

Sure you can. Try it and rejoice:

void main()
{
     import std.container, std.stdio;
     Array!int a = make!(Array!int)(1,2,3,4);
     //the rule is: if a can be sliced then slice it and use that slice
     foreach(v; a)
     {
         writeln(v);
     }
}

> So, forgetting syntax preferences, there needs to be some work on
> containers before they can "just work" like the builtins.

Depends on what's required for you to consider it "just works".
But in general they can't be complete replica of built-ins for many 
reasons, built-ins being designed with GC in mind is one.
Other problems include having no user-land analog of implicit tail-const 
of arrays.

> If it's possible, I'd rather see the converse -- that code that assumes
> the GC will "just work" with other allocation strategies, so one can use
> the builtins without worrying.

Only if you are switching to from one GC kind to another. There is no 
way out of automatic memory management.

> But am I being naively hopeful in
> seeking that? :-)

Yes.

-- 
Dmitry Olshansky


More information about the Digitalmars-d mailing list