llvm-project
96 строк · 2.5 Кб
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
18#include "test_macros.h"19#include "../../../test_compare.h"20#include "test_allocator.h"21
22int main(int, char**)23{
24{25typedef int V;26V ar[] =27{281,291,301,312,322,332,343,353,36337};38typedef test_less<int> C;39typedef test_allocator<V> A;40std::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7));41std::set<int, C, A> m = mo;42assert(m.get_allocator() == A(7));43assert(m.key_comp() == C(5));44assert(m.size() == 3);45assert(std::distance(m.begin(), m.end()) == 3);46assert(*m.begin() == 1);47assert(*std::next(m.begin()) == 2);48assert(*std::next(m.begin(), 2) == 3);49
50assert(mo.get_allocator() == A(7));51assert(mo.key_comp() == C(5));52assert(mo.size() == 3);53assert(std::distance(mo.begin(), mo.end()) == 3);54assert(*mo.begin() == 1);55assert(*std::next(mo.begin()) == 2);56assert(*std::next(mo.begin(), 2) == 3);57}58#if TEST_STD_VER >= 1159{60typedef int V;61V ar[] =62{631,641,651,662,672,682,693,703,71372};73typedef test_less<int> C;74typedef other_allocator<V> A;75std::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7));76std::set<int, C, A> m = mo;77assert(m.get_allocator() == A(-2));78assert(m.key_comp() == C(5));79assert(m.size() == 3);80assert(std::distance(m.begin(), m.end()) == 3);81assert(*m.begin() == 1);82assert(*std::next(m.begin()) == 2);83assert(*std::next(m.begin(), 2) == 3);84
85assert(mo.get_allocator() == A(7));86assert(mo.key_comp() == C(5));87assert(mo.size() == 3);88assert(std::distance(mo.begin(), mo.end()) == 3);89assert(*mo.begin() == 1);90assert(*std::next(mo.begin()) == 2);91assert(*std::next(mo.begin(), 2) == 3);92}93#endif94
95return 0;96}
97