Differences to respect:
- A std::variant holds for better or worse, which type is stored, needing additional memory
- Wherever the object is transmitted or stored, all alternatives have to be listed (as template parameters to the std::variant type)
- std::variant also works with non-polymorphic types
-----Ursprüngliche Nachricht-----
Von: Robin Savonen Söderholm via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Di 10.06.2025 11:42
Betreff: Re: [std-proposals] std::polyhandle (Draft Paper Attached)
An: C++ Proposals <std-proposals@lists.isocpp.org>;
CC: Robin Savonen Söderholm <robinsavonensoderholm@gmail.com>;
So we have a use-case: you want to create a container of both Qt and Wx widgets. A safe solution that you can use today:```C++
std::vector<std::variant<QWindow, wxWidget>> g_all_windows;
for (auto& p : g_all_windows) {
if(auto* p = std::get_if<QWindow>(&p); p != nullptr) DoSomething();
else if(auto* p = std::get_if<wxWidget>(&p); p != nullptr) DoSomethingElse();
}
```
// Robin