ends_with.char.pass.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
  9. // <string_view>
  10. // constexpr bool ends_with(charT x) const noexcept;
  11. #include <string_view>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. #include "constexpr_char_traits.h"
  15. int main(int, char**)
  16. {
  17. {
  18. typedef std::string_view SV;
  19. SV sv1 {};
  20. SV sv2 { "abcde", 5 };
  21. ASSERT_NOEXCEPT(sv1.ends_with('e'));
  22. assert (!sv1.ends_with('e'));
  23. assert (!sv1.ends_with('x'));
  24. assert ( sv2.ends_with('e'));
  25. assert (!sv2.ends_with('x'));
  26. }
  27. #if TEST_STD_VER > 11
  28. {
  29. typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
  30. constexpr SV sv1 {};
  31. constexpr SV sv2 { "abcde", 5 };
  32. static_assert (!sv1.ends_with('e'), "" );
  33. static_assert (!sv1.ends_with('x'), "" );
  34. static_assert ( sv2.ends_with('e'), "" );
  35. static_assert (!sv2.ends_with('x'), "" );
  36. }
  37. #endif
  38. return 0;
  39. }