Suppose we have a function foo
that does something
to all the elements between *firsta
and *lastb
:
foo(Rando
The answer might be a bit picky, but you could call foo(firsta,i-1)
and foo(i+1,lastb)
or something similar to have the desired effect.
The best way to do this would be to use an iterator that knows how to skip that element. A more generalized idea though, is an iterator that simply iterates over two separate ranges under the hood. I don't know of anything in boost that does this, so, here's one I just whipped up: http://coliru.stacked-crooked.com/a/588afa2a353942fc
Unfortunately, the code to detect which element to skip adds a teeny tiny amount of overhead to each and every iterator increment, so the overhead is technically proportional to lasta-firsta
. Realistically, using this wrapper around a vector::iterator
or a char*
should bring it roughly to the same performance level as std::deque::iterator
, so it's not like this should be a major slowdown.