我正在尝试编写这样的代码:
template <typename K, typename T, template <typename, typename> class C>
boost::optional<T> search(const C<K, T>& dict,
const K& key)
{
auto it = dict.find(key);
if (it != dict.end()) {
return it->second;
} else {
return boost::none;
}
}
希望能够在(std::[unordered_][multi]map)
具有字典接口的各种容器上调用上述函数,例如:
std::map<std::string, Foo> strToFoo;
auto val = search(strToFoo);
我知道函数模板不允许模板模板参数。但是还有其他方法可以达到同样的效果吗?