Skip to content

Conversation

@AnyOldName3
Copy link
Contributor

An alternative to #1609

The original PR's description, which is almost entirely relevant to this one, too:

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.

Unlike the original PR:

  • for classes that don't use this feature, nothing about them changes as all the templates expand to exactly what was used before.
  • for classes that do use this feature, there's no need to specify complicated template conditions as that's handled automatically.
  • it relies on more basic template features.
…mentation. Like e07a87f / vsg-dev#1609, but a bit simpler and easier to use
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant