我想實現一個使用不同鍵值容器(例如map,unordered_map)的包裝類。STL容器上的模板模板參數
我希望用戶可以使用這樣的代碼方式:
MyWrapper<std::map> w1;
MyWrapper<std::tr1::unordered_map> w2;
我用「模板模板paramteres」實現這一點, 但地圖和unordered_map的模板參數是不同 ..
// but this Wrapper is for std::map only....
template< template<typename,typename,typename,typename> class CONTAINER>
class MyWrapper
{
CONTAINER<string, string,
std::less<string>,
std::allocator<std::pair<const string, string> > > c_;
};
MyWrapper<std::map> w1;
MyWrapper<std::tr1::unordered_map> w1; // not compiled!!!
有什麼辦法可以讓一個類可以傳遞map或unordered_map作爲模板參數嗎? 謝謝!
只是有用戶通過您的全部類型... – Xeo