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 // <array> 11 12 // void swap(array& a); 13 // namespace std { void swap(array<T, N> &x, array<T, N> &y); 14 15 #include <cassert> 16 #include <array> 17 18 // std::array is explicitly allowed to be initialized with A a = { init-list };. 19 // Disable the missing braces warning for this reason. 20 #include "disable_missing_braces_warning.h" 21 22 int main() 23 { 24 { 25 typedef double T; 26 typedef std::array<T, 3> C; 27 C c1 = {1, 2, 3.5}; 28 C c2 = {4, 5, 6.5}; 29 c1.swap(c2); 30 assert(c1.size() == 3); 31 assert(c1[0] == 4); 32 assert(c1[1] == 5); 33 assert(c1[2] == 6.5); 34 assert(c2.size() == 3); 35 assert(c2[0] == 1); 36 assert(c2[1] == 2); 37 assert(c2[2] == 3.5); 38 } 39 { 40 typedef double T; 41 typedef std::array<T, 3> C; 42 C c1 = {1, 2, 3.5}; 43 C c2 = {4, 5, 6.5}; 44 std::swap(c1, c2); 45 assert(c1.size() == 3); 46 assert(c1[0] == 4); 47 assert(c1[1] == 5); 48 assert(c1[2] == 6.5); 49 assert(c2.size() == 3); 50 assert(c2[0] == 1); 51 assert(c2[1] == 2); 52 assert(c2[2] == 3.5); 53 } 54 55 { 56 typedef double T; 57 typedef std::array<T, 0> C; 58 C c1 = {}; 59 C c2 = {}; 60 c1.swap(c2); 61 assert(c1.size() == 0); 62 assert(c2.size() == 0); 63 } 64 { 65 typedef double T; 66 typedef std::array<T, 0> C; 67 C c1 = {}; 68 C c2 = {}; 69 std::swap(c1, c2); 70 assert(c1.size() == 0); 71 assert(c2.size() == 0); 72 } 73 74 } 75