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 // <valarray> 11 12 // template<class T> class valarray; 13 14 // template<class T> 15 // void 16 // swap(valarray<T>& x, valarray<T>& y); 17 18 #include <valarray> 19 #include <cassert> 20 #include <cstddef> 21 22 int main() 23 { 24 { 25 typedef int T; 26 T a1[] = {1, 2, 3, 4, 5}; 27 T a2[] = {6, 7, 8, 9, 10, 11, 12}; 28 const unsigned N1 = sizeof(a1)/sizeof(a1[0]); 29 const unsigned N2 = sizeof(a2)/sizeof(a2[0]); 30 std::valarray<T> v1(a1, N1); 31 std::valarray<T> v2(a2, N2); 32 std::valarray<T> v1_save = v1; 33 std::valarray<T> v2_save = v2; 34 swap(v1, v2); 35 assert(v1.size() == v2_save.size()); 36 for (std::size_t i = 0; i < v1.size(); ++i) 37 assert(v1[i] == v2_save[i]); 38 assert(v2.size() == v1_save.size()); 39 for (std::size_t i = 0; i < v2.size(); ++i) 40 assert(v2[i] == v1_save[i]); 41 } 42 { 43 typedef int T; 44 T a1[] = {1, 2, 3, 4, 5}; 45 const unsigned N1 = sizeof(a1)/sizeof(a1[0]); 46 std::valarray<T> v1(a1, N1); 47 std::valarray<T> v2; 48 std::valarray<T> v1_save = v1; 49 std::valarray<T> v2_save = v2; 50 swap(v1, v2); 51 assert(v1.size() == v2_save.size()); 52 for (std::size_t i = 0; i < v1.size(); ++i) 53 assert(v1[i] == v2_save[i]); 54 assert(v2.size() == v1_save.size()); 55 for (std::size_t i = 0; i < v2.size(); ++i) 56 assert(v2[i] == v1_save[i]); 57 } 58 { 59 typedef int T; 60 T a2[] = {6, 7, 8, 9, 10, 11, 12}; 61 const unsigned N2 = sizeof(a2)/sizeof(a2[0]); 62 std::valarray<T> v1; 63 std::valarray<T> v2(a2, N2); 64 std::valarray<T> v1_save = v1; 65 std::valarray<T> v2_save = v2; 66 swap(v1, v2); 67 assert(v1.size() == v2_save.size()); 68 for (std::size_t i = 0; i < v1.size(); ++i) 69 assert(v1[i] == v2_save[i]); 70 assert(v2.size() == v1_save.size()); 71 for (std::size_t i = 0; i < v2.size(); ++i) 72 assert(v2[i] == v1_save[i]); 73 } 74 { 75 typedef int T; 76 std::valarray<T> v1; 77 std::valarray<T> v2; 78 std::valarray<T> v1_save = v1; 79 std::valarray<T> v2_save = v2; 80 swap(v1, v2); 81 assert(v1.size() == v2_save.size()); 82 for (std::size_t i = 0; i < v1.size(); ++i) 83 assert(v1[i] == v2_save[i]); 84 assert(v2.size() == v1_save.size()); 85 for (std::size_t i = 0; i < v2.size(); ++i) 86 assert(v2[i] == v1_save[i]); 87 } 88 } 89