Boost logo

Boost :

From: Darin Adler (darin_at_[hidden])
Date: 2000-01-03 11:57:11


Name suggestions:

    My favorite of the ones already mentioned: array.
    Names I like: fixed_size_vector, sized_vector.
    Other variations: fixed_size_array, fixed_vector, fixed_array,
                      sized_array

I don't like names that use the word static simply because of its presence
as a (heavily overloaded) keyword.

> He implements the class as POD (making the internal array public),
> so that the following is possible:
> carray<int,6> a = { 1, 2, 3, 4, 5, 6 }

One downside of this is that we then can't define any of the constructors
that are available for the other container types. For example:

    1) Default constructor: If there is no constructor and the elements are
objects that also have POD type, then the elements will be uninitialized
[8.5/9]. This is like built-in C arrays, but unlike vectors, for example.
    2) Constructor that takes a single value for the entire container. For a
vector, you can give an initial value that's used for all the elements as
in: "std::vector<int> a(6, 23); // 6 elements with the value 23".
    3) Constructor that takes a pair of iterators. In the case of carray,
the iterators, there would have to be some decision of what happens when the
size of the range does not match the size of the carray. We could leave the
behavior undefined or fill with default-initialized values if the iterator
range is too small and ignore any extra values if the iterator range is too
large.

> In addition, he introduces op==, op<, swap(), and reverse iterators.

Those are good additions. I'd want to include a few other things that are in
both vector and deque in the class for a little more flexibility in generic
programs:

    assign();
    empty(); // true for zero-sized instances
    at();
    front();
    back();
    operators !=, >, >=, <=

I'd also like to have a nice way to copy a non-carray-wrapped array into the
carray and vice versa in a way that creates a compile-time error if the
length is wrong. Probably this could be done some free function templates
that could use the stuff in <array.hpp>.

    -- Darin


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