reference.swap.pass.cpp revision 56a0a437b7685fe2e43e89149f4f2f9447a6b17a
1005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow//===----------------------------------------------------------------------===// 2005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow// 3005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow// The LLVM Compiler Infrastructure 4005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow// 5005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow// This file is dual licensed under the MIT and the University of Illinois Open 6005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow// Source Licenses. See LICENSE.TXT for details. 7005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow// 8005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow//===----------------------------------------------------------------------===// 9005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow 10005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow// <vector> 11005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow// vector<bool> 12005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow 13005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow// static void swap(reference x, reference y) noexcept; 14005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow 15005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow#include <vector> 16005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow#include <cassert> 17005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow 18005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clowint main() 19005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow{ 2056a0a437b7685fe2e43e89149f4f2f9447a6b17aMarshall Clow 21005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow bool a[] = {false, true, false, true}; 22005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow bool* an = a + sizeof(a)/sizeof(a[0]); 23005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow 24005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow std::vector<bool> v(a, an); 25005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow std::vector<bool>::reference r1 = v[0]; 26005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow std::vector<bool>::reference r2 = v[3]; 2756a0a437b7685fe2e43e89149f4f2f9447a6b17aMarshall Clow 2856a0a437b7685fe2e43e89149f4f2f9447a6b17aMarshall Clow#if __has_feature(cxx_noexcept) 2956a0a437b7685fe2e43e89149f4f2f9447a6b17aMarshall Clow static_assert((noexcept(v.swap(r1,r2))), ""); 3056a0a437b7685fe2e43e89149f4f2f9447a6b17aMarshall Clow#endif 3156a0a437b7685fe2e43e89149f4f2f9447a6b17aMarshall Clow 32005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow assert(!r1); 33005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow assert( r2); 34005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow v.swap(r1, r2); 35005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow assert( r1); 36005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow assert(!r2); 37005c60b6662440b1ea9d2ab7505948e2bfc87fe0Marshall Clow}