xref: /minix3/external/bsd/libc++/dist/libcxx/test/strings/basic.string/string.access/front.pass.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
14684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
24684ddb6SLionel Sambuc //
34684ddb6SLionel Sambuc //                     The LLVM Compiler Infrastructure
44684ddb6SLionel Sambuc //
54684ddb6SLionel Sambuc // This file is dual licensed under the MIT and the University of Illinois Open
64684ddb6SLionel Sambuc // Source Licenses. See LICENSE.TXT for details.
74684ddb6SLionel Sambuc //
84684ddb6SLionel Sambuc //===----------------------------------------------------------------------===//
94684ddb6SLionel Sambuc 
104684ddb6SLionel Sambuc // <string>
114684ddb6SLionel Sambuc 
124684ddb6SLionel Sambuc // const charT& front() const;
134684ddb6SLionel Sambuc //       charT& front();
144684ddb6SLionel Sambuc 
154684ddb6SLionel Sambuc #ifdef _LIBCPP_DEBUG
164684ddb6SLionel Sambuc #define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0))
174684ddb6SLionel Sambuc #endif
184684ddb6SLionel Sambuc 
194684ddb6SLionel Sambuc #include <string>
204684ddb6SLionel Sambuc #include <cassert>
214684ddb6SLionel Sambuc 
22*0a6a1f1dSLionel Sambuc #include "min_allocator.h"
234684ddb6SLionel Sambuc 
244684ddb6SLionel Sambuc template <class S>
254684ddb6SLionel Sambuc void
test(S s)264684ddb6SLionel Sambuc test(S s)
274684ddb6SLionel Sambuc {
284684ddb6SLionel Sambuc     const S& cs = s;
294684ddb6SLionel Sambuc     assert(&cs.front() == &cs[0]);
304684ddb6SLionel Sambuc     assert(&s.front() == &s[0]);
314684ddb6SLionel Sambuc     s.front() = typename S::value_type('z');
324684ddb6SLionel Sambuc     assert(s.front() == typename S::value_type('z'));
334684ddb6SLionel Sambuc }
344684ddb6SLionel Sambuc 
main()354684ddb6SLionel Sambuc int main()
364684ddb6SLionel Sambuc {
374684ddb6SLionel Sambuc     {
384684ddb6SLionel Sambuc     typedef std::string S;
394684ddb6SLionel Sambuc     test(S("1"));
404684ddb6SLionel Sambuc     test(S("1234567890123456789012345678901234567890"));
414684ddb6SLionel Sambuc     }
424684ddb6SLionel Sambuc #if __cplusplus >= 201103L
434684ddb6SLionel Sambuc     {
444684ddb6SLionel Sambuc     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
454684ddb6SLionel Sambuc     test(S("1"));
464684ddb6SLionel Sambuc     test(S("1234567890123456789012345678901234567890"));
474684ddb6SLionel Sambuc     }
484684ddb6SLionel Sambuc #endif
494684ddb6SLionel Sambuc #ifdef _LIBCPP_DEBUG
504684ddb6SLionel Sambuc     {
514684ddb6SLionel Sambuc         std::string s;
524684ddb6SLionel Sambuc         char c = s.front();
534684ddb6SLionel Sambuc         assert(false);
544684ddb6SLionel Sambuc     }
554684ddb6SLionel Sambuc #endif
564684ddb6SLionel Sambuc }
57