Hi, I have two questions. I have the following program: 
    
    
    type
      StackObj*[T] = object
        data: seq[T]
        size: int
      StackRef*[T] = ref StackObj[T]
    
    proc newStackObj*[T](vals: varargs[T]): StackObj =
      var tempData = newSeq[T]()
      for datum in vals: tempData.add(datum)
      return StackObj[T](data: tempData, size: tempData.len())
    
    proc `$`*[T; C : StackObj[T] | StackRef[T]](stack: C): string =
      return $stack.data
    
    proc pushback*[T; C : StackObj[T] | StackRef[T]](stack: var C; val : T) =
      stack.data.add(val)
      stack.size.inc()
    
    proc popback*[T; C : StackObj[T] | StackRef[T]](stack: var C): T =
      stack.size.dec()
      return stack.data[stack.size]
    
    proc empty*[T; C : StackObj[T] | StackRef[T]](stack: C): bool =
      return stack.size == 0
    
    static:
      var stack = newStackObj[int](10)   # cannot instantiate: 
newStackObj[int]; got 1 type(s) but expected 2
      var stack = newStackObj(10)  # cannot instantiate: 'StackObj'
      # var stack = StackRef[int](data: @[12], size: 1)
      # stack.pushback(2)
      # echo stack.popback()
      # echo $stack
    

  1. Can you explain these error messages?
  2. It seems that I am writing [T; C : StackObj[T] | StackRef[T]] quite a lot. 
Any tips to go around this?



\---

Also, I'd love if there's a way to turn varargs into a vector (preferably 
R-valued)

Reply via email to