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 
16 #include <experimental/string_view>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 
21 template<typename CharT>
test(const CharT * s)22 void test ( const CharT *s ) {
23     typedef std::experimental::basic_string_view<CharT> string_view_t;
24     typedef std::basic_string<CharT> string_t;
25 
26     {
27     string_view_t sv1 ( s );
28     string_t      str = (string_t) sv1;
29 
30     assert ( sv1.size() == str.size ());
31     assert ( std::char_traits<CharT>::compare ( sv1.data(), str.data(), sv1.size()) == 0 );
32     }
33 
34     {
35     string_view_t sv1;
36     string_t      str = (string_t) sv1;
37 
38     assert ( sv1.size() ==  0);
39     assert ( sv1.size() == str.size ());
40     }
41 }
42 
main()43 int main () {
44     test ( "ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
45     test ( "ABCDE");
46     test ( "a" );
47     test ( "" );
48 
49     test ( L"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
50     test ( L"ABCDE" );
51     test ( L"a" );
52     test ( L"" );
53 
54 #if TEST_STD_VER >= 11
55     test ( u"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
56     test ( u"ABCDE" );
57     test ( u"a" );
58     test ( u"" );
59 
60     test ( U"ABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDEABCDE" );
61     test ( U"ABCDE" );
62     test ( U"a" );
63     test ( U"" );
64 #endif
65 }
66