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 | // |
Howard Hinnant | 412dbeb | 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 | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Asiri Rathnayake | f520c14 | 2015-11-10 11:41:22 +0000 | [diff] [blame] | 10 | // XFAIL: libcpp-no-exceptions |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 11 | // <string> |
| 12 | |
| 13 | // const_reference at(size_type pos) const; |
| 14 | // reference at(size_type pos); |
| 15 | |
| 16 | #include <string> |
| 17 | #include <stdexcept> |
| 18 | #include <cassert> |
| 19 | |
Marshall Clow | e34f6f6 | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 20 | #include "min_allocator.h" |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 21 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 22 | template <class S> |
| 23 | void |
| 24 | test(S s, typename S::size_type pos) |
| 25 | { |
| 26 | try |
| 27 | { |
| 28 | const S& cs = s; |
| 29 | assert(s.at(pos) == s[pos]); |
| 30 | assert(cs.at(pos) == cs[pos]); |
| 31 | assert(pos < cs.size()); |
| 32 | } |
| 33 | catch (std::out_of_range&) |
| 34 | { |
| 35 | assert(pos >= s.size()); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | int main() |
| 40 | { |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 41 | { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 42 | typedef std::string S; |
| 43 | test(S(), 0); |
| 44 | test(S("123"), 0); |
| 45 | test(S("123"), 1); |
| 46 | test(S("123"), 2); |
| 47 | test(S("123"), 3); |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 48 | } |
Eric Fiselier | f2f2a63 | 2016-06-14 21:31:42 +0000 | [diff] [blame^] | 49 | #if TEST_STD_VER >= 11 |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 50 | { |
| 51 | typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; |
| 52 | test(S(), 0); |
| 53 | test(S("123"), 0); |
| 54 | test(S("123"), 1); |
| 55 | test(S("123"), 2); |
| 56 | test(S("123"), 3); |
| 57 | } |
| 58 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 59 | } |