Boost logo

Boost :

From: Douglas Paul Gregor (gregod_at_[hidden])
Date: 2003-12-03 17:58:16


On Wed, 3 Dec 2003, David B. Held wrote:

> "Douglas Paul Gregor" <gregod_at_[hidden]> wrote in message
> news:20031203132418.C2024_at_ashley.cs.rpi.edu...
> > [...]
> > Well, arrays are just not _objects_ like all of the STL containers.
> > They don't have begin()/end() to get iterators, they don't have a
> > size() member function, or a value_type typedef, and can't be
> > copied around like objects can. The lib plays nice with arrays,
> > but arrays don't want to join in the fun.
> > [...]
>
> On the other hand, I'm not sure how to use an initializer list
> with a non-array container. I have a fair amount of code that
> uses local const data like so:
>
> void foo()
> {
> my_data const d[] = {a, b, c, d};
> ...
> my_data const* end = d + dimension(d);
> for (my_data const* p = d; p != end; ++p)
> {
> ...
> }
> }
>
> Obviously, I use the sizeof idiom instead, but it would be a lot
> nicer to use the size/dimension trick instead. Is it possible to
> use a user-defined container instead?

Well, std::tr1::array (and boost::array) support brace initialization but
you need to know the size ahead of time :(. Help may be on the way:

  http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/papers/2003/n1509.pdf

        Doug


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