S
subramanian100in
I assign an initial iterator value returned by 'find()' algorithm to a
variable called 'first'.
Container::const_iterator first = find(c.begin(), c.end(), value);
Then I want to find the next occurrence of the 'value' in the sequence
to 'first'. To do this, I write the following code.
if (first != c.end())
{
first = find(++first, c.end(), value);
// do something with 'first'
}
Is the above assignment correct ? Or does it invoke undefined
behaviour because I do an increment of 'first' inside 'find()'
algorithm and store the result returned by 'find()' in 'first'
itself ?
Should I equivalently write the following piece of code ?
Container::const_iterator temp;
if (first != c.end())
{
temp = find(++first, c.end(), value);
// do something with 'temp'
}
Kindly clarify.
Thanks
V.Subramanian
variable called 'first'.
Container::const_iterator first = find(c.begin(), c.end(), value);
Then I want to find the next occurrence of the 'value' in the sequence
to 'first'. To do this, I write the following code.
if (first != c.end())
{
first = find(++first, c.end(), value);
// do something with 'first'
}
Is the above assignment correct ? Or does it invoke undefined
behaviour because I do an increment of 'first' inside 'find()'
algorithm and store the result returned by 'find()' in 'first'
itself ?
Should I equivalently write the following piece of code ?
Container::const_iterator temp;
if (first != c.end())
{
temp = find(++first, c.end(), value);
// do something with 'temp'
}
Kindly clarify.
Thanks
V.Subramanian