Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | 5b08a8a | 2010-05-11 21:36:01 +0000 | [diff] [blame^] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
| 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 | |
| 19 | template <class S> |
| 20 | void |
| 21 | test(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 | |
| 36 | int 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 | } |