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