Documentation
¶
Overview ¶
Package new allocates a new variable of a given value and returns a pointer to it.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Of ¶
func Of[T any](value T) *T
Of allocates a new variable of a given value and returns a pointer to it.
Example ¶
package main
import (
"fmt"
"github.com/carlmjohnson/new"
)
func main() {
strptr1 := new.Of("meaning of life")
strptr2 := new.Of("meaning of life")
fmt.Println(strptr1 != strptr2)
fmt.Println(*strptr1 == *strptr2)
intp1 := new.Of(42)
intp2 := new.Of(42)
fmt.Println(intp1 != intp2)
fmt.Println(*intp1 == *intp2)
type MyFloat float64
fp := new.Of[MyFloat](42)
fmt.Println(fp != nil)
fmt.Println(*fp == 42)
}
Output: true true true true true true
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.
