我如何将MPL地图插入

How do I insert into a Boost MPL map

本文关键字:地图 插入 MPL      更新时间:2023-10-16

我设法使用了boost mpl向量,列表很好,但我只是无法弄清楚地图。当我尝试将其插入一个时,我会从Clang 3.1中获得"太少的争论"(GCC 4.7说的类似)。有一个版本的插入物,第二个参数为pos,应该被忽略,所以我尝试在那里插入虚拟类型(int),但这只是给出了一个新的且令人困惑的错误。

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错误即使有clang,也不是完全有帮助的,所以我只是不明白我在这里做错了什么?我确定这很愚蠢。

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

add

#include <boost/mpl/insert.hpp>

和正确的支架,从')'到'>'

http://liveworkspace.org/code/afb6632c3eb800412ea551f50c07fb0a