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 "../../../MoveOnly.h" 22 #include "test_allocator.h" 23 24 template <class T> 25 struct some_alloc 26 { 27 typedef T value_type; 28 29 some_alloc() {} 30 some_alloc(const some_alloc&); 31 void deallocate(void*, unsigned) {} 32 33 typedef std::true_type propagate_on_container_swap; 34 }; 35 36 int main() 37 { 38 #if __has_feature(cxx_noexcept) 39 { 40 typedef std::vector<MoveOnly> C; 41 C c1, c2; 42 static_assert(noexcept(swap(c1, c2)), ""); 43 } 44 { 45 typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C; 46 C c1, c2; 47 static_assert(noexcept(swap(c1, c2)), ""); 48 } 49 { 50 typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C; 51 C c1, c2; 52 static_assert(noexcept(swap(c1, c2)), ""); 53 } 54 { 55 typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C; 56 C c1, c2; 57 static_assert(!noexcept(swap(c1, c2)), ""); 58 } 59 #endif 60 } 61