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 // basic_string_view(const basic_string<_CharT, _Traits, Allocator>& _str) noexcept
15 
16 
17 #include <experimental/string_view>
18 #include <string>
19 #include <cassert>
20 
21 struct dummy_char_traits : public std::char_traits<char> {};
22 
23 template<typename CharT, typename Traits>
test(const std::basic_string<CharT,Traits> & str)24 void test ( const std::basic_string<CharT, Traits> &str ) {
25     std::experimental::basic_string_view<CharT, Traits> sv1 ( str );
26     assert ( sv1.size() == str.size());
27     assert ( sv1.data() == str.data());
28 }
29 
main()30 int main () {
31 
32     test ( std::string("QBCDE") );
33     test ( std::string("") );
34     test ( std::string() );
35 
36     test ( std::wstring(L"QBCDE") );
37     test ( std::wstring(L"") );
38     test ( std::wstring() );
39 
40 #if __cplusplus >= 201103L
41     test ( std::u16string{u"QBCDE"} );
42     test ( std::u16string{u""} );
43     test ( std::u16string{} );
44 
45     test ( std::u32string{U"QBCDE"} );
46     test ( std::u32string{U""} );
47     test ( std::u32string{} );
48 #endif
49 
50     test ( std::basic_string<char, dummy_char_traits>("QBCDE") );
51     test ( std::basic_string<char, dummy_char_traits>("") );
52     test ( std::basic_string<char, dummy_char_traits>() );
53 
54 }
55