allocator_pointers.pass.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // UNSUPPORTED: c++98, c++03
  9. #include <memory>
  10. #include <cassert>
  11. // #include <memory>
  12. //
  13. // template <class Alloc>
  14. // struct allocator_traits
  15. // {
  16. // typedef Alloc allocator_type;
  17. // typedef typename allocator_type::value_type
  18. // value_type;
  19. //
  20. // typedef Alloc::pointer | value_type* pointer;
  21. // typedef Alloc::const_pointer
  22. // | pointer_traits<pointer>::rebind<const value_type>
  23. // const_pointer;
  24. // typedef Alloc::void_pointer
  25. // | pointer_traits<pointer>::rebind<void>
  26. // void_pointer;
  27. // typedef Alloc::const_void_pointer
  28. // | pointer_traits<pointer>::rebind<const void>
  29. // const_void_pointer;
  30. template <typename Alloc>
  31. void test_pointer()
  32. {
  33. typename std::allocator_traits<Alloc>::pointer vp;
  34. typename std::allocator_traits<Alloc>::const_pointer cvp;
  35. ((void)vp); // Prevent unused warning
  36. ((void)cvp); // Prevent unused warning
  37. static_assert(std::is_same<bool, decltype( vp == vp)>::value, "");
  38. static_assert(std::is_same<bool, decltype( vp != vp)>::value, "");
  39. static_assert(std::is_same<bool, decltype( vp > vp)>::value, "");
  40. static_assert(std::is_same<bool, decltype( vp >= vp)>::value, "");
  41. static_assert(std::is_same<bool, decltype( vp < vp)>::value, "");
  42. static_assert(std::is_same<bool, decltype( vp <= vp)>::value, "");
  43. static_assert(std::is_same<bool, decltype( vp == cvp)>::value, "");
  44. static_assert(std::is_same<bool, decltype(cvp == vp)>::value, "");
  45. static_assert(std::is_same<bool, decltype( vp != cvp)>::value, "");
  46. static_assert(std::is_same<bool, decltype(cvp != vp)>::value, "");
  47. static_assert(std::is_same<bool, decltype( vp > cvp)>::value, "");
  48. static_assert(std::is_same<bool, decltype(cvp > vp)>::value, "");
  49. static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, "");
  50. static_assert(std::is_same<bool, decltype(cvp >= vp)>::value, "");
  51. static_assert(std::is_same<bool, decltype( vp < cvp)>::value, "");
  52. static_assert(std::is_same<bool, decltype(cvp < vp)>::value, "");
  53. static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, "");
  54. static_assert(std::is_same<bool, decltype(cvp <= vp)>::value, "");
  55. static_assert(std::is_same<bool, decltype(cvp == cvp)>::value, "");
  56. static_assert(std::is_same<bool, decltype(cvp != cvp)>::value, "");
  57. static_assert(std::is_same<bool, decltype(cvp > cvp)>::value, "");
  58. static_assert(std::is_same<bool, decltype(cvp >= cvp)>::value, "");
  59. static_assert(std::is_same<bool, decltype(cvp < cvp)>::value, "");
  60. static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, "");
  61. }
  62. template <typename Alloc>
  63. void test_void_pointer()
  64. {
  65. typename std::allocator_traits<Alloc>::void_pointer vp;
  66. typename std::allocator_traits<Alloc>::const_void_pointer cvp;
  67. ((void)vp); // Prevent unused warning
  68. ((void)cvp); // Prevent unused warning
  69. static_assert(std::is_same<bool, decltype( vp == vp)>::value, "");
  70. static_assert(std::is_same<bool, decltype( vp != vp)>::value, "");
  71. static_assert(std::is_same<bool, decltype( vp > vp)>::value, "");
  72. static_assert(std::is_same<bool, decltype( vp >= vp)>::value, "");
  73. static_assert(std::is_same<bool, decltype( vp < vp)>::value, "");
  74. static_assert(std::is_same<bool, decltype( vp <= vp)>::value, "");
  75. static_assert(std::is_same<bool, decltype( vp == cvp)>::value, "");
  76. static_assert(std::is_same<bool, decltype(cvp == vp)>::value, "");
  77. static_assert(std::is_same<bool, decltype( vp != cvp)>::value, "");
  78. static_assert(std::is_same<bool, decltype(cvp != vp)>::value, "");
  79. static_assert(std::is_same<bool, decltype( vp > cvp)>::value, "");
  80. static_assert(std::is_same<bool, decltype(cvp > vp)>::value, "");
  81. static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, "");
  82. static_assert(std::is_same<bool, decltype(cvp >= vp)>::value, "");
  83. static_assert(std::is_same<bool, decltype( vp < cvp)>::value, "");
  84. static_assert(std::is_same<bool, decltype(cvp < vp)>::value, "");
  85. static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, "");
  86. static_assert(std::is_same<bool, decltype(cvp <= vp)>::value, "");
  87. static_assert(std::is_same<bool, decltype(cvp == cvp)>::value, "");
  88. static_assert(std::is_same<bool, decltype(cvp != cvp)>::value, "");
  89. static_assert(std::is_same<bool, decltype(cvp > cvp)>::value, "");
  90. static_assert(std::is_same<bool, decltype(cvp >= cvp)>::value, "");
  91. static_assert(std::is_same<bool, decltype(cvp < cvp)>::value, "");
  92. static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, "");
  93. }
  94. struct Foo { int x; };
  95. int main(int, char**)
  96. {
  97. test_pointer<std::allocator<char>> ();
  98. test_pointer<std::allocator<int>> ();
  99. test_pointer<std::allocator<Foo>> ();
  100. test_void_pointer<std::allocator<char>> ();
  101. test_void_pointer<std::allocator<int>> ();
  102. test_void_pointer<std::allocator<Foo>> ();
  103. return 0;
  104. }