construct_default.pass.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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<bool>
  9. // vector();
  10. // vector(const Alloc&);
  11. // This tests a conforming extension
  12. // For vector<>, this was added to the standard by N4258,
  13. // but vector<bool> was not changed.
  14. #include <vector>
  15. #include <cassert>
  16. #include "test_macros.h"
  17. #include "test_allocator.h"
  18. #include "min_allocator.h"
  19. template <class C>
  20. void
  21. test0()
  22. {
  23. #if TEST_STD_VER > 14
  24. LIBCPP_STATIC_ASSERT((noexcept(C{})), "" );
  25. #elif TEST_STD_VER >= 11
  26. LIBCPP_STATIC_ASSERT((noexcept(C()) == noexcept(typename C::allocator_type())), "" );
  27. #endif
  28. C c;
  29. LIBCPP_ASSERT(c.__invariants());
  30. assert(c.empty());
  31. assert(c.get_allocator() == typename C::allocator_type());
  32. #if TEST_STD_VER >= 11
  33. C c1 = {};
  34. LIBCPP_ASSERT(c1.__invariants());
  35. assert(c1.empty());
  36. assert(c1.get_allocator() == typename C::allocator_type());
  37. #endif
  38. }
  39. template <class C>
  40. void
  41. test1(const typename C::allocator_type& a)
  42. {
  43. #if TEST_STD_VER > 14
  44. LIBCPP_STATIC_ASSERT((noexcept(C{typename C::allocator_type{}})), "" );
  45. #elif TEST_STD_VER >= 11
  46. LIBCPP_STATIC_ASSERT((noexcept(C(typename C::allocator_type())) == std::is_nothrow_copy_constructible<typename C::allocator_type>::value), "" );
  47. #endif
  48. C c(a);
  49. LIBCPP_ASSERT(c.__invariants());
  50. assert(c.empty());
  51. assert(c.get_allocator() == a);
  52. }
  53. int main(int, char**)
  54. {
  55. {
  56. test0<std::vector<bool> >();
  57. test1<std::vector<bool, test_allocator<bool> > >(test_allocator<bool>(3));
  58. }
  59. #if TEST_STD_VER >= 11
  60. {
  61. test0<std::vector<bool, min_allocator<bool>> >();
  62. test1<std::vector<bool, min_allocator<bool> > >(min_allocator<bool>());
  63. }
  64. {
  65. test0<std::vector<bool, explicit_allocator<bool>> >();
  66. test1<std::vector<bool, explicit_allocator<bool> > >(explicit_allocator<bool>());
  67. }
  68. #endif
  69. return 0;
  70. }