Home | History | Annotate | Download | only in string.accessors
      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 template <class S>
     18 void
     19 test(const S& s)
     20 {
     21     typedef typename S::traits_type T;
     22     const typename S::value_type* str = s.c_str();
     23     if (s.size() > 0)
     24     {
     25         assert(T::compare(str, &s[0], s.size()) == 0);
     26         assert(T::eq(str[s.size()], typename S::value_type()));
     27     }
     28     else
     29         assert(T::eq(str[0], typename S::value_type()));
     30 }
     31 
     32 int main()
     33 {
     34     typedef std::string S;
     35     test(S(""));
     36     test(S("abcde"));
     37     test(S("abcdefghij"));
     38     test(S("abcdefghijklmnopqrst"));
     39 }
     40