Article View: be.comp.programming
Article #1708Re: Rare C++ fout (std::map)
From: Arnold Hendriks
Date: Wed, 15 Dec 2004 09:48
Date: Wed, 15 Dec 2004 09:48
21 lines
1815 bytes
1815 bytes
"Aquila" <braempje@netscape.net> wrote in message
news:ZJKdne45LpA4YyLcRVnyvA@scarlet.biz...
> bool PossibleState::operator<(const PossibleState & state) const{
> return turning != state.turning;
Deze is verdacht. De operator zegt het volgende:
false < false == false
false < true == true
true < false == true
true < true == false
Met andere woorden: false < true, en true < false. Daarmee voldoet je
compare niet aan de eis dat het een 'strict weak ordering' is: als a < b, en
b < c, dan moet a < c ook waar zijn. Bij bijvoorbeeld a=false,b=true,c=false
gaat dit mis.
Als je je operator bijvoorbeeld als turning < state.turning definieert, dan
zou de compare wel moeten werken. Nu de compare niet strict is, deugt de
sortering niet en dat kan best verklaren waarom de find() functie niet goed
werkt.
Technical Details
Message-ID:
<cpp19f$ipt$1@netlx020.civ.utwente.nl>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!surfnet.nl!news.utwente.nl!not-for-mailReferences:
<ZJKdne45LpA4YyLcRVnyvA@scarlet.biz>Show Full Headers
Complete Article Headers
X-Google-Thread: fcea4,f50cab2f57916087 X-Google-Attributes: gidfcea4,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!surfnet.nl!news.utwente.nl!not-for-mail From: "Arnold Hendriks" <a.hendriks@b-lex.nl> Newsgroups: be.comp.programming Subject: Re: Rare C++ fout (std::map) Date: Wed, 15 Dec 2004 10:48:31 +0100 Organization: University of Twente, Enschede, The Netherlands Lines: 23 Message-ID: <cpp19f$ipt$1@netlx020.civ.utwente.nl> References: <ZJKdne45LpA4YyLcRVnyvA@scarlet.biz> NNTP-Posting-Host: jeltsin.student.utwente.nl X-Trace: netlx020.civ.utwente.nl 1103104111 19261 130.89.163.169 (15 Dec 2004 09:48:31 GMT) X-Complaints-To: abuse@utwente.nl NNTP-Posting-Date: Wed, 15 Dec 2004 09:48:31 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-RFC2646: Format=Flowed; Original