Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

G++ 4.3.4 stl iterator, problem?

2 views
Skip to first unread message

lk

unread,
Aug 23, 2009, 12:43:05 PM8/23/09
to
I've got the following piece of code. It compiled just fine, until I
added -D_GLIBCXX_DEBUG to my compile flags, then it gave a compiler
error. I was able to fix it in debug mode by changing
map<BIGNUM*,BIGNUM*>::iterator to map<BIGNUM*,BIGNUM*,bncmp>::iterator

I'm not quite sure whether the original code below is correct or not,
but it seems suspicious that compilation should succeed or fail
differently depending on whether the debug flags are in effect. I
thought the debug stuff was for catching runtime errors? If it is
wrong then shouldn't it also fail normally?

struct bncmp {
bool operator() (BIGNUM* lhs, BIGNUM* rhs) const
{return BN_cmp(lhs,rhs)<0;}
};
class DDB {
public:
map<BIGNUM*, BIGNUM*, bncmp> thedb;
...
}
map<BIGNUM*,BIGNUM*>::iterator it;
for (it = ddb.thedb.begin(); it != ddb.thedb.end(); ++it) {

---
error: no match for ‘operator!=’ in ‘it != std::__debug::map<_Key,
_Tp, _Compare, _Allocator>::end() [with _Key = BIGNUM*, _Tp = BIGNUM*,
_Compare = bncmp, _Allocator = std::allocator<std::pair<BIGNUM* const,
BIGNUM*> >]()’
make: *** [IARPA_DB/KO.o] Error 1

Paul Floyd

unread,
Aug 24, 2009, 3:08:44 PM8/24/09
to
On Sun, 23 Aug 2009 09:43:05 -0700 (PDT), lk <lpkr...@gmail.com> wrote:
> I've got the following piece of code. It compiled just fine, until I
> added -D_GLIBCXX_DEBUG to my compile flags, then it gave a compiler
> error. I was able to fix it in debug mode by changing
> map<BIGNUM*,BIGNUM*>::iterator to map<BIGNUM*,BIGNUM*,bncmp>::iterator
>
> I'm not quite sure whether the original code below is correct or not,
> but it seems suspicious that compilation should succeed or fail
> differently depending on whether the debug flags are in effect. I
> thought the debug stuff was for catching runtime errors? If it is
> wrong then shouldn't it also fail normally?
>
> struct bncmp {
> bool operator() (BIGNUM* lhs, BIGNUM* rhs) const
> {return BN_cmp(lhs,rhs)<0;}
> };
> class DDB {
> public:
> map<BIGNUM*, BIGNUM*, bncmp> thedb;

The type of 'thedb' here does not match ...

> ...
> }
> map<BIGNUM*,BIGNUM*>::iterator it;

... the type used for this iterator here.

I'd expect that to be

map<BIGNUM*, BIGNUM*, bncmp>::iterator it;

(and to make it easier to read, a typedef would help as well).

A bientot
Paul
--
Paul Floyd http://paulf.free.fr

0 new messages