Hi,
Is it possible to receive a template parameter just the same way as a proc parameter? For example if I have a template like
template Foo(x: seq[int]): expr =
echo x.len
echo x.len
Then the call Foo(f()) will call f() twice, which is not desied in my case. I could write
template Foo2(x: seq[int]): expr =
var y = x
echo y.len
echo y.len
which solves this problem, and only calls f() once. However, the problem with Foo2 is that if I write Foo2(largeSeq), then it will copy the largeSeq to y, which is costly and not necessary.
Do you have any ideas how to make both examples effective? (Please correct me if I misunderstand any of these behaviours.)
If I used a proc instead of a template, then it would solve both of these examples (f() would be called only once, there is no need to copy the seq). However, I need to use a template because of other reasons.