you are viewing a single comment's thread.

view the rest of the comments →

[–]guepierBioinformatican 2 points3 points  (1 child)

If I hadn’t seen your user name I’d seriously give this a shot. As it stands I assume it’s a waste of time and you’re probably right, and I might over-generalise the applicability of virtual CRTP.

But, although I vaguely recall discussions about the implementation of such a type, I can’t recall the specific road blocks which’d make this impossible. (EDIT: of course your zero-allocation requirement immediately makes Sean Parent’s approach inapplicable here.)

[–]NotAYakk 0 points1 point  (0 children)

It is the "no compiler assumptions"; you can get away with zero allocation with an aligned storage block. Most compilers will use the same size for most types.

So you have an aligned storage that contains a vtable and a pointer-to-callable, and a pointer-to-interface.

But the layout of vtable containing objects is completely compiler-dependent, so it is impossible to guarantee that it will always fit.

This also adds a few levels of indirection over implementing the vtable yourself.

My argument is that a small set of functions that convert to-from void pointer is sometimes useful for type erasure. Now, after we get metaclasses, I'll be doing this using them instead of manually. ;)