Date: Tue, 10 Jun 2025 12:40:16 +0200
wt., 10 cze 2025 o 12:14 Sebastian Wittmeier via Std-Proposals
<std-proposals_at_[hidden]> napisał(a):
>
> Differences to respect:
>
> - A std::variant holds for better or worse, which type is stored, needing additional memory
>
If all types in the variant are pointers then no additional memory is
needed as we can use target pointers.
At least 4 different types can be held for 32bit CPU, for 64bit it
probably over 1000 could be held.
> - 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
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
<std-proposals_at_[hidden]> napisał(a):
>
> Differences to respect:
>
> - A std::variant holds for better or worse, which type is stored, needing additional memory
>
If all types in the variant are pointers then no additional memory is
needed as we can use target pointers.
At least 4 different types can be held for 32bit CPU, for 64bit it
probably over 1000 could be held.
> - 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
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
Received on 2025-06-10 10:40:29