github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/internal/constraints/constraints.go (about)

     1  // Copyright 2021 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package constraints defines a set of useful constraints to be used
     6  // with type parameters.
     7  package constraints
     8  
     9  // Signed is a constraint that permits any signed integer type.
    10  // If future releases of Go add new predeclared signed integer types,
    11  // this constraint will be modified to include them.
    12  type Signed interface {
    13  	~int | ~int8 | ~int16 | ~int32 | ~int64
    14  }
    15  
    16  // Unsigned is a constraint that permits any unsigned integer type.
    17  // If future releases of Go add new predeclared unsigned integer types,
    18  // this constraint will be modified to include them.
    19  type Unsigned interface {
    20  	~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
    21  }
    22  
    23  // Integer is a constraint that permits any integer type.
    24  // If future releases of Go add new predeclared integer types,
    25  // this constraint will be modified to include them.
    26  type Integer interface {
    27  	Signed | Unsigned
    28  }
    29  
    30  // Float is a constraint that permits any floating-point type.
    31  // If future releases of Go add new predeclared floating-point types,
    32  // this constraint will be modified to include them.
    33  type Float interface {
    34  	~float32 | ~float64
    35  }
    36  
    37  // RealNumber is a constraint that permits any integer and floating-point type.
    38  type RealNumber interface {
    39  	Integer | Float
    40  }
    41  
    42  // Complex is a constraint that permits any complex numeric type.
    43  // If future releases of Go add new predeclared complex numeric types,
    44  // this constraint will be modified to include them.
    45  type Complex interface {
    46  	~complex64 | ~complex128
    47  }
    48  
    49  // Ordered is a constraint that permits any ordered type: any type
    50  // that supports the operators < <= >= >.
    51  // If future releases of Go add new ordered types,
    52  // this constraint will be modified to include them.
    53  type Ordered interface {
    54  	Integer | Float | ~string
    55  }