|
@@ -154,4 +154,77 @@ func Add1024[T integer](s []T) {
|
154
|
154
|
s[i] = v + 1024 // INVALID: 1024 not permitted by int8/uint8
|
155
|
155
|
}
|
156
|
156
|
}
|
157
|
|
-// UNTYPED CONSTANTS OMIT
|
|
157
|
+// UNTYPED CONSTANTS OMIT
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+// EMBED INTERSECTION OMIT
|
|
161
|
+// Addable is types that support the + operator.
|
|
162
|
+type Addable interface {
|
|
163
|
+ ~int | ~int8 | ~int16 | ~int32 | ~int64 |
|
|
164
|
+ ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
|
|
165
|
+ ~float32 | ~float64 | ~complex64 | ~complex128 |
|
|
166
|
+ ~string
|
|
167
|
+}
|
|
168
|
+
|
|
169
|
+// Byteseq is a byte sequence: either string or []byte.
|
|
170
|
+type Byteseq interface {
|
|
171
|
+ ~string | ~[]byte
|
|
172
|
+}
|
|
173
|
+
|
|
174
|
+// AddableByteseq is a byte sequence that supports +.
|
|
175
|
+// This is every type that is both Addable and Byteseq.
|
|
176
|
+// In other words, just the type set ~string.
|
|
177
|
+type AddableByteseq interface {
|
|
178
|
+ Addable
|
|
179
|
+ Byteseq
|
|
180
|
+}
|
|
181
|
+// EMBED INTERSECTION OMIT
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+// EMBED UNION OMIT
|
|
186
|
+// Signed is a constraint with a type set of all signed integer
|
|
187
|
+// types.
|
|
188
|
+type Signed interface {
|
|
189
|
+ ~int | ~int8 | ~int16 | ~int32 | ~int64
|
|
190
|
+}
|
|
191
|
+
|
|
192
|
+// Unsigned is a constraint with a type set of all unsigned integer
|
|
193
|
+// types.
|
|
194
|
+type Unsigned interface {
|
|
195
|
+ ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr
|
|
196
|
+}
|
|
197
|
+
|
|
198
|
+// Integer is a constraint with a type set of all integer types.
|
|
199
|
+type Integer interface {
|
|
200
|
+ Signed | Unsigned
|
|
201
|
+}
|
|
202
|
+// EMBED UNION OMIT
|
|
203
|
+
|
|
204
|
+// INTERFACE IN UNION OMIT
|
|
205
|
+type Stringish interface {
|
|
206
|
+ string | fmt.Stringer
|
|
207
|
+}
|
|
208
|
+
|
|
209
|
+func ToString[T Stringish](v T) string {
|
|
210
|
+ switch x := (interface{})(v).(type) {
|
|
211
|
+ case string:
|
|
212
|
+ return x
|
|
213
|
+
|
|
214
|
+ case fmt.Stringer:
|
|
215
|
+ return x.String()
|
|
216
|
+ }
|
|
217
|
+
|
|
218
|
+ panic("impossible")
|
|
219
|
+ }
|
|
220
|
+// INTERFACE IN UNION OMIT
|
|
221
|
+
|
|
222
|
+// EMPTY TYPE SETS OMIT
|
|
223
|
+// Unsatisfiable is an unsatisfiable constraint with an empty type set.
|
|
224
|
+// No predeclared types have any methods.
|
|
225
|
+// If this used ~int | ~float32 the type set would not be empty.
|
|
226
|
+type Unsatisfiable interface {
|
|
227
|
+ int | float32
|
|
228
|
+ String() string
|
|
229
|
+}
|
|
230
|
+// EMPTY TYPE SETS OMIT
|