automem v0.3.5 - now with more vector (like std::vector, not Physics)!

Atila Neves atila.neves at gmail.com
Thu Sep 20 14:57:42 UTC 2018


If you've never heard of automem before, I wrote it to have 
C++-style smart pointers in D that I could use in @nogc code:


http://code.dlang.org/packages/automem


I needed something like a std::vector that can be @nogc so I 
wrote it. I wondered whether or not to put it in a collections 
package or not, then punted on the decision and just stuck it in 
automem. Anyway, code:


     // *no* GC allocations below if theAllocator is set to an 
allocator that
     // never allocates on the GC heap

     import automem.vector;  // there's an `array` alias too
     auto v = vector(0, 1, 2);
     v ~= 3;
     v ~= only(4, 5);
     assert(v[] == [0, 1, 2, 3, 4, 5]);


If you want the @nogc compile-time guarantee, specify an 
allocator:

     () @nogc {
         auto v = vector!Mallocator(0, 1, 2, 3);
         v ~= only(4, 5, 6);
         // etc.
     }();


Enjoy (hopefully)!


More information about the Digitalmars-d-announce mailing list