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
16 namespace test {
17
18 template <typename T>
19 struct 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)
allocatortest::allocator29 allocator() throw() {}
allocatortest::allocator30 allocator (const allocator& alloc) throw()
31 :alloc_(alloc.alloc_) {}
32 template <class U>
allocatortest::allocator33 allocator (const allocator<U>& alloc) throw()
34 :alloc_(alloc.alloc_) {}
35
36
constructtest::allocator37 void construct ( pointer p, const_reference val ) {
38 return alloc_.construct(p, val);
39 }
max_sizetest::allocator40 size_type max_size() const throw() { return alloc_.max_size(); }
41 #else // defined(MSGPACK_USE_CPP03)
allocatortest::allocator42 allocator() noexcept {}
allocatortest::allocator43 allocator (const allocator& alloc) noexcept
44 :alloc_(alloc.alloc_) {}
45 template <class U>
allocatortest::allocator46 allocator (const allocator<U>& alloc) noexcept
47 :alloc_(alloc.alloc_) {}
48 template <class U, class... Args>
constructtest::allocator49 void construct (U* p, Args&&... args) {
50 return alloc_.construct(p, std::forward<Args>(args)...);
51 }
max_sizetest::allocator52 size_type max_size() const noexcept { return alloc_.max_size(); }
53 #endif // defined(MSGPACK_USE_CPP03)
allocatetest::allocator54 pointer allocate (size_type n) {
55 return alloc_.allocate(n);
56 }
deallocatetest::allocator57 void deallocate (pointer p, size_type n) {
58 return alloc_.deallocate(p, n);
59 }
destroytest::allocator60 void destroy (pointer p) {
61 alloc_.destroy(p);
62 }
63
64 std::allocator<T> alloc_;
65 };
66
67 template <typename T>
operator ==(allocator<T> const & lhs,allocator<T> const & rhs)68 inline bool operator==(allocator<T> const& lhs, allocator<T> const& rhs) {
69 return lhs.alloc_ == rhs.alloc_;
70 }
71
72 template <typename T>
operator !=(allocator<T> const & lhs,allocator<T> const & rhs)73 inline 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