| 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 |
// UNSUPPORTED: c++03 |
| 10 |
|
| 11 |
// <set> |
| 12 |
|
| 13 |
// class set |
| 14 |
|
| 15 |
// set& operator=(initializer_list<value_type> il); |
| 16 |
|
| 17 |
#include <set> |
| 18 |
#include <cassert> |
| 19 |
|
| 20 |
#include "test_macros.h" |
| 21 |
#include "min_allocator.h" |
| 22 |
#include "test_allocator.h" |
| 23 |
|
| 24 |
void basic_test() { |
| 25 |
{ |
| 26 |
typedef std::set<int> C; |
| 27 |
typedef C::value_type V; |
| 28 |
C m = {10, 8}; |
| 29 |
m = {1, 2, 3, 4, 5, 6}; |
| 30 |
assert(m.size() == 6); |
| 31 |
assert(std::distance(m.begin(), m.end()) == 6); |
| 32 |
C::const_iterator i = m.cbegin(); |
| 33 |
assert(*i == V(1)); |
| 34 |
assert(*++i == V(2)); |
| 35 |
assert(*++i == V(3)); |
| 36 |
assert(*++i == V(4)); |
| 37 |
assert(*++i == V(5)); |
| 38 |
assert(*++i == V(6)); |
| 39 |
} |
| 40 |
{ |
| 41 |
typedef std::set<int, std::less<int>, min_allocator<int> > C; |
| 42 |
typedef C::value_type V; |
| 43 |
C m = {10, 8}; |
| 44 |
m = {1, 2, 3, 4, 5, 6}; |
| 45 |
assert(m.size() == 6); |
| 46 |
assert(std::distance(m.begin(), m.end()) == 6); |
| 47 |
C::const_iterator i = m.cbegin(); |
| 48 |
assert(*i == V(1)); |
| 49 |
assert(*++i == V(2)); |
| 50 |
assert(*++i == V(3)); |
| 51 |
assert(*++i == V(4)); |
| 52 |
assert(*++i == V(5)); |
| 53 |
assert(*++i == V(6)); |
| 54 |
} |
| 55 |
} |
| 56 |
|
| 57 |
void duplicate_keys_test() { |
| 58 |
test_allocator_statistics alloc_stats; |
| 59 |
typedef std::set<int, std::less<int>, test_allocator<int> > Set; |
| 60 |
{ |
| 61 |
LIBCPP_ASSERT(alloc_stats.alloc_count == 0); |
| 62 |
Set s({1, 2, 3}, std::less<int>(), test_allocator<int>(&alloc_stats)); |
| 63 |
LIBCPP_ASSERT(alloc_stats.alloc_count == 3); |
| 64 |
s = {4, 4, 4, 4, 4}; |
| 65 |
LIBCPP_ASSERT(alloc_stats.alloc_count == 1); |
| 66 |
assert(s.size() == 1); |
| 67 |
assert(*s.begin() == 4); |
| 68 |
} |
| 69 |
LIBCPP_ASSERT(alloc_stats.alloc_count == 0); |
| 70 |
} |
| 71 |
|
| 72 |
int main(int, char**) { |
| 73 |
basic_test(); |
| 74 |
duplicate_keys_test(); |
| 75 |
|
| 76 |
return 0; |
| 77 |
} |