C++ Logo

std-proposals

Advanced search

Re: a new proposal.

From: Gašper Ažman <gasper.azman_at_[hidden]>
Date: Tue, 13 Jul 2021 17:42:32 +0100
the dynamic_cast to a type-id is a really interesting call-site syntax for
open multimethods - the problem isn't that this hasn't been tried (just
look for multimethods) - the problem is we don't know of an efficient and
correct way to implement the dispatch tables.

If you are forced to write the switch statement based on the type-index
yourself, then at least you need to list, exhaustively, the types you care
about. Pattern matching is another way to do this. I'm not sure your
proposal is implementable.

G

On Tue, Jul 13, 2021 at 11:26 AM Marcin Jaczewski via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> I look like `dynamic` form C# but this mean it relay on reflection to
> work correctly:
> ```c#
> dynamic d = x;
> int i = d.item;
> ```
> is equal to
> ```c#
> DynamicType d = new DynamicType(x);
> int i = (int)d["item"];
> ```
> C++ could have static reflection but this requires dynamic reflection
> to work (static could generate dynamic but it will be costly).
> Another thing is dynamic code generation other wise you can't have code
> like:
>
> ```c++
> std::cout << declarative_cast<type_var>(var);
> ```
> where type can be `int`, `long` or `std::vector<int>` and all need
> have its own `<<` that is templated function that usually is inlined.
> Does this mean `type_var` needs to store all possible template functions?
>
> Beside syntax like `declarative_cast<arg[0]->i>` is wrong as it mix
> compile time template arguments with runtime arguments, something only
> could work
> if you use constexpr variables but it's not something your example wants
> to do.
>
>
> Lot better would expand `std::any` and allow easy way to have multiple
> type callbacks like:
> ```c++
> std::any z = 17;
>
> vist_any<int, long, std::vector<int>>(z, [](auto& w) { std::cout <<
> w; }); //you need name all types you want use
> ```
> and this is possible even if C++14
>
> wt., 13 lip 2021 o 11:27 Jaroslav Moravec via Std-Proposals
> <std-proposals_at_[hidden]> napisał(a):
> >
> > The proposal is in attachments. --
> > Std-Proposals mailing list
> > Std-Proposals_at_[hidden]
> > https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2021-07-13 11:42:50