alloc.pass.cpp 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <string>
  10. // explicit basic_string(const Allocator& a = Allocator());
  11. #include <string>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. #include "test_allocator.h"
  15. #include "min_allocator.h"
  16. template <class S>
  17. void
  18. test()
  19. {
  20. {
  21. #if TEST_STD_VER > 14
  22. static_assert((noexcept(S{})), "" );
  23. #elif TEST_STD_VER >= 11
  24. static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" );
  25. #endif
  26. S s;
  27. assert(s.__invariants());
  28. assert(s.data());
  29. assert(s.size() == 0);
  30. assert(s.capacity() >= s.size());
  31. assert(s.get_allocator() == typename S::allocator_type());
  32. }
  33. {
  34. #if TEST_STD_VER > 14
  35. static_assert((noexcept(S{typename S::allocator_type{}})), "" );
  36. #elif TEST_STD_VER >= 11
  37. static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" );
  38. #endif
  39. S s(typename S::allocator_type(5));
  40. assert(s.__invariants());
  41. assert(s.data());
  42. assert(s.size() == 0);
  43. assert(s.capacity() >= s.size());
  44. assert(s.get_allocator() == typename S::allocator_type(5));
  45. }
  46. }
  47. #if TEST_STD_VER >= 11
  48. template <class S>
  49. void
  50. test2()
  51. {
  52. {
  53. #if TEST_STD_VER > 14
  54. static_assert((noexcept(S{})), "" );
  55. #elif TEST_STD_VER >= 11
  56. static_assert((noexcept(S()) == noexcept(typename S::allocator_type())), "" );
  57. #endif
  58. S s;
  59. assert(s.__invariants());
  60. assert(s.data());
  61. assert(s.size() == 0);
  62. assert(s.capacity() >= s.size());
  63. assert(s.get_allocator() == typename S::allocator_type());
  64. }
  65. {
  66. #if TEST_STD_VER > 14
  67. static_assert((noexcept(S{typename S::allocator_type{}})), "" );
  68. #elif TEST_STD_VER >= 11
  69. static_assert((noexcept(S(typename S::allocator_type())) == std::is_nothrow_copy_constructible<typename S::allocator_type>::value), "" );
  70. #endif
  71. S s(typename S::allocator_type{});
  72. assert(s.__invariants());
  73. assert(s.data());
  74. assert(s.size() == 0);
  75. assert(s.capacity() >= s.size());
  76. assert(s.get_allocator() == typename S::allocator_type());
  77. }
  78. }
  79. #endif
  80. int main()
  81. {
  82. test<std::basic_string<char, std::char_traits<char>, test_allocator<char> > >();
  83. #if TEST_STD_VER >= 11
  84. test2<std::basic_string<char, std::char_traits<char>, min_allocator<char> > >();
  85. #endif
  86. }