data.pass.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 const _CharT* data() const noexcept;
  10. #include <string_view>
  11. #include <cassert>
  12. #include "test_macros.h"
  13. template <typename CharT>
  14. void test ( const CharT *s, size_t len ) {
  15. std::basic_string_view<CharT> sv ( s, len );
  16. assert ( sv.length() == len );
  17. assert ( sv.data() == s );
  18. #if TEST_STD_VER > 14
  19. // make sure we pick up std::data, too!
  20. assert ( sv.data() == std::data(sv));
  21. #endif
  22. }
  23. int main(int, char**) {
  24. test ( "ABCDE", 5 );
  25. test ( "a", 1 );
  26. test ( L"ABCDE", 5 );
  27. test ( L"a", 1 );
  28. #if TEST_STD_VER >= 11
  29. test ( u"ABCDE", 5 );
  30. test ( u"a", 1 );
  31. test ( U"ABCDE", 5 );
  32. test ( U"a", 1 );
  33. #endif
  34. #if TEST_STD_VER > 11
  35. {
  36. constexpr const char *s = "ABC";
  37. constexpr std::basic_string_view<char> sv( s, 2 );
  38. static_assert( sv.length() == 2, "" );
  39. static_assert( sv.data() == s, "" );
  40. }
  41. #endif
  42. return 0;
  43. }