Documentation ¶
Overview ¶
pointer is a pointer to a value of type T.
Example (SimpleNewAndUse) ¶
package main import ( "fmt" "github.com/snowmerak/generics-for-go/v2/types/pointer" ) func main() { i := 10 a := pointer.New(&i) *a.Load() = 20 fmt.Println(i) }
Output: 20
Example (SwapPointer) ¶
package main import ( "fmt" "github.com/snowmerak/generics-for-go/v2/types/pointer" ) func main() { i := 10 a := pointer.New(&i) n := 20 a.CompareAndSwap(&n, &i) fmt.Println(*a.Load()) }
Output: 20
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pointer ¶
type Pointer[T any] struct { // contains filtered or unexported fields }
Pointer is a container of T pointer.
func (*Pointer[T]) CompareAndSwap ¶
CompareAndSwap sets the value of the Pointer if the current value is equal to the expected value.
func (*Pointer[T]) Run ¶
Run is a function that takes a pointer of type T. if pointer is nil, returns false.
Click to show internal directories.
Click to hide internal directories.