blob: cd3162385160200845b30594d3730117cdc5c0c2 [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
Howard Hinnant145afa12013-08-23 20:10:18 +000015#ifdef _LIBCPP_DEBUG
Howard Hinnantfc88dbd2013-08-23 17:37:05 +000016#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
17#endif
18
Howard Hinnant3e519522010-05-11 19:42:16 +000019#include <string>
20#include <cassert>
21
Marshall Clowe34f6f62013-11-26 20:58:02 +000022#include "min_allocator.h"
Howard Hinnanteec72182013-06-28 16:59:19 +000023
Howard Hinnant3e519522010-05-11 19:42:16 +000024int main()
25{
Howard Hinnanteec72182013-06-28 16:59:19 +000026 {
Howard Hinnant3e519522010-05-11 19:42:16 +000027 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');
Howard Hinnanteec72182013-06-28 16:59:19 +000038 }
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
Howard Hinnant145afa12013-08-23 20:10:18 +000054#ifdef _LIBCPP_DEBUG
Howard Hinnantfc88dbd2013-08-23 17:37:05 +000055 {
56 std::string s;
57 char c = s[0];
58 assert(c == '\0');
59 c = s[1];
60 assert(false);
61 }
62#endif
Howard Hinnant3e519522010-05-11 19:42:16 +000063}