Write a PropertyBag storing std::any values by name with a template get<T>(name) returning std::optional<T> (empty if missing or the wrong type); store and read ints, strings and doubles.
std::any stores any type; the pointer form of any_cast returns nullptr for a type mismatch, which get turns into an empty optional instead of an exception.
More Modern C++ Features (C++11 to C++23) practice questions
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!
We use Google Analytics cookies to see how LearnFrenzy is used and make it better, and Google AdSense to keep it free.
No analytics or ad cookies are set until you accept. Privacy Policy
·
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!