back.pass.cpp 1.2 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_view>
  10. // constexpr const _CharT& front();
  11. #include <string_view>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. template <typename CharT>
  15. bool test ( const CharT *s, size_t len ) {
  16. std::basic_string_view<CharT> sv ( s, len );
  17. assert ( sv.length() == len );
  18. assert ( sv.back() == s[len-1] );
  19. return &sv.back() == s + len - 1;
  20. }
  21. int main () {
  22. assert ( test ( "ABCDE", 5 ));
  23. assert ( test ( "a", 1 ));
  24. assert ( test ( L"ABCDE", 5 ));
  25. assert ( test ( L"a", 1 ));
  26. #if TEST_STD_VER >= 11
  27. assert ( test ( u"ABCDE", 5 ));
  28. assert ( test ( u"a", 1 ));
  29. assert ( test ( U"ABCDE", 5 ));
  30. assert ( test ( U"a", 1 ));
  31. #endif
  32. #if TEST_STD_VER >= 11
  33. {
  34. constexpr std::basic_string_view<char> sv ( "ABC", 2 );
  35. static_assert ( sv.length() == 2, "" );
  36. static_assert ( sv.back() == 'B', "" );
  37. }
  38. #endif
  39. }