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 // const_reference operator[](size_type pos) const; 12 // reference operator[](size_type pos); 13 14 #ifdef _LIBCPP_DEBUG 15 #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) 16 #endif 17 18 #include <string> 19 #include <cassert> 20 21 #include "min_allocator.h" 22 23 int main(int, char**) 24 { 25 { 26 typedef std::string S; 27 S s("0123456789"); 28 const S& cs = s; 29 for (S::size_type i = 0; i < cs.size(); ++i) 30 { 31 assert(s[i] == static_cast<char>('0' + i)); 32 assert(cs[i] == s[i]); 33 } 34 assert(cs[cs.size()] == '\0'); 35 const S s2 = S(); 36 assert(s2[0] == '\0'); 37 } 38 #if TEST_STD_VER >= 11 39 { 40 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 41 S s("0123456789"); 42 const S& cs = s; 43 for (S::size_type i = 0; i < cs.size(); ++i) 44 { 45 assert(s[i] == static_cast<char>('0' + i)); 46 assert(cs[i] == s[i]); 47 } 48 assert(cs[cs.size()] == '\0'); 49 const S s2 = S(); 50 assert(s2[0] == '\0'); 51 } 52 #endif 53 #ifdef _LIBCPP_DEBUG 54 { 55 std::string s; 56 char c = s[0]; 57 assert(c == '\0'); 58 c = s[1]; 59 assert(false); 60 } 61 #endif 62 63 return 0; 64 } 65