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(); 14 // iterator end(); 15 // const_iterator begin() const; 16 // const_iterator end() const; 17 // const_iterator cbegin() const; 18 // const_iterator cend() const; 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 { 28 { // N3644 testing 29 typename C::iterator ii1{}, ii2{}; 30 typename C::iterator ii4 = ii1; 31 typename C::const_iterator cii{}; 32 33 assert ( ii1 == ii2 ); 34 assert ( ii1 == ii4 ); 35 36 assert (!(ii1 != ii2 )); 37 38 assert ( (ii1 == cii )); 39 assert ( (cii == ii1 )); 40 assert (!(ii1 != cii )); 41 assert (!(cii != ii1 )); 42 assert (!(ii1 < cii )); 43 assert (!(cii < ii1 )); 44 assert ( (ii1 <= cii )); 45 assert ( (cii <= ii1 )); 46 assert (!(ii1 > cii )); 47 assert (!(cii > ii1 )); 48 assert ( (ii1 >= cii )); 49 assert ( (cii >= ii1 )); 50 assert (cii - ii1 == 0); 51 assert (ii1 - cii == 0); 52 } 53 { 54 C a; 55 typename C::iterator i1 = a.begin(); 56 typename C::iterator i2; 57 assert ( i1 != i2 ); 58 i2 = i1; 59 assert ( i1 == i2 ); 60 } 61 } 62 63 TEST_CONSTEXPR_CXX20 bool test() { 64 test<std::string>(); 65 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 66 test<std::wstring>(); 67 #endif 68 69 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L 70 test<std::u8string>(); 71 #endif 72 73 test<std::u16string>(); 74 test<std::u32string>(); 75 76 return true; 77 } 78 79 int main(int, char**) 80 { 81 test(); 82 #if defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L 83 static_assert(test()); 84 #endif 85 return 0; 86 } 87