C++ Logo

SG12

Advanced search

Subject: Fwd: Predicate evaluation order for std::remove_if
From: Eugene Kozlov (nekoeuge_at_[hidden])
Date: 2020-10-16 11:33:50


Hello.

std::remove_if doesn't have any specified evaluation order of predicate,
unlike e.g. std::for_each that is explicitly required to evaluate predicate
from first to last element in range.

Is there any reason why it is so?
Do you maybe know any implementation that has a different implementation?
I cannot imagine any sane implementation benefitting from unspecified order
of evaluation.
It would be nice to have the order explicitly specified in standard.

In my current task I need a function that sequentially iterates a vector
and removes some elements based on prior elements values. And apparently I
cannot use std::remove_if because I cannot be sure that predicate for the
first element is called first, and so on.

How dangerous it would be to rely on this implementation detail and use
std::remove_if for this task?

Thanks.



SG12 list run by sg12-owner@lists.isocpp.org