Here is some pseudocode for what I would like to do: template SIMD(actions:untyped) = if AVX2_Available(): import AVX2 # use the avx2 version of Add/Mul etc. actions else: import SSE # use the sse version of Add/Mul etc. actions SIMD: let c = SIMD_Add(a,b) SIMD_Mul(b,c)
But I can't do that because imports have to be top level. I can do include instead of import, that will lead to massive code size if someone had multiple uses of the template in their code, as it will reproduce the same functions over and over. Is there some way to accomplish this?