--Dear C++ Committee,
I hope this message finds you well. I am writing to propose an enhancement to the template class
std::anyin the C++ standard library. The proposed enhancement aims to simplify the usage ofstd::anyby adding a conversion function, thereby eliminating the need for explicitstd::any_castoperations.Currently, using
std::anyrequires explicit casting usingstd::any_castbut adding a conversion function tostd::anywill allow users to convert the stored value to a specified type directly, without the need forstd::any_castwhich will
- Improve Readability: The proposed conversion function makes code more readable by eliminating the need for explicit casts.
- Simplified Usage: Developers can use the conversion function directly, reducing the complexity of working with
std::any.Considering the scenario wherestd::anyis 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@lists.isocpp.org
https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals