blob: d51a12f0a77b5490ff26725efefdde81620f82a0 [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
Howard Hinnant145afa12013-08-23 20:10:18 +000014#ifdef _LIBCPP_DEBUG
Howard Hinnantfc88dbd2013-08-23 17:37:05 +000015#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
16#endif
17
Howard Hinnant3e519522010-05-11 19:42:16 +000018#include <string>
19#include <cassert>
20
Marshall Clowe34f6f62013-11-26 20:58:02 +000021#include "min_allocator.h"
Howard Hinnanteec72182013-06-28 16:59:19 +000022
Howard Hinnant3e519522010-05-11 19:42:16 +000023template <class S>
24void
25test(S s)
26{
27 const S& cs = s;
28 assert(&cs.front() == &cs[0]);
29 assert(&s.front() == &s[0]);
30 s.front() = typename S::value_type('z');
31 assert(s.front() == typename S::value_type('z'));
32}
33
JF Bastien2df59c52019-02-04 20:31:13 +000034int main(int, char**)
Howard Hinnant3e519522010-05-11 19:42:16 +000035{
Howard Hinnanteec72182013-06-28 16:59:19 +000036 {
Howard Hinnant3e519522010-05-11 19:42:16 +000037 typedef std::string S;
38 test(S("1"));
39 test(S("1234567890123456789012345678901234567890"));
Howard Hinnanteec72182013-06-28 16:59:19 +000040 }
Eric Fiselierf2f2a632016-06-14 21:31:42 +000041#if TEST_STD_VER >= 11
Howard Hinnanteec72182013-06-28 16:59:19 +000042 {
43 typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
44 test(S("1"));
45 test(S("1234567890123456789012345678901234567890"));
46 }
47#endif
Howard Hinnant145afa12013-08-23 20:10:18 +000048#ifdef _LIBCPP_DEBUG
Howard Hinnantfc88dbd2013-08-23 17:37:05 +000049 {
50 std::string s;
51 char c = s.front();
52 assert(false);
53 }
54#endif
JF Bastien2df59c52019-02-04 20:31:13 +000055
56 return 0;
Howard Hinnant3e519522010-05-11 19:42:16 +000057}