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