mirror of
https://github.com/golang/go
synced 2024-11-17 14:14:56 -07:00
19457a58e5
A generic conversion might be required for when converting T->interface{}. When stenciled with T=interface{}, then that conversion doesn't need to do anything. Fixes #48276 Change-Id: Ife65d01c99fbd0895cb7eec79df9e93e752b1fa5 Reviewed-on: https://go-review.googlesource.com/c/go/+/348736 Trust: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org>
20 lines
360 B
Go
20 lines
360 B
Go
// run -gcflags=-G=3
|
|
|
|
// Copyright 2021 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package main
|
|
|
|
import "fmt"
|
|
|
|
func main() {
|
|
IsZero[interface{}]("")
|
|
}
|
|
|
|
func IsZero[T comparable](val T) bool {
|
|
var zero T
|
|
fmt.Printf("%v:%v\n", zero, val)
|
|
return val != zero
|
|
}
|