add enumutils.items for sparse enums, typetraits.SomeSparseEnum (#17080)

* add enumutils.items for enum with holes
* changelog
* ref in lib.rst
* use `type SomeSparseEnum* = (not Ordinal) and enum` instead of concept
* address comment: rename back to enum with holes
This commit is contained in:
Timothee Cour 2021-02-23 11:25:35 -08:00 • committed by GitHub
commit c274e67198
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 6 deletions

View file

@ -15,6 +15,17 @@
import std/private/since
export system.`$` # for backward compatibility
type SomeEnumWithHoles* = (not Ordinal) and enum ## Enum with holes.
runnableExamples:
type A = enum a0 = 2, a1 = 4, a2
type B = enum b0 = 2, b1, b2
assert A is SomeEnumWithHoles
assert B isnot SomeEnumWithHoles
assert int isnot SomeEnumWithHoles
type C[T] = enum h0 = 2, h1 = 4
assert C[float] is SomeEnumWithHoles
proc name*(t: typedesc): string {.magic: "TypeTrait".} =
## Returns the name of the given type.
##