[Cs3] Lab06 Part2 Question

Mikhail Nesterenko mikhail at cs.kent.edu
Fri Feb 21 10:58:15 EST 2020


It would be easier accomlished with accumulate(). It is a stretch for
an STL algorithms, but we are practicing algorithms so work with it. I
updated the assignment to reflect it.

Thanks,
--
Mikhail

> 
> I am a CS3 student with a question about the last function of Part 2. It
> states that:
> // use a binder to create a functor with configurable max weight
> // count_if() then remove_if()
> 
> for (auto it = crate.begin(); it != crate.end();)
>      if (it->weight < weightToJam)
> {
>      jamWeight += it->weight;
>      it = crate.erase(it);
> }
> else
> ++it;
> 
> I am trying to wrap my head around how count_if will help us with the
> function. Count_if returns the number of elements that satisfy the state
> conditions. Wouldn't for_each be a much easier way to go about adding to
> the jam weight to be printed later? I know it mentions using a binder and
> functor, but I still don't see how count_if helps with the task that needs
> to be done. Any tips or hints as to how this can be tackled would be highly
> appreciated.


More information about the cs3 mailing list