Personally I don't think a completely, um, generic version of generics is
needed. But something like a list comprehension, possibly specifically
limited to "select"/"map" type comprehensions which do not change slice or
map length, would be invaluable. There's already a lot of special magic
around slices and maps, so adding more wouldn't be as world-changing as
adding it everywhere else (in both good and bad ways), while enabling one
to write a lot of useful list-processing utilities once instead of several
times. Since most of real-life software engineering turns into list
processing at some point, that would be super nice.
On Friday, August 4, 2017 at 9:30:43 PM UTC-7, Lucio wrote:
>
> We know how to deal with that without generics. But how would you define
> generics to address that more elegantly than you would with already
> available Go constructs (type assertions)?
>
> Lucio.
>
> On Saturday, 5 August 2017 01:48:28 UTC+2, T L wrote:
>>
>> A case:
>>
>> func iterateAndCopy(slice []T, p *T) {
>> for _, v := range slice {
>> *p = v
>> }
>> }
>>
>> func Benchmark_CopyCosts(b *testing.B) {
>> b.Run("bool-4", func(b *testing.B){
>> iterateAndCopy(make([]bool, 4), new(bool))
>> })
>> b.Run("int32-4", func(b *testing.B){
>> iterateAndCopy(make([]int32, 4), new(int32))
>> })
>> b.Run("int64-4", func(b *testing.B){
>> iterateAndCopy(make([]int64, 4), new(int64))
>> })
>> b.Run("[128]int-4", func(b *testing.B){
>> iterateAndCopy(make([][128]int64, 4), new([128]int64))
>> })
>> b.Run("struct{a,b,c,d int32}-100", func(b *testing.B){
>> iterateAndCopy(make([]struct{a,b,c,d int32}, 100),
>> new(struct{a,b,c,d int32}))
>> })
>> b.Run("bool-100", func(b *testing.B){
>> iterateAndCopy(make([]bool, 100), new(bool))
>> })
>> b.Run("int32-100", func(b *testing.B){
>> iterateAndCopy(make([]int32, 100), new(int32))
>> })
>> b.Run("int64-100", func(b *testing.B){
>> iterateAndCopy(make([]int64, 100), new(int64))
>> })
>> b.Run("[128]int-100", func(b *testing.B){
>> iterateAndCopy(make([][128]int64, 100), new([128]int64))
>> })
>> b.Run("struct{a,b,c,d int32}-100", func(b *testing.B){
>> iterateAndCopy(make([]struct{a,b,c,d int32}, 100),
>> new(struct{a,b,c,d int32}))
>> })
>> }
>>
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.