C++ Logo

std-proposals

Advanced search

Re: a new proposal.

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Tue, 13 Jul 2021 12:26:01 +0200
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

Received on 2021-07-13 05:26:14