Hi, Thanks both for your responses.

I didn't know that I could treat result as a normal variable. The template := 
will also be very helpful for me.

The porblem remains when using containers like double queue where the 
implementation will make copies. For this reason, I tried to play with the 
assignement operator, however, when implementing the operator, I obtain a 
runtime error:
    
    
    ype
        container[T] = object
            val: seq[T]
    
    proc `=`[T](d: var container[T], s: container[T]) =
        echo "= container called"
        echo s
        echo d
        shallowCopy(d.val, s.val)
    
    var c = container[int](val: @[1, 2, 3])
    

which outputs:

= container called

(val: @[1, 2, 3])

(val: nil)

Traceback (most recent call last)

main2.nim(11) main2

main2.nim(9) =

gc.nim(287) unsureAsgnRef

gc.nim(196) incRef

SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Any idea how can I solve this error ? 

Reply via email to