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