/* * Copyright 2018, Oath Inc. Licensed under the terms of the * Apache License 2.0. See LICENSE file at the project root for terms. */ extern "C" { #include } #include #include template class palloc_allocator { public: typedef T value_type; typedef value_type* pointer; typedef const value_type* const_pointer; typedef value_type& reference; typedef const value_type& const_reference; typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; template struct rebind { typedef palloc_allocator other; }; palloc_allocator() {} palloc_allocator(const palloc_allocator&) {} template palloc_allocator(const palloc_allocator&) {} ~palloc_allocator() {} pointer address(reference x) const { return &x; } const_pointer address(const_reference x) const { return x; } pointer allocate(size_type n, const_pointer = 0) { void* p = palloc(n * sizeof(T)); if (!p) throw std::bad_alloc(); return static_cast(p); } void deallocate(pointer p, size_type) { pfree(p); } size_type max_size() const { return static_cast(-1) / sizeof(T); } void construct(pointer p, const value_type&& x) { new(p) value_type(std::forward(x)); } void destroy(pointer p) { p->~value_type(); } private: void operator=(const palloc_allocator&); }; template<> class palloc_allocator { public: typedef void value_type; typedef void* pointer; typedef const void* const_pointer; template struct rebind { typedef palloc_allocator other; }; }; template inline bool operator==(const palloc_allocator&, const palloc_allocator&) { return true; } template inline bool operator!=(const palloc_allocator&, const palloc_allocator&) { return false; }