diff options
-rw-r--r-- | changelog.md | 2 | ||||
-rw-r--r-- | lib/pure/typetraits.nim | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/changelog.md b/changelog.md index daed6c02b..a452965b2 100644 --- a/changelog.md +++ b/changelog.md @@ -122,7 +122,7 @@ echo f - Added `net.getPeerCertificates` and `asyncnet.getPeerCertificates` for retrieving the verified certificate chain of the peer we are connected to through an SSL-wrapped `Socket`/`AsyncSocket`. - +- Added `distinctBase` overload for values: `assert 12.MyInt.distinctBase == 12` ## Library changes diff --git a/lib/pure/typetraits.nim b/lib/pure/typetraits.nim index 66b94e238..ef28f83b0 100644 --- a/lib/pure/typetraits.nim +++ b/lib/pure/typetraits.nim @@ -71,6 +71,13 @@ proc distinctBase*(T: typedesc): typedesc {.magic: "TypeTrait".} ## Returns base type for distinct types, works only for distinct types. ## compile time error otherwise +since (1, 1): + template distinctBase*[T](a: T): untyped = + ## overload for values + runnableExamples: + type MyInt = distinct int + doAssert 12.MyInt.distinctBase == 12 + distinctBase(type(a))(a) proc tupleLen*(T: typedesc[tuple]): int {.magic: "TypeTrait", since: (1, 1).} ## Return number of elements of `T` |