I need get the type of container item(seq, array, iterator etc), so I write an 
template to get the item type, but when work with the generic, sometime it will 
fail to compile using the wrapper. Here is the code 
    
    
    import macros
    
    template getTypeOfItem(t: untyped): auto =
       type(t[0])
    
    template getType(t: untyped): auto =
       type(t[0])
    
    template foo1(t: untyped) =
       var x: type(t[0])
    
    template foo2(t: untyped) =
       var x: getType(t)
    
    template foo3(t: untyped) =
       var x: getTypeOfItem(t)
    
    proc foo[T](x: seq[seq[T]]) =
       foo1(x)     # this works
       
       foo2(x)     # this works too if we import the macros
                   # without import macros, it fail to compile too
                   # because there is proc in the macros named getType
                   # very strange why it affect
       
       foo3(x)     # this works for non generic function
                   # but it fail in this function
    
    foo(@[@[1,2], @[3,4]])
    

My question is:

  1. Is there a way to make the foo3(x) compile?
  2. Why the foo2(x) compiles when import the macros, it seems very strange?



Thank you.

Reply via email to