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* c_str() const; 12 13 #include <string> 14 #include <cassert> 15 16 #include "min_allocator.h" 17 18 template <class S> 19 void 20 test(const S& s) 21 { 22 typedef typename S::traits_type T; 23 const typename S::value_type* str = s.c_str(); 24 if (s.size() > 0) 25 { 26 assert(T::compare(str, &s[0], s.size()) == 0); 27 assert(T::eq(str[s.size()], typename S::value_type())); 28 } 29 else 30 assert(T::eq(str[0], typename S::value_type())); 31 } 32 33 int main() 34 { 35 { 36 typedef std::string S; 37 test(S("")); 38 test(S("abcde")); 39 test(S("abcdefghij")); 40 test(S("abcdefghijklmnopqrst")); 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("")); 46 test(S("abcde")); 47 test(S("abcdefghij")); 48 test(S("abcdefghijklmnopqrst")); 49 } 50 #endif 51 } 52