[swift-evolution] [Pitch] Add the DefaultConstructible protocol to the standard library
David Sweeris
davesweeris at mac.com
Mon Dec 26 13:57:26 CST 2016
> On Dec 26, 2016, at 11:35, Tony Allevato <allevato at google.com> wrote:
>
> Mathematically, identities are associated with (type, operation) pairs, not types alone.
>
> This conversation has put me in the column of "numeric types shouldn't have default initializers at all", personally.
I'd agree, except sometimes you need a T, any T, for when you want to create a "pre-sized" array for stuffing results into by index:
for i in ... {
a[i] = ...
}
Simply saying "var a =[T](); a.reserveCapacity()" doesn't cut it because it'll still crash if you try to store anything in a[i] without somehow putting at least i+1 elements in the array first.
- Dave Sweeris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161226/b5e0bc84/attachment.html>
More information about the swift-evolution
mailing list