1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <string> 11 12 // const_reference operator[](size_type pos) const; 13 // reference operator[](size_type pos); 14 15 #include <string> 16 #include <cassert> 17 18 #include "../min_allocator.h" 19 main()20int main() 21 { 22 { 23 typedef std::string S; 24 S s("0123456789"); 25 const S& cs = s; 26 for (S::size_type i = 0; i < cs.size(); ++i) 27 { 28 assert(s[i] == '0' + i); 29 assert(cs[i] == s[i]); 30 } 31 assert(cs[cs.size()] == '\0'); 32 const S s2 = S(); 33 assert(s2[0] == '\0'); 34 } 35 #if __cplusplus >= 201103L 36 { 37 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; 38 S s("0123456789"); 39 const S& cs = s; 40 for (S::size_type i = 0; i < cs.size(); ++i) 41 { 42 assert(s[i] == '0' + i); 43 assert(cs[i] == s[i]); 44 } 45 assert(cs[cs.size()] == '\0'); 46 const S s2 = S(); 47 assert(s2[0] == '\0'); 48 } 49 #endif 50 } 51