1 //===----------------------------------------------------------------------===// 2 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 // <string> 10 11 // const charT& front() const; 12 // charT& front(); 13 14 #include <string> 15 #include <cassert> 16 17 #include "test_macros.h" 18 #include "min_allocator.h" 19 20 template <class S> 21 void test(S s)22test(S s) 23 { 24 const S& cs = s; 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()); 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 main(int,char **)35int main(int, char**) 36 { 37 { 38 typedef std::string S; 39 test(S("1")); 40 test(S("1234567890123456789012345678901234567890")); 41 } 42 #if TEST_STD_VER >= 11 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 49 50 return 0; 51 } 52