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