On Wednesday, August 3, 2016 at 11:46:43 PM UTC+8, Axel Wagner wrote: > > True, but it would still be just the same loop, it wouldn't actually be > significantly faster. And you'd need to put quite some machinery into a > pretty rarely used functionality, which means it also wouldn't be cleaner. > > The thing is, that the memory representation of []T and []J, with J being > an interface type, is very different form each other and differs also for > each (T, J) pair, AIUI. So you can't really efficiently generalize this. > The only thing it could possibly safe you, is writing the actual loop and > in general go doesn't really do this kind of tradeoff (saving small amounts > of trivial work by complicating the language and -implementation). >
so the copy buitlin function is not essential? > > On Wed, Aug 3, 2016 at 5:19 PM, T L <tapi...@gmail.com <javascript:>> > wrote: > >> >> >> On Wednesday, August 3, 2016 at 10:54:29 PM UTC+8, Axel Wagner wrote: >>> >>> Why is converting it in a loop "neither clean nor efficient"? It seems >>> to be both to me: a) It's clean, as it's type-safe, so much less can go >>> wrong and it's obvious what it does and b) it's efficient, becaue a >>> func([]T) []interface{} would need to use reflection, just to also have the >>> same loop (but a less efficient one, as every operation would need to >>> reflect). So, writing a loop would, in fact, be *more* efficient and clean >>> than a function. >>> >> >> If the functionality is provided by builltin package, the reflection is >> not needed, just like the copy builtin function. >> >> >>> >>> On Wed, Aug 3, 2016 at 4:35 PM, T L <tapi...@gmail.com> wrote: >>> >>>> Often, I need converting a []T to []interface{} to use the []interface >>>> as a variable length parameter. >>>> But converting a []T for []interface{} in a for loop is neither clean >>>> nor efficient. >>>> >>>> So is there a function in standard lib to convert []T to a >>>> []interface{}? >>>> >>>> -- >>>> 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...@googlegroups.com. >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> >>> -- >> 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...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.