Date: Tue, 10 Jun 2025 12:06:38 +0200
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_at_[hidden]>
Gesendet:Di 10.06.2025 11:42
Betreff:Re: [std-proposals] std::polyhandle (Draft Paper Attached)
An:C++ Proposals <std-proposals_at_[hidden]>;
CC:Robin Savonen Söderholm <robinsavonensoderholm_at_[hidden]>;
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
Received on 2025-06-10 10:14:50