| 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 | |
| 9 | // UNSUPPORTED: !stdlib=libc++ && (c++03 || c++11 || c++14) |
| 10 | |
| 11 | // <string_view> |
| 12 | |
| 13 | // class iterator |
| 14 | |
| 15 | #include <cassert> |
| 16 | #include <concepts> |
| 17 | #include <iterator> |
| 18 | #include <string_view> |
| 19 | |
| 20 | #include "test_macros.h" |
| 21 | #include "make_string.h" |
| 22 | |
| 23 | template <class CharT> |
| 24 | TEST_CONSTEXPR_CXX14 void test_type() { |
| 25 | using C = std::basic_string_view<CharT>; |
| 26 | typename C::iterator ii1 = typename C::iterator(), ii2 = typename C::iterator(); |
| 27 | typename C::iterator ii4 = ii1; |
| 28 | typename C::const_iterator cii = typename C::const_iterator(); |
| 29 | assert(ii1 == ii2); |
| 30 | assert(ii1 == ii4); |
| 31 | assert(ii1 == cii); |
| 32 | |
| 33 | assert(!(ii1 != ii2)); |
| 34 | assert(!(ii1 != cii)); |
| 35 | |
| 36 | #if TEST_STD_VER >= 17 |
| 37 | C c = MAKE_STRING_VIEW(CharT, "abc" ); |
| 38 | assert(c.begin() == std::begin(c)); |
| 39 | assert(c.rbegin() == std::rbegin(c)); |
| 40 | assert(c.cbegin() == std::cbegin(c)); |
| 41 | assert(c.crbegin() == std::crbegin(c)); |
| 42 | |
| 43 | assert(c.end() == std::end(c)); |
| 44 | assert(c.rend() == std::rend(c)); |
| 45 | assert(c.cend() == std::cend(c)); |
| 46 | assert(c.crend() == std::crend(c)); |
| 47 | |
| 48 | assert(std::begin(c) != std::end(c)); |
| 49 | assert(std::rbegin(c) != std::rend(c)); |
| 50 | assert(std::cbegin(c) != std::cend(c)); |
| 51 | assert(std::crbegin(c) != std::crend(c)); |
| 52 | #endif |
| 53 | |
| 54 | #if TEST_STD_VER >= 20 |
| 55 | // P1614 + LWG3352 |
| 56 | std::same_as<std::strong_ordering> decltype(auto) r1 = ii1 <=> ii2; |
| 57 | assert(r1 == std::strong_ordering::equal); |
| 58 | |
| 59 | std::same_as<std::strong_ordering> decltype(auto) r2 = ii1 <=> ii2; |
| 60 | assert(r2 == std::strong_ordering::equal); |
| 61 | #endif |
| 62 | } |
| 63 | |
| 64 | TEST_CONSTEXPR_CXX14 bool test() { |
| 65 | test_type<char>(); |
| 66 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 67 | test_type<wchar_t>(); |
| 68 | #endif |
| 69 | #ifndef TEST_HAS_NO_CHAR8_T |
| 70 | test_type<char8_t>(); |
| 71 | #endif |
| 72 | test_type<char16_t>(); |
| 73 | test_type<char32_t>(); |
| 74 | |
| 75 | return true; |
| 76 | } |
| 77 | |
| 78 | int main(int, char**) { |
| 79 | test(); |
| 80 | #if TEST_STD_VER >= 14 |
| 81 | static_assert(test(), "" ); |
| 82 | #endif |
| 83 | |
| 84 | return 0; |
| 85 | } |
| 86 | |