2012-11-02 37 views
1

我設法使用Boost MPL向量和列表很好,但我無法弄清楚地圖。當我試圖插入到一箇中時,我從叮噹聲3.1中得到「太少的參數」(gcc 4.7說了類似的東西)。有一個插入版本,其中第二個參數是POS,這應該被忽略,所以我嘗試在其中插入一個虛擬類型(int),但這只是給出了一個新的令人困惑的錯誤。如何插入Boost MPL映射

include <iostream> 

#include <boost/mpl/key_type.hpp> 
#include <boost/mpl/map.hpp> 

using namespace boost; 
using namespace mpl; 

int main(){ 

    typedef pair<int_<3>, int_<6>> obj; 

    std::cout << key_type<map<>, obj >::type::value << std::endl; //works 

    std::cout << has_key<insert<map<>, obj>::type, obj)::type::value << std::endl; //complains on "too few template arguments for class template 'insert' 

    std::cout << has_key<insert<map<>, int, obj>::type, obj)::type::value << std::endl; // gives "implicit instantiation of undefined template 'boost::mpl::insert<..." 
} 

MPL錯誤是不完全有益的,即使有鐺,所以我只是不明白我在做什麼錯在這裏?我相信這是愚蠢的。

http://www.boost.org/doc/libs/1_51_0/libs/mpl/doc/refmanual/map.html

回答

2

添加

#include <boost/mpl/insert.hpp> 

和正確的支架,從 ')' 到 '>'

http://liveworkspace.org/code/afb6632c3eb800412ea551f50c07fb0a

+0

D'哦,我是一個白癡:)。我認爲導入map.hpp會導入與地圖相關的所有內容。順便說一下,在我看來,如果這些類型包含自己的方法(如map <> :: insert),而不是重載序列的元函數,那將更自然。 – Gurgeh