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 | |
| 15 | #include <string> |
| 16 | #include <cassert> |
| 17 | |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame^] | 18 | #include "../min_allocator.h" |
| 19 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 20 | template <class S> |
| 21 | void |
| 22 | test(S s) |
| 23 | { |
| 24 | const S& cs = s; |
| 25 | assert(&cs.back() == &cs[cs.size()-1]); |
| 26 | assert(&s.back() == &s[cs.size()-1]); |
| 27 | s.back() = typename S::value_type('z'); |
| 28 | assert(s.back() == typename S::value_type('z')); |
| 29 | } |
| 30 | |
| 31 | int main() |
| 32 | { |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame^] | 33 | { |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 34 | typedef std::string S; |
| 35 | test(S("1")); |
| 36 | test(S("1234567890123456789012345678901234567890")); |
Howard Hinnant | 9dcdcde | 2013-06-28 16:59:19 +0000 | [diff] [blame^] | 37 | } |
| 38 | #if __cplusplus >= 201103L |
| 39 | { |
| 40 | typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S; |
| 41 | test(S("1")); |
| 42 | test(S("1234567890123456789012345678901234567890")); |
| 43 | } |
| 44 | #endif |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 45 | } |