proposal: Go 2: permit builtin make function to initialize returned slice #29186
Labels
FrozenDueToAge
LanguageChange
Suggested changes to the Go language
Proposal
v2
An incompatible library change
Milestone
Uh oh!
There was an error while loading. Please reload this page.
This is an alternative proposal for my another one: #23905
Short description of the problem
Sometimes, we may want to merge several slices (with the same element type).
The current implementation is like:
There are two problems in the implementation:
make
call is unnecessary.My original proposal thread (#23905) is closed for three possible other solutions:
However, I think the three solutions are hard to be implemented perfectly or not very practical.
So here I propose another alternative solution.
The solution: enhance the built-in
make
functionI propose to let
make
calls support the following manner:where each
gapN
is anint
value, eachaSliceN
is a slice with element type ofT
.Only the elements at the gap segments will be zeroed.
All
gapN
can be omitted. So the following call is also valid:Omitted gaps are viewed as zero.
I think the alternative solution is both efficient and much less verbose.
============================================
Bonus for proposal (please ignore this bonus if you don't like it, I mean don't reject this main proposal by disliking the bonus):
The text was updated successfully, but these errors were encountered: