For no. 1, maybe like this?
    
    
    type
      TypeError = object of Exception
    
    proc withmytype[T](a: T) =
      when (T is ref or T is ptr):
        raise newException(TypeError, "Supply only primitive value type")
      else:
        discard
    
    
    var a = newSeq[int]()
    try:
      withmytype(a.addr)
    except TypeError:
      echo getCurrentExceptionMsg()
    withmytype(5)
    

it's explained here, 
[https://nim-lang.org/docs/manual.html#generics-is-operator](https://nim-lang.org/docs/manual.html#generics-is-operator)

Also, maybe `typetraits` module can help? 
[https://nim-lang.org/docs/typetraits.html](https://nim-lang.org/docs/typetraits.html)

especially `genericHead` proc

Reply via email to