Biohazrd
Biohazrd copied to clipboard
Explore using source generators to last-second compile template specializations referenced only from C#
Idea mentioned by ChemBB during development stream. Supposedly cppyy kinda works like this.
This is definitely a pie-in-the-sky concept and would be extremely non-trivial to implement. It'd also have lots of edge cases that would be un-fun to handle due to how flexible C++ templates are. (IE: What happens if a C++ template tries to call a method on a templated C# type?)
Would require C++ headers to be distributed to the library consumer and would require library consumer have a C++ toolchain.
Also need to explore if there's any chance of doing this efficiently with actual C# generics with the .NET JIT without generic specialization. (Also need to explore if maybe generic specialization exists at the runtime level -- pretty sure it doesn't though.)
Another possibility is requiring the C# consumer to explicitly specify a type, IE:
[CppTemplateSpecialization("std::vector", typeof(int))]
internal sealed partial class VectorOfInt
{
}
An added bonus of this strategy would be that it could support non-type template arguments.