From 0bdb6b8a8a1cb82a89ae36343c8b0ce3cc3c9e52 Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Wed, 30 Jan 2019 14:01:25 -0800 Subject: [PATCH] workaround a compile error with some compilers --- libs/utils/include/utils/Allocator.h | 34 ++++++++++++++++------------ libs/utils/test/test_Allocators.cpp | 4 ++++ 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/libs/utils/include/utils/Allocator.h b/libs/utils/include/utils/Allocator.h index 68f1836f13..a16a376dcf 100644 --- a/libs/utils/include/utils/Allocator.h +++ b/libs/utils/include/utils/Allocator.h @@ -18,17 +18,18 @@ #define TNT_UTILS_ALLOCATOR_H -#include -#include -#include - -#include -#include - #include #include #include +#include +#include +#include + +#include +#include +#include + namespace utils { namespace pointermath { @@ -746,17 +747,22 @@ public: mArena.free(p, n * sizeof(TYPE)); } -private: - template - friend bool operator==(const STLAllocator& rhs, const STLAllocator& lhs) { - return &rhs.mArena == &lhs.mArena; + // these should be out-of-class friends, but this doesn't seem to work with some compilers + // which complain about multiple definition each time a STLAllocator<> is instantiated. + template + bool operator==(const STLAllocator& lhs) noexcept { + return std::addressof(mArena) == std::addressof(lhs.mArena); } - template - friend bool operator!=(const STLAllocator& rhs, const STLAllocator& lhs) { - return !operator==(rhs, lhs); + template + bool operator!=(const STLAllocator& lhs) noexcept { + return !operator==(lhs); } +private: + template + friend class STLAllocator; + ARENA& mArena; }; diff --git a/libs/utils/test/test_Allocators.cpp b/libs/utils/test/test_Allocators.cpp index af4fff3ff1..746e6740e1 100644 --- a/libs/utils/test/test_Allocators.cpp +++ b/libs/utils/test/test_Allocators.cpp @@ -302,7 +302,11 @@ TEST(AllocatorTest, STLAllocator) { using Arena = Arena; Arena arena("arena", 1204); + Arena arena2("arena2", 1204); STLAllocator allocator(arena); + STLAllocator allocator2(arena2); + EXPECT_TRUE(allocator != allocator2); + EXPECT_TRUE(allocator == allocator); { #if !defined(WIN32)