您将如何遍历 boost::shared_array
中的项目?您会对其执行 get()
并使用原始指针作为迭代器吗?
最佳答案
因为你已经在使用 boost,所以可能是这样的:
#include <boost/shared_array.hpp>
#include <boost/range.hpp>
#include <iostream>
int main()
{
boost::shared_array<int> arr(new int[10]());
int* ptr = arr.get();
for (int i : boost::make_iterator_range(ptr, ptr+10))
{
std::cout << i << ',';
}
}
无论如何,您需要自己记录数组的大小。
关于c++ - 遍历 boost::shared_array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15380589/