FAQ
It would be nice if go can recognize the pattern below and bypass the
bounds checking:

// where l is a slice, array or pointer to an array
for i := range l {
    v := &l[i] // nice if bounds check isn't done here, as i hasn't changed
and is in range of l
    // ... work on v
}

I have no idea the difficulty in implementing this. But I do this a fair
amount in my code, and would love to see it supported.

I do it when my array/slice has value objects, which I want to be together,
but I want to check state in them.

Using for i, v := range l { ... } will return a copy of each element in the
array, which is not what I want.


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 14, '15 at 2:21p
activeOct 14, '15 at 2:21p
posts1
users1
websitegolang.org

1 user in discussion

Ugorji Nwoke: 1 post

People

Translate

site design / logo © 2022 Grokbase