In article <
13819f2e-c2cd-4afd...@googlegroups.com>
fl <
rxj...@gmail.com> writes:
>Hi,
>
>When I read the for loop below, I feel that it is so different from the
>normal integer as the index in a for loop.
>
>It is easy to understand the first two value, i.e.
>
> iter = items.begin();
> iter != items.end();
>
>
>My question is about the third, iter = items.upper_bound(*iter).
>
>In a general for loop, the third is the step size for the variable.
The third expression in the 'for' is most commonly an increment or
decrement, but that is not the only thing that it can be. It can
be anything that is useful.
>Here, I do not see
>
>items.upper_bound(*iter)
>
>is a step from the std::multiset documentation.
It has the effect of a step, but not a fixed size step.
Multiset can have multiple objects that compare as equal.
The effect of
iter = items.upper_bound(*iter)
is to move to the next item which is not equal to the current one.
It is skipping duplicates.
http://www.cplusplus.com/reference/set/multiset/upper_bound/
Returns an iterator pointing to the first element in the container
which is considered to go after val.
> for (const_iter iter = items.begin();
> iter != items.end();
> iter = items.upper_bound(*iter))
> {
> // we know there's at least one element with this key in the Basket
> print_total(cout, *(iter->h), items.count(*iter));
> // virtual call to net_price applies appropriate discounts, if any
> sum += (*iter)->net_price(items.count(*iter));
> }
--
Drew Lawson For it's not the fall, but landing,
That will alter your social standing