add typetraits.elementType (#14780)
* add typetraits.elementType * add a test for 0-sized seq
This commit is contained in:
parent
0434aef4cd
commit
3e5743d6f7
3 changed files with 33 additions and 0 deletions
|
|
@ -93,6 +93,18 @@ since (1, 1):
|
|||
type StaticParam*[value: static type] = object
|
||||
## used to wrap a static value in `genericParams`
|
||||
|
||||
since (1, 3, 5):
|
||||
template elementType*(a: untyped): typedesc =
|
||||
## return element type of `a`, which can be any iterable (over which you
|
||||
## can iterate)
|
||||
runnableExamples:
|
||||
iterator myiter(n: int): auto =
|
||||
for i in 0..<n: yield i
|
||||
doAssert elementType(@[1,2]) is int
|
||||
doAssert elementType("asdf") is char
|
||||
doAssert elementType(myiter(3)) is int
|
||||
typeof(block: (for ai in a: ai))
|
||||
|
||||
import std/macros
|
||||
|
||||
macro genericParamsImpl(T: typedesc): untyped =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue