From: Jonathan Turkanis (technews_at_[hidden])
Date: 2005-06-06 17:36:54
Dave Harris wrote:
> In-Reply-To: <d80h47$irf$1_at_[hidden]>
> technews_at_[hidden] (Jonathan Turkanis) wrote (abridged):
>> array can't be given constructors without sacrificing the aggregate
>> initialization syntax.
> OK... although I'd rather have constructors than aggregate
> initialisation syntax. If the problem is performance, surely the
> compiler can optimise away the difference (given that it's a
> standard library component with known semantics)?
No, it's not performance -- it's compatibility with built-in arrays.
Furthermore, array initializers are considered pretty natural, and the trend is
to try to make user-defined types more like arrays in that respect. (See, e.g.,
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1509.pdf; this may not
be the most recent paper.)
> Anyway, it sounds like this battle is already lost.
> Is there a rational for not allowing zero-sized arrays? What is the
> intended semantics of:
> array<int> a; // Or array<int,0>.
> assert( a.empty() );
Zero sized arrays are allowed, at least by TR1:
18.104.22.168 Zero sized arrays [tr.array.zero]
array shall provide support for the special case N == 0.
In the case that N == 0, begin() == end() == unique value.
An instance of array<T, N> stores N elements of type T, so that size() == N
is an invariant.
This implies that an array has size 0 iff it empty() is true.
> ? Isn't this kind of thing likely to occur in generic template code?
I don't know.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk