aligned_allocator_adaptor_incomplete_test.cpp 1.4 KB

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