Not completely sure what you're asking, more detail or example ( pseudo) code would help but just in case I understand:
Yes, generic varargs are possible, and yes you can type specialise:
import sequtils
proc trs[T](args:varargs[T]):seq[T] =
when T is int:
args.mapIt(it*2)
else:
args.toSeq()
echo trs(3,4,5) # @[6,8,10]
echo trs('a','b','c') #['a','b','c']
When I saw your code, I thought it might be possible to specialize trs[int] like this:
import sequtils
proc trs[T](args: varargs[T]): seq[T] =
args.toSeq()
proc trs[int](args: varargs[int]): seq[int] =
args.mapIt(it*2)
echo trs(3,4,5) # @[6,8,10]
echo trs('a','b','c') # @['a','b','c']
But this gives a compiler error about redefining trs.
I was wondering: If the first version of trs had already been written, would it be possible to specialize it without changing the code of the general proc that uses T? If yes, how?
You could do
import sequtils
proc trs[T](args: varargs[T]): seq[T] =
args.toSeq()
proc trs[T:int](args: varargs[T]): seq[T] =
args.mapIt(it*2)
echo trs(3,4,5) # @[6,8,10]
echo trs('a','b','c') # @['a','b','c']
Seems to work as long as int is generic.you need to provide a proc (like $) that converts all the types you're interested in to a single type
import sequtils
proc toSeqofString(args:varargs[string,`$`]):seq[string] = args.toSeq
echo toSeqofString(3,7.5,'a',"steven",(3,4,5))