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