diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2021-02-20 09:02:57 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-20 18:02:57 +0100 |
commit | 6b3bdd798d235a465d94ebedbc784d6b41057798 (patch) | |
tree | 7fd925946f4bbba405804bdbf70faee65ead536a /lib/std | |
parent | cbbb6ca4d74391b624eec78059e081bbde61e04f (diff) | |
download | Nim-6b3bdd798d235a465d94ebedbc784d6b41057798.tar.gz |
enable bsd for tsetutils; improve setutils API (#17098)
Diffstat (limited to 'lib/std')
-rw-r--r-- | lib/std/setutils.nim | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/std/setutils.nim b/lib/std/setutils.nim index 74f0dc819..d5d60d4ab 100644 --- a/lib/std/setutils.nim +++ b/lib/std/setutils.nim @@ -38,18 +38,21 @@ template toSet*(iter: untyped): untyped = macro enmRange(enm: typed): untyped = result = newNimNode(nnkCurly).add(enm.getType[1][1..^1]) -proc fullSet*(T: typedesc): auto {.inline.} = - ## Returns a full set of all valid elements. +# proc fullSet*(T: typedesc): set[T] {.inline.} = # xxx would give: Error: ordinal type expected +proc fullSet*[T](U: typedesc[T]): set[T] {.inline.} = + ## Returns a set containing all elements in `U`. runnableExamples: - assert {true, false} == fullSet(bool) + assert bool.fullSet == {true, false} + type A = range[1..3] + assert A.fullSet == {1.A, 2, 3} + assert int8.fullSet.len == 256 when T is Ordinal: {T.low..T.high} else: # Hole filled enum enmRange(T) proc complement*[T](s: set[T]): set[T] {.inline.} = - ## Returns the complement of the set. - ## Can also be thought of as inverting the set. + ## Returns the set complement of `a`. runnableExamples: type Colors = enum red, green = 3, blue |