Send type into function using templates
问题 I have this function for finding key in map and return the right value with type: template< typename T > T Foo::findInMap(std::string key) { std::map<std::string, std::any>::iterator it = options.find(key); if (it != options.end()) { return std::any_cast<T>(it->second); } return nullptr; } the map looks like this: std::map<std::string, std::any> options; How can I call and modify the function to get the best out of C++17? 回答1: Returning a nullptr is not always possible. Modern C++ way of