blob: b5643533b007fdfc43db6ec2f057b50606a3f125 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00004//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:16 +00007//
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
Howard Hinnanteec72182013-06-28 16:59:19 +000018#include "../min_allocator.h"
19
Howard Hinnant3e519522010-05-11 19:42:16 +000020int main()
21{
Howard Hinnanteec72182013-06-28 16:59:19 +000022 {
Howard Hinnant3e519522010-05-11 19:42:16 +000023 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');
Howard Hinnanteec72182013-06-28 16:59:19 +000034 }
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
Howard Hinnant3e519522010-05-11 19:42:16 +000050}