[flang] [unittests] Link to libMLIR in optimizer tests (#123476)
[llvm-project.git] / libcxx / test / std / containers / sequences / vector / vector.special / swap_noexcept.compile.pass.cpp
blobd38a00c789f8e37ea7ec8709c8434c58f2e8425a
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03
11 // <vector>
13 // void swap(vector& c)
14 // noexcept(!allocator_type::propagate_on_container_swap::value ||
15 // __is_nothrow_swappable<allocator_type>::value);
17 // In C++17, the standard says that swap shall have:
18 // noexcept(allocator_traits<Allocator>::propagate_on_container_swap::value ||
19 // allocator_traits<Allocator>::is_always_equal::value);
21 // This tests a conforming extension
23 #include <vector>
24 #include <utility>
25 #include <cassert>
27 #include "test_macros.h"
28 #include "MoveOnly.h"
29 #include "test_allocator.h"
31 template <class T>
32 struct some_alloc
34 typedef T value_type;
36 some_alloc() {}
37 some_alloc(const some_alloc&);
38 void allocate(std::size_t);
39 void deallocate(void*, unsigned) {}
41 typedef std::true_type propagate_on_container_swap;
44 template <class T>
45 struct some_alloc2
47 typedef T value_type;
49 some_alloc2() {}
50 some_alloc2(const some_alloc2&);
51 void allocate(std::size_t);
52 void deallocate(void*, unsigned) {}
54 typedef std::false_type propagate_on_container_swap;
55 typedef std::true_type is_always_equal;
58 void test()
61 typedef std::vector<MoveOnly> C;
62 static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
64 #if defined(_LIBCPP_VERSION)
66 typedef std::vector<MoveOnly, test_allocator<MoveOnly>> C;
67 static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
69 #endif
71 typedef std::vector<MoveOnly, other_allocator<MoveOnly>> C;
72 static_assert(noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
75 typedef std::vector<MoveOnly, some_alloc<MoveOnly>> C;
76 #if TEST_STD_VER >= 14
77 // In C++14, if POCS is set, swapping the allocator is required not to throw
78 static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
79 #else
80 static_assert(!noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
81 #endif
83 #if TEST_STD_VER >= 14
85 typedef std::vector<MoveOnly, some_alloc2<MoveOnly>> C;
86 // If the allocators are always equal, then the swap can be noexcept
87 static_assert( noexcept(swap(std::declval<C&>(), std::declval<C&>())), "");
89 #endif