> How would you define a function that accepts/returns FancyDataStructure of any type or only of a type that has X embedded?
I'm not sure what you mean by this. If you mean that it accepts any type known at compile time, then you use the code generator (we're talking about a function template, after all). If you want this to work with any type known at runtime, then use Go's interface since you need the vtable.
> BTW type erasure isn't necessarily a bad thing when the compiler can prove the code is correct at compile time.
Sure, though I'm not sure what the performance implications -- and while I can think of some counter-examples were this wouldn't be the case, in most cases the impact would probably negative.
BTW type erasure isn't necessarily a bad thing when the compiler can prove the code is correct at compile time.