[英]In c++ how to move range elements for a vector of vectors
Say I have a: 说我有一个:
std::vector<std::vector<int> > indices;
I fill these up, where each index of both outer and inner vectors have 3 entries. 我将这些填满,其中外部和内部向量的每个索引都有3个条目。 Now I want to do something similar to applying
std:move_backward()
on single vector-containers. 现在,我想做一些类似于在单个向量容器上应用
std:move_backward()
操作。
Let me give an example. 让我举个例子吧。 Here is my initial container filled at the following indices:
这是我在以下索引处填充的初始容器:
[0][0][0][1][0][2] , [1][0][1][1][1][2] , [2][0][2][1][2][2] , [3][0][3][0][3][0]
After moving from an i-th element backwards, in this example: the outer-index [1]
, I would get: 从第i个元素向后移动后,在此示例中:external-index
[1]
,我将得到:
[0][0][0][1][0][2] , [1][0][1][1][1][2] , [1][0][1][1][1][2] , [2][0][2][1][2][2]
Basically, the outer-index [1]
is placed in [2]
, and [3]
is replaced by the original [2]
, moving the inner-vectors along with it. 基本上,将外部索引
[1]
放置在[2]
,然后将[3]
替换为原始索引[1]
[2]
,将内部向量与其一起移动。
Any ideas on how this can be done? 关于如何做到这一点的任何想法? Perhaps with a function template?
也许带有功能模板?
This should do what you describe: 这应该按照您的描述进行:
std::copy_backward(indices.begin()+1, indices.begin()+3, indices.end());
No special manipulation of the inner vector is necessary. 不需要对内部向量进行特殊处理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.