blob: 4cc9f31caaf4b62de4faa7dcd671f661b9fdab21 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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 Hinnant3e519522010-05-11 19:42:16 +00006//
7//===----------------------------------------------------------------------===//
8
9// <string>
10
11// const charT& front() const;
12// charT& front();
13
14#include <string>
15#include <cassert>
16
Marshall Clow7fc6a552019-05-31 18:35:30 +000017#include "test_macros.h"
Marshall Clowe34f6f62013-11-26 20:58:02 +000018#include "min_allocator.h"
Howard Hinnanteec72182013-06-28 16:59:19 +000019
Howard Hinnant3e519522010-05-11 19:42:16 +000020template <class S>
21void
22test(S s)
23{
24 const S& cs = s;
Marshall Clow9ea0e472019-03-19 03:30:07 +000025 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 Hinnant3e519522010-05-11 19:42:16 +000029 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 Bastien2df59c52019-02-04 20:31:13 +000035int main(int, char**)
Howard Hinnant3e519522010-05-11 19:42:16 +000036{
Howard Hinnanteec72182013-06-28 16:59:19 +000037 {
Howard Hinnant3e519522010-05-11 19:42:16 +000038 typedef std::string S;
39 test(S("1"));
40 test(S("1234567890123456789012345678901234567890"));
Howard Hinnanteec72182013-06-28 16:59:19 +000041 }
Eric Fiselierf2f2a632016-06-14 21:31:42 +000042#if TEST_STD_VER >= 11
Howard Hinnanteec72182013-06-28 16:59:19 +000043 {
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 Bastien2df59c52019-02-04 20:31:13 +000049
Louis Dionne2908eb22020-10-14 10:54:59 -040050 return 0;
Howard Hinnant3e519522010-05-11 19:42:16 +000051}