Fix various issues related to stability when using highly compliant compilers such as Comeau 4.3.0.1, VC7.1 and GCC 3.2

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@108 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
rani_sharoni 2003-02-27 20:09:08 +00:00
parent 80e63b12a3
commit b53b3265e4
56 changed files with 441 additions and 203 deletions

View file

@ -18,6 +18,7 @@
#include "SmallObj.h"
#include <cassert>
#include <algorithm>
#include <functional>
using namespace Loki;
@ -365,6 +366,20 @@ SmallObjAllocator::SmallObjAllocator(
{
}
namespace { // anoymous
// See LWG DR #270
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;
}
};
} // anoymous namespace
////////////////////////////////////////////////////////////////////////////////
// SmallObjAllocator::Allocate
// Allocates 'numBytes' memory
@ -379,7 +394,8 @@ void* SmallObjAllocator::Allocate(std::size_t numBytes)
{
return pLastAlloc_->Allocate();
}
Pool::iterator i = std::lower_bound(pool_.begin(), pool_.end(), numBytes);
Pool::iterator i = std::lower_bound(pool_.begin(), pool_.end(), numBytes,
CompareFixedAllocatorSize());
if (i == pool_.end() || i->BlockSize() != numBytes)
{
i = pool_.insert(i, FixedAllocator(numBytes));
@ -404,7 +420,8 @@ void SmallObjAllocator::Deallocate(void* p, std::size_t numBytes)
pLastDealloc_->Deallocate(p);
return;
}
Pool::iterator i = std::lower_bound(pool_.begin(), pool_.end(), numBytes);
Pool::iterator i = std::lower_bound(pool_.begin(), pool_.end(), numBytes,
CompareFixedAllocatorSize());
assert(i != pool_.end());
assert(i->BlockSize() == numBytes);
pLastDealloc_ = &*i;