blob: 8fada8fb1eea8f2b8cc2c4afdea69fdf45e9a2a2 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-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 Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <string>
11
12// const_reference at(size_type pos) const;
13// reference at(size_type pos);
14
15#include <string>
16#include <stdexcept>
17#include <cassert>
18
Marshall Clow061d0cc2013-11-26 20:58:02 +000019#include "min_allocator.h"
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000020
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000021template <class S>
22void
23test(S s, typename S::size_type pos)
24{
25 try
26 {
27 const S& cs = s;
28 assert(s.at(pos) == s[pos]);
29 assert(cs.at(pos) == cs[pos]);
30 assert(pos < cs.size());
31 }
32 catch (std::out_of_range&)
33 {
34 assert(pos >= s.size());
35 }
36}
37
38int main()
39{
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000040 {
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000041 typedef std::string S;
42 test(S(), 0);
43 test(S("123"), 0);
44 test(S("123"), 1);
45 test(S("123"), 2);
46 test(S("123"), 3);
Howard Hinnant9dcdcde2013-06-28 16:59:19 +000047 }
48#if __cplusplus >= 201103L
49 {
50 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
51 test(S(), 0);
52 test(S("123"), 0);
53 test(S("123"), 1);
54 test(S("123"), 2);
55 test(S("123"), 3);
56 }
57#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000058}