reserve.pass.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 reserve(size_type n);
  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;
  19. v.reserve(10);
  20. assert(v.capacity() >= 10);
  21. }
  22. {
  23. std::vector<bool> v(100);
  24. assert(v.capacity() >= 100);
  25. v.reserve(50);
  26. assert(v.size() == 100);
  27. assert(v.capacity() >= 100);
  28. v.reserve(150);
  29. assert(v.size() == 100);
  30. assert(v.capacity() >= 150);
  31. }
  32. #if TEST_STD_VER >= 11
  33. {
  34. std::vector<bool, min_allocator<bool>> v;
  35. v.reserve(10);
  36. assert(v.capacity() >= 10);
  37. }
  38. {
  39. std::vector<bool, min_allocator<bool>> v(100);
  40. assert(v.capacity() >= 100);
  41. v.reserve(50);
  42. assert(v.size() == 100);
  43. assert(v.capacity() >= 100);
  44. v.reserve(150);
  45. assert(v.size() == 100);
  46. assert(v.capacity() >= 150);
  47. }
  48. #endif
  49. return 0;
  50. }