blob: c97839994fc5f52a02b012037060cdaa91d44e5a [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//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
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
19template <class S>
20void
21test(S s, typename S::size_type pos)
22{
23 try
24 {
25 const S& cs = s;
26 assert(s.at(pos) == s[pos]);
27 assert(cs.at(pos) == cs[pos]);
28 assert(pos < cs.size());
29 }
30 catch (std::out_of_range&)
31 {
32 assert(pos >= s.size());
33 }
34}
35
36int main()
37{
38 typedef std::string S;
39 test(S(), 0);
40 test(S("123"), 0);
41 test(S("123"), 1);
42 test(S("123"), 2);
43 test(S("123"), 3);
44}