Home > Archive > VC STL > March 2005 > Debugging stuff in xutility for VC 2005 Beta
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Debugging stuff in xutility for VC 2005 Beta
|
|
| Markus Ewald 2005-03-15, 4:02 pm |
| I am just trying to compile Loki
(http://sourceforge.net/projects/loki-lib/) using the Community
Technology Preview of VisualC++ 2005. Needless to say that it's using
some advanced C++ stuff and even the previous Visual Studio required
workarounds, but I dared to enable the reference implementation anyway,
to test whether it would work using the new compiler.
Well, it actually worked, with the exception of debug builds, where an
error pops up in xutility, line 207:
if (!_Pred(_Left, _Right))
return (false);
else if (_Pred(_Right, _Left)) // <------- HERE
_DEBUG_ERROR2("invalid operator<", _Where);
return (true);
Isn't this code kinda... wrong ?
I mean, it uses the comparator _Pred to compare _Left to _Right and
then, vice versa, _Right to _Left, but there's no guarantee that _Left
and _Right are of the same type or that _Pred could compare those two
types in reverse order.
The comparator specified by Loki to std::lower_bound() has exactly this
problem, _Left uses the type const FixedAllocator & and _Right uses the
type std::size_t
struct CompareFixedAllocatorSize
: std::binary_function<const FixedAllocator &, std::size_t,
bool>
{
bool operator()(const FixedAllocator &x, std::size_t
numBytes) const
{
return x.BlockSize() < numBytes;
}
};
Is it a bug or have I maybe overlooked something ?
-Markus-
| |
| Pete Becker 2005-03-15, 4:02 pm |
| Markus Ewald wrote:
>
> Isn't this code kinda... wrong ?
> I mean, it uses the comparator _Pred to compare _Left to _Right and
> then, vice versa, _Right to _Left, but there's no guarantee that _Left
> and _Right are of the same type or that _Pred could compare those two
> types in reverse order.
The Compare object for an associative container must impose a strict
weak ordering on the elements. In part that means that if pred(a,b) is
true, then pred(b,a) must be false.
>
> The comparator specified by Loki to std::lower_bound() has exactly this
> problem, _Left uses the type const FixedAllocator & and _Right uses the
> type std::size_t
>
> struct CompareFixedAllocatorSize
> : std::binary_function<const FixedAllocator &, std::size_t,
> bool>
> {
> bool operator()(const FixedAllocator &x, std::size_t
> numBytes) const
> {
> return x.BlockSize() < numBytes;
> }
> };
>
> Is it a bug or have I maybe overlooked something ?
>
That doesn't meet the requirements for a comparison object in the
standard library, and that's what the debugging code is checking for.
--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
| |
| Pete Becker 2005-03-15, 4:02 pm |
| Pete Becker wrote:
> Markus Ewald wrote:
>
>
>
> The Compare object for an associative container must impose a strict
> weak ordering on the elements. In part that means that if pred(a,b) is
> true, then pred(b,a) must be false.
Sorry, I jumped on lower_bound for containers. For the standalone
lower_bound algorithm the requirement seems to be less strict: the
elements of the sequence have to be "partitioned with respect to" the
comparision object.
--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
|
|
|
|
|