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 i2 = i1; 58 assert ( i1 == i2 ); 59 } 60 } 61 62 TEST_CONSTEXPR_CXX20 bool test() { 63 test<std::string>(); 64 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 65 test<std::wstring>(); 66 #endif 67 68 #if defined(__cpp_lib_char8_t) && __cpp_lib_char8_t >= 201811L 69 test<std::u8string>(); 70 #endif 71 72 test<std::u16string>(); 73 test<std::u32string>(); 74 75 return true; 76 } 77 78 int main(int, char**) 79 { 80 test(); 81 #if defined(__cpp_lib_constexpr_string) && __cpp_lib_constexpr_string >= 201907L 82 static_assert(test()); 83 #endif 84 return 0; 85 } 86