Easy:
proc createT[T](x: T): T=
static: assert sizeof(T) == 4
result = x
Run
I thought it could be easly done via concept like this:
type AnyOfSize[S: static int] = concept type T
sizeof(T) == S
proc p(a: AnyOfSize[4]) =
echo a
p(0'i16) # <-- error
Run
However this code also works... maybe it's a bug?
Does Nim have the ability to constrain a generic type to be of a certain size?
For example, can I create MyObject[T] where T is any type that is 4 Bytes?
I should also have mentioned that I have a `d=nimPreviewSlimSystem` in my
`nim.cfg` which still breaks many things (self tests,
[nimble](https://github.com/nim-lang/nimble/issues/1050), etc.) but which does
make the empty file compile time `1.0779 +- 0.0088` times faster (notably,
quite a bit s
While I see you already figured out your answer, since you revived this ancient
thread, I can perhaps say some other things that might be helpful for fast
compiles. I do this in my $HOME/.config/nim/nim.cfg:
# Ideally, each Nim compiler flag would have an associated defineSymbol,
B
Maybe you guys should read more than the headline...
Could you share the script to compile with tinycc?
I hope there will be a duckdb component available in Nim .