1// 2// MessagePack for C++ static resolution routine 3// 4// Copyright (C) 2015 KONDO Takatoshi 5// 6// Distributed under the Boost Software License, Version 1.0. 7// (See accompanying file LICENSE_1_0.txt or copy at 8// http://www.boost.org/LICENSE_1_0.txt) 9// 10 11#ifndef TEST_ALLOCATOR_HPP 12#define TEST_ALLOCATOR_HPP 13 14#include <memory> 15 16namespace test { 17 18template <typename T> 19struct allocator { 20 typedef typename std::allocator<T>::value_type value_type; 21 typedef typename std::allocator<T>::pointer pointer; 22 typedef typename std::allocator<T>::reference reference; 23 typedef typename std::allocator<T>::const_pointer const_pointer; 24 typedef typename std::allocator<T>::const_reference const_reference; 25 typedef typename std::allocator<T>::size_type size_type; 26 typedef typename std::allocator<T>::difference_type difference_type; 27 template <class U> struct rebind { typedef allocator<U> other; }; 28#if defined(MSGPACK_USE_CPP03) 29 allocator() throw() {} 30 allocator (const allocator& alloc) throw() 31 :alloc_(alloc.alloc_) {} 32 template <class U> 33 allocator (const allocator<U>& alloc) throw() 34 :alloc_(alloc.alloc_) {} 35 36 37 void construct ( pointer p, const_reference val ) { 38 return alloc_.construct(p, val); 39 } 40 size_type max_size() const throw() { return alloc_.max_size(); } 41#else // defined(MSGPACK_USE_CPP03) 42 allocator() noexcept {} 43 allocator (const allocator& alloc) noexcept 44 :alloc_(alloc.alloc_) {} 45 template <class U> 46 allocator (const allocator<U>& alloc) noexcept 47 :alloc_(alloc.alloc_) {} 48 template <class U, class... Args> 49 void construct (U* p, Args&&... args) { 50 return alloc_.construct(p, std::forward<Args>(args)...); 51 } 52 size_type max_size() const noexcept { return alloc_.max_size(); } 53#endif // defined(MSGPACK_USE_CPP03) 54 pointer allocate (size_type n) { 55 return alloc_.allocate(n); 56 } 57 void deallocate (pointer p, size_type n) { 58 return alloc_.deallocate(p, n); 59 } 60 void destroy (pointer p) { 61 alloc_.destroy(p); 62 } 63 64 std::allocator<T> alloc_; 65}; 66 67template <typename T> 68inline bool operator==(allocator<T> const& lhs, allocator<T> const& rhs) { 69 return lhs.alloc_ == rhs.alloc_; 70} 71 72template <typename T> 73inline bool operator!=(allocator<T> const& lhs, allocator<T> const& rhs) { 74 return lhs.alloc_ != rhs.alloc_; 75} 76 77} // namespace test 78 79#endif // TEST_ALLOCATOR_HPP 80