resize_size.pass.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. // vector<bool>
  10. // void resize(size_type sz);
  11. #include <vector>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. #include "min_allocator.h"
  15. int main(int, char**)
  16. {
  17. {
  18. std::vector<bool> v(100);
  19. v.resize(50);
  20. assert(v.size() == 50);
  21. assert(v.capacity() >= 100);
  22. v.resize(200);
  23. assert(v.size() == 200);
  24. assert(v.capacity() >= 200);
  25. v.reserve(400);
  26. v.resize(300); // check the case when resizing and we already have room
  27. assert(v.size() == 300);
  28. assert(v.capacity() >= 400);
  29. }
  30. #if TEST_STD_VER >= 11
  31. {
  32. std::vector<bool, min_allocator<bool>> v(100);
  33. v.resize(50);
  34. assert(v.size() == 50);
  35. assert(v.capacity() >= 100);
  36. v.resize(200);
  37. assert(v.size() == 200);
  38. assert(v.capacity() >= 200);
  39. v.reserve(400);
  40. v.resize(300); // check the case when resizing and we already have room
  41. assert(v.size() == 300);
  42. assert(v.capacity() >= 400);
  43. }
  44. #endif
  45. return 0;
  46. }