size.pass.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. // <vector>
  9. // class vector
  10. // size_type size() const noexcept;
  11. #include <vector>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. #include "min_allocator.h"
  15. int main(int, char**)
  16. {
  17. {
  18. typedef std::vector<bool> C;
  19. C c;
  20. ASSERT_NOEXCEPT(c.size());
  21. assert(c.size() == 0);
  22. c.push_back(false);
  23. assert(c.size() == 1);
  24. c.push_back(true);
  25. assert(c.size() == 2);
  26. c.push_back(false);
  27. assert(c.size() == 3);
  28. c.erase(c.begin());
  29. assert(c.size() == 2);
  30. c.erase(c.begin());
  31. assert(c.size() == 1);
  32. c.erase(c.begin());
  33. assert(c.size() == 0);
  34. }
  35. #if TEST_STD_VER >= 11
  36. {
  37. typedef std::vector<bool, min_allocator<bool>> C;
  38. C c;
  39. ASSERT_NOEXCEPT(c.size());
  40. assert(c.size() == 0);
  41. c.push_back(false);
  42. assert(c.size() == 1);
  43. c.push_back(true);
  44. assert(c.size() == 2);
  45. c.push_back(false);
  46. assert(c.size() == 3);
  47. c.erase(c.begin());
  48. assert(c.size() == 2);
  49. c.erase(c.begin());
  50. assert(c.size() == 1);
  51. c.erase(c.begin());
  52. assert(c.size() == 0);
  53. }
  54. #endif
  55. return 0;
  56. }