Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <string> |
| 10 | |
| 11 | // const charT& front() const; |
| 12 | // charT& front(); |
| 13 | |
| 14 | #include <string> |
| 15 | #include <cassert> |
| 16 | |
Marshall Clow | 7fc6a55 | 2019-05-31 18:35:30 +0000 | [diff] [blame] | 17 | #include "test_macros.h" |
Marshall Clow | e34f6f6 | 2013-11-26 20:58:02 +0000 | [diff] [blame] | 18 | #include "min_allocator.h" |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 19 | |
Howard Hinnant | 3e51952 | 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; |
Marshall Clow | 9ea0e47 | 2019-03-19 03:30:07 +0000 | [diff] [blame] | 25 | ASSERT_SAME_TYPE(decltype( s.front()), typename S::reference); |
| 26 | ASSERT_SAME_TYPE(decltype(cs.front()), typename S::const_reference); |
| 27 | LIBCPP_ASSERT_NOEXCEPT( s.front()); |
| 28 | LIBCPP_ASSERT_NOEXCEPT( cs.front()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 29 | assert(&cs.front() == &cs[0]); |
| 30 | assert(&s.front() == &s[0]); |
| 31 | s.front() = typename S::value_type('z'); |
| 32 | assert(s.front() == typename S::value_type('z')); |
| 33 | } |
| 34 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 35 | int main(int, char**) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 36 | { |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 37 | { |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 38 | typedef std::string S; |
| 39 | test(S("1")); |
| 40 | test(S("1234567890123456789012345678901234567890")); |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 41 | } |
Eric Fiselier | f2f2a63 | 2016-06-14 21:31:42 +0000 | [diff] [blame] | 42 | #if TEST_STD_VER >= 11 |
Howard Hinnant | eec7218 | 2013-06-28 16:59:19 +0000 | [diff] [blame] | 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 |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 49 | |
Louis Dionne | 2908eb2 | 2020-10-14 10:54:59 -0400 | [diff] [blame] | 50 | return 0; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 51 | } |