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 charT& back() const; |
| 13 | // charT& back(); |
| 14 | |
Howard Hinnant | 5e57142 | 2013-08-23 20:10:18 +0000 | [diff] [blame] | 15 | #ifdef _LIBCPP_DEBUG |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 16 | #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) |
| 17 | #endif |
| 18 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 19 | #include <string> |
| 20 | #include <cassert> |
| 21 | |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 22 | #include "../min_allocator.h" |
| 23 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 24 | template <class S> |
| 25 | void |
| 26 | test(S s) |
| 27 | { |
| 28 | const S& cs = s; |
| 29 | assert(&cs.back() == &cs[cs.size()-1]); |
| 30 | assert(&s.back() == &s[cs.size()-1]); |
| 31 | s.back() = typename S::value_type('z'); |
| 32 | assert(s.back() == typename S::value_type('z')); |
| 33 | } |
| 34 | |
| 35 | int main() |
| 36 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 37 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 38 | typedef std::string S; |
| 39 | test(S("1")); |
| 40 | test(S("1234567890123456789012345678901234567890")); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 41 | } |
| 42 | #if __cplusplus >= 201103L |
| 43 | { |
| 44 | typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; |
| 45 | test(S("1")); |
| 46 | test(S("1234567890123456789012345678901234567890")); |
| 47 | } |
| 48 | #endif |
Howard Hinnant | 5e57142 | 2013-08-23 20:10:18 +0000 | [diff] [blame] | 49 | #ifdef _LIBCPP_DEBUG |
Howard Hinnant | 499cea1 | 2013-08-23 17:37:05 +0000 | [diff] [blame] | 50 | { |
| 51 | std::string s; |
| 52 | char c = s.back(); |
| 53 | assert(false); |
| 54 | } |
| 55 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 56 | } |