There is nothing in the standard library that would do exactly what you want, you must provide such a class yourself.
, (, std::map); , , . , , :
template <class K, class V, class C, class A>
void foo(const std::map<K, V, C, A> &arg)
{
doSomething(arg.at(K()));
}
struct MyMap : std::map<int, int>
{
int at(int) { return 7; }
};
int main()
{
MyMap m;
foo(m);
}
std::map (, , std::unordered_map, , ) . , , , , . :
template <
class Key,
class Value,
class Comparator = typename std::map<Key, Value>::key_compare,
class Allocator = typename std::map<Key, Value>::allocator_type
>
class DefaultDict : private std::map<Key, Value, Comparator, Allocator>
{
public:
using std::map<Key, Value, Comparator, Allocator>::clear;
Value& at(const Key &key) {
return std::map<Key, Value, Comparator, Allocator>::operator[](key);
}
};