gpt4 book ai didi

c++ - 如何插入到 Boost MPL 映射中

转载 作者:行者123 更新时间:2023-11-30 04:23:47 24 4
gpt4 key购买 nike

我成功地使用了 Boost MPL vector 和列表,但我就是无法弄清楚 map 。当我尝试插入一个时,我从 clang 3.1 得到“参数太少”(gcc 4.7 说了类似的话)。有一个 insert 版本,其中第二个参数是 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

最佳答案

添加

#include <boost/mpl/insert.hpp>

和正确的括号,从')'到'>'

http://liveworkspace.org/code/afb6632c3eb800412ea551f50c07fb0a

关于c++ - 如何插入到 Boost MPL 映射中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13198745/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com