I want to use static generics in object definition for memory efficiency. But this makes many trouble especially with concepts. The following code cannot be compiled with message "SC: cannot generate code for: b". What is happening?
I also know that if I comment out line "x is S" in the concept definition, the code can be compiled.
type S[T;b:static[bool]] = object
a:int
when b:
x:int
var af:S[int, false]
var at:S[int, true]
type SC = concept x
x is S # when commnet out this, it can be compiled
discard
static:
echo S is SC
proc test[CLS:SC](self: CLS):CLS =
return self
echo af.test()
echo at.test()
what are you trying to do?
type S[T;b:static[bool]] = object
a:int
when b:
x:int
var af:S[int, false]
var at:S[int, true]
type SC = concept x,type T
T is S # when commnet out this, it can be compiled
discard
static:
echo S[int,true] is SC
proc test[CLS:S](self: CLS):CLS =
return self
echo af.test()
echo at.test()
S[int, true] doesn't satisfy the concept SC, which is why it won't compile, but also the concept isn't required for at least this reduced example.
Thanks! I understand the reason.
I wonder why S[int, true] don't satisfy the concept SC but S[int, TRUE] in my alternative satisfy the concept SC.