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
11 // <string_view>
12
13 // template<class Allocator>
14 // explicit operator basic_string<_CharT, _Traits, Allocator> () const;
15 // template<class _CharT, class _Traits = char_traits<_CharT>, class Allocator = allocator<_CharT> >
16 // basic_string<_CharT, _Traits, Allocator> to_string (
17 // basic_string_view<_CharT, _Traits> _sv, const Allocator& _a = Allocator()) const;
18
19 #include <experimental/string_view>
20 #include <cassert>
21 #include "min_allocator.h"
22
23 template<typename CharT>
test(const CharT * s)24 void test ( const CharT *s ) {
25 typedef std::basic_string<CharT> String ;
26 {
27 const std::experimental::basic_string_view<CharT> sv1 ( s );
28 String str1 = (String) sv1;
29
30 assert ( sv1.size() == str1.size ());
31 assert ( std::char_traits<CharT>::compare ( sv1.data(), str1.data(), sv1.size()) == 0 );
32
33 #if __cplusplus >= 201103L
34 auto str2 = sv1.to_string(min_allocator<CharT>());
35 assert ( sv1.size() == str2.size ());
36 assert ( std::char_traits<CharT>::compare ( sv1.data(), str2.data(), sv1.size()) == 0 );
37 #endif
38 }
39
40 {
41 const std::experimental::basic_string_view<CharT> sv1;
42 String str1 = (String) sv1;
43
44 assert ( sv1.size() == 0);
45 assert ( sv1.size() == str1.size ());
46
47 #if __cplusplus >= 201103L
48 auto str2 = sv1.to_string(min_allocator<CharT>());
49 assert ( sv1.size() == str2.size ());
50 #endif
51 }
52 }
53
main()54 int main () {
55 test ( "ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
56 test ( "ABCDE");
57 test ( "a" );
58 test ( "" );
59
60 test ( L"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
61 test ( L"ABCDE" );
62 test ( L"a" );
63 test ( L"" );
64
65 #if __cplusplus >= 201103L
66 test ( u"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
67 test ( u"ABCDE" );
68 test ( u"a" );
69 test ( u"" );
70
71 test ( U"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
72 test ( U"ABCDE" );
73 test ( U"a" );
74 test ( U"" );
75 #endif
76 }
77