add typetraits.elementType (#14780)

* add typetraits.elementType

* add a test for 0-sized seq
This commit is contained in:
Timothee Cour 2020-06-24 13:31:07 -07:00 • committed by GitHub
commit 3e5743d6f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View file

@ -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 =