workaround a compile error with some compilers

This commit is contained in:
Mathias Agopian
2019-01-30 14:01:25 -08:00
committed by Mathias Agopian
parent 447f44539f
commit 0bdb6b8a8a
2 changed files with 24 additions and 14 deletions

View File

@@ -18,17 +18,18 @@
#define TNT_UTILS_ALLOCATOR_H
#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
#include <atomic>
#include <mutex>
#include <utils/compiler.h>
#include <utils/memalign.h>
#include <utils/Mutex.h>
#include <atomic>
#include <mutex>
#include <type_traits>
#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
namespace utils {
namespace pointermath {
@@ -746,17 +747,22 @@ public:
mArena.free(p, n * sizeof(TYPE));
}
private:
template <typename T, typename U, typename A>
friend bool operator==(const STLAllocator<T, A>& rhs, const STLAllocator<U, A>& 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 <typename U, typename A>
bool operator==(const STLAllocator<U, A>& lhs) noexcept {
return std::addressof(mArena) == std::addressof(lhs.mArena);
}
template <typename T, typename U, typename A>
friend bool operator!=(const STLAllocator<T, A>& rhs, const STLAllocator<U, A>& lhs) {
return !operator==(rhs, lhs);
template <typename U, typename A>
bool operator!=(const STLAllocator<U, A>& lhs) noexcept {
return !operator==(lhs);
}
private:
template<typename U, typename A>
friend class STLAllocator;
ARENA& mArena;
};

View File

@@ -302,7 +302,11 @@ TEST(AllocatorTest, STLAllocator) {
using Arena = Arena<LinearAllocator, LockingPolicy::NoLock, Tracking>;
Arena arena("arena", 1204);
Arena arena2("arena2", 1204);
STLAllocator<int, Arena> allocator(arena);
STLAllocator<int, Arena> allocator2(arena2);
EXPECT_TRUE(allocator != allocator2);
EXPECT_TRUE(allocator == allocator);
{
#if !defined(WIN32)