VulkanSceneGraph icon indicating copy to clipboard operation
VulkanSceneGraph copied to clipboard

Allow specialisation of vsg::Inherit for sublasses

Open AnyOldName3 opened this issue 1 month ago • 3 comments

This allows default implementations of members to be provided, prevents copying and pasting of lots of trivial functions, and makes it possible to generate a compiler error if a subclass fails to provide a particular member without making it a pure virtual function.

This is a pretty close equivalent to how in the OSG, there was a META_Object macro that did roughly what the VSG's Inherit template does, but also there were specialised macros like META_Node and META_StateAttribute to do extra things for particular kinds of object.

I've only used this for vsg::ArrayState so far as that was the place where the problem came up in my work (I needed to add extra cloneArrayState overloads and ensure subclasses overrode them). I think it's a fairly safe bet that there are other places where using this would be helpful, as I know I've been annoyed by the lack of such a feature in the past, although I can't remember when or why.

This isn't the prettiest code in the world, and has a bonus extra annoying feature that it makes the Visual Studio debugger add an extra level of indentation to loads of things, but it's the best that can be done until P3469 https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2024/p3469r0.pdf is ratified and becomes part of C++ (it's too late to get into C++26) and finally makes CRTP fully obsolete.

AnyOldName3 avatar Nov 26 '25 18:11 AnyOldName3