assign.pass.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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_view>
  9. // constexpr basic_string_view& operator=(const basic_string_view &) noexcept = default;
  10. #include <string_view>
  11. #include <cassert>
  12. #include "test_macros.h"
  13. template<typename T>
  14. #if TEST_STD_VER > 11
  15. constexpr
  16. #endif
  17. bool test (T sv0)
  18. {
  19. T sv1;
  20. sv1 = sv0;
  21. // We can't just say "sv0 == sv1" here because string_view::compare
  22. // isn't constexpr until C++17, and we want to support back to C++14
  23. return sv0.size() == sv1.size() && sv0.data() == sv1.data();
  24. }
  25. int main(int, char**) {
  26. assert( test<std::string_view> ( "1234"));
  27. #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
  28. assert( test<std::u8string_view> (u8"1234"));
  29. #endif
  30. #if TEST_STD_VER >= 11
  31. #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
  32. assert( test<std::u16string_view> ( u"1234"));
  33. assert( test<std::u32string_view> ( U"1234"));
  34. #endif
  35. #endif
  36. assert( test<std::wstring_view> ( L"1234"));
  37. #if TEST_STD_VER > 11
  38. static_assert( test<std::string_view> ({ "abc", 3}), "");
  39. #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
  40. static_assert( test<std::u8string_view> ({u8"abc", 3}), "");
  41. #endif
  42. #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
  43. static_assert( test<std::u16string_view> ({ u"abc", 3}), "");
  44. static_assert( test<std::u32string_view> ({ U"abc", 3}), "");
  45. #endif
  46. static_assert( test<std::wstring_view> ({ L"abc", 3}), "");
  47. #endif
  48. return 0;
  49. }