Boost logo

Boost :

Subject: [boost] [array] - array_vector
From: Hite, Christopher (Christopher.Hite_at_[hidden])
Date: 2012-07-20 10:18:56


I've a got a small utility class that is a cross between boost::array and std::vector for when I only have a compile time constant max things. This is beats to complexity of fighting with custom allocators/pools.
        const unsigned n=100;
        Thing array[n];
        unsigned count=0;
goes to:
        array_vector<Thing,100> things;

It's stl compliant and should drop in anywhere you've got a vector. Like vector and unlike boost::array (or regular array) 100 Things are not constructed.

Have I reinvented something in boost? Should I submit it?

Also related to this. There are a class of problems where n is known only on runtime, but you still only need it in a certain scope. gcc (C99 standard) allows variable length arrays on the stack. Does anyone know if that is allowed in C++11?

What would think about something like this?
        unsigned n=readInt();
        placeholder<Thing> bufffer[n]; //variable length data on stack
        buffer_vector<Thing> v(buffer,n);

Chris


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk