Re: converter with static generics not working

2020-06-29 Thread jxy
I have filed this open issue since years ago, 
[https://github.com/nim-lang/Nim/issues/4554](https://github.com/nim-lang/Nim/issues/4554)


Re: converter with static generics not working

2020-06-28 Thread SolitudeSF
there is no way for generic to infer the value of N, so it cant work as a 
converter.


converter with static generics not working

2020-06-28 Thread chaemon
I have a question. In the following code, the converter with static int 
generics fails. Are there any way to avoid this?

My purpose is to make C++-like constructor for which calling (value) 
generates S object because the conventional constructor using init*** is 
inconvenient in programming with generics.

I know that this is possible by using converter. Are there any other way to 
make this kind of constructor?


type S[N:static[int]] = object
  a:int

converter toS[N:static[int]](a:int):S[N] = S[N](a:a mod N)

echo toS[13](19) # works
#var x:S[13] = 19 # Error: type mismatch: got  but 
expected 'S[13]'
#echo S[13](19) # Error: type mismatch: got  but expected 
'S[13]'


type S2[T] = object
  a:T

converter toS2[T](a:T):S2[T] = S2[T](a:a)

echo toS2(21) # works
var y:S2[int] = 21 # works
echo S2(21) # works


Run