| 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: c++03, c++11 |
| 10 | |
| 11 | // <string> |
| 12 | |
| 13 | // iterator begin(); // constexpr since C++20 |
| 14 | // iterator end(); // constexpr since C++20 |
| 15 | // const_iterator begin() const; // constexpr since C++20 |
| 16 | // const_iterator end() const; // constexpr since C++20 |
| 17 | // const_iterator cbegin() const; // constexpr since C++20 |
| 18 | // const_iterator cend() const; // constexpr since C++20 |
| 19 | |
| 20 | #include <string> |
| 21 | #include <cassert> |
| 22 | |
| 23 | #include "test_macros.h" |
| 24 | |
| 25 | template <class C> |
| 26 | TEST_CONSTEXPR_CXX20 void test() { |
| 27 | { // N3644 testing |
| 28 | typename C::iterator ii1{}, ii2{}; |
| 29 | typename C::iterator ii4 = ii1; |
| 30 | typename C::const_iterator cii{}; |
| 31 | |
| 32 | assert(ii1 == ii2); |
| 33 | assert(ii1 == ii4); |
| 34 | |
| 35 | assert(!(ii1 != ii2)); |
| 36 | |
| 37 | assert((ii1 == cii)); |
| 38 | assert((cii == ii1)); |
| 39 | assert(!(ii1 != cii)); |
| 40 | assert(!(cii != ii1)); |
| 41 | assert(!(ii1 < cii)); |
| 42 | assert(!(cii < ii1)); |
| 43 | assert((ii1 <= cii)); |
| 44 | assert((cii <= ii1)); |
| 45 | assert(!(ii1 > cii)); |
| 46 | assert(!(cii > ii1)); |
| 47 | assert((ii1 >= cii)); |
| 48 | assert((cii >= ii1)); |
| 49 | assert(cii - ii1 == 0); |
| 50 | assert(ii1 - cii == 0); |
| 51 | } |
| 52 | { |
| 53 | C a; |
| 54 | typename C::iterator i1 = a.begin(); |
| 55 | typename C::iterator i2; |
| 56 | i2 = i1; |
| 57 | assert(i1 == i2); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | TEST_CONSTEXPR_CXX20 bool test() { |
| 62 | test<std::string>(); |
| 63 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 64 | test<std::wstring>(); |
| 65 | #endif |
| 66 | |
| 67 | #ifndef TEST_HAS_NO_CHAR8_T |
| 68 | test<std::u8string>(); |
| 69 | #endif |
| 70 | |
| 71 | test<std::u16string>(); |
| 72 | test<std::u32string>(); |
| 73 | |
| 74 | return true; |
| 75 | } |
| 76 | |
| 77 | int main(int, char**) { |
| 78 | test(); |
| 79 | #if TEST_STD_VER > 17 |
| 80 | static_assert(test()); |
| 81 | #endif |
| 82 | return 0; |
| 83 | } |
| 84 | |