• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 Copyright 2018 Glen Joseph Fernandes
3 (glenjofe@gmail.com)
4 
5 Distributed under the Boost Software License, Version 1.0.
6 (http://www.boost.org/LICENSE_1_0.txt)
7 */
8 #include <boost/align/aligned_allocator_adaptor.hpp>
9 
10 template<class T>
11 class A {
12 public:
13     typedef T value_type;
14     typedef T* pointer;
15     typedef std::size_t size_type;
16     typedef std::ptrdiff_t difference_type;
17 
18     template<class U>
19     struct rebind {
20         typedef A<U> other;
21     };
22 
A(int state)23     A(int state)
24         : state_(state) { }
25 
26     template<class U>
A(const A<U> & other)27     A(const A<U>& other)
28         : state_(other.state()) { }
29 
allocate(std::size_t size,const void * =0)30     T* allocate(std::size_t size, const void* = 0) {
31         return static_cast<T*>(::operator new(sizeof(T) * size));
32     }
33 
deallocate(T * ptr,std::size_t)34     void deallocate(T* ptr, std::size_t) {
35         ::operator delete(ptr);
36     }
37 
state() const38     int state() const {
39         return state_;
40     }
41 
42 private:
43     int state_;
44 };
45 
46 template<class T, class U>
47 inline bool
operator ==(const A<T> & a,const A<U> & b)48 operator==(const A<T>& a, const A<U>& b)
49 {
50     return a.state() == b.state();
51 }
52 
53 template<class T, class U>
54 inline bool
operator !=(const A<T> & a,const A<U> & b)55 operator!=(const A<T>& a, const A<U>& b)
56 {
57     return !(a == b);
58 }
59 
60 struct S;
61 struct V { };
62 
value_test()63 void value_test()
64 {
65     boost::alignment::aligned_allocator_adaptor<A<S> > a(A<S>(1));
66     (void)a;
67 }
68 
rebind_test()69 void rebind_test()
70 {
71     boost::alignment::aligned_allocator_adaptor<A<V> > a(A<V>(1));
72     boost::alignment::aligned_allocator_adaptor<A<V> >::rebind<S>::other r(a);
73     (void)r;
74 }
75