This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Iterator "convertable to" problem


Hello,

I recently posted on comp.std.c++ about a problem I believe exists in quite a few of the algorithms in libstdc++. It might end up not being as serious as I think, but it worries me.

The problem stems from the various places where the standard says that the return types of various operators on iterators have to be "convertable to T", "convertable to bool", etc.

The problem is that the standard doesn't appear to put any other constraints on these types other than they are convertable to the type we would expect them to be.

Consider for example two input iterators a and b which iterate over a range of integers. Then the standard states that *a and *b are both "convertable to int".

However, it does not state that *a==*b has to produce the same result as static_cast<int>(*a) == static_cast<int>(*b).

Also a==b has to be "convertable to bool". However, there is nothing to stop us defining an operator && on what the type of "a==b" is, so statements like (a==b) && ... wouldn't operate as expected (and also break short-cutting).

Does this seem to be a correct reading of the standard? Do we need nasty static_casts all over the place?

Chris


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]