pointer.pass.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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<charT,traits,Allocator>& assign(const charT* s);
  11. #include <string>
  12. #include <stdexcept>
  13. #include <cassert>
  14. #include "test_macros.h"
  15. #include "min_allocator.h"
  16. template <class S>
  17. void
  18. test(S s, const typename S::value_type* str, S expected)
  19. {
  20. s.assign(str);
  21. LIBCPP_ASSERT(s.__invariants());
  22. assert(s == expected);
  23. }
  24. int main()
  25. {
  26. {
  27. typedef std::string S;
  28. test(S(), "", S());
  29. test(S(), "12345", S("12345"));
  30. test(S(), "12345678901234567890", S("12345678901234567890"));
  31. test(S("12345"), "", S());
  32. test(S("12345"), "12345", S("12345"));
  33. test(S("12345"), "1234567890", S("1234567890"));
  34. test(S("12345678901234567890"), "", S());
  35. test(S("12345678901234567890"), "12345", S("12345"));
  36. test(S("12345678901234567890"), "12345678901234567890",
  37. S("12345678901234567890"));
  38. }
  39. #if TEST_STD_VER >= 11
  40. {
  41. typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
  42. test(S(), "", S());
  43. test(S(), "12345", S("12345"));
  44. test(S(), "12345678901234567890", S("12345678901234567890"));
  45. test(S("12345"), "", S());
  46. test(S("12345"), "12345", S("12345"));
  47. test(S("12345"), "1234567890", S("1234567890"));
  48. test(S("12345678901234567890"), "", S());
  49. test(S("12345678901234567890"), "12345", S("12345"));
  50. test(S("12345678901234567890"), "12345678901234567890",
  51. S("12345678901234567890"));
  52. }
  53. #endif
  54. }