如何创建boost::unordereded_map的子类

How do I create a subclass of boost::unordered_map?

本文关键字:unordereded 子类 map boost 何创建 创建      更新时间:2023-10-16

我正在尝试子类化boost::unordered_map(这样我就可以捕获异常,而不会让异常捕获逻辑扰乱我的程序)。我已经成功地包装了boost::unordered_map,但我想尝试创建一个子类。

无论如何,我在确定正确的子类语法时遇到了问题。

以下不起作用:

template<typename Key, typename Mapped, typename Hash = boost::hash<Key>,
         typename Pred = std::equal_to<Key>,
         typename Alloc = std::allocator<std::pair<Key const, Mapped>> >
class unordered_map : public boost::unordered_map<typename Key, typename Mapped, typename Hash = boost::hash<Key>,
                                                  typename Pred = std::equal_to<Key>,
                                                  typename Alloc = std::allocator<std::pair<Key const, Mapped>> >
{
};
#include <boost/unordered_map.hpp>
template<typename Key, typename Mapped, typename Hash = boost::hash<Key>,
         typename Pred = std::equal_to<Key>,
         typename Alloc = std::allocator<std::pair<Key const, Mapped> > >
class my_unordered_map : public boost::unordered_map<Key, Mapped, Hash,Pred,Alloc>
{
};
void main(){
    my_unordered_map<int,int> kk;
}