Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 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 | |
Marshall Clow | 061d0cc | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 19 | #include "min_allocator.h" |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 20 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 21 | template <class S> |
| 22 | void |
| 23 | test(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 | |
| 38 | int main() |
| 39 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 40 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 41 | 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 Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 47 | } |
| 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 Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 58 | } |