How do I erase the first 7 rows plus the 9th in a 3d vector like vector<vector<pair<int,int> > >?

Thing is that I have tried with memcpy, assign, copy_n, and copy, to no avail in the last two weeks by now. If you have an idea please use my code above to show me how to do it.

I want to describe my problem like this:
“You could, as I do, look upon allPathCoordinates(vector<vector<pair<int,int> > > allPathCoordinates;) as a dynamic 3d array with 9 rowss an unknown number of columns with different amount of integer pairs. What I want to keep is the 8th row intact with its unknown amount of integer pairs as the 3rd dimension.
That should be understood as if I'm not primarily interested in the elements i.e. the single first or second integer value in a pair. When having the 8th row extracted ( with memcpy, assign, copy_n, copy or some other better way) , I will iterate it to get the integer pairs (coordinates) for further use in a point() function like point[first][second]=Yellow;
Thanks for your interest.
Bo


if(allPathCoordinates.size()>0)
{
for (vector<vector<pair<int,int> > >::iterator it = allPathCoordinates.begin();
it!=allPathCoordinates.end();
it+=1)
{
v_temp = *it;
for(vector<pair<int,int> >::iterator it2 = v_temp.begin();
it2 != v_temp.end();
++it2)
{
m++;
apair = *it2;
openPoints[apair.first][apair.second]=0;
closedPoints[apair.first][apair.second]=1;
allObstacles[apair.first][apair.second]=Wall;
point[apair.first][apair.second]=Purple;
}
}
cout<<"allPathCoordinates.size():"<<allPathCoordinates.size()<<endl;//79512
cout<<"sizeof(allPathCoordinates):"<<sizeof(allPathCoordinates)<<endl;//24

vector< vector<pair<int,int> > >::size_type sz;
sz=allPathCoordinates.capacity();
cout<< "capacity: " << sz << '\n';

allPathCoordinates.erase(allPathCoordinates.begin(),allPathCoordinates.begin()+7);
cout<<"allPathCoordinates.size():"<<allPathCoordinates.size()<<endl;
cout<<"sizeof(allPathCoordinates):"<<sizeof(allPathCoordinates)<<endl;

sz=allPathCoordinates.capacity();
cout<< "capacity: " << sz << '\n';

Output:
allPathCoordinates.size():79512
sizeof(allPathCoordinates):24
capacity: 131072
allPathCoordinates.size():79505
sizeof(allPathCoordinates):24
capacity: 131072

As can be seen I have only reduced the number of elements with 7.Not what I wanted. I want to reduce the number of columns with 8 out of the totally 9.
}
Last edited on
First, a vector of vectors is 2d. Your problem statement is unclear. If you wish to keep the 6th, 7th and 8th rows, something like the following:

1
2
3
4
5
6
7
8
9
10
11
    if (allPathCoordinates.size() >= 8)
    {
        using vec_type = decltype(allPathCoordinates);
        vec_type v { std::move(allPathCoordinates[5]), 
                     std::move(allPathCoordinates[6]),
                     std::move(allPathCoordinates[7]) };

        allPathCoordinates = std::move(v);
    }
    // manipulate allPathCoordinates as required


Note this is untested, but it should give you the idea.
Last edited on
Thank you cire for your quick answer.I did what you proposed and manipulated allPathCoordinates as required. You can see the code below. I am sorry to say that your proposition had no effect. The color of the paths are still purple and not yellow as I had hoped. Besides there are drawn 9 paths. None are erased.

if(allPathCoordinates.size()>0)
{
int l,m,n=0;
//allPathCoordinates.erase(allPathCoordinates.begin(),allPathCoordinates.begin()+2);
for (vector<vector<pair<int,int> > >::iterator it = allPathCoordinates.begin();
it!=allPathCoordinates.end();
it+=1)
{

v_temp = *it;
for(vector<pair<int,int> >::iterator it2 = v_temp.begin();
it2 != v_temp.end();
++it2)
{
m++;
apair = *it2;
openPoints[apair.first][apair.second]=0;
closedPoints[apair.first][apair.second]=1;
allObstacles[apair.first][apair.second]=Wall;
point[apair.first][apair.second]=Purple;
}
}
}
/*******************Problems Occur*****************/


if (allPathCoordinates.size() >= 8)
{
using vec_type = decltype(allPathCoordinates);
vec_type v { std::move(allPathCoordinates[5]),
std::move(allPathCoordinates[6]),
std::move(allPathCoordinates[7]) };

allPathCoordinates = std::move(v);
}

for (vector<vector<pair<int,int> > >::iterator it = allPathCoordinates.begin();
it!=allPathCoordinates.end();
it+=1)
{
//
v_temp = *it;
for(vector<pair<int,int> >::iterator it2 = v_temp.begin();
it2 != v_temp.end();
++it2)
{
//m++;
apair = *it2;
openPoints[apair.first][apair.second]=0;
closedPoints[apair.first][apair.second]=1;
allObstacles[apair.first][apair.second]=Wall;
point[apair.first][apair.second]=Yellow;
}
}
Topic archived. No new replies allowed.