C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::any ehancement

From: Peter Bindels <dascandy_at_[hidden]>
Date: Mon, 13 May 2024 10:30:46 +0200
Hi Ahmad,

Did you look into why the current situation is as it is?

I can find any_cast references back to 2015. I can't seem to find when it
was introduced, but it's been in Fundamentals TS v2 for a long time before
making it into C++17.

I can find wg21.link/p0032 which proposes a different syntax.

That said, I think any_cast has the benefit of looking ugly and making
people think whether it's correct to extract a given value, which is a plus
IMO. Willing to be convinced otherwise though.

Regards,
Peter

On Mon, May 13, 2024 at 9:45 AM Ahmed Elbadawy via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Dear C++ Committee,
>
> I hope this message finds you well. I am writing to propose an enhancement
> to the template class std::any in the C++ standard library. The proposed
> enhancement aims to simplify the usage of std::any by adding a conversion
> function, thereby eliminating the need for explicit std::any_cast
> operations.
>
> Currently, using std::any requires explicit casting using std::any_cast but
> adding a conversion function to std::any will allow users to convert the
> stored value to a specified type directly, without the need for
> std::any_cast which will
>
> 1. Improve Readability: The proposed conversion function makes code
> more readable by eliminating the need for explicit casts.
> 2. Simplified Usage: Developers can use the conversion function
> directly, reducing the complexity of working with std::any.
>
> Considering the scenario where std::any is used as an argument to an
> overloaded function. With the proposed conversion function, we can use the
> builtin *static_cast* which is more convenient to be used than the
> template function *std::any_cast.*
> The attached file is a simple implementation of the *std::any* with the
> conversion function and simple usage of it, I would appreciate it if you
> could review the attached file and provide feedback.
>
> *Sincerely, Ahmed Elbadawy*
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2024-05-13 08:31:02