diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-05-11 14:33:26 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2020-05-11 14:33:26 +0000 |
commit | 8a1a73fcb28a548b5d3266ab45f236b9033c39ba (patch) | |
tree | 71643887a10f4743c2422c8a560fa448f05c0a17 /vespalib/src | |
parent | efe84b0f2c3720e98a26a509fd70a9e2307e14db (diff) |
Implemtent equality operator.
Diffstat (limited to 'vespalib/src')
-rw-r--r-- | vespalib/src/vespa/vespalib/stllike/allocator.h | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/vespalib/src/vespa/vespalib/stllike/allocator.h b/vespalib/src/vespa/vespalib/stllike/allocator.h index 3aaa05a7d8f..3d8c2f03154 100644 --- a/vespalib/src/vespa/vespalib/stllike/allocator.h +++ b/vespalib/src/vespa/vespalib/stllike/allocator.h @@ -2,6 +2,8 @@ #pragma once +#include <vespa/vespalib/util/alloc.h> + namespace vespalib { /** @@ -13,16 +15,22 @@ template <typename T> class allocator_large { using PtrAndSize = alloc::MemoryAllocator::PtrAndSize; public: - allocator_large() : _allocator(alloc::MemoryAllocator::select_allocator()) {} + allocator_large() noexcept : _allocator(alloc::MemoryAllocator::select_allocator()) {} using value_type = T; - T * allocate(std::size_t n) { + constexpr T * allocate(std::size_t n) { return static_cast<T *>(_allocator->alloc(n*sizeof(T)).first); } void deallocate(T * p, std::size_t n) { _allocator->free(p, n*sizeof(T)); } + alloc::MemoryAllocator * allocator() const { return _allocator; } private: const alloc::MemoryAllocator * _allocator; }; +template< class T1, class T2 > +constexpr bool operator==( const allocator_large<T1>& lhs, const allocator_large<T2>& rhs ) noexcept { + return lhs.allocator() == rhs.allocator(); +} + } |