Boost logo

Boost Users :

From: gast128 (gast128_at_[hidden])
Date: 2005-08-07 16:46:52

Merrill Cornish <merrill.cornish <at>> writes:

> >>> the places where you would use fixed arrays,
> >>> you probably also know at what indexes certain data resides.
> If you use fixed arrays in that way, then you are using them much like
structs where, say, [0] mean THIS and [1]
> means THAT and [2] means something else etc. If that were the case, then
individually named variables
> would likely work better.
> The more common reason for fixed arrays is that the array is matching
something in the real world: I'm doing a
> 256 element Fast Forier Transform, I'm processing census data for 50 US
states, I'm tallying sales for the
> 12 months.

Your own argument exactly describes my case: you have a fixed array for the
months, so you know in which position the month november is. With enumerates
this mapping can be done easily.

> Again, the number of places where checking array bounds on fixed length
arrays is too small to justify work involved.

If you don't need it, don't use it. I hardly uses reverse iterators, but that
doesn't mean that they are useless, or don't justify their existance. Further
you use big words for such a small enhancement. A simple implementation would
be something like:

template <typename T, std::size_t N>
class array
  template <unsigned u>
  T& get()
     return elems[u];

A golden rule is alays to use as much error checking as possible, which is
compile time error checking.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at