diff --git a/CMakeLists.txt b/CMakeLists.txt index 636c6295..0566a735 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,6 +200,7 @@ SET (REACTPHYSICS3D_SOURCES "src/containers/List.h" "src/containers/Map.h" "src/containers/Set.h" + "src/containers/Pair.h" ) # Create the library diff --git a/src/collision/CollisionDetection.cpp b/src/collision/CollisionDetection.cpp index c337e10a..32269336 100644 --- a/src/collision/CollisionDetection.cpp +++ b/src/collision/CollisionDetection.cpp @@ -104,7 +104,7 @@ void CollisionDetection::computeMiddlePhase() { PROFILE("CollisionDetection::computeMiddlePhase()", mProfiler); // For each possible collision pair of bodies - Map::Iterator it; + Map, OverlappingPair*>::Iterator it; for (it = mOverlappingPairs.begin(); it != mOverlappingPairs.end(); ) { OverlappingPair* pair = it->second; @@ -317,7 +317,7 @@ void CollisionDetection::broadPhaseNotifyOverlappingPair(ProxyShape* shape1, Pro (shape1->getCollisionCategoryBits() & shape2->getCollideWithMaskBits()) == 0) return; // Compute the overlapping pair ID - OverlappingPair::OverlappingPairId pairID = OverlappingPair::computeID(shape1, shape2); + Pair pairID = OverlappingPair::computeID(shape1, shape2); // Check if the overlapping pair already exists if (mOverlappingPairs.containsKey(pairID)) return; @@ -328,7 +328,7 @@ void CollisionDetection::broadPhaseNotifyOverlappingPair(ProxyShape* shape1, Pro mMemoryManager.getSingleFrameAllocator()); assert(newPair != nullptr); - mOverlappingPairs.add(make_pair(pairID, newPair)); + mOverlappingPairs.add(Pair, OverlappingPair*>(pairID, newPair)); // Wake up the two bodies shape1->getBody()->setIsSleeping(false); @@ -341,7 +341,7 @@ void CollisionDetection::removeProxyCollisionShape(ProxyShape* proxyShape) { assert(proxyShape->mBroadPhaseID != -1); // Remove all the overlapping pairs involving this proxy shape - Map::Iterator it; + Map, OverlappingPair*>::Iterator it; for (it = mOverlappingPairs.begin(); it != mOverlappingPairs.end(); ) { if (it->second->getShape1()->mBroadPhaseID == proxyShape->mBroadPhaseID|| it->second->getShape2()->mBroadPhaseID == proxyShape->mBroadPhaseID) { @@ -367,7 +367,7 @@ void CollisionDetection::addAllContactManifoldsToBodies() { PROFILE("CollisionDetection::addAllContactManifoldsToBodies()", mProfiler); // For each overlapping pairs in contact during the narrow-phase - Map::Iterator it; + Map, OverlappingPair*>::Iterator it; for (it = mOverlappingPairs.begin(); it != mOverlappingPairs.end(); ++it) { // Add all the contact manifolds of the pair into the list of contact manifolds @@ -418,7 +418,7 @@ void CollisionDetection::processAllPotentialContacts() { PROFILE("CollisionDetection::processAllPotentialContacts()", mProfiler); // For each overlapping pairs in contact during the narrow-phase - Map::Iterator it; + Map, OverlappingPair*>::Iterator it; for (it = mOverlappingPairs.begin(); it != mOverlappingPairs.end(); ++it) { // Process the potential contacts of the overlapping pair @@ -457,7 +457,7 @@ void CollisionDetection::reportAllContacts() { PROFILE("CollisionDetection::reportAllContacts()", mProfiler); // For each overlapping pairs in contact during the narrow-phase - Map::Iterator it; + Map, OverlappingPair*>::Iterator it; for (it = mOverlappingPairs.begin(); it != mOverlappingPairs.end(); ++it) { // If there is a user callback @@ -912,7 +912,7 @@ void CollisionDetection::testCollision(CollisionCallback* callback) { computeBroadPhase(); // For each possible collision pair of bodies - Map::Iterator it; + Map, OverlappingPair*>::Iterator it; for (it = mOverlappingPairs.begin(); it != mOverlappingPairs.end(); ++it) { OverlappingPair* originalPair = it->second; diff --git a/src/collision/CollisionDetection.h b/src/collision/CollisionDetection.h index f06d52f0..4dc45634 100644 --- a/src/collision/CollisionDetection.h +++ b/src/collision/CollisionDetection.h @@ -38,23 +38,6 @@ #include "containers/Set.h" #include -// Hash function for struct VerticesPair -// TOOD : REMOVE THIS -namespace std { - - template <> struct hash { - - size_t operator()(const reactphysics3d::bodyindexpair& pair) const { - - std::size_t seed = 0; - reactphysics3d::hash_combine(seed, pair.first); - reactphysics3d::hash_combine(seed, pair.second); - - return seed; - } - }; -} - /// ReactPhysics3D namespace namespace reactphysics3d { @@ -96,7 +79,7 @@ class CollisionDetection { NarrowPhaseInfo* mNarrowPhaseInfoList; /// Broad-phase overlapping pairs - Map mOverlappingPairs; + Map, OverlappingPair*> mOverlappingPairs; /// Broad-phase algorithm BroadPhaseAlgorithm mBroadPhaseAlgorithm; diff --git a/src/collision/HalfEdgeStructure.cpp b/src/collision/HalfEdgeStructure.cpp index b9106d78..b5fd6140 100644 --- a/src/collision/HalfEdgeStructure.cpp +++ b/src/collision/HalfEdgeStructure.cpp @@ -26,26 +26,11 @@ // Libraries #include "HalfEdgeStructure.h" #include "containers/Map.h" +#include "containers/Pair.h" #include "containers/containers_common.h" using namespace reactphysics3d; -// Hash function for struct VerticesPair -namespace std { - - template <> struct hash { - - size_t operator()(const HalfEdgeStructure::VerticesPair& pair) const { - - std::size_t seed = 0; - hash_combine(seed, pair.vertex1); - hash_combine(seed, pair.vertex2); - - return seed; - } - }; -} - // Initialize the structure (when all vertices and faces have been added) void HalfEdgeStructure::init() { @@ -63,7 +48,7 @@ void HalfEdgeStructure::init() { Face face = mFaces[f]; - VerticesPair firstEdgeKey; + VerticesPair firstEdgeKey(0, 0); // For each vertex of the face for (uint v=0; v < face.faceVertices.size(); v++) { @@ -80,19 +65,19 @@ void HalfEdgeStructure::init() { firstEdgeKey = pairV1V2; } else if (v >= 1) { - nextEdges.add(std::make_pair(currentFaceEdges[currentFaceEdges.size() - 1], pairV1V2)); + nextEdges.add(Pair(currentFaceEdges[currentFaceEdges.size() - 1], pairV1V2)); } if (v == (face.faceVertices.size() - 1)) { - nextEdges.add(std::make_pair(pairV1V2, firstEdgeKey)); + nextEdges.add(Pair(pairV1V2, firstEdgeKey)); } - edges.add(std::make_pair(pairV1V2, edge)); + edges.add(Pair(pairV1V2, edge)); const VerticesPair pairV2V1(v2Index, v1Index); - mapEdgeToStartVertex.add(std::make_pair(pairV1V2, v1Index), true); - mapEdgeToStartVertex.add(std::make_pair(pairV2V1, v2Index), true); + mapEdgeToStartVertex.add(Pair(pairV1V2, v1Index), true); + mapEdgeToStartVertex.add(Pair(pairV2V1, v2Index), true); - mapFaceIndexToEdgeKey.add(std::make_pair(f, pairV1V2), true); + mapFaceIndexToEdgeKey.add(Pair(f, pairV1V2), true); auto itEdge = edges.find(pairV2V1); if (itEdge != edges.end()) { @@ -102,14 +87,14 @@ void HalfEdgeStructure::init() { itEdge->second.twinEdgeIndex = edgeIndex + 1; edge.twinEdgeIndex = edgeIndex; - mapEdgeIndexToKey.add(std::make_pair(edgeIndex, pairV2V1)); - mapEdgeIndexToKey.add(std::make_pair(edgeIndex + 1, pairV1V2)); + mapEdgeIndexToKey.add(Pair(edgeIndex, pairV2V1)); + mapEdgeIndexToKey.add(Pair(edgeIndex + 1, pairV1V2)); mVertices[v1Index].edgeIndex = edgeIndex + 1; mVertices[v2Index].edgeIndex = edgeIndex; - mapEdgeToIndex.add(std::make_pair(pairV1V2, edgeIndex + 1)); - mapEdgeToIndex.add(std::make_pair(pairV2V1, edgeIndex)); + mapEdgeToIndex.add(Pair(pairV1V2, edgeIndex + 1)); + mapEdgeToIndex.add(Pair(pairV2V1, edgeIndex)); mEdges.add(itEdge->second); mEdges.add(edge); diff --git a/src/collision/HalfEdgeStructure.h b/src/collision/HalfEdgeStructure.h index b5668182..3f351533 100644 --- a/src/collision/HalfEdgeStructure.h +++ b/src/collision/HalfEdgeStructure.h @@ -41,23 +41,7 @@ class HalfEdgeStructure { public: - /// Pair of vertices - struct VerticesPair { - - uint vertex1; - uint vertex2; - - /// Constructor - VerticesPair() = default; - - /// Constructor - VerticesPair(uint v1, uint v2) : vertex1(v1), vertex2(v2) {} - - /// Equality operator - bool operator==(const VerticesPair& pair) const { - return vertex1 == pair.vertex1 && vertex2 == pair.vertex2; - } - }; + using VerticesPair = Pair; /// Edge struct Edge { diff --git a/src/configuration.h b/src/configuration.h index 96391e76..3cde138c 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -32,6 +32,7 @@ #include #include #include "decimal.h" +#include "containers/Pair.h" // Windows platform #if defined(WIN32) ||defined(_WIN32) || defined(_WIN64) ||defined(__WIN32__) || defined(__WINDOWS__) @@ -52,7 +53,7 @@ using uchar = unsigned char; using ushort = unsigned short; using luint = long unsigned int; using bodyindex = luint; -using bodyindexpair = std::pair; +using bodyindexpair = Pair; using int8 = std::int8_t; using uint8 = std::uint8_t; diff --git a/src/containers/Map.h b/src/containers/Map.h index 89594370..cea9342c 100644 --- a/src/containers/Map.h +++ b/src/containers/Map.h @@ -29,6 +29,7 @@ // Libraries #include "memory/MemoryAllocator.h" #include "mathematics/mathematics_functions.h" +#include "containers/Pair.h" #include #include #include @@ -52,7 +53,7 @@ class Map { size_t hashCode; // Hash code of the entry int next; // Index of the next entry - std::pair* keyValue; // Pointer to the pair with key and value + Pair* keyValue; // Pointer to the pair with key and value /// Constructor Entry() { @@ -296,10 +297,10 @@ class Map { public: // Iterator traits - using value_type = std::pair; + using value_type = Pair; using difference_type = std::ptrdiff_t; - using pointer = std::pair*; - using reference = std::pair&; + using pointer = Pair*; + using reference = Pair&; using iterator_category = std::forward_iterator_tag; /// Constructor @@ -396,8 +397,8 @@ class Map { new (&mEntries[i]) Entry(map.mEntries[i].hashCode, map.mEntries[i].next); if (map.mEntries[i].keyValue != nullptr) { - mEntries[i].keyValue = static_cast*>(mAllocator.allocate(sizeof(std::pair))); - new (mEntries[i].keyValue) std::pair(*(map.mEntries[i].keyValue)); + mEntries[i].keyValue = static_cast*>(mAllocator.allocate(sizeof(Pair))); + new (mEntries[i].keyValue) Pair(*(map.mEntries[i].keyValue)); } } } @@ -429,7 +430,7 @@ class Map { } /// Add an element into the map - void add(const std::pair& keyValue, bool insertIfAlreadyPresent = false) { + void add(const Pair& keyValue, bool insertIfAlreadyPresent = false) { if (mCapacity == 0) { initialize(0); @@ -450,10 +451,10 @@ class Map { if (insertIfAlreadyPresent) { // Destruct the previous key/value - mEntries[i].keyValue->~pair(); + mEntries[i].keyValue->~Pair(); // Copy construct the new key/value - new (mEntries[i].keyValue) std::pair(keyValue); + new (mEntries[i].keyValue) Pair(keyValue); return; } @@ -491,9 +492,9 @@ class Map { assert(mEntries[entryIndex].keyValue == nullptr); mEntries[entryIndex].hashCode = hashCode; mEntries[entryIndex].next = mBuckets[bucket]; - mEntries[entryIndex].keyValue = static_cast*>(mAllocator.allocate(sizeof(std::pair))); + mEntries[entryIndex].keyValue = static_cast*>(mAllocator.allocate(sizeof(Pair))); assert(mEntries[entryIndex].keyValue != nullptr); - new (mEntries[entryIndex].keyValue) std::pair(keyValue); + new (mEntries[entryIndex].keyValue) Pair(keyValue); mBuckets[bucket] = entryIndex; } @@ -529,8 +530,8 @@ class Map { // Release memory for the key/value pair if any if (mEntries[i].keyValue != nullptr) { - mEntries[i].keyValue->~pair(); - mAllocator.release(mEntries[i].keyValue, sizeof(std::pair)); + mEntries[i].keyValue->~Pair(); + mAllocator.release(mEntries[i].keyValue, sizeof(Pair)); mEntries[i].keyValue = nullptr; } mEntries[i].hashCode = -1; @@ -567,8 +568,8 @@ class Map { mBuckets[i] = -1; mEntries[i].next = -1; if (mEntries[i].keyValue != nullptr) { - mEntries[i].keyValue->~pair(); - mAllocator.release(mEntries[i].keyValue, sizeof(std::pair)); + mEntries[i].keyValue->~Pair(); + mAllocator.release(mEntries[i].keyValue, sizeof(Pair)); mEntries[i].keyValue = nullptr; } } @@ -714,8 +715,8 @@ class Map { new (&mEntries[i]) Entry(map.mEntries[i].hashCode, map.mEntries[i].next); if (map.mEntries[i].keyValue != nullptr) { - mEntries[i].keyValue = static_cast*>(mAllocator.allocate(sizeof(std::pair))); - new (mEntries[i].keyValue) std::pair(*(map.mEntries[i].keyValue)); + mEntries[i].keyValue = static_cast*>(mAllocator.allocate(sizeof(Pair))); + new (mEntries[i].keyValue) Pair(*(map.mEntries[i].keyValue)); } } diff --git a/src/containers/Pair.h b/src/containers/Pair.h index e6a9ff8f..8c34b4ac 100644 --- a/src/containers/Pair.h +++ b/src/containers/Pair.h @@ -29,6 +29,7 @@ // Libraries #include "configuration.h" #include "memory/MemoryAllocator.h" +#include "containers/containers_common.h" #include #include @@ -54,211 +55,52 @@ class Pair { // -------------------- Methods -------------------- // /// Constructor - List(MemoryAllocator& allocator, size_t capacity = 0) - : mBuffer(nullptr), mSize(0), mCapacity(0), mAllocator(allocator) { + Pair(const T1& item1, const T2& item2) : first(item1), second(item2) { - if (capacity > 0) { - - // Allocate memory - reserve(capacity); - } } /// Copy constructor - List(const List& list) : mBuffer(nullptr), mSize(0), mCapacity(0), mAllocator(list.mAllocator) { + Pair(const Pair& pair) : first(pair.first), second(pair.second) { - // All all the elements of the list to the current one - addRange(list); } /// Destructor - ~List() { - - // If elements have been allocated - if (mCapacity > 0) { - - // Clear the list - clear(); - - // Release the memory allocated on the heap - mAllocator.release(mBuffer, mCapacity * sizeof(T)); - } - } - - /// Allocate memory for a given number of elements - void reserve(size_t capacity) { - - if (capacity <= mCapacity) return; - - // Allocate memory for the new array - void* newMemory = mAllocator.allocate(capacity * sizeof(T)); - - if (mBuffer != nullptr) { - - // Copy the elements to the new allocated memory location - std::memcpy(newMemory, mBuffer, mSize * sizeof(T)); - - // Release the previously allocated memory - mAllocator.release(mBuffer, mCapacity * sizeof(T)); - } - - mBuffer = newMemory; - assert(mBuffer != nullptr); - - mCapacity = capacity; - } - - /// Add an element into the list - void add(const T& element) { - - // If we need to allocate more memory - if (mSize == mCapacity) { - reserve(mCapacity == 0 ? 1 : mCapacity * 2); - } - - // Use the copy-constructor to construct the element - new (static_cast(mBuffer) + mSize * sizeof(T)) T(element); - - mSize++; - } - - /// Try to find a given item of the list and return an iterator - /// pointing to that element if it exists in the list. Otherwise, - /// this method returns the end() iterator - Iterator find(const T& element) { - - for (uint i=0; i(mBuffer)[i])) { - return Iterator(mBuffer, i, mSize); - } - } - - return end(); - } - - /// Remove an element from the list - void remove(const Iterator& it) { - assert(it.mBuffer == mBuffer); - remove(it.mCurrentIndex); - } - - /// Remove an element from the list at a given index - void remove(uint index) { - - assert(index >= 0 && index < mSize); - - // Call the destructor - (static_cast(mBuffer)[index]).~T(); - - mSize--; - - if (index != mSize) { - - // Move the elements to fill in the empty slot - char* dest = static_cast(mBuffer) + index * sizeof(T); - char* src = dest + sizeof(T); - std::memcpy(static_cast(dest), static_cast(src), (mSize - index) * sizeof(T)); - } - } - - /// Append another list at the end of the current one - void addRange(const List& list) { - - // If we need to allocate more memory - if (mSize + list.size() > mCapacity) { - - // Allocate memory - reserve(mSize + list.size()); - } - - // Add the elements of the list to the current one - for(uint i=0; i(mBuffer) + mSize * sizeof(T)) T(list[i]); - mSize++; - } - } - - /// Clear the list - void clear() { - - // Call the destructor of each element - for (uint i=0; i < mSize; i++) { - (static_cast(mBuffer)[i]).~T(); - } - - mSize = 0; - } - - /// Return the number of elements in the list - size_t size() const { - return mSize; - } - - /// Return the capacity of the list - size_t capacity() const { - return mCapacity; - } - - /// Overloaded index operator - T& operator[](const uint index) { - assert(index >= 0 && index < mSize); - return (static_cast(mBuffer)[index]); - } - - /// Overloaded const index operator - const T& operator[](const uint index) const { - assert(index >= 0 && index < mSize); - return (static_cast(mBuffer)[index]); - } + ~Pair() = default; /// Overloaded equality operator - bool operator==(const List& list) const { - - if (mSize != list.mSize) return false; - - T* items = static_cast(mBuffer); - for (int i=0; i < mSize; i++) { - if (items[i] != list[i]) { - return false; - } - } - - return true; + bool operator==(const Pair& pair) const { + return first == pair.first && second == pair.second; } /// Overloaded not equal operator - bool operator!=(const List& list) const { - - return !((*this) == list); + bool operator!=(const Pair& pair) const { + return !((*this) == pair); } /// Overloaded assignment operator - List& operator=(const List& list) { - - if (this != &list) { - - // Clear all the elements - clear(); - - // Add all the elements of the list to the current one - addRange(list); - } - - return *this; - } - - /// Return a begin iterator - Iterator begin() const { - return Iterator(mBuffer, 0, mSize); - } - - /// Return a end iterator - Iterator end() const { - return Iterator(mBuffer, mSize, mSize); + Pair& operator=(const Pair& pair) { + first = pair.first; + second = pair.second; } }; } +// Hash function for struct VerticesPair +namespace std { + + template struct hash> { + + size_t operator()(const reactphysics3d::Pair& pair) const { + + std::size_t seed = 0; + reactphysics3d::hash_combine(seed, pair.first); + reactphysics3d::hash_combine(seed, pair.second); + + return seed; + } + }; +} + + #endif diff --git a/src/engine/DynamicsWorld.cpp b/src/engine/DynamicsWorld.cpp index 77938f9e..ee270519 100644 --- a/src/engine/DynamicsWorld.cpp +++ b/src/engine/DynamicsWorld.cpp @@ -828,7 +828,7 @@ List DynamicsWorld::getContactsList() { List contactManifolds(mMemoryManager.getPoolAllocator()); // For each currently overlapping pair of bodies - Map::Iterator it; + Map, OverlappingPair*>::Iterator it; for (it = mCollisionDetection.mOverlappingPairs.begin(); it != mCollisionDetection.mOverlappingPairs.end(); ++it) { diff --git a/src/engine/OverlappingPair.cpp b/src/engine/OverlappingPair.cpp index 3dbdc2f4..16e077e9 100644 --- a/src/engine/OverlappingPair.cpp +++ b/src/engine/OverlappingPair.cpp @@ -164,7 +164,7 @@ void OverlappingPair::addLastFrameInfoIfNecessary(uint shapeId1, uint shapeId2) LastFrameCollisionInfo(); // Add it into the map of collision infos - mLastFrameCollisionInfos.add(std::make_pair(shapeIdPair, collisionInfo)); + mLastFrameCollisionInfos.add(Pair(shapeIdPair, collisionInfo)); } else { diff --git a/src/engine/OverlappingPair.h b/src/engine/OverlappingPair.h index c7653942..e93658d0 100644 --- a/src/engine/OverlappingPair.h +++ b/src/engine/OverlappingPair.h @@ -31,6 +31,7 @@ #include "collision/ProxyShape.h" #include "collision/shapes/CollisionShape.h" #include "containers/Map.h" +#include "containers/Pair.h" #include "containers/containers_common.h" /// ReactPhysics3D namespace @@ -95,35 +96,8 @@ class OverlappingPair { public: - /// Pair of shape ids - struct ShapeIdPair { - - uint shapeIdBody1; - uint shapeIdBody2; - - /// Constructor - ShapeIdPair(uint id1, uint id2) : shapeIdBody1(id1), shapeIdBody2(id2) {} - - /// Equality operator - bool operator==(const ShapeIdPair& pair) const { - return shapeIdBody1 == pair.shapeIdBody1 && shapeIdBody2 == pair.shapeIdBody2; - } - }; - - /// Pair of broad-phase ids - struct OverlappingPairId { - - uint body1Id; - uint body2Id; - - /// Constructor - OverlappingPairId(uint id1, uint id2) : body1Id(id1), body2Id(id2) {} - - /// Equality operator - bool operator==(const OverlappingPairId& pair) const { - return body1Id == pair.body1Id && body2Id == pair.body2Id; - } - }; + using OverlappingPairId = Pair; + using ShapeIdPair = Pair; private: @@ -277,7 +251,7 @@ inline OverlappingPair::OverlappingPairId OverlappingPair::computeID(ProxyShape* OverlappingPairId pairID = shape1->mBroadPhaseID < shape2->mBroadPhaseID ? OverlappingPairId(shape1->mBroadPhaseID, shape2->mBroadPhaseID) : OverlappingPairId(shape2->mBroadPhaseID, shape1->mBroadPhaseID); - assert(pairID.body1Id != pairID.body2Id); + assert(pairID.first != pairID.second); return pairID; } @@ -287,8 +261,8 @@ inline bodyindexpair OverlappingPair::computeBodiesIndexPair(CollisionBody* body // Construct the pair of body index bodyindexpair indexPair = body1->getID() < body2->getID() ? - std::make_pair(body1->getID(), body2->getID()) : - std::make_pair(body2->getID(), body1->getID()); + bodyindexpair(body1->getID(), body2->getID()) : + bodyindexpair(body2->getID(), body1->getID()); assert(indexPair.first != indexPair.second); return indexPair; } @@ -331,33 +305,5 @@ inline LastFrameCollisionInfo* OverlappingPair::getLastFrameCollisionInfo(uint s } -// Hash function for struct ShapeIdPair -namespace std { - - template <> struct hash { - - size_t operator()(const reactphysics3d::OverlappingPair::ShapeIdPair& pair) const { - - std::size_t seed = 0; - reactphysics3d::hash_combine(seed, pair.shapeIdBody1); - reactphysics3d::hash_combine(seed, pair.shapeIdBody2); - - return seed; - } - }; - - template <> struct hash { - - size_t operator()(const reactphysics3d::OverlappingPair::OverlappingPairId& pair) const { - - std::size_t seed = 0; - reactphysics3d::hash_combine(seed, pair.body1Id); - reactphysics3d::hash_combine(seed, pair.body2Id); - - return seed; - } - }; -} - #endif diff --git a/test/tests/containers/TestMap.h b/test/tests/containers/TestMap.h index 2e9b3133..d75de2aa 100644 --- a/test/tests/containers/TestMap.h +++ b/test/tests/containers/TestMap.h @@ -111,9 +111,9 @@ class TestMap : public Test { test(map3.size() == map1.size()); Map map4(mAllocator); - map4.add(std::make_pair(1, 10)); - map4.add(std::make_pair(2, 20)); - map4.add(std::make_pair(3, 30)); + map4.add(Pair(1, 10)); + map4.add(Pair(2, 20)); + map4.add(Pair(3, 30)); test(map4.capacity() >= 3); test(map4.size() == 3); @@ -130,8 +130,8 @@ class TestMap : public Test { Map map1(mAllocator); map1.reserve(15); test(map1.capacity() >= 15); - map1.add(std::make_pair(1, "test1")); - map1.add(std::make_pair(2, "test2")); + map1.add(Pair(1, "test1")); + map1.add(Pair(2, "test2")); test(map1.capacity() >= 15); map1.reserve(10); @@ -148,9 +148,9 @@ class TestMap : public Test { // ----- Test add() ----- // Map map1(mAllocator); - map1.add(std::make_pair(1, 10)); - map1.add(std::make_pair(8, 80)); - map1.add(std::make_pair(13, 130)); + map1.add(Pair(1, 10)); + map1.add(Pair(8, 80)); + map1.add(Pair(13, 130)); test(map1[1] == 10); test(map1[8] == 80); test(map1[13] == 130); @@ -158,7 +158,7 @@ class TestMap : public Test { Map map2(mAllocator, 15); for (int i = 0; i < 1000000; i++) { - map2.add(std::make_pair(i, i * 100)); + map2.add(Pair(i, i * 100)); } bool isValid = true; for (int i = 0; i < 1000000; i++) { @@ -167,14 +167,14 @@ class TestMap : public Test { test(isValid); map1.remove(1); - map1.add(std::make_pair(1, 10)); + map1.add(Pair(1, 10)); test(map1.size() == 3); test(map1[1] == 10); - map1.add(std::make_pair(56, 34)); + map1.add(Pair(56, 34)); test(map1[56] == 34); test(map1.size() == 4); - map1.add(std::make_pair(56, 13), true); + map1.add(Pair(56, 13), true); test(map1[56] == 13); test(map1.size() == 4); @@ -212,13 +212,13 @@ class TestMap : public Test { Map map3(mAllocator); for (int i=0; i < 1000000; i++) { - map3.add(std::make_pair(i, i * 10)); + map3.add(Pair(i, i * 10)); map3.remove(i); } - map3.add(std::make_pair(1, 10)); - map3.add(std::make_pair(2, 20)); - map3.add(std::make_pair(3, 30)); + map3.add(Pair(1, 10)); + map3.add(Pair(2, 20)); + map3.add(Pair(3, 30)); test(map3.size() == 3); it = map3.begin(); map3.remove(it++); @@ -226,8 +226,8 @@ class TestMap : public Test { test(map3.size() == 2); test(it->second == 20); - map3.add(std::make_pair(56, 32)); - map3.add(std::make_pair(23, 89)); + map3.add(Pair(56, 32)); + map3.add(Pair(23, 89)); for (it = map3.begin(); it != map3.end();) { it = map3.remove(it); } @@ -236,12 +236,12 @@ class TestMap : public Test { // ----- Test clear() ----- // Map map4(mAllocator); - map4.add(std::make_pair(2, 20)); - map4.add(std::make_pair(4, 40)); - map4.add(std::make_pair(6, 60)); + map4.add(Pair(2, 20)); + map4.add(Pair(4, 40)); + map4.add(Pair(6, 60)); map4.clear(); test(map4.size() == 0); - map4.add(std::make_pair(2, 20)); + map4.add(Pair(2, 20)); test(map4.size() == 1); test(map4[2] == 20); map4.clear(); @@ -255,7 +255,7 @@ class TestMap : public Test { Map map6(mAllocator); for (int i=0; i < 1000; i++) { - map6.add(std::make_pair(TestKey(i), i)); + map6.add(Pair(TestKey(i), i)); } bool isTestValid = true; for (int i=0; i < 1000; i++) { @@ -278,9 +278,9 @@ class TestMap : public Test { test(!map1.containsKey(4)); test(!map1.containsKey(6)); - map1.add(std::make_pair(2, 20)); - map1.add(std::make_pair(4, 40)); - map1.add(std::make_pair(6, 60)); + map1.add(Pair(2, 20)); + map1.add(Pair(4, 40)); + map1.add(Pair(6, 60)); test(map1.containsKey(2)); test(map1.containsKey(4)); @@ -299,9 +299,9 @@ class TestMap : public Test { void testIndexing() { Map map1(mAllocator); - map1.add(std::make_pair(2, 20)); - map1.add(std::make_pair(4, 40)); - map1.add(std::make_pair(6, 60)); + map1.add(Pair(2, 20)); + map1.add(Pair(4, 40)); + map1.add(Pair(6, 60)); test(map1[2] == 20); test(map1[4] == 40); test(map1[6] == 60); @@ -318,9 +318,9 @@ class TestMap : public Test { void testFind() { Map map1(mAllocator); - map1.add(std::make_pair(2, 20)); - map1.add(std::make_pair(4, 40)); - map1.add(std::make_pair(6, 60)); + map1.add(Pair(2, 20)); + map1.add(Pair(4, 40)); + map1.add(Pair(6, 60)); test(map1.find(2)->second == 20); test(map1.find(4)->second == 40); test(map1.find(6)->second == 60); @@ -342,13 +342,13 @@ class TestMap : public Test { test(map1 == map2); - map1.add(std::make_pair("a", 1)); - map1.add(std::make_pair("b", 2)); - map1.add(std::make_pair("c", 3)); + map1.add(Pair("a", 1)); + map1.add(Pair("b", 2)); + map1.add(Pair("c", 3)); - map2.add(std::make_pair("a", 1)); - map2.add(std::make_pair("b", 2)); - map2.add(std::make_pair("c", 4)); + map2.add(Pair("a", 1)); + map2.add(Pair("b", 2)); + map2.add(Pair("c", 4)); test(map1 == map1); test(map2 == map2); @@ -359,7 +359,7 @@ class TestMap : public Test { test(map1 == map2); Map map3(mAllocator); - map3.add(std::make_pair("a", 1)); + map3.add(Pair("a", 1)); test(map1 != map3); test(map2 != map3); @@ -368,9 +368,9 @@ class TestMap : public Test { void testAssignment() { Map map1(mAllocator); - map1.add(std::make_pair(1, 3)); - map1.add(std::make_pair(2, 6)); - map1.add(std::make_pair(10, 30)); + map1.add(Pair(1, 3)); + map1.add(Pair(2, 6)); + map1.add(Pair(10, 30)); Map map2(mAllocator); map2 = map1; @@ -394,8 +394,8 @@ class TestMap : public Test { test(map3 == map4); Map map5(mAllocator); - map5.add(std::make_pair(7, 8)); - map5.add(std::make_pair(19, 70)); + map5.add(Pair(7, 8)); + map5.add(Pair(19, 70)); map1 = map5; test(map5.size() == map1.size()); test(map5 == map1); @@ -409,10 +409,10 @@ class TestMap : public Test { test(map1.begin() == map1.end()); - map1.add(std::make_pair(1, 5)); - map1.add(std::make_pair(2, 6)); - map1.add(std::make_pair(3, 8)); - map1.add(std::make_pair(4, -1)); + map1.add(Pair(1, 5)); + map1.add(Pair(2, 6)); + map1.add(Pair(3, 8)); + map1.add(Pair(4, -1)); Map::Iterator itBegin = map1.begin(); Map::Iterator it = map1.begin();