Topic: Quizz: STL set bug.


Author: martelli@cadlab.it (Alex Martelli)
Date: 1996/06/27
Raw View
Willy Wood <ofile@aquanet.co.il> writes:
 ...
>The following is a declaration of a set of pointers to class X.
> Who can tell me why it contains an almost impossible
>to detect bug ?

>#include <set.h>

>class X
>{
>};

>typedef set<X*,less<X*> > setX;

You are allowed to compare two pointers (in either C, or C++) only
if they point within the same array.  Your setX will work if, and
only if, it is only every instantiated with members which all point
into the same array, since using "less<X*>" implies using operator<()
to compare pointers to X.


Alex
--
DISCLAIMER: these are TOTALLY personal opinions and viewpoints, NOT connected
in any way with my employer, nor any other organization or individual!
Email: martelli@cadlab.it                            Phone: +39 (51) 597313
CAD.LAB s.p.a., v. Ronzani 7/29, Casalecchio, Italia   Fax: +39 (51) 597120


[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: Willy Wood <ofile@aquanet.co.il>
Date: 1996/05/28
Raw View
The following is a declaration of a set of pointers to class X.
 Who can tell me why it contains an almost impossible
to detect bug ?

#include <set.h>

class X
{
};

typedef set<X*,less<X*> > setX;


--
Willy Wood, Israel.



[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]