copy.pass.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. // basic_string(const basic_string<charT,traits,Allocator>& str);
  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(S s1)
  19. {
  20. S s2 = s1;
  21. LIBCPP_ASSERT(s2.__invariants());
  22. assert(s2 == s1);
  23. assert(s2.capacity() >= s2.size());
  24. assert(s2.get_allocator() == s1.get_allocator());
  25. }
  26. int main()
  27. {
  28. {
  29. typedef test_allocator<char> A;
  30. typedef std::basic_string<char, std::char_traits<char>, A> S;
  31. test(S(A(3)));
  32. test(S("1", A(5)));
  33. test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A(7)));
  34. }
  35. #if TEST_STD_VER >= 11
  36. {
  37. typedef min_allocator<char> A;
  38. typedef std::basic_string<char, std::char_traits<char>, A> S;
  39. test(S(A{}));
  40. test(S("1", A()));
  41. test(S("1234567890123456789012345678901234567890123456789012345678901234567890", A()));
  42. }
  43. #endif
  44. }