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 // <vector> 11 12 // void swap(vector& c) 13 // noexcept(!allocator_type::propagate_on_container_swap::value || 14 // __is_nothrow_swappable<allocator_type>::value); 15 16 // This tests a conforming extension 17 18 #include <vector> 19 #include <cassert> 20 21 #include "test_allocator.h" 22 23 template <class T> 24 struct some_alloc 25 { 26 typedef T value_type; 27 28 some_alloc() {} 29 some_alloc(const some_alloc&); 30 void deallocate(void*, unsigned) {} 31 32 typedef std::true_type propagate_on_container_swap; 33 }; 34 35 int main() 36 { 37 #if __has_feature(cxx_noexcept) 38 { 39 typedef std::vector<bool> C; 40 C c1, c2; 41 static_assert(noexcept(swap(c1, c2)), ""); 42 } 43 { 44 typedef std::vector<bool, test_allocator<bool>> C; 45 C c1, c2; 46 static_assert(noexcept(swap(c1, c2)), ""); 47 } 48 { 49 typedef std::vector<bool, other_allocator<bool>> C; 50 C c1, c2; 51 static_assert(noexcept(swap(c1, c2)), ""); 52 } 53 { 54 typedef std::vector<bool, some_alloc<bool>> C; 55 C c1, c2; 56 static_assert(!noexcept(swap(c1, c2)), ""); 57 } 58 #endif 59 } 60