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 // <string>
11 
12 // void swap(basic_string& 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 <string>
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::string C;
40         C c1, c2;
41         static_assert(noexcept(swap(c1, c2)), "");
42     }
43     {
44         typedef std::basic_string<char, std::char_traits<char>, test_allocator<char>> C;
45         C c1, c2;
46         static_assert(noexcept(swap(c1, c2)), "");
47     }
48     {
49         typedef std::basic_string<char, std::char_traits<char>, some_alloc<char>> C;
50         C c1, c2;
51         static_assert(!noexcept(swap(c1, c2)), "");
52     }
53 #endif
54 }
55