• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <string>
11 
12 // const charT* c_str() const;
13 
14 #include <string>
15 #include <cassert>
16 
17 #include "min_allocator.h"
18 
19 template <class S>
20 void
test(const S & s)21 test(const S& s)
22 {
23     typedef typename S::traits_type T;
24     const typename S::value_type* str = s.c_str();
25     if (s.size() > 0)
26     {
27         assert(T::compare(str, &s[0], s.size()) == 0);
28         assert(T::eq(str[s.size()], typename S::value_type()));
29     }
30     else
31         assert(T::eq(str[0], typename S::value_type()));
32 }
33 
main()34 int main()
35 {
36     {
37     typedef std::string S;
38     test(S(""));
39     test(S("abcde"));
40     test(S("abcdefghij"));
41     test(S("abcdefghijklmnopqrst"));
42     }
43 #if TEST_STD_VER >= 11
44     {
45     typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
46     test(S(""));
47     test(S("abcde"));
48     test(S("abcdefghij"));
49     test(S("abcdefghijklmnopqrst"));
50     }
51 #endif
52 }
53