diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2020-03-25 13:47:03 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-25 21:47:03 +0100 |
commit | 98753da33188e3eef2362c4ed3c2bea166b8f10b (patch) | |
tree | 4101b2de85a08414566fdde9dd76f9e569bf2331 /lib | |
parent | 764a81ca253b78d0faa75a24dffc8d111362974f (diff) | |
download | Nim-98753da33188e3eef2362c4ed3c2bea166b8f10b.tar.gz |
distinctBase overload for values (#13746)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/typetraits.nim | 7 |
1 files changed, 7 insertions, 0 deletions
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` |