Remove element from vector.Vector
//Remove cl (*client) from clients (vector.Vector)
for i := 0; i < clients.Len(); i++ {
if cl == clients.At(i).(*client) {
clients开发者_JS百科.Delete(i)
break
}
}
Is there a shorter way to remove an element from a vector?
Not really what you asked for, but do not use Vector, use a slice instead, see here for a summary of some slice-idioms and their (deprecated/discouraged) Vector equivalents.
You could do something like:
for i, c := range clients {
if c == client {
clients = append(clients[:i], clients[i+1:]...)
}
}
And obviously it is trivial to define your own delete method for your own types which does the same.
精彩评论