from_string.pass.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. // template<class Allocator>
  10. // basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept
  11. #include <string_view>
  12. #include <string>
  13. #include <cassert>
  14. #include "test_macros.h"
  15. struct dummy_char_traits : public std::char_traits<char> {};
  16. template<typename CharT, typename Traits>
  17. void test ( const std::basic_string<CharT, Traits> &str ) {
  18. typedef std::basic_string_view<CharT, Traits> SV;
  19. ASSERT_NOEXCEPT(SV(str));
  20. SV sv1 ( str );
  21. assert ( sv1.size() == str.size());
  22. assert ( sv1.data() == str.data());
  23. }
  24. int main(int, char**) {
  25. test ( std::string("QBCDE") );
  26. test ( std::string("") );
  27. test ( std::string() );
  28. test ( std::wstring(L"QBCDE") );
  29. test ( std::wstring(L"") );
  30. test ( std::wstring() );
  31. #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L
  32. test ( std::u8string{u8"QBCDE"} );
  33. test ( std::u8string{u8""} );
  34. test ( std::u8string{} );
  35. #endif
  36. #if TEST_STD_VER >= 11
  37. test ( std::u16string{u"QBCDE"} );
  38. test ( std::u16string{u""} );
  39. test ( std::u16string{} );
  40. test ( std::u32string{U"QBCDE"} );
  41. test ( std::u32string{U""} );
  42. test ( std::u32string{} );
  43. #endif
  44. test ( std::basic_string<char, dummy_char_traits>("QBCDE") );
  45. test ( std::basic_string<char, dummy_char_traits>("") );
  46. test ( std::basic_string<char, dummy_char_traits>() );
  47. return 0;
  48. }