allocator_pointers.pass.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. #include "test_macros.h"
  13. //
  14. // template <class Alloc>
  15. // struct allocator_traits
  16. // {
  17. // typedef Alloc allocator_type;
  18. // typedef typename allocator_type::value_type
  19. // value_type;
  20. //
  21. // typedef Alloc::pointer | value_type* pointer;
  22. // typedef Alloc::const_pointer
  23. // | pointer_traits<pointer>::rebind<const value_type>
  24. // const_pointer;
  25. // typedef Alloc::void_pointer
  26. // | pointer_traits<pointer>::rebind<void>
  27. // void_pointer;
  28. // typedef Alloc::const_void_pointer
  29. // | pointer_traits<pointer>::rebind<const void>
  30. // const_void_pointer;
  31. template <typename Alloc>
  32. void test_pointer()
  33. {
  34. typename std::allocator_traits<Alloc>::pointer vp;
  35. typename std::allocator_traits<Alloc>::const_pointer cvp;
  36. ((void)vp); // Prevent unused warning
  37. ((void)cvp); // Prevent unused warning
  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 <= vp)>::value, "");
  44. static_assert(std::is_same<bool, decltype( vp == cvp)>::value, "");
  45. static_assert(std::is_same<bool, decltype(cvp == vp)>::value, "");
  46. static_assert(std::is_same<bool, decltype( vp != cvp)>::value, "");
  47. static_assert(std::is_same<bool, decltype(cvp != vp)>::value, "");
  48. static_assert(std::is_same<bool, decltype( vp > cvp)>::value, "");
  49. static_assert(std::is_same<bool, decltype(cvp > vp)>::value, "");
  50. static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, "");
  51. static_assert(std::is_same<bool, decltype(cvp >= vp)>::value, "");
  52. static_assert(std::is_same<bool, decltype( vp < cvp)>::value, "");
  53. static_assert(std::is_same<bool, decltype(cvp < vp)>::value, "");
  54. static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, "");
  55. static_assert(std::is_same<bool, decltype(cvp <= vp)>::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. static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, "");
  62. }
  63. template <typename Alloc>
  64. void test_void_pointer()
  65. {
  66. typename std::allocator_traits<Alloc>::void_pointer vp;
  67. typename std::allocator_traits<Alloc>::const_void_pointer cvp;
  68. ((void)vp); // Prevent unused warning
  69. ((void)cvp); // Prevent unused warning
  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 <= vp)>::value, "");
  76. static_assert(std::is_same<bool, decltype( vp == cvp)>::value, "");
  77. static_assert(std::is_same<bool, decltype(cvp == vp)>::value, "");
  78. static_assert(std::is_same<bool, decltype( vp != cvp)>::value, "");
  79. static_assert(std::is_same<bool, decltype(cvp != vp)>::value, "");
  80. static_assert(std::is_same<bool, decltype( vp > cvp)>::value, "");
  81. static_assert(std::is_same<bool, decltype(cvp > vp)>::value, "");
  82. static_assert(std::is_same<bool, decltype( vp >= cvp)>::value, "");
  83. static_assert(std::is_same<bool, decltype(cvp >= vp)>::value, "");
  84. static_assert(std::is_same<bool, decltype( vp < cvp)>::value, "");
  85. static_assert(std::is_same<bool, decltype(cvp < vp)>::value, "");
  86. static_assert(std::is_same<bool, decltype( vp <= cvp)>::value, "");
  87. static_assert(std::is_same<bool, decltype(cvp <= vp)>::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. static_assert(std::is_same<bool, decltype(cvp <= cvp)>::value, "");
  94. }
  95. struct Foo { int x; };
  96. int main(int, char**)
  97. {
  98. test_pointer<std::allocator<char>> ();
  99. test_pointer<std::allocator<int>> ();
  100. test_pointer<std::allocator<Foo>> ();
  101. test_void_pointer<std::allocator<char>> ();
  102. test_void_pointer<std::allocator<int>> ();
  103. test_void_pointer<std::allocator<Foo>> ();
  104. return 0;
  105. }