logoalt Hacker News

nananana9 • today at 8:00 AM • 2 replies • view on HN

> This has nothing to do with what the blog post is about.

It's an alternative way to solve the problem presented, which trivially allows you to make a std::vector<Event> (the whole point the article is building up to).

> the only thing std::polymorphism brings is the ability to do it without dynamic allocations, emplacement new or lifetime problems.

Which the version I showed has none of.


Replies

adev_ • today at 8:05 AM

> it's an alternative way to solve the problem presented

No it's not and you apparently did not understand the concept behind it (or more likely, do not want to understand the concept behind it).

Your solution is not an implementation of Open Polymorphism, it is just a poor man implementation of std::variant.

> Which the version I showed has none of.

Because it is not the same thing like explain by my previous comment and in around 5 other comments around mine soon I guess.

But you are entirely free to grunt around and continue to imply that C++ committee people are implementing something useless (Which they are not, this is useful).

➕ show 1 reply
OskarS • today at 8:42 AM

> Which the version I showed has none of.

No, it has something much worse, it has a memory leak. The nested types inside the union allocate memory, and they don't get destructed when Event gets destructed. Don't do this in modern C++, it's a terrible terrible idea, these kinds of constructs are very hard to get correct manually. Just use std::variant.