index to iterator

M

m_schellens

How can I get from a vector index the iterator?

typedef std::vector< doubleT> doubleV;

doubleV xV;
doubleV yV;

// fill xV and yV with values (they have the same size)
....


for( SizeT i=0; i<yV->size(); ++i)
{
if( (*yV)[ i] <= 0.0)
{
yV->erase( ***what? ***); // want to erase yV
xV->erase( ***what? ***); // want to earse xV
}
}


I know I could iterate through an iterator.
But to much typing for xV then.

Thanks,
Marc
 
T

Thomas Tutone

How can I get from a vector index the iterator?

typedef std::vector< doubleT> doubleV;

doubleV xV;
doubleV yV;

// fill xV and yV with values (they have the same size)
...


for( SizeT i=0; i<yV->size(); ++i)

I think you mean:

for (doubleV::size_type i = 0; i<yV.size(); ++i)
{
if( (*yV)[ i] <= 0.0)

I think you mean:

if (yV<=0.0)
{
yV->erase( ***what? ***); // want to erase yV


yV.erase(yV.begin() + i);
xV->erase( ***what? ***); // want to earse xV
}
}


I know I could iterate through an iterator.


Yes, that would make this easier and clearer.
But to much typing for xV then.

I don't understand what you mean.

Best regards,

Tom
 
T

Thorsten Kiefer

How can I get from a vector index the iterator?

typedef std::vector< doubleT> doubleV;

doubleV xV;
doubleV yV;

// fill xV and yV with values (they have the same size)
...


for( SizeT i=0; i<yV->size(); ++i)
{
if( (*yV)[ i] <= 0.0)
{
yV->erase( ***what? ***); // want to erase yV yV->erase(yV->begin() + i);
xV->erase( ***what? ***); // want to earse xV xV->erase(xV->begin() + i);
}
}


I know I could iterate through an iterator.
But to much typing for xV then.

Thanks,
Marc
 
G

Gernot Frisch

How can I get from a vector index the iterator?

typedef std::vector< doubleT> doubleV;

doubleV xV;
doubleV yV;

// fill xV and yV with values (they have the same size)
...


for( SizeT i=0; i<yV->size(); ++i)
{
if( (*yV)[ i] <= 0.0)
{
yV->erase( ***what? ***); // want to erase yV
xV->erase( ***what? ***); // want to earse xV



(yV->begin() + i) // gives a forward iterator, increased by 'i'
elements.

See also std::advance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,144
Latest member
KetoBaseReviews
Top