construct_size.pass.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. // explicit vector(size_type n);
  11. #include <vector>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. #include "min_allocator.h"
  15. #include "test_allocator.h"
  16. template <class C>
  17. void
  18. test2(typename C::size_type n,
  19. typename C::allocator_type const& a = typename C::allocator_type ())
  20. {
  21. #if TEST_STD_VER >= 14
  22. C c(n, a);
  23. LIBCPP_ASSERT(c.__invariants());
  24. assert(c.size() == n);
  25. assert(c.get_allocator() == a);
  26. for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
  27. assert(*i == typename C::value_type());
  28. #else
  29. ((void)n);
  30. ((void)a);
  31. #endif
  32. }
  33. template <class C>
  34. void
  35. test1(typename C::size_type n)
  36. {
  37. C c(n);
  38. LIBCPP_ASSERT(c.__invariants());
  39. assert(c.size() == n);
  40. assert(c.get_allocator() == typename C::allocator_type());
  41. for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i)
  42. assert(*i == typename C::value_type());
  43. }
  44. template <class C>
  45. void
  46. test(typename C::size_type n)
  47. {
  48. test1<C> ( n );
  49. test2<C> ( n );
  50. }
  51. int main(int, char**)
  52. {
  53. test<std::vector<bool> >(50);
  54. #if TEST_STD_VER >= 11
  55. test<std::vector<bool, min_allocator<bool>> >(50);
  56. test2<std::vector<bool, test_allocator<bool>> >( 100, test_allocator<bool>(23));
  57. #endif
  58. return 0;
  59. }