copy.pass.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. // <string>
  9. // basic_string(const basic_string<charT,traits,Allocator>& str);
  10. #include <string>
  11. #include <cassert>
  12. #include "test_macros.h"
  13. #include "test_allocator.h"
  14. #include "min_allocator.h"
  15. template <class S>
  16. void
  17. test(S s1)
  18. {
  19. S s2 = s1;
  20. LIBCPP_ASSERT(s2.__invariants());
  21. assert(s2 == s1);
  22. assert(s2.capacity() >= s2.size());
  23. assert(s2.get_allocator() == s1.get_allocator());
  24. }
  25. int main(int, char**)
  26. {
  27. {
  28. typedef test_allocator<char> A;
  29. typedef std::basic_string<char, std::char_traits<char>, A> S;
  30. test(S(A(3)));
  31. test(S("1", A(5)));
  32. test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)));
  33. }
  34. #if TEST_STD_VER >= 11
  35. {
  36. typedef min_allocator<char> A;
  37. typedef std::basic_string<char, std::char_traits<char>, A> S;
  38. test(S(A{}));
  39. test(S("1", A()));
  40. test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()));
  41. }
  42. #endif
  43. return 0;
  44. }