Date: Wed, 4 Jan 2023 23:10:08 +0000
On Wed, 4 Jan 2023 at 22:37, Frederick Virchanza Gotham via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> 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.
>
I believe this was in reference to Giuseppe D'Angelo's suggestion that
std::any type-erase the `std::ostream& <<` operation.
Note that `<iostream>` for formatting is on the path to deprecation; any
new proposal should target `<format>`.
You also might want to take a look at the implementation in
https://en.cppreference.com/w/cpp/utility/any/type since that looks to be
significantly more efficient than yours.
std-proposals_at_[hidden]> wrote:
> 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.
>
I believe this was in reference to Giuseppe D'Angelo's suggestion that
std::any type-erase the `std::ostream& <<` operation.
Note that `<iostream>` for formatting is on the path to deprecation; any
new proposal should target `<format>`.
You also might want to take a look at the implementation in
https://en.cppreference.com/w/cpp/utility/any/type since that looks to be
significantly more efficient than yours.
Received on 2023-01-04 23:10:22