C++ Logo

std-proposals

Advanced search

Re: [std-proposals] cout << any

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Thu, 5 Jan 2023 18:31:29 +0100
śr., 4 sty 2023 o 23:38 Frederick Virchanza Gotham via Std-Proposals
<std-proposals_at_[hidden]> napisał(a):
>
> On Wed, Jan 4, 2023 at 10:04 PM Andrey Semashev via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
> > Even if you never call the
> > operator<< in your program that uses std::any, the compiler still has to
> > generate the implementation for it - for every type that you ever store
> > in std::any. Eventually this makes std::any too expensive to use for
> > more and more people.
>
>
> If none of the source files in your project have:
>
> #include <any_ostream>
>
> then your program will never have the extra classes and functions I wrote.
>
> And even if you _do_ include my header file and never use anything in
> it, your compiler will eradicate unreachable code.
>
> I don't know why you think std::any has to become any more complicated
> or less efficient.


Is even `std::any` a correct type erasure abstraction in this case?
if you want some arbitrary object and do some operations on it (`<<`
is only special case there)
then should https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p0957r5.pdf
be a better match?
We could even pre define some interfaces in `std` that will by default
interact with `stream <<` or new format functions.
Like:
```
std::proxy<std::printable, std::dynamic_cast_like_in_any,
FMyOperationA, FMyOperationB> my_any;
```
And this should have similar capabilities to current `std::any` and
have functionality you want plus more.

Received on 2023-01-05 17:31:41