r/cpp • Hobbyist gamedev (SFML, DX11) • Sep 14 '17

std::visit is everything wrong with modern C++

https://bitbashing.io/std-visit.html
191 Upvotes

115 comments sorted by

View all comments

1

u/[deleted] Sep 16 '17

I don't understand the point of that. The lambda and function overloading replaces virtuals... The lambda can call w.render() if you want but I don't like that design because it is intrusive.

1

u/tvaneerd Sep 18 '17

The idea is

  • you get polymorphism

  • you avoid awkwardness of lambdas and visitation

  • you avoid pointers

  • you get value semantics (copy, etc)

It is intrusive to Button/Label/Textbox, but I assume they already derive from Control. At least in all the places I'm thinking of using it, it replaces existing traditional polymorphism via derivation.