如何优雅的读取list<list<int>>中第一个list<int>的大小?
How to elegantly read the size of the first list<int> in the list<list<int>>?
我有一个list<list<int>>
,我想阅读列表中第一个list<int>
的size
,但我仍然需要循环遍历list<list<int>>
] 稍后。
所以目前我要做的是,我必须使用front()
获取大小,然后使用back()
回滚迭代器指针:
int rowCount = vList.front().size();
vList.back();
for (auto iterator = vList.begin(); iterator != vList.end();++iterator)
{
//do iterator access here
}
我觉得一点都不优雅。
无论如何,我可以用更优雅的方式来做到这一点吗?
我读错了the documentation; front()
和 back()
只访问列表中的第一个和最后一个元素,它们根本不推进迭代器。
因此,如果我删除 back()
行,我的代码将正常工作。
我有一个list<list<int>>
,我想阅读列表中第一个list<int>
的size
,但我仍然需要循环遍历list<list<int>>
] 稍后。
所以目前我要做的是,我必须使用front()
获取大小,然后使用back()
回滚迭代器指针:
int rowCount = vList.front().size();
vList.back();
for (auto iterator = vList.begin(); iterator != vList.end();++iterator)
{
//do iterator access here
}
我觉得一点都不优雅。
无论如何,我可以用更优雅的方式来做到这一点吗?
我读错了the documentation; front()
和 back()
只访问列表中的第一个和最后一个元素,它们根本不推进迭代器。
因此,如果我删除 back()
行,我的代码将正常工作。