Re:In C++, is empty() faster than comparing the size with zero?
by gumby on Thursday October 28, 2021 @10:28PM
(#29034517)
> As far as I know, these are not optimizations a compiler is capable of.
If <some code> has side effects I don’t want the compiler to make that optimization as the order might be important and there is no way to tell.
(If there are no side effects the compiler can optimize — by removing the loop!).
You can tell the compiler you don’t care about order by replacing the for loop with an algorithm like for_each which is allowed to do this kind of thing, and can take a parallel policy too.
(Though is there an implementation that uses execution policies?)
If <some code> has side effects I don’t want the compiler to make that optimization as the order might be important and there is no way to tell.
(If there are no side effects the compiler can optimize — by removing the loop!).
You can tell the compiler you don’t care about order by replacing the for loop with an algorithm like for_each which is allowed to do this kind of thing, and can take a parallel policy too.
(Though is there an implementation that uses execution policies?)