Skip to content

Commit 0e45f9e

Browse files
committed
1 parent 1e30310 commit 0e45f9e

File tree

3 files changed

+0
-61
lines changed

3 files changed

+0
-61
lines changed

changelog.md

-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@
5050
- Added `sugar.collect` that does comprehension for seq/set/table collections.
5151
- Added `sugar.capture` for capturing some local loop variables when creating a closure.
5252
This is an enhanced version of `closureScope`.
53-
- Added `typetraits.lenTuple` to get number of elements of a tuple/type tuple,
54-
and `typetraits.get` to get the ith element of a type tuple.
55-
- Added `typetraits.genericParams` to return a tuple of generic params from a generic instantiation
5653
- Added `os.normalizePathEnd` for additional path sanitization.
5754
- Added `times.fromUnixFloat,toUnixFloat`, subsecond resolution versions of `fromUnix`,`toUnixFloat`.
5855
- Added `wrapnils` module for chains of field-access and indexing where the LHS can be nil.

lib/pure/typetraits.nim

-42
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
export system.`$` # for backward compatibility
1616

17-
include "system/inclrtl"
18-
1917
proc name*(t: typedesc): string {.magic: "TypeTrait".}
2018
## Returns the name of the given type.
2119
##
@@ -71,46 +69,6 @@ proc distinctBase*(T: typedesc): typedesc {.magic: "TypeTrait".}
7169
## Returns base type for distinct types, works only for distinct types.
7270
## compile time error otherwise
7371

74-
import std/macros
75-
76-
macro lenTuple*(t: tuple): int {.since: (1, 1).} =
77-
## Return number of elements of `t`
78-
newLit t.len
79-
80-
macro lenTuple*(t: typedesc[tuple]): int {.since: (1, 1).} =
81-
## Return number of elements of `T`
82-
newLit t.len
83-
84-
since (1, 1):
85-
template get*(T: typedesc[tuple], i: static int): untyped =
86-
## Return `i`th element of `T`
87-
# Note: `[]` currently gives: `Error: no generic parameters allowed for ...`
88-
type(default(T)[i])
89-
90-
macro genericParams*(T: typedesc): untyped {.since: (1, 1).} =
91-
## return tuple of generic params for generic `T`
92-
runnableExamples:
93-
type Foo[T1, T2]=object
94-
doAssert genericParams(Foo[float, string]) is (float, string)
95-
result = newNimNode(nnkTupleConstr)
96-
var impl = getTypeImpl(T)
97-
expectKind(impl, nnkBracketExpr)
98-
impl = impl[1]
99-
while true:
100-
case impl.kind
101-
of nnkSym:
102-
impl = impl.getImpl
103-
continue
104-
of nnkTypeDef:
105-
impl = impl[2]
106-
continue
107-
of nnkBracketExpr:
108-
for i in 1..<impl.len:
109-
result.add impl[i]
110-
break
111-
else:
112-
error "wrong kind: " & $impl.kind
113-
11472
when isMainModule:
11573
static:
11674
doAssert $type(42) == "int"

tests/metatype/ttypetraits.nim

-16
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,6 @@ block distinctBase:
9292
doAssert($distinctBase(typeof(b2)) == "string")
9393
doAssert($distinctBase(typeof(c2)) == "int")
9494

95-
block genericParams:
96-
type Foo[T1, T2]=object
97-
doAssert genericParams(Foo[float, string]) is (float, string)
98-
type Foo1 = Foo[float, int]
99-
doAssert genericParams(Foo1) is (float, int)
100-
type Foo2 = Foo[float, Foo1]
101-
doAssert genericParams(Foo2) is (float, Foo[float, int])
102-
doAssert genericParams(Foo2) is (float, Foo1)
103-
doAssert genericParams(Foo2).get(1) is Foo1
104-
doAssert (int,).get(0) is int
105-
doAssert (int, float).get(1) is float
106-
static: doAssert (int, float).lenTuple == 2
107-
static: doAssert (1, ).lenTuple == 1
108-
static: doAssert ().lenTuple == 0
109-
110-
11195
##############################################
11296
# bug 13095
11397

0 commit comments

Comments
 (0)