Skip to content

Commit 98753da

Browse files
authored
distinctBase overload for values (#13746)
1 parent 764a81c commit 98753da

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ echo f
122122
- Added `net.getPeerCertificates` and `asyncnet.getPeerCertificates` for
123123
retrieving the verified certificate chain of the peer we are connected to
124124
through an SSL-wrapped `Socket`/`AsyncSocket`.
125-
125+
- Added `distinctBase` overload for values: `assert 12.MyInt.distinctBase == 12`
126126

127127
## Library changes
128128

lib/pure/typetraits.nim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ proc distinctBase*(T: typedesc): typedesc {.magic: "TypeTrait".}
7171
## Returns base type for distinct types, works only for distinct types.
7272
## compile time error otherwise
7373

74+
since (1, 1):
75+
template distinctBase*[T](a: T): untyped =
76+
## overload for values
77+
runnableExamples:
78+
type MyInt = distinct int
79+
doAssert 12.MyInt.distinctBase == 12
80+
distinctBase(type(a))(a)
7481
7582
proc tupleLen*(T: typedesc[tuple]): int {.magic: "TypeTrait", since: (1, 1).}
7683
## Return number of elements of `T`

0 commit comments

Comments
 (0)