将 boost::counting_iterator 与现有向量一起使用?

Using boost::counting_iterator with an existing vector?

目前我正在这样做:

const int n = 13;

std::vector<int> v(boost::counting_iterator<int>(0), boost::counting_iterator<int>(n + 1));
std::copy(v.begin(), v.end(), back_inserter(m_vecAssignmentIndex));

m_vecAssignmentIndex 定义如下:

ByteVector m_vecAssignmentIndex;

并且,ByteVector

using ByteVector = std::vector<BYTE>;

是否可以直接赋值给m_vecAssignmentIndex而避免std::copy


更新

所以,这样的代码就可以了:

std::vector<BYTE> v2(boost::counting_iterator<BYTE>(0), boost::counting_iterator<BYTE>(n + 1));
std::vector<int> v(boost::counting_iterator<int>(0), boost::counting_iterator<int>(n + 1));
std::copy(v.begin(), v.end(), back_inserter(m_vecAssignmentSortedIndex));

因此,我可以直接增加 BYTE 值。那么我怎样才能避免对临时向量的要求呢?

我现在在官方文档中找到了samples

int N = 7;
std::vector<int> numbers;
typedef std::vector<int>::iterator n_iter;
std::copy(boost::counting_iterator<int>(0),
         boost::counting_iterator<int>(N),
         std::back_inserter(numbers));

std::vector<std::vector<int>::iterator> pointers;
std::copy(boost::make_counting_iterator(numbers.begin()),
          boost::make_counting_iterator(numbers.end()),
          std::back_inserter(pointers));

std::cout << "indirectly printing out the numbers from 0 to "
          << N << std::endl;
std::copy(boost::make_indirect_iterator(pointers.begin()),
          boost::make_indirect_iterator(pointers.end()),
          std::ostream_iterator<int>(std::cout, " "));
std::cout << std::endl;

所以:

std::copy(boost::counting_iterator<BYTE>(0),
    boost::counting_iterator<BYTE>(n), std::back_inserter(m_vecAssignmentSortedIndex));