| 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 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <set> |
| 10 | |
| 11 | // class set |
| 12 | |
| 13 | // set(const set& m); |
| 14 | |
| 15 | #include <set> |
| 16 | #include <cassert> |
| 17 | #include <iterator> |
| 18 | |
| 19 | #include "test_macros.h" |
| 20 | #include "../../../test_compare.h" |
| 21 | #include "test_allocator.h" |
| 22 | |
| 23 | int main(int, char**) { |
| 24 | { |
| 25 | typedef int V; |
| 26 | V ar[] = {1, 1, 1, 2, 2, 2, 3, 3, 3}; |
| 27 | typedef test_less<int> C; |
| 28 | typedef test_allocator<V> A; |
| 29 | std::set<int, C, A> mo(ar, ar + sizeof(ar) / sizeof(ar[0]), C(5), A(7)); |
| 30 | std::set<int, C, A> m = mo; |
| 31 | assert(m.get_allocator() == A(7)); |
| 32 | assert(m.key_comp() == C(5)); |
| 33 | assert(m.size() == 3); |
| 34 | assert(std::distance(m.begin(), m.end()) == 3); |
| 35 | assert(*m.begin() == 1); |
| 36 | assert(*std::next(m.begin()) == 2); |
| 37 | assert(*std::next(m.begin(), 2) == 3); |
| 38 | |
| 39 | assert(mo.get_allocator() == A(7)); |
| 40 | assert(mo.key_comp() == C(5)); |
| 41 | assert(mo.size() == 3); |
| 42 | assert(std::distance(mo.begin(), mo.end()) == 3); |
| 43 | assert(*mo.begin() == 1); |
| 44 | assert(*std::next(mo.begin()) == 2); |
| 45 | assert(*std::next(mo.begin(), 2) == 3); |
| 46 | } |
| 47 | #if TEST_STD_VER >= 11 |
| 48 | { |
| 49 | typedef int V; |
| 50 | V ar[] = {1, 1, 1, 2, 2, 2, 3, 3, 3}; |
| 51 | typedef test_less<int> C; |
| 52 | typedef other_allocator<V> A; |
| 53 | std::set<int, C, A> mo(ar, ar + sizeof(ar) / sizeof(ar[0]), C(5), A(7)); |
| 54 | std::set<int, C, A> m = mo; |
| 55 | assert(m.get_allocator() == A(-2)); |
| 56 | assert(m.key_comp() == C(5)); |
| 57 | assert(m.size() == 3); |
| 58 | assert(std::distance(m.begin(), m.end()) == 3); |
| 59 | assert(*m.begin() == 1); |
| 60 | assert(*std::next(m.begin()) == 2); |
| 61 | assert(*std::next(m.begin(), 2) == 3); |
| 62 | |
| 63 | assert(mo.get_allocator() == A(7)); |
| 64 | assert(mo.key_comp() == C(5)); |
| 65 | assert(mo.size() == 3); |
| 66 | assert(std::distance(mo.begin(), mo.end()) == 3); |
| 67 | assert(*mo.begin() == 1); |
| 68 | assert(*std::next(mo.begin()) == 2); |
| 69 | assert(*std::next(mo.begin(), 2) == 3); |
| 70 | } |
| 71 | #endif |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |