That is exactly what I meant.
Compiler generates dynamic switch over 68 cases, each case block
made with SFINAE for type handled in that block. Basically just
odd syntax sugar to hide long switch-case. You yourself said you
have very numerous of those. Therefore certain combo of classical
dynamic polymorphism and classical visitor pattern will win the
huge variant of everything (my modules handle rarely over 50 classes)
in all areas easily and without much doubt.
>
> >
> > > > > Now that's pretty cool pattern matching, but let's face it, this would be much more understandable:
> > > > >
> > > > > Node setExposedPosition(Node node, Vec2 p) {
> > > > > if(hasField(node, EXPOSED_POSITION_BIT)) {
> > > > > node.exposedPosition = p;
> > > > > }
> > > > > return node;
> > > > > }
> > > >
> > > > External setter? I do not have setter members no idea why I
> > > > would want external setters.
> > > >
> > > > >
> > > > > I've found that if I simply make Node a struct with every possible data member from all the variant types, it only increases the size of Node by a factor of two, which is totally fine. (I could use std::optional for each member, but that would increase the size, and potentially be more dynamic than I need)
> > > > >
> > > > > Does that sound like the approach you would take?
> > > >
> > > > No. Only by factor of two? Then those are rather similar classes.
> > > >
> > > > From 68 mostly similar to each other "node" classes I would make plain
> > > > old polymorphic hierarchy.
> > >
> > > I used to do a traditional polymorphic hierarchy: it's harder to make value types, and requires much more boilerplate.
> >
> > Value types in sense that little, immutable objects, passed by value?
> > These do not make sense in context of your post at all.
>
> Not necessarily immutable, but yes passed by value. I'm using value-oriented design.
Yeah I noticed that you both pass and return that variant as value
in your examples. Are you sure that "value-oriented design" means
that "always make copies when possible"?
> > On the contrary, it is boilerplate of piles of those inefficient
> > switches from 68 cases all around your code that traditional
> > polymorphic hierarchy would remove with just one cheap level of
> > indirection added. I have measured it enough to predict that
> > program would be at least 4 times quicker, data about 4 times
> > smaller and executable also about twice smaller.
>
> This is not runtime performance critical code. (That's all on another thread)
It was you who said that people "might be baffled by the c++ fancyness"
of your code. There are no performance, no robustness, no clarity,
no readability ... what *is* the point?
> >
> > > > If there is need to keep objects of these classes in a single
> > > > container then I would use Boost.PolyCollection for efficiency.
> > > >
https://www.boost.org/doc/libs/1_71_0/doc/html/poly_collection.html
> > > >
> > > > That design beats both your variant and your monster struct blindfolded
> > > > with right hand tied behind back I can bet.
> > >
> > > I'm using
https://github.com/arximboldi/immer ...
> >
> > I do not know the lib but it is seems from afar that public common
> > setters sound like total bullshit with those immers that are
> > immutable after construction. Come again and tell what you really
> > need.
> >
> > > ... and can't change my containers.
> >
> > That is defect of mind. Software is *soft*. It is like drawing on
> > sand not carving on obsidian.
>
> Of course, but it takes time to make bigger changes.
True. That is why I keep my stuff very modular. Bit more work
with making and keeping the architecture clean but lot easier to
replace the parts with better or even to have (optional) alternatives
side-by-side.
> >
> > Most projects usually combine data initially from rather few container
> > types like:
> > std::array, std::vector, std::unordered_set, std::unordered_map.
> > Then, later, when the needs become more clear those are maintained
> > to be more special, precisely suitable containers.
>
> There are big advantages to be had with using those Immer containers which I would not want to abandon.
Huh? When you are collector of worthless recommendations then ask for
advice but keep the situation that you are in and constraints that you
have ... in secrecy. Instead make confusing claims with strange
examples. ;) That immer seemed to be all for performance in concurrent
processing. But just plain old "favor immutability" does not need
special libraries for it so it did not make me to feel interested.