|
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-06 03:10:21
On 06/12/12 00:21, John Bytheway wrote:
> On 05/12/12 07:42, "Claas H. Köhler" wrote:
>> 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;
>
> Did you look at std::array's iterator? That should be just a raw
> pointer (I believe the standard guarantees that?), so will behave in a
> similar way to counting_iterator.
Hi John. You are correct. The following code returns false/0 (with gcc-4.7):
typedef std::array<double, 10>::iterator T;
T ita1, ita2;
std::cout << (ita1 == ita2) <<std::endl;
However, you can tweak it like this:
typedef std::array<double, 10>::iterator T;
T ita1=T(), ita2=T();
std::cout << (ita1 == ita2) <<std::endl;
and it returns true /1. It is mainly the lack of this functionality which is on my wish-list for the
counting_iterator.
Regards
Claas
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk