summaryrefslogtreecommitdiffstats
path: root/vespalib
diff options
context:
space:
mode:
Diffstat (limited to 'vespalib')
-rw-r--r--vespalib/src/vespa/vespalib/stllike/allocator.h12
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();
+}
+
}