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 // void swap(basic_string_view& _other) noexcept 14 15 #include <experimental/string_view> 16 #include <cassert> 17 18 template<typename CharT> 19 void test ( const CharT *s, size_t len ) { 20 typedef std::experimental::basic_string_view<CharT> SV; 21 { 22 SV sv1(s); 23 SV sv2; 24 25 assert ( sv1.size() == len ); 26 assert ( sv1.data() == s ); 27 assert ( sv2.size() == 0 ); 28 29 sv1.swap ( sv2 ); 30 assert ( sv1.size() == 0 ); 31 assert ( sv2.size() == len ); 32 assert ( sv2.data() == s ); 33 } 34 35 } 36 37 #if _LIBCPP_STD_VER > 11 38 constexpr size_t test_ce ( size_t n, size_t k ) { 39 typedef std::experimental::basic_string_view<char> SV; 40 SV sv1{ "ABCDEFGHIJKL", n }; 41 SV sv2 { sv1.data(), k }; 42 sv1.swap ( sv2 ); 43 return sv1.size(); 44 } 45 #endif 46 47 48 int main () { 49 test ( "ABCDE", 5 ); 50 test ( "a", 1 ); 51 test ( "", 0 ); 52 53 test ( L"ABCDE", 5 ); 54 test ( L"a", 1 ); 55 test ( L"", 0 ); 56 57 #if __cplusplus >= 201103L 58 test ( u"ABCDE", 5 ); 59 test ( u"a", 1 ); 60 test ( u"", 0 ); 61 62 test ( U"ABCDE", 5 ); 63 test ( U"a", 1 ); 64 test ( U"", 0 ); 65 #endif 66 67 #if _LIBCPP_STD_VER > 11 68 { 69 static_assert ( test_ce (2, 3) == 3, "" ); 70 static_assert ( test_ce (5, 3) == 3, "" ); 71 static_assert ( test_ce (0, 1) == 1, "" ); 72 } 73 #endif 74 } 75