Boost logo

Boost :

From: Greg Colvin (gcolvin_at_[hidden])
Date: 2000-01-04 15:57:37


From: Nicolai Josuttis <nicolai.josuttis_at_[hidden]>
> Darin Adler wrote:
> > > 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 }

This is cute, but it does cause some difficulties. We can
work around them (see below) but maybe if you want to do this
you can just use a built-in array. Another possibility is
some magic to allow:
   int data[] = { 0,1,2,3,4 };
   array<int,5> x(data);
or maybe
   int data[] = { 0,1,2,3,4 };
   array<int,data> x;
or perhaps if we ever pick up the C99 extensions we could do:
   array<int,5> x( { 0,1,2,3,4 } );

> > 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.

You can provide the same functionality with free functions.

> THIS is an important design issue. Unless somebody has a solution to fit
> both needs, we have to decide between what I would call an
> - array wrapper and

This we need, and want to call array. If it can't have the have the
same constructors as vector it can at least meet the STL container
requirements.

> - an STL container similar to vector with static size.
> Or may be we introduce both.

What do we need this for? If you don't want to change the size of
a vector you don't have to.

> However, if we introduce both, then we need a name for both
> (I' suggest array for the array wrapper and ???vector for the latter).
>
> Opinions, please!
>
>
> --
> Nicolai M. Josuttis http://www.josuttis.de/
> Solutions in Time mailto:solutions_at_[hidden]
>
> ------------------------------------------------------------------------
> Want to send money instantly to anyone, anywhere, anytime?
> You can today at X.com - and we'll give you $20 to try it! Sign
> up today at X.com. It's quick, free, & there's no obligation!
> http://click.egroups.com/1/332/1/_/9351/_/946924564
>
> -- Easily schedule meetings and events using the group calendar!
> -- http://www.egroups.com/cal?listname=boost&m=1
>
>
>


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