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 // XFAIL: LIBCXX-AIX-FIXME 10 11 // <string> 12 13 // iterator end(); // constexpr since C++20 14 // const_iterator end() const; // constexpr since C++20 15 16 #include <string> 17 #include <cassert> 18 #include <cstddef> 19 20 #include "test_macros.h" 21 #include "min_allocator.h" 22 23 template <class S> 24 TEST_CONSTEXPR_CXX20 void 25 test(S s) 26 { 27 const S& cs = s; 28 typename S::iterator e = s.end(); 29 typename S::const_iterator ce = cs.end(); 30 if (s.empty()) 31 { 32 assert(e == s.begin()); 33 assert(ce == cs.begin()); 34 } 35 assert(static_cast<std::size_t>(e - s.begin()) == s.size()); 36 assert(static_cast<std::size_t>(ce - cs.begin()) == cs.size()); 37 } 38 39 TEST_CONSTEXPR_CXX20 bool test() { 40 { 41 typedef std::string S; 42 test(S()); 43 test(S("123")); 44 } 45 #if TEST_STD_VER >= 11 46 { 47 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 48 test(S()); 49 test(S("123")); 50 } 51 #endif 52 53 return true; 54 } 55 56 int main(int, char**) 57 { 58 test(); 59 #if TEST_STD_VER > 17 60 static_assert(test()); 61 #endif 62 63 return 0; 64 } 65