list - boost 分配空列表

标签 list boost assign

我想 boost::将列表分配给空值。 像这样的东西:

using namespace boost::assign;
std::list<int> myList = list_of<int>();

我想要这样做的原因是我有一个要初始化的列表映射,并且映射中的一个列表是空的。 所以我实际上想要:

std::map<int, std::list<int> > myMap = 
    (map_list_of(0, list_of<int>())
                (1, list_of<int>(1)(2))
                (3, list_of<int>(99));

最佳答案

使用std::list<int>()而不是list_of<int>() :

std::map<int, std::list<int> > myMap = 
    (map_list_of(0, std::list<int>())
                (1, list_of<int>(1)(2))
                (3, list_of<int>(99));

关于list - boost 分配空列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8447449/

相关文章:

java - 列表意外更新

java - 从n个列表中获取交集

c++ - 如何让迭代器进入 boost fusion map?

c++ - 了解类共享指针及其在继承中的使用

python - 将函数的输出分配给python中的空列表常量

C# 循环遍历两个列表,从列表 #2 中删除重复项

python - 如何过滤字典以仅包含给定列表中的键?

c++ - std::async 中的奇怪行为

c - 无法理解表达式如何变得错误

javascript - 在合并对象的键中创建值数组