Building a special order of elements for a given sequence

Pages: 12
If somebody interested:
Effective STL wrote:
Item 39. Make predicates pure functions.


abhishekm71 wrote:
I think the lambda function should return the "not" of what it is returning right now.
If you are talking about my second algorithm, it is fine. Note order of output iterators. If I would negate predicate, I should swap it again.
@MiiNiPaa

The problem is that predicate

[a](int& x)->bool{return (&x - a)%2;}

may not be applied for example to an std::list object.
@MiiNiPaa

Oops... didn't see the not that you had already placed.
Yes. That is the problem. My solution can be applied only to arrays, std::array, vectors and strings.
However for list you can probably use splice with custom iterators (which advance twice at the time).
I just don't like to use something which can lead to hard-to-find errors with different compilers.
I would like only to append that there is a solution that can be applied to input iterators of the original sequence when a new sequence must be build..:) Of course the target sequence shall heve a bidirectional iterator.
I would like only to append that there is a solution that can be applied to input iterators of the original sequence when a new sequence must be build.
Start iterating from the beginning. Copy first element to beginnging of target sequence and increment beginning iterator, next to the end and decrement end, next to beginning...
@MiiNiPaa
Start iterating from the beginning. Copy first element to beginnging of target sequence and increment beginning iterator, next to the end and decrement end, next to beginning...


You are right!:)

Start iterating from the beginning. Copy first element to beginnging of target sequence and increment beginning iterator, next to the end and decrement end, next to beginning...

Can we do this without using a for loop or one of the previously chosen in-built algorithms? Please do not post the solution yet, I wanna rack my brains a bit.
Topic archived. No new replies allowed.
Pages: 12