mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-06 04:57:49 +00:00
distinctBase overload for values (#13746)
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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`
|
||||
|
||||
Reference in New Issue
Block a user