|
Boost Users : |
Subject: Re: [Boost-users] [foreach] BOOST_FOREACH question...
From: Dmitry Vinogradov (sraider_at_[hidden])
Date: 2010-01-07 20:14:38
> Does the BOOST_FOREACH macro work for empty sequences or must a size check
> be done explicitly?
>
>
> list<int> mylist;
>
> if (!mylist.empty()) //<--- necessary?
> {
> foreach(int& i, mylist)
> {
> // take action
> }
> }
>
>
> The reason I ask is that neither begin() nor end() return valid iterators
> for empty sequences, but it is my understanding that BOOST_FOREACH needs
> iterators to work properly.
To be short: it's not necessary.
BTW, begin() and end() for an empty list are valid. You can't
dereference them, but they are valid. So one can use them for
comparison. And BOOST_FOREACH does.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net