From 98753da33188e3eef2362c4ed3c2bea166b8f10b Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 25 Mar 2020 13:47:03 -0700 Subject: [PATCH] distinctBase overload for values (#13746) --- changelog.md | 2 +- lib/pure/typetraits.nim | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index daed6c02bb..a452965b20 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 66b94e2384..ef28f83b0b 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`