-
Notifications
You must be signed in to change notification settings - Fork 1
/
constraints.go
46 lines (38 loc) · 1.38 KB
/
constraints.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// 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 constraints defines a set of useful constraints to be used
// with type parameters.
// This package was called "constriants" and was removed from the Go standard library
// before the 1.18 release, but is reproduced here inside the fn library because we
// need the numeric types. See https://github.com/golang/go/issues/50792
package constraints
// Signed is a constraint that permits any signed integer type.
type Signed interface {
~int | ~int8 | ~int16 | ~int32 | ~int64
}
// Unsigned is a constraint that permits any unsigned integer type.
type Unsigned interface {
~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
}
// Integer is a constraint that permits any integer type.
type Integer interface {
Signed | Unsigned
}
// Float is a constraint that permits any floating-point type.
type Float interface {
~float32 | ~float64
}
// Complex is a constraint that permits any complex numeric type.
type Complex interface {
~complex64 | ~complex128
}
// Ordered is a constraint that permits any ordered type: any type
// that supports the operators < <= >= >.
type Ordered interface {
Integer | Float | ~string
}
// Arithmetic is the type union of all numeric types.
type Arithmetic interface {
Integer | Float | Complex
}