|
Boost : |
Subject: Re: [boost] [iterator] UB when implicitly using default constructed counting_iterator<unsigned>
From: Claas H. Köhler (claas.koehler_at_[hidden])
Date: 2012-12-05 07:42:14
On 05/12/12 09:48, Olaf van der Spek wrote:
> On Wed, Dec 5, 2012 at 8:53 AM, "Claas H. Köhler" <claas.koehler_at_[hidden]> wrote:
>> To be very precise, it was actually the assumption that counting_iterator behaves similar to
>> all other iterators in the standard library, which guarantee a defined behaviour when default
>> constructed. (By guaranteed I mean as far as I have seen so far. Not sure what the standard
>> says about them)
>
> AFAIK you can't expect default constructed iterators to be usable (in general).
> For example, this will assert in VC11:
> typedef std::map<int, int> C;
> C::iterator a;
> C::iterator b;
> a == b;
>
Hi Olaf!
Thanks for the info. That's very interesting. So it seems to be implementation dependent. Using
gcc-4.7 the following code outputs true/ 1 for all 5 comparisons.
std::vector<double>::iterator itv1, itv2;
std::string::iterator itstr1, itstr2;
std::set<double>::iterator its1, its2;
std::map<double, double>::iterator itm1, itm2;
std::list<double>::iterator itl1, itl2;
std::cout << (its1 == its2) <<std::endl
<< (itv1 == itv2) <<std::endl
<< (itstr1 == itstr2) <<std::endl
<< (itm1 == itm2) <<std::endl
<< (itl1 == itl2) <<std::endl;
Claas
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk