From 5a83710e371fe68a06e6e3876c6a2c8b820a8976 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Sat, 20 Dec 2014 01:40:03 +0000 Subject: Move test into test/std subdirectory. llvm-svn: 224658 --- libcxx/test/std/containers/Copyable.h | 18 + libcxx/test/std/containers/Emplaceable.h | 54 + libcxx/test/std/containers/MoveOnly.h | 50 + libcxx/test/std/containers/NotConstructible.h | 39 + .../containers/associative/map/compare.pass.cpp | 32 + .../associative/map/map.access/at.pass.cpp | 154 ++ .../associative/map/map.access/empty.pass.cpp | 43 + .../associative/map/map.access/index_key.pass.cpp | 105 ++ .../map/map.access/index_rv_key.pass.cpp | 58 + .../map/map.access/index_tuple.pass.cpp | 33 + .../associative/map/map.access/iterator.pass.cpp | 227 +++ .../associative/map/map.access/max_size.pass.cpp | 35 + .../associative/map/map.access/size.pass.cpp | 59 + .../associative/map/map.cons/alloc.pass.cpp | 42 + .../map/map.cons/assign_initializer_list.pass.cpp | 75 + .../associative/map/map.cons/compare.pass.cpp | 40 + .../map/map.cons/compare_alloc.pass.cpp | 45 + .../associative/map/map.cons/copy.pass.cpp | 131 ++ .../associative/map/map.cons/copy_alloc.pass.cpp | 95 ++ .../associative/map/map.cons/copy_assign.pass.cpp | 182 +++ .../associative/map/map.cons/default.pass.cpp | 40 + .../map/map.cons/default_noexcept.pass.cpp | 53 + .../map/map.cons/default_recursive.pass.cpp | 29 + .../map/map.cons/dtor_noexcept.pass.cpp | 51 + .../map/map.cons/initializer_list.pass.cpp | 67 + .../map/map.cons/initializer_list_compare.pass.cpp | 69 + .../initializer_list_compare_alloc.pass.cpp | 100 ++ .../associative/map/map.cons/iter_iter.pass.cpp | 68 + .../map/map.cons/iter_iter_comp.pass.cpp | 73 + .../map/map.cons/iter_iter_comp_alloc.pass.cpp | 108 ++ .../associative/map/map.cons/move.pass.cpp | 120 ++ .../associative/map/map.cons/move_alloc.pass.cpp | 186 +++ .../associative/map/map.cons/move_assign.pass.cpp | 190 +++ .../map/map.cons/move_assign_noexcept.pass.cpp | 53 + .../map/map.cons/move_noexcept.pass.cpp | 51 + .../associative/map/map.modifiers/clear.pass.cpp | 63 + .../associative/map/map.modifiers/emplace.pass.cpp | 165 ++ .../map/map.modifiers/emplace_hint.pass.cpp | 160 ++ .../map/map.modifiers/erase_iter.pass.cpp | 237 +++ .../map/map.modifiers/erase_iter_iter.pass.cpp | 157 ++ .../map/map.modifiers/erase_key.pass.cpp | 275 ++++ .../map/map.modifiers/insert_cv.pass.cpp | 89 ++ .../map.modifiers/insert_initializer_list.pass.cpp | 71 + .../map/map.modifiers/insert_iter_cv.pass.cpp | 81 + .../map/map.modifiers/insert_iter_iter.pass.cpp | 77 + .../map/map.modifiers/insert_iter_rv.pass.cpp | 87 ++ .../map/map.modifiers/insert_rv.pass.cpp | 93 ++ .../associative/map/map.ops/count.pass.cpp | 173 ++ .../associative/map/map.ops/equal_range.pass.cpp | 437 ++++++ .../associative/map/map.ops/find.pass.cpp | 240 +++ .../associative/map/map.ops/lower_bound.pass.cpp | 336 ++++ .../associative/map/map.ops/upper_bound.pass.cpp | 335 ++++ .../map/map.special/member_swap.pass.cpp | 201 +++ .../map/map.special/non_member_swap.pass.cpp | 306 ++++ .../map/map.special/swap_noexcept.pass.cpp | 60 + .../std/containers/associative/map/types.pass.cpp | 70 + .../containers/associative/map/version.pass.cpp | 20 + .../containers/associative/multimap/empty.pass.cpp | 43 + .../associative/multimap/iterator.pass.cpp | 231 +++ .../associative/multimap/max_size.pass.cpp | 35 + .../multimap/multimap.cons/alloc.pass.cpp | 42 + .../multimap.cons/assign_initializer_list.pass.cpp | 85 + .../multimap/multimap.cons/compare.pass.cpp | 40 + .../multimap/multimap.cons/compare_alloc.pass.cpp | 45 + .../multimap/multimap.cons/copy.pass.cpp | 104 ++ .../multimap/multimap.cons/copy_alloc.pass.cpp | 77 + .../multimap/multimap.cons/copy_assign.pass.cpp | 125 ++ .../multimap/multimap.cons/default.pass.cpp | 40 + .../multimap.cons/default_noexcept.pass.cpp | 53 + .../multimap/multimap.cons/dtor_noexcept.pass.cpp | 51 + .../multimap.cons/initializer_list.pass.cpp | 83 + .../initializer_list_compare.pass.cpp | 91 ++ .../initializer_list_compare_alloc.pass.cpp | 129 ++ .../multimap/multimap.cons/iter_iter.pass.cpp | 112 ++ .../multimap/multimap.cons/iter_iter_comp.pass.cpp | 86 + .../multimap.cons/iter_iter_comp_alloc.pass.cpp | 91 ++ .../multimap/multimap.cons/move.pass.cpp | 132 ++ .../multimap/multimap.cons/move_alloc.pass.cpp | 186 +++ .../multimap/multimap.cons/move_assign.pass.cpp | 190 +++ .../multimap.cons/move_assign_noexcept.pass.cpp | 53 + .../multimap/multimap.cons/move_noexcept.pass.cpp | 51 + .../multimap/multimap.modifiers/clear.pass.cpp | 63 + .../multimap/multimap.modifiers/emplace.pass.cpp | 150 ++ .../multimap.modifiers/emplace_hint.pass.cpp | 160 ++ .../multimap.modifiers/erase_iter.pass.cpp | 279 ++++ .../multimap.modifiers/erase_iter_iter.pass.cpp | 157 ++ .../multimap/multimap.modifiers/erase_key.pass.cpp | 153 ++ .../multimap/multimap.modifiers/insert_cv.pass.cpp | 81 + .../insert_initializer_list.pass.cpp | 91 ++ .../multimap.modifiers/insert_iter_cv.pass.cpp | 81 + .../multimap.modifiers/insert_iter_iter.pass.cpp | 101 ++ .../multimap.modifiers/insert_iter_rv.pass.cpp | 87 ++ .../multimap/multimap.modifiers/insert_rv.pass.cpp | 85 + .../multimap/multimap.ops/count.pass.cpp | 159 ++ .../multimap/multimap.ops/equal_range.pass.cpp | 264 ++++ .../multimap/multimap.ops/find.pass.cpp | 209 +++ .../multimap/multimap.ops/lower_bound.pass.cpp | 221 +++ .../multimap/multimap.ops/upper_bound.pass.cpp | 221 +++ .../multimap/multimap.special/member_swap.pass.cpp | 200 +++ .../multimap.special/non_member_swap.pass.cpp | 305 ++++ .../multimap.special/swap_noexcept.pass.cpp | 60 + .../containers/associative/multimap/scary.pass.cpp | 24 + .../containers/associative/multimap/size.pass.cpp | 59 + .../containers/associative/multimap/types.pass.cpp | 70 + .../containers/associative/multiset/clear.pass.cpp | 63 + .../containers/associative/multiset/count.pass.cpp | 160 ++ .../associative/multiset/emplace.pass.cpp | 83 + .../associative/multiset/emplace_hint.pass.cpp | 83 + .../containers/associative/multiset/empty.pass.cpp | 43 + .../associative/multiset/equal_range.pass.cpp | 263 ++++ .../associative/multiset/erase_iter.pass.cpp | 181 +++ .../associative/multiset/erase_iter_iter.pass.cpp | 141 ++ .../associative/multiset/erase_key.pass.cpp | 129 ++ .../containers/associative/multiset/find.pass.cpp | 240 +++ .../associative/multiset/insert_cv.pass.cpp | 73 + .../multiset/insert_initializer_list.pass.cpp | 61 + .../associative/multiset/insert_iter_cv.pass.cpp | 73 + .../associative/multiset/insert_iter_iter.pass.cpp | 85 + .../associative/multiset/insert_iter_rv.pass.cpp | 76 + .../associative/multiset/insert_rv.pass.cpp | 76 + .../associative/multiset/iterator.pass.cpp | 215 +++ .../associative/multiset/lower_bound.pass.cpp | 223 +++ .../associative/multiset/max_size.pass.cpp | 35 + .../multiset/multiset.cons/alloc.pass.cpp | 29 + .../multiset.cons/assign_initializer_list.pass.cpp | 57 + .../multiset/multiset.cons/compare.pass.cpp | 28 + .../multiset/multiset.cons/compare_alloc.pass.cpp | 31 + .../multiset/multiset.cons/copy.pass.cpp | 118 ++ .../multiset/multiset.cons/copy_alloc.pass.cpp | 68 + .../multiset/multiset.cons/copy_assign.pass.cpp | 138 ++ .../multiset/multiset.cons/default.pass.cpp | 40 + .../multiset.cons/default_noexcept.pass.cpp | 53 + .../multiset/multiset.cons/dtor_noexcept.pass.cpp | 51 + .../multiset.cons/initializer_list.pass.cpp | 73 + .../initializer_list_compare.pass.cpp | 38 + .../initializer_list_compare_alloc.pass.cpp | 41 + .../multiset/multiset.cons/iter_iter.pass.cpp | 83 + .../multiset.cons/iter_iter_alloc.pass.cpp | 92 ++ .../multiset/multiset.cons/iter_iter_comp.pass.cpp | 53 + .../multiset/multiset.cons/move.pass.cpp | 119 ++ .../multiset/multiset.cons/move_alloc.pass.cpp | 141 ++ .../multiset/multiset.cons/move_assign.pass.cpp | 186 +++ .../multiset.cons/move_assign_noexcept.pass.cpp | 53 + .../multiset/multiset.cons/move_noexcept.pass.cpp | 51 + .../multiset/multiset.special/member_swap.pass.cpp | 201 +++ .../multiset.special/non_member_swap.pass.cpp | 177 +++ .../multiset.special/swap_noexcept.pass.cpp | 60 + .../containers/associative/multiset/scary.pass.cpp | 24 + .../containers/associative/multiset/size.pass.cpp | 59 + .../containers/associative/multiset/types.pass.cpp | 70 + .../associative/multiset/upper_bound.pass.cpp | 222 +++ .../std/containers/associative/set/clear.pass.cpp | 63 + .../std/containers/associative/set/count.pass.cpp | 168 ++ .../containers/associative/set/emplace.pass.cpp | 90 ++ .../associative/set/emplace_hint.pass.cpp | 83 + .../std/containers/associative/set/empty.pass.cpp | 43 + .../associative/set/equal_range.pass.cpp | 370 +++++ .../containers/associative/set/erase_iter.pass.cpp | 181 +++ .../associative/set/erase_iter_iter.pass.cpp | 141 ++ .../containers/associative/set/erase_key.pass.cpp | 203 +++ .../std/containers/associative/set/find.pass.cpp | 240 +++ .../containers/associative/set/insert_cv.pass.cpp | 81 + .../set/insert_initializer_list.pass.cpp | 61 + .../associative/set/insert_iter_cv.pass.cpp | 73 + .../associative/set/insert_iter_iter.pass.cpp | 73 + .../associative/set/insert_iter_rv.pass.cpp | 76 + .../containers/associative/set/insert_rv.pass.cpp | 84 + .../containers/associative/set/iterator.pass.cpp | 211 +++ .../associative/set/lower_bound.pass.cpp | 337 ++++ .../containers/associative/set/max_size.pass.cpp | 35 + .../associative/set/set.cons/alloc.pass.cpp | 29 + .../set/set.cons/assign_initializer_list.pass.cpp | 57 + .../associative/set/set.cons/compare.pass.cpp | 28 + .../set/set.cons/compare_alloc.pass.cpp | 31 + .../associative/set/set.cons/copy.pass.cpp | 94 ++ .../associative/set/set.cons/copy_alloc.pass.cpp | 56 + .../associative/set/set.cons/copy_assign.pass.cpp | 109 ++ .../associative/set/set.cons/default.pass.cpp | 40 + .../set/set.cons/default_noexcept.pass.cpp | 53 + .../set/set.cons/dtor_noexcept.pass.cpp | 51 + .../set/set.cons/initializer_list.pass.cpp | 55 + .../set/set.cons/initializer_list_compare.pass.cpp | 38 + .../initializer_list_compare_alloc.pass.cpp | 63 + .../associative/set/set.cons/iter_iter.pass.cpp | 71 + .../set/set.cons/iter_iter_alloc.pass.cpp | 84 + .../set/set.cons/iter_iter_comp.pass.cpp | 47 + .../associative/set/set.cons/move.pass.cpp | 107 ++ .../associative/set/set.cons/move_alloc.pass.cpp | 141 ++ .../associative/set/set.cons/move_assign.pass.cpp | 186 +++ .../set/set.cons/move_assign_noexcept.pass.cpp | 53 + .../set/set.cons/move_noexcept.pass.cpp | 51 + .../set/set.special/member_swap.pass.cpp | 201 +++ .../set/set.special/non_member_swap.pass.cpp | 177 +++ .../set/set.special/swap_noexcept.pass.cpp | 60 + .../std/containers/associative/set/size.pass.cpp | 59 + .../std/containers/associative/set/types.pass.cpp | 70 + .../associative/set/upper_bound.pass.cpp | 336 ++++ .../containers/associative/set/version.pass.cpp | 20 + .../associative/tree_balance_after_insert.pass.cpp | 1616 +++++++++++++++++++ .../associative/tree_left_rotate.pass.cpp | 98 ++ .../containers/associative/tree_remove.pass.cpp | 1648 ++++++++++++++++++++ .../associative/tree_right_rotate.pass.cpp | 98 ++ .../container.adaptors/nothing_to_do.pass.cpp | 12 + .../priqueue.cons.alloc/ctor_alloc.pass.cpp | 48 + .../priqueue.cons.alloc/ctor_comp_alloc.pass.cpp | 48 + .../ctor_comp_cont_alloc.pass.cpp | 62 + .../ctor_comp_rcont_alloc.pass.cpp | 61 + .../priqueue.cons.alloc/ctor_copy_alloc.pass.cpp | 58 + .../priqueue.cons.alloc/ctor_move_alloc.pass.cpp | 68 + .../priqueue.cons/assign_copy.pass.cpp | 36 + .../priqueue.cons/assign_move.pass.cpp | 42 + .../priqueue.cons/ctor_comp.pass.cpp | 27 + .../priqueue.cons/ctor_comp_container.pass.cpp | 34 + .../priqueue.cons/ctor_comp_rcontainer.pass.cpp | 40 + .../priqueue.cons/ctor_copy.pass.cpp | 35 + .../priqueue.cons/ctor_default.pass.cpp | 27 + .../priqueue.cons/ctor_iter_iter.pass.cpp | 25 + .../priqueue.cons/ctor_iter_iter_comp.pass.cpp | 27 + .../ctor_iter_iter_comp_cont.pass.cpp | 27 + .../ctor_iter_iter_comp_rcont.pass.cpp | 32 + .../priqueue.cons/ctor_move.pass.cpp | 41 + .../priqueue.cons/default_noexcept.pass.cpp | 31 + .../priqueue.cons/dtor_noexcept.pass.cpp | 27 + .../priqueue.cons/move_assign_noexcept.pass.cpp | 31 + .../priqueue.cons/move_noexcept.pass.cpp | 31 + .../priqueue.members/emplace.pass.cpp | 32 + .../priority.queue/priqueue.members/empty.pass.cpp | 27 + .../priority.queue/priqueue.members/pop.pass.cpp | 34 + .../priority.queue/priqueue.members/push.pass.cpp | 28 + .../priqueue.members/push_rvalue.pass.cpp | 32 + .../priority.queue/priqueue.members/size.pass.cpp | 27 + .../priority.queue/priqueue.members/swap.pass.cpp | 30 + .../priority.queue/priqueue.members/top.pass.cpp | 28 + .../priority.queue/priqueue.special/swap.pass.cpp | 32 + .../priqueue.special/swap_noexcept.pass.cpp | 32 + .../priority.queue/types.pass.cpp | 60 + .../queue/queue.cons.alloc/ctor_alloc.pass.cpp | 38 + .../queue.cons.alloc/ctor_container_alloc.pass.cpp | 57 + .../queue.cons.alloc/ctor_queue_alloc.pass.cpp | 52 + .../ctor_rcontainer_alloc.pass.cpp | 59 + .../queue.cons.alloc/ctor_rqueue_alloc.pass.cpp | 60 + .../queue/queue.cons/ctor_container.pass.cpp | 37 + .../queue/queue.cons/ctor_copy.pass.cpp | 32 + .../queue/queue.cons/ctor_default.pass.cpp | 28 + .../queue/queue.cons/ctor_move.pass.cpp | 41 + .../queue/queue.cons/ctor_rcontainer.pass.cpp | 39 + .../queue/queue.cons/default_noexcept.pass.cpp | 30 + .../queue/queue.cons/dtor_noexcept.pass.cpp | 27 + .../queue/queue.cons/move_assign_noexcept.pass.cpp | 30 + .../queue/queue.cons/move_noexcept.pass.cpp | 30 + .../queue/queue.defn/assign_copy.pass.cpp | 33 + .../queue/queue.defn/assign_move.pass.cpp | 42 + .../queue/queue.defn/back.pass.cpp | 26 + .../queue/queue.defn/back_const.pass.cpp | 27 + .../queue/queue.defn/emplace.pass.cpp | 30 + .../queue/queue.defn/empty.pass.cpp | 25 + .../queue/queue.defn/front.pass.cpp | 26 + .../queue/queue.defn/front_const.pass.cpp | 27 + .../queue/queue.defn/pop.pass.cpp | 37 + .../queue/queue.defn/push.pass.cpp | 32 + .../queue/queue.defn/push_rv.pass.cpp | 36 + .../queue/queue.defn/size.pass.cpp | 23 + .../queue/queue.defn/swap.pass.cpp | 36 + .../queue/queue.defn/types.pass.cpp | 58 + .../container.adaptors/queue/queue.ops/eq.pass.cpp | 40 + .../container.adaptors/queue/queue.ops/lt.pass.cpp | 45 + .../queue/queue.special/swap.pass.cpp | 37 + .../queue/queue.special/swap_noexcept.pass.cpp | 31 + .../container.adaptors/queue/version.pass.cpp | 20 + .../stack/stack.cons.alloc/ctor_alloc.pass.cpp | 38 + .../stack.cons.alloc/ctor_container_alloc.pass.cpp | 57 + .../stack.cons.alloc/ctor_copy_alloc.pass.cpp | 52 + .../ctor_rcontainer_alloc.pass.cpp | 59 + .../stack.cons.alloc/ctor_rqueue_alloc.pass.cpp | 60 + .../stack/stack.cons/ctor_container.pass.cpp | 37 + .../stack/stack.cons/ctor_copy.pass.cpp | 32 + .../stack/stack.cons/ctor_default.pass.cpp | 28 + .../stack/stack.cons/ctor_move.pass.cpp | 41 + .../stack/stack.cons/ctor_rcontainer.pass.cpp | 39 + .../stack/stack.cons/default_noexcept.pass.cpp | 30 + .../stack/stack.cons/dtor_noexcept.pass.cpp | 27 + .../stack/stack.cons/move_assign_noexcept.pass.cpp | 30 + .../stack/stack.cons/move_noexcept.pass.cpp | 30 + .../stack/stack.defn/assign_copy.pass.cpp | 33 + .../stack/stack.defn/assign_move.pass.cpp | 42 + .../stack/stack.defn/emplace.pass.cpp | 29 + .../stack/stack.defn/empty.pass.cpp | 25 + .../stack/stack.defn/pop.pass.cpp | 34 + .../stack/stack.defn/push.pass.cpp | 29 + .../stack/stack.defn/push_rv.pass.cpp | 33 + .../stack/stack.defn/size.pass.cpp | 23 + .../stack/stack.defn/swap.pass.cpp | 36 + .../stack/stack.defn/top.pass.cpp | 26 + .../stack/stack.defn/top_const.pass.cpp | 27 + .../stack/stack.defn/types.pass.cpp | 59 + .../container.adaptors/stack/stack.ops/eq.pass.cpp | 40 + .../container.adaptors/stack/stack.ops/lt.pass.cpp | 45 + .../stack/stack.special/swap.pass.cpp | 37 + .../stack/stack.special/swap_noexcept.pass.cpp | 31 + .../container.adaptors/stack/version.pass.cpp | 20 + .../nothing_to_do.pass.cpp | 12 + .../associative.reqmts/nothing_to_do.pass.cpp | 12 + .../nothing_to_do.pass.cpp | 12 + .../nothing_to_do.pass.cpp | 12 + .../container.requirements/nothing_to_do.pass.cpp | 12 + .../sequence.reqmts/nothing_to_do.pass.cpp | 12 + .../unord.req/nothing_to_do.pass.cpp | 12 + .../unord.req.except/nothing_to_do.pass.cpp | 12 + .../containers.general/nothing_to_do.pass.cpp | 12 + libcxx/test/std/containers/nothing_to_do.pass.cpp | 12 + .../sequences/array/array.cons/default.pass.cpp | 31 + .../array/array.cons/initializer_list.pass.cpp | 34 + .../sequences/array/array.data/data.pass.cpp | 35 + .../sequences/array/array.data/data_const.pass.cpp | 35 + .../sequences/array/array.fill/fill.pass.cpp | 36 + .../sequences/array/array.size/size.pass.cpp | 53 + .../sequences/array/array.special/swap.pass.cpp | 43 + .../sequences/array/array.swap/swap.pass.cpp | 43 + .../sequences/array/array.tuple/get.fail.cpp | 25 + .../sequences/array/array.tuple/get.pass.cpp | 52 + .../sequences/array/array.tuple/get_const.pass.cpp | 37 + .../sequences/array/array.tuple/get_rv.pass.cpp | 29 + .../array/array.tuple/tuple_element.pass.cpp | 33 + .../array/array.tuple/tuple_size.pass.cpp | 28 + .../array/array.zero/tested_elsewhere.pass.cpp | 18 + .../std/containers/sequences/array/at.pass.cpp | 67 + .../std/containers/sequences/array/begin.pass.cpp | 32 + .../containers/sequences/array/front_back.pass.cpp | 62 + .../containers/sequences/array/indexing.pass.cpp | 60 + .../containers/sequences/array/iterators.pass.cpp | 110 ++ .../std/containers/sequences/array/types.pass.cpp | 62 + .../containers/sequences/array/version.pass.cpp | 20 + .../sequences/deque/deque.capacity/access.pass.cpp | 91 ++ .../deque/deque.capacity/resize_size.pass.cpp | 86 + .../deque.capacity/resize_size_value.pass.cpp | 86 + .../deque/deque.capacity/shrink_to_fit.pass.cpp | 77 + .../sequences/deque/deque.cons/alloc.pass.cpp | 38 + .../deque.cons/assign_initializer_list.pass.cpp | 43 + .../deque/deque.cons/assign_iter_iter.pass.cpp | 109 ++ .../deque/deque.cons/assign_size_value.pass.cpp | 85 + .../sequences/deque/deque.cons/copy.pass.cpp | 61 + .../sequences/deque/deque.cons/copy_alloc.pass.cpp | 51 + .../sequences/deque/deque.cons/default.pass.cpp | 41 + .../deque/deque.cons/default_noexcept.pass.cpp | 50 + .../deque/deque.cons/dtor_noexcept.pass.cpp | 52 + .../deque/deque.cons/initializer_list.pass.cpp | 41 + .../deque.cons/initializer_list_alloc.pass.cpp | 44 + .../sequences/deque/deque.cons/iter_iter.pass.cpp | 62 + .../deque/deque.cons/iter_iter_alloc.pass.cpp | 51 + .../sequences/deque/deque.cons/move.pass.cpp | 72 + .../sequences/deque/deque.cons/move_alloc.pass.cpp | 87 ++ .../deque/deque.cons/move_assign.pass.cpp | 91 ++ .../deque/deque.cons/move_assign_noexcept.pass.cpp | 52 + .../deque/deque.cons/move_noexcept.pass.cpp | 50 + .../sequences/deque/deque.cons/op_equal.pass.cpp | 63 + .../deque.cons/op_equal_initializer_list.pass.cpp | 43 + .../sequences/deque/deque.cons/size.pass.cpp | 113 ++ .../sequences/deque/deque.cons/size_value.pass.cpp | 51 + .../deque/deque.cons/size_value_alloc.pass.cpp | 67 + .../deque/deque.modifiers/emplace.pass.cpp | 112 ++ .../deque/deque.modifiers/emplace_back.pass.cpp | 87 ++ .../deque/deque.modifiers/emplace_front.pass.cpp | 87 ++ .../deque/deque.modifiers/erase_iter.pass.cpp | 90 ++ .../deque/deque.modifiers/erase_iter_iter.pass.cpp | 96 ++ .../insert_iter_initializer_list.pass.cpp | 63 + .../deque.modifiers/insert_iter_iter.pass.cpp | 256 +++ .../deque/deque.modifiers/insert_rvalue.pass.cpp | 118 ++ .../deque.modifiers/insert_size_value.pass.cpp | 159 ++ .../deque/deque.modifiers/insert_value.pass.cpp | 139 ++ .../deque/deque.modifiers/pop_back.pass.cpp | 84 + .../deque/deque.modifiers/pop_front.pass.cpp | 84 + .../deque/deque.modifiers/push_back.pass.cpp | 73 + .../push_back_exception_safety.pass.cpp | 81 + .../deque.modifiers/push_back_rvalue.pass.cpp | 80 + .../deque/deque.modifiers/push_front.pass.cpp | 83 + .../push_front_exception_safety.pass.cpp | 81 + .../deque.modifiers/push_front_rvalue.pass.cpp | 90 ++ .../sequences/deque/deque.special/copy.pass.cpp | 88 ++ .../deque/deque.special/copy_backward.pass.cpp | 87 ++ .../sequences/deque/deque.special/move.pass.cpp | 87 ++ .../deque/deque.special/move_backward.pass.cpp | 87 ++ .../sequences/deque/deque.special/swap.pass.cpp | 110 ++ .../deque/deque.special/swap_noexcept.pass.cpp | 60 + .../containers/sequences/deque/iterators.pass.cpp | 79 + .../std/containers/sequences/deque/types.pass.cpp | 90 ++ .../containers/sequences/deque/version.pass.cpp | 20 + .../dynarray/dynarray.cons/alloc.pass.cpp | 86 + .../dynarray/dynarray.cons/default.pass.cpp | 95 ++ .../dynarray/dynarray.data/default.pass.cpp | 67 + .../dynarray/dynarray.mutate/default.pass.cpp | 48 + .../dynarray/dynarray.overview/at.pass.cpp | 94 ++ .../dynarray/dynarray.overview/begin_end.pass.cpp | 108 ++ .../dynarray/dynarray.overview/capacity.pass.cpp | 57 + .../dynarray/dynarray.overview/front_back.pass.cpp | 68 + .../dynarray/dynarray.overview/indexing.pass.cpp | 71 + .../dynarray/dynarray.traits/default.pass.cpp | 31 + .../dynarray/dynarray.zero/default.pass.cpp | 50 + .../sequences/dynarray/nothing_to_do.pass.cpp | 12 + .../forwardlist/forwardlist.access/front.pass.cpp | 61 + .../forwardlist/forwardlist.cons/alloc.fail.cpp | 30 + .../forwardlist/forwardlist.cons/alloc.pass.cpp | 41 + .../forwardlist.cons/assign_copy.pass.cpp | 146 ++ .../forwardlist.cons/assign_init.pass.cpp | 70 + .../forwardlist.cons/assign_move.pass.cpp | 199 +++ .../forwardlist.cons/assign_op_init.pass.cpp | 70 + .../forwardlist.cons/assign_range.pass.cpp | 78 + .../forwardlist.cons/assign_size_value.pass.cpp | 68 + .../forwardlist/forwardlist.cons/copy.pass.cpp | 69 + .../forwardlist.cons/copy_alloc.pass.cpp | 67 + .../forwardlist/forwardlist.cons/default.pass.cpp | 41 + .../forwardlist.cons/default_noexcept.pass.cpp | 50 + .../forwardlist.cons/default_recursive.pass.cpp | 25 + .../forwardlist.cons/dtor_noexcept.pass.cpp | 52 + .../forwardlist/forwardlist.cons/init.pass.cpp | 43 + .../forwardlist.cons/init_alloc.pass.cpp | 48 + .../forwardlist/forwardlist.cons/move.pass.cpp | 73 + .../forwardlist.cons/move_alloc.pass.cpp | 73 + .../forwardlist.cons/move_assign_noexcept.pass.cpp | 52 + .../forwardlist.cons/move_noexcept.pass.cpp | 50 + .../forwardlist/forwardlist.cons/range.pass.cpp | 48 + .../forwardlist.cons/range_alloc.pass.cpp | 54 + .../forwardlist/forwardlist.cons/size.fail.cpp | 35 + .../forwardlist/forwardlist.cons/size.pass.cpp | 66 + .../forwardlist.cons/size_value.pass.cpp | 45 + .../forwardlist.cons/size_value_alloc.pass.cpp | 50 + .../forwardlist.iter/before_begin.pass.cpp | 104 ++ .../forwardlist.iter/iterators.pass.cpp | 145 ++ .../forwardlist.modifiers/clear.pass.cpp | 62 + .../forwardlist.modifiers/emplace_after.pass.cpp | 89 ++ .../forwardlist.modifiers/emplace_front.pass.cpp | 50 + .../erase_after_many.pass.cpp | 155 ++ .../forwardlist.modifiers/erase_after_one.pass.cpp | 97 ++ .../insert_after_const.pass.cpp | 87 ++ .../insert_after_init.pass.cpp | 75 + .../insert_after_range.pass.cpp | 80 + .../forwardlist.modifiers/insert_after_rv.pass.cpp | 90 ++ .../insert_after_size_value.pass.cpp | 73 + .../forwardlist.modifiers/pop_front.pass.cpp | 78 + .../push_front_const.pass.cpp | 47 + .../push_front_exception_safety.pass.cpp | 73 + .../forwardlist.modifiers/push_front_rv.pass.cpp | 50 + .../forwardlist.modifiers/resize_size.pass.cpp | 114 ++ .../resize_size_value.pass.cpp | 84 + .../forwardlist/forwardlist.ops/merge.pass.cpp | 48 + .../forwardlist.ops/merge_pred.pass.cpp | 49 + .../forwardlist/forwardlist.ops/remove.pass.cpp | 155 ++ .../forwardlist/forwardlist.ops/remove_if.pass.cpp | 155 ++ .../forwardlist/forwardlist.ops/reverse.pass.cpp | 42 + .../forwardlist/forwardlist.ops/sort.pass.cpp | 47 + .../forwardlist/forwardlist.ops/sort_pred.pass.cpp | 48 + .../forwardlist.ops/splice_after_flist.pass.cpp | 75 + .../forwardlist.ops/splice_after_one.pass.cpp | 140 ++ .../forwardlist.ops/splice_after_range.pass.cpp | 169 ++ .../forwardlist/forwardlist.ops/unique.pass.cpp | 120 ++ .../forwardlist.ops/unique_pred.pass.cpp | 125 ++ .../forwardlist/forwardlist.spec/equal.pass.cpp | 60 + .../forwardlist.spec/member_swap.pass.cpp | 259 +++ .../forwardlist.spec/non_member_swap.pass.cpp | 260 +++ .../forwardlist.spec/relational.pass.cpp | 65 + .../forwardlist.spec/swap_noexcept.pass.cpp | 60 + .../sequences/forwardlist/max_size.pass.cpp | 35 + .../sequences/forwardlist/types.pass.cpp | 60 + .../sequences/forwardlist/version.pass.cpp | 20 + .../std/containers/sequences/list/db_back.pass.cpp | 56 + .../containers/sequences/list/db_cback.pass.cpp | 52 + .../containers/sequences/list/db_cfront.pass.cpp | 52 + .../containers/sequences/list/db_front.pass.cpp | 56 + .../sequences/list/db_iterators_6.pass.cpp | 58 + .../sequences/list/db_iterators_7.pass.cpp | 58 + .../sequences/list/db_iterators_8.pass.cpp | 54 + .../sequences/list/db_iterators_9.pass.cpp | 67 + .../containers/sequences/list/iterators.pass.cpp | 159 ++ .../list/list.capacity/resize_size.pass.cpp | 81 + .../list/list.capacity/resize_size_value.pass.cpp | 53 + .../sequences/list/list.cons/assign_copy.pass.cpp | 44 + .../list.cons/assign_initializer_list.pass.cpp | 45 + .../sequences/list/list.cons/assign_move.pass.cpp | 82 + .../sequences/list/list.cons/copy.pass.cpp | 54 + .../sequences/list/list.cons/copy_alloc.pass.cpp | 42 + .../sequences/list/list.cons/default.pass.cpp | 58 + .../list/list.cons/default_noexcept.pass.cpp | 50 + .../list/list.cons/default_stack_alloc.pass.cpp | 48 + .../list/list.cons/dtor_noexcept.pass.cpp | 52 + .../list/list.cons/initializer_list.pass.cpp | 43 + .../list/list.cons/initializer_list_alloc.pass.cpp | 46 + .../list/list.cons/input_iterator.pass.cpp | 77 + .../sequences/list/list.cons/move.pass.cpp | 74 + .../sequences/list/list.cons/move_alloc.pass.cpp | 78 + .../list/list.cons/move_assign_noexcept.pass.cpp | 52 + .../list/list.cons/move_noexcept.pass.cpp | 50 + .../list.cons/op_equal_initializer_list.pass.cpp | 44 + .../sequences/list/list.cons/size_type.pass.cpp | 103 ++ .../list/list.cons/size_value_alloc.pass.cpp | 79 + .../sequences/list/list.modifiers/clear.pass.cpp | 35 + .../sequences/list/list.modifiers/emplace.pass.cpp | 88 ++ .../list/list.modifiers/emplace_back.pass.cpp | 66 + .../list/list.modifiers/emplace_front.pass.cpp | 66 + .../list/list.modifiers/erase_iter.pass.cpp | 65 + .../list/list.modifiers/erase_iter_db1.pass.cpp | 51 + .../list/list.modifiers/erase_iter_db2.pass.cpp | 53 + .../list/list.modifiers/erase_iter_iter.pass.cpp | 84 + .../list.modifiers/erase_iter_iter_db1.pass.cpp | 51 + .../list.modifiers/erase_iter_iter_db2.pass.cpp | 51 + .../list.modifiers/erase_iter_iter_db3.pass.cpp | 51 + .../list.modifiers/erase_iter_iter_db4.pass.cpp | 49 + .../insert_iter_initializer_list.pass.cpp | 67 + .../list.modifiers/insert_iter_iter_iter.pass.cpp | 185 +++ .../list.modifiers/insert_iter_rvalue.pass.cpp | 68 + .../list.modifiers/insert_iter_size_value.pass.cpp | 106 ++ .../list/list.modifiers/insert_iter_value.pass.cpp | 112 ++ .../list/list.modifiers/pop_back.pass.cpp | 55 + .../list/list.modifiers/pop_front.pass.cpp | 43 + .../list/list.modifiers/push_back.pass.cpp | 37 + .../push_back_exception_safety.pass.cpp | 73 + .../list/list.modifiers/push_back_rvalue.pass.cpp | 46 + .../list/list.modifiers/push_front.pass.cpp | 37 + .../push_front_exception_safety.pass.cpp | 73 + .../list/list.modifiers/push_front_rvalue.pass.cpp | 46 + .../sequences/list/list.ops/merge.pass.cpp | 41 + .../sequences/list/list.ops/merge_comp.pass.cpp | 42 + .../sequences/list/list.ops/remove.pass.cpp | 69 + .../sequences/list/list.ops/remove_if.pass.cpp | 64 + .../sequences/list/list.ops/reverse.pass.cpp | 37 + .../sequences/list/list.ops/sort.pass.cpp | 37 + .../sequences/list/list.ops/sort_comp.pass.cpp | 38 + .../list/list.ops/splice_pos_list.pass.cpp | 803 ++++++++++ .../list/list.ops/splice_pos_list_iter.pass.cpp | 357 +++++ .../list.ops/splice_pos_list_iter_iter.pass.cpp | 237 +++ .../sequences/list/list.ops/unique.pass.cpp | 37 + .../sequences/list/list.ops/unique_pred.pass.cpp | 42 + .../sequences/list/list.special/db_swap_1.pass.cpp | 59 + .../sequences/list/list.special/swap.pass.cpp | 146 ++ .../list/list.special/swap_noexcept.pass.cpp | 60 + .../std/containers/sequences/list/types.pass.cpp | 46 + .../std/containers/sequences/list/version.pass.cpp | 20 + .../containers/sequences/nothing_to_do.pass.cpp | 12 + .../sequences/vector.bool/assign_copy.pass.cpp | 44 + .../vector.bool/assign_initializer_list.pass.cpp | 43 + .../sequences/vector.bool/assign_move.pass.cpp | 81 + .../sequences/vector.bool/capacity.pass.cpp | 44 + .../vector.bool/construct_default.pass.cpp | 59 + .../vector.bool/construct_iter_iter.pass.cpp | 48 + .../vector.bool/construct_iter_iter_alloc.pass.cpp | 55 + .../sequences/vector.bool/construct_size.pass.cpp | 64 + .../vector.bool/construct_size_value.pass.cpp | 37 + .../construct_size_value_alloc.pass.cpp | 39 + .../containers/sequences/vector.bool/copy.pass.cpp | 65 + .../sequences/vector.bool/copy_alloc.pass.cpp | 62 + .../vector.bool/default_noexcept.pass.cpp | 49 + .../sequences/vector.bool/dtor_noexcept.pass.cpp | 51 + .../sequences/vector.bool/emplace.pass.cpp | 68 + .../sequences/vector.bool/emplace_back.pass.cpp | 57 + .../sequences/vector.bool/erase_iter.pass.cpp | 65 + .../sequences/vector.bool/erase_iter_iter.pass.cpp | 85 + .../containers/sequences/vector.bool/find.pass.cpp | 40 + .../vector.bool/initializer_list.pass.cpp | 41 + .../vector.bool/initializer_list_alloc.pass.cpp | 44 + .../insert_iter_initializer_list.pass.cpp | 65 + .../vector.bool/insert_iter_iter_iter.pass.cpp | 126 ++ .../vector.bool/insert_iter_size_value.pass.cpp | 81 + .../vector.bool/insert_iter_value.pass.cpp | 77 + .../sequences/vector.bool/iterators.pass.cpp | 123 ++ .../containers/sequences/vector.bool/move.pass.cpp | 64 + .../sequences/vector.bool/move_alloc.pass.cpp | 77 + .../vector.bool/move_assign_noexcept.pass.cpp | 51 + .../sequences/vector.bool/move_noexcept.pass.cpp | 49 + .../vector.bool/op_equal_initializer_list.pass.cpp | 43 + .../sequences/vector.bool/push_back.pass.cpp | 48 + .../sequences/vector.bool/reserve.pass.cpp | 54 + .../sequences/vector.bool/resize_size.pass.cpp | 50 + .../vector.bool/resize_size_value.pass.cpp | 52 + .../sequences/vector.bool/shrink_to_fit.pass.cpp | 38 + .../containers/sequences/vector.bool/swap.pass.cpp | 98 ++ .../sequences/vector.bool/swap_noexcept.pass.cpp | 59 + .../sequences/vector.bool/types.pass.cpp | 72 + .../sequences/vector.bool/vector_bool.pass.cpp | 51 + .../std/containers/sequences/vector/asan.pass.cpp | 52 + .../containers/sequences/vector/asan_throw.pass.cc | 198 +++ .../sequences/vector/const_value_type.pass.cpp | 22 + .../containers/sequences/vector/db_back.pass.cpp | 56 + .../containers/sequences/vector/db_cback.pass.cpp | 52 + .../containers/sequences/vector/db_cfront.pass.cpp | 52 + .../containers/sequences/vector/db_cindex.pass.cpp | 54 + .../containers/sequences/vector/db_front.pass.cpp | 56 + .../containers/sequences/vector/db_index.pass.cpp | 56 + .../sequences/vector/db_iterators_2.pass.cpp | 54 + .../sequences/vector/db_iterators_3.pass.cpp | 54 + .../sequences/vector/db_iterators_4.pass.cpp | 56 + .../sequences/vector/db_iterators_5.pass.cpp | 60 + .../sequences/vector/db_iterators_6.pass.cpp | 58 + .../sequences/vector/db_iterators_7.pass.cpp | 58 + .../sequences/vector/db_iterators_8.pass.cpp | 54 + .../containers/sequences/vector/iterators.pass.cpp | 165 ++ .../std/containers/sequences/vector/types.pass.cpp | 84 + .../vector/vector.capacity/capacity.pass.cpp | 48 + .../vector/vector.capacity/reserve.pass.cpp | 69 + .../vector/vector.capacity/resize_size.pass.cpp | 83 + .../vector.capacity/resize_size_value.pass.cpp | 76 + .../vector/vector.capacity/shrink_to_fit.pass.cpp | 62 + .../sequences/vector/vector.capacity/swap.pass.cpp | 50 + .../vector/vector.cons/assign_copy.pass.cpp | 44 + .../vector.cons/assign_initializer_list.pass.cpp | 46 + .../vector/vector.cons/assign_move.pass.cpp | 101 ++ .../vector/vector.cons/construct_default.pass.cpp | 78 + .../vector.cons/construct_iter_iter.pass.cpp | 56 + .../vector.cons/construct_iter_iter_alloc.pass.cpp | 71 + .../vector/vector.cons/construct_size.pass.cpp | 73 + .../vector.cons/construct_size_value.pass.cpp | 40 + .../construct_size_value_alloc.pass.cpp | 39 + .../sequences/vector/vector.cons/copy.pass.cpp | 78 + .../vector/vector.cons/copy_alloc.pass.cpp | 64 + .../vector/vector.cons/default.recursive.pass.cpp | 23 + .../vector/vector.cons/default_noexcept.pass.cpp | 50 + .../vector/vector.cons/dtor_noexcept.pass.cpp | 52 + .../vector/vector.cons/initializer_list.pass.cpp | 43 + .../vector.cons/initializer_list_alloc.pass.cpp | 47 + .../sequences/vector/vector.cons/move.pass.cpp | 103 ++ .../vector/vector.cons/move_alloc.pass.cpp | 99 ++ .../vector.cons/move_assign_noexcept.pass.cpp | 52 + .../vector/vector.cons/move_noexcept.pass.cpp | 50 + .../vector.cons/op_equal_initializer_list.pass.cpp | 46 + .../sequences/vector/vector.data/data.pass.cpp | 44 + .../vector/vector.data/data_const.pass.cpp | 44 + .../vector/vector.modifiers/emplace.pass.cpp | 160 ++ .../vector/vector.modifiers/emplace_back.pass.cpp | 107 ++ .../vector/vector.modifiers/emplace_extra.pass.cpp | 62 + .../vector/vector.modifiers/erase_iter.pass.cpp | 74 + .../vector.modifiers/erase_iter_db1.pass.cpp | 51 + .../vector.modifiers/erase_iter_db2.pass.cpp | 53 + .../vector.modifiers/erase_iter_iter.pass.cpp | 127 ++ .../vector.modifiers/erase_iter_iter_db1.pass.cpp | 51 + .../vector.modifiers/erase_iter_iter_db2.pass.cpp | 51 + .../vector.modifiers/erase_iter_iter_db3.pass.cpp | 51 + .../vector.modifiers/erase_iter_iter_db4.pass.cpp | 49 + .../insert_iter_initializer_list.pass.cpp | 68 + .../insert_iter_iter_iter.pass.cpp | 190 +++ .../vector.modifiers/insert_iter_rvalue.pass.cpp | 86 + .../insert_iter_size_value.pass.cpp | 132 ++ .../vector.modifiers/insert_iter_value.pass.cpp | 116 ++ .../vector/vector.modifiers/pop_back.pass.cpp | 55 + .../vector/vector.modifiers/push_back.pass.cpp | 108 ++ .../push_back_exception_safety.pass.cpp | 86 + .../vector.modifiers/push_back_rvalue.pass.cpp | 111 ++ .../vector/vector.special/db_swap_1.pass.cpp | 56 + .../sequences/vector/vector.special/swap.pass.cpp | 187 +++ .../vector/vector.special/swap_noexcept.pass.cpp | 60 + .../containers/sequences/vector/version.pass.cpp | 20 + libcxx/test/std/containers/stack_allocator.h | 66 + libcxx/test/std/containers/test_compare.h | 36 + libcxx/test/std/containers/test_hash.h | 32 + .../test/std/containers/unord/next_prime.pass.cpp | 51 + .../std/containers/unord/unord.map/bucket.pass.cpp | 77 + .../unord/unord.map/bucket_count.pass.cpp | 80 + .../unord/unord.map/bucket_size.pass.cpp | 81 + .../containers/unord/unord.map/compare.pass.cpp | 42 + .../std/containers/unord/unord.map/count.pass.cpp | 65 + .../unord/unord.map/db_iterators_7.pass.cpp | 60 + .../unord/unord.map/db_iterators_8.pass.cpp | 56 + .../unord/unord.map/db_local_iterators_7.pass.cpp | 57 + .../unord/unord.map/db_local_iterators_8.pass.cpp | 54 + .../std/containers/unord/unord.map/eq.pass.cpp | 163 ++ .../unord/unord.map/equal_range_const.pass.cpp | 75 + .../unord/unord.map/equal_range_non_const.pass.cpp | 75 + .../containers/unord/unord.map/find_const.pass.cpp | 71 + .../unord/unord.map/find_non_const.pass.cpp | 71 + .../containers/unord/unord.map/iterators.pass.cpp | 128 ++ .../unord/unord.map/load_factor.pass.cpp | 77 + .../unord/unord.map/local_iterators.pass.cpp | 421 +++++ .../unord/unord.map/max_bucket_count.pass.cpp | 43 + .../unord/unord.map/max_load_factor.pass.cpp | 71 + .../containers/unord/unord.map/max_size.pass.cpp | 36 + .../std/containers/unord/unord.map/rehash.pass.cpp | 91 ++ .../containers/unord/unord.map/reserve.pass.cpp | 91 ++ .../unord/unord.map/swap_member.pass.cpp | 572 +++++++ .../std/containers/unord/unord.map/types.pass.cpp | 72 + .../unord.map/unord.map.cnstr/allocator.pass.cpp | 111 ++ .../unord.map/unord.map.cnstr/assign_copy.pass.cpp | 185 +++ .../unord.map/unord.map.cnstr/assign_init.pass.cpp | 97 ++ .../unord.map/unord.map.cnstr/assign_move.pass.cpp | 229 +++ .../unord/unord.map/unord.map.cnstr/copy.pass.cpp | 151 ++ .../unord.map/unord.map.cnstr/copy_alloc.pass.cpp | 110 ++ .../unord.map/unord.map.cnstr/default.pass.cpp | 78 + .../unord.map.cnstr/default_noexcept.pass.cpp | 70 + .../unord.map.cnstr/dtor_noexcept.pass.cpp | 67 + .../unord/unord.map/unord.map.cnstr/init.pass.cpp | 162 ++ .../unord.map/unord.map.cnstr/init_size.pass.cpp | 100 ++ .../unord.map.cnstr/init_size_hash.pass.cpp | 102 ++ .../unord.map.cnstr/init_size_hash_equal.pass.cpp | 105 ++ .../init_size_hash_equal_allocator.pass.cpp | 107 ++ .../unord/unord.map/unord.map.cnstr/move.pass.cpp | 199 +++ .../unord.map/unord.map.cnstr/move_alloc.pass.cpp | 157 ++ .../unord.map.cnstr/move_assign_noexcept.pass.cpp | 69 + .../unord.map.cnstr/move_noexcept.pass.cpp | 66 + .../unord/unord.map/unord.map.cnstr/range.pass.cpp | 170 ++ .../unord.map/unord.map.cnstr/range_size.pass.cpp | 105 ++ .../unord.map.cnstr/range_size_hash.pass.cpp | 108 ++ .../unord.map.cnstr/range_size_hash_equal.pass.cpp | 110 ++ .../range_size_hash_equal_allocator.pass.cpp | 113 ++ .../unord/unord.map/unord.map.cnstr/size.fail.cpp | 69 + .../unord/unord.map/unord.map.cnstr/size.pass.cpp | 69 + .../unord.map/unord.map.cnstr/size_hash.pass.cpp | 73 + .../unord.map.cnstr/size_hash_equal.pass.cpp | 75 + .../size_hash_equal_allocator.pass.cpp | 77 + .../unord/unord.map/unord.map.elem/at.pass.cpp | 134 ++ .../unord/unord.map/unord.map.elem/index.pass.cpp | 115 ++ .../unord.map/unord.map.elem/index_tuple.pass.cpp | 41 + .../unord.map/unord.map.swap/db_swap_1.pass.cpp | 44 + .../unord.map.swap/swap_noexcept.pass.cpp | 73 + .../unord.map.swap/swap_non_member.pass.cpp | 572 +++++++ .../unord.map/unorder.map.modifiers/clear.pass.cpp | 61 + .../unorder.map.modifiers/emplace.pass.cpp | 80 + .../unorder.map.modifiers/emplace_hint.pass.cpp | 93 ++ .../erase_const_iter.pass.cpp | 69 + .../unorder.map.modifiers/erase_iter_db1.pass.cpp | 39 + .../unorder.map.modifiers/erase_iter_db2.pass.cpp | 42 + .../erase_iter_iter_db1.pass.cpp | 41 + .../erase_iter_iter_db2.pass.cpp | 41 + .../erase_iter_iter_db3.pass.cpp | 41 + .../erase_iter_iter_db4.pass.cpp | 40 + .../unorder.map.modifiers/erase_key.pass.cpp | 177 +++ .../unorder.map.modifiers/erase_range.pass.cpp | 99 ++ .../insert_const_lvalue.pass.cpp | 86 + .../insert_hint_const_lvalue.pass.cpp | 97 ++ .../insert_hint_rvalue.pass.cpp | 156 ++ .../unorder.map.modifiers/insert_init.pass.cpp | 72 + .../unorder.map.modifiers/insert_range.pass.cpp | 71 + .../unorder.map.modifiers/insert_rvalue.pass.cpp | 152 ++ .../containers/unord/unord.map/version.pass.cpp | 20 + .../unord/unord.multimap/bucket.pass.cpp | 77 + .../unord/unord.multimap/bucket_count.pass.cpp | 49 + .../unord/unord.multimap/bucket_size.pass.cpp | 85 + .../containers/unord/unord.multimap/count.pass.cpp | 71 + .../unord/unord.multimap/db_iterators_7.pass.cpp | 60 + .../unord/unord.multimap/db_iterators_8.pass.cpp | 56 + .../unord.multimap/db_local_iterators_7.pass.cpp | 57 + .../unord.multimap/db_local_iterators_8.pass.cpp | 54 + .../containers/unord/unord.multimap/eq.pass.cpp | 181 +++ .../unord.multimap/equal_range_const.pass.cpp | 97 ++ .../unord.multimap/equal_range_non_const.pass.cpp | 97 ++ .../unord/unord.multimap/find_const.pass.cpp | 71 + .../unord/unord.multimap/find_non_const.pass.cpp | 71 + .../unord/unord.multimap/iterators.fail.cpp | 69 + .../unord/unord.multimap/iterators.pass.cpp | 134 ++ .../unord/unord.multimap/load_factor.pass.cpp | 77 + .../unord/unord.multimap/local_iterators.fail.cpp | 286 ++++ .../unord/unord.multimap/local_iterators.pass.cpp | 549 +++++++ .../unord/unord.multimap/max_bucket_count.pass.cpp | 43 + .../unord/unord.multimap/max_load_factor.pass.cpp | 71 + .../unord/unord.multimap/max_size.pass.cpp | 36 + .../unord/unord.multimap/rehash.pass.cpp | 119 ++ .../unord/unord.multimap/reserve.pass.cpp | 93 ++ .../containers/unord/unord.multimap/scary.pass.cpp | 24 + .../unord/unord.multimap/swap_member.pass.cpp | 585 +++++++ .../containers/unord/unord.multimap/types.pass.cpp | 72 + .../unord.multimap.cnstr/allocator.pass.cpp | 111 ++ .../unord.multimap.cnstr/assign_copy.pass.cpp | 227 +++ .../unord.multimap.cnstr/assign_init.pass.cpp | 146 ++ .../unord.multimap.cnstr/assign_move.pass.cpp | 306 ++++ .../unord.multimap.cnstr/copy.pass.cpp | 193 +++ .../unord.multimap.cnstr/copy_alloc.pass.cpp | 138 ++ .../unord.multimap.cnstr/default.pass.cpp | 78 + .../unord.multimap.cnstr/default_noexcept.pass.cpp | 70 + .../unord.multimap.cnstr/dtor_noexcept.pass.cpp | 67 + .../unord.multimap.cnstr/init.pass.cpp | 254 +++ .../unord.multimap.cnstr/init_size.pass.cpp | 144 ++ .../unord.multimap.cnstr/init_size_hash.pass.cpp | 146 ++ .../init_size_hash_equal.pass.cpp | 149 ++ .../init_size_hash_equal_allocator.pass.cpp | 151 ++ .../unord.multimap.cnstr/move.pass.cpp | 243 +++ .../unord.multimap.cnstr/move_alloc.pass.cpp | 228 +++ .../move_assign_noexcept.pass.cpp | 69 + .../unord.multimap.cnstr/move_noexcept.pass.cpp | 66 + .../unord.multimap.cnstr/range.pass.cpp | 263 ++++ .../unord.multimap.cnstr/range_size.pass.cpp | 149 ++ .../unord.multimap.cnstr/range_size_hash.pass.cpp | 152 ++ .../range_size_hash_equal.pass.cpp | 154 ++ .../range_size_hash_equal_allocator.pass.cpp | 157 ++ .../unord.multimap.cnstr/size.fail.cpp | 69 + .../unord.multimap.cnstr/size.pass.cpp | 69 + .../unord.multimap.cnstr/size_hash.pass.cpp | 73 + .../unord.multimap.cnstr/size_hash_equal.pass.cpp | 75 + .../size_hash_equal_allocator.pass.cpp | 77 + .../unord.multimap.modifiers/clear.pass.cpp | 61 + .../unord.multimap.modifiers/emplace.pass.cpp | 74 + .../unord.multimap.modifiers/emplace_hint.pass.cpp | 109 ++ .../erase_const_iter.pass.cpp | 117 ++ .../erase_iter_db1.pass.cpp | 39 + .../erase_iter_db2.pass.cpp | 42 + .../erase_iter_iter_db1.pass.cpp | 41 + .../erase_iter_iter_db2.pass.cpp | 41 + .../erase_iter_iter_db3.pass.cpp | 41 + .../erase_iter_iter_db4.pass.cpp | 40 + .../unord.multimap.modifiers/erase_key.pass.cpp | 388 +++++ .../unord.multimap.modifiers/erase_range.pass.cpp | 179 +++ .../insert_const_lvalue.pass.cpp | 78 + .../insert_hint_const_lvalue.pass.cpp | 97 ++ .../insert_hint_rvalue.pass.cpp | 156 ++ .../unord.multimap.modifiers/insert_init.pass.cpp | 122 ++ .../unord.multimap.modifiers/insert_range.pass.cpp | 121 ++ .../insert_rvalue.pass.cpp | 136 ++ .../unord.multimap.swap/db_swap_1.pass.cpp | 44 + .../unord.multimap.swap/swap_noexcept.pass.cpp | 73 + .../unord.multimap.swap/swap_non_member.pass.cpp | 584 +++++++ .../unord/unord.multiset/bucket.pass.cpp | 76 + .../unord/unord.multiset/bucket_count.pass.cpp | 79 + .../unord/unord.multiset/bucket_size.pass.cpp | 84 + .../containers/unord/unord.multiset/clear.pass.cpp | 60 + .../containers/unord/unord.multiset/count.pass.cpp | 70 + .../unord/unord.multiset/db_iterators_7.pass.cpp | 58 + .../unord/unord.multiset/db_iterators_8.pass.cpp | 54 + .../unord.multiset/db_local_iterators_7.pass.cpp | 57 + .../unord.multiset/db_local_iterators_8.pass.cpp | 54 + .../unord/unord.multiset/emplace.pass.cpp | 64 + .../unord/unord.multiset/emplace_hint.pass.cpp | 80 + .../containers/unord/unord.multiset/eq.pass.cpp | 180 +++ .../unord.multiset/equal_range_const.pass.cpp | 90 ++ .../unord.multiset/equal_range_non_const.pass.cpp | 90 ++ .../unord/unord.multiset/erase_const_iter.pass.cpp | 70 + .../unord/unord.multiset/erase_iter_db1.pass.cpp | 38 + .../unord/unord.multiset/erase_iter_db2.pass.cpp | 41 + .../unord.multiset/erase_iter_iter_db1.pass.cpp | 40 + .../unord.multiset/erase_iter_iter_db2.pass.cpp | 40 + .../unord.multiset/erase_iter_iter_db3.pass.cpp | 40 + .../unord.multiset/erase_iter_iter_db4.pass.cpp | 39 + .../unord/unord.multiset/erase_key.pass.cpp | 176 +++ .../unord/unord.multiset/erase_range.pass.cpp | 94 ++ .../unord/unord.multiset/find_const.pass.cpp | 68 + .../unord/unord.multiset/find_non_const.pass.cpp | 68 + .../unord.multiset/insert_const_lvalue.pass.cpp | 70 + .../insert_hint_const_lvalue.pass.cpp | 89 ++ .../unord.multiset/insert_hint_rvalue.pass.cpp | 138 ++ .../unord/unord.multiset/insert_init.pass.cpp | 71 + .../unord/unord.multiset/insert_range.pass.cpp | 70 + .../unord/unord.multiset/insert_rvalue.pass.cpp | 118 ++ .../unord/unord.multiset/iterators.fail.cpp | 67 + .../unord/unord.multiset/iterators.pass.cpp | 127 ++ .../unord/unord.multiset/load_factor.pass.cpp | 76 + .../unord/unord.multiset/local_iterators.fail.cpp | 261 ++++ .../unord/unord.multiset/local_iterators.pass.cpp | 500 ++++++ .../unord/unord.multiset/max_bucket_count.pass.cpp | 38 + .../unord/unord.multiset/max_load_factor.pass.cpp | 70 + .../unord/unord.multiset/max_size.pass.cpp | 36 + .../unord/unord.multiset/rehash.pass.cpp | 90 ++ .../unord/unord.multiset/reserve.pass.cpp | 90 ++ .../containers/unord/unord.multiset/scary.pass.cpp | 24 + .../unord/unord.multiset/swap_member.pass.cpp | 571 +++++++ .../containers/unord/unord.multiset/types.pass.cpp | 69 + .../unord.multiset.cnstr/allocator.pass.cpp | 109 ++ .../unord.multiset.cnstr/assign_copy.pass.cpp | 209 +++ .../unord.multiset.cnstr/assign_init.pass.cpp | 97 ++ .../unord.multiset.cnstr/assign_move.pass.cpp | 286 ++++ .../unord.multiset.cnstr/copy.pass.cpp | 171 ++ .../unord.multiset.cnstr/copy_alloc.pass.cpp | 123 ++ .../unord.multiset.cnstr/default.pass.cpp | 74 + .../unord.multiset.cnstr/default_noexcept.pass.cpp | 70 + .../unord.multiset.cnstr/dtor_noexcept.pass.cpp | 67 + .../unord.multiset.cnstr/init.pass.cpp | 163 ++ .../unord.multiset.cnstr/init_size.pass.cpp | 97 ++ .../unord.multiset.cnstr/init_size_hash.pass.cpp | 100 ++ .../init_size_hash_equal.pass.cpp | 102 ++ .../init_size_hash_equal_allocator.pass.cpp | 104 ++ .../unord.multiset.cnstr/move.pass.cpp | 194 +++ .../unord.multiset.cnstr/move_alloc.pass.cpp | 213 +++ .../move_assign_noexcept.pass.cpp | 69 + .../unord.multiset.cnstr/move_noexcept.pass.cpp | 66 + .../unord.multiset.cnstr/range.pass.cpp | 167 ++ .../unord.multiset.cnstr/range_size.pass.cpp | 101 ++ .../unord.multiset.cnstr/range_size_hash.pass.cpp | 104 ++ .../range_size_hash_equal.pass.cpp | 106 ++ .../range_size_hash_equal_allocator.pass.cpp | 109 ++ .../unord.multiset.cnstr/size.fail.cpp | 65 + .../unord.multiset.cnstr/size.pass.cpp | 65 + .../unord.multiset.cnstr/size_hash.pass.cpp | 69 + .../unord.multiset.cnstr/size_hash_equal.pass.cpp | 71 + .../size_hash_equal_allocator.pass.cpp | 73 + .../unord.multiset.swap/db_swap_1.pass.cpp | 43 + .../unord.multiset.swap/swap_noexcept.pass.cpp | 73 + .../unord.multiset.swap/swap_non_member.pass.cpp | 571 +++++++ .../std/containers/unord/unord.set/bucket.pass.cpp | 75 + .../unord/unord.set/bucket_count.pass.cpp | 77 + .../unord/unord.set/bucket_size.pass.cpp | 79 + .../std/containers/unord/unord.set/clear.pass.cpp | 59 + .../std/containers/unord/unord.set/count.pass.cpp | 69 + .../unord/unord.set/db_iterators_7.pass.cpp | 58 + .../unord/unord.set/db_iterators_8.pass.cpp | 54 + .../unord/unord.set/db_local_iterators_7.pass.cpp | 57 + .../unord/unord.set/db_local_iterators_8.pass.cpp | 54 + .../containers/unord/unord.set/emplace.pass.cpp | 70 + .../unord/unord.set/emplace_hint.pass.cpp | 80 + .../std/containers/unord/unord.set/eq.pass.cpp | 159 ++ .../unord/unord.set/equal_range_const.pass.cpp | 81 + .../unord/unord.set/equal_range_non_const.pass.cpp | 81 + .../unord/unord.set/erase_const_iter.pass.cpp | 67 + .../unord/unord.set/erase_iter_db1.pass.cpp | 38 + .../unord/unord.set/erase_iter_db2.pass.cpp | 41 + .../unord/unord.set/erase_iter_iter_db1.pass.cpp | 40 + .../unord/unord.set/erase_iter_iter_db2.pass.cpp | 40 + .../unord/unord.set/erase_iter_iter_db3.pass.cpp | 40 + .../unord/unord.set/erase_iter_iter_db4.pass.cpp | 39 + .../containers/unord/unord.set/erase_key.pass.cpp | 175 +++ .../unord/unord.set/erase_range.pass.cpp | 93 ++ .../containers/unord/unord.set/find_const.pass.cpp | 67 + .../unord/unord.set/find_non_const.pass.cpp | 67 + .../unord/unord.set/insert_const_lvalue.pass.cpp | 78 + .../unord.set/insert_hint_const_lvalue.pass.cpp | 89 ++ .../unord/unord.set/insert_hint_rvalue.pass.cpp | 138 ++ .../unord/unord.set/insert_init.pass.cpp | 71 + .../unord/unord.set/insert_range.pass.cpp | 70 + .../unord/unord.set/insert_rvalue.pass.cpp | 134 ++ .../containers/unord/unord.set/iterators.fail.cpp | 67 + .../containers/unord/unord.set/iterators.pass.cpp | 127 ++ .../unord/unord.set/load_factor.pass.cpp | 76 + .../unord/unord.set/local_iterators.fail.cpp | 261 ++++ .../unord/unord.set/local_iterators.pass.cpp | 388 +++++ .../unord/unord.set/max_bucket_count.pass.cpp | 38 + .../unord/unord.set/max_load_factor.pass.cpp | 70 + .../containers/unord/unord.set/max_size.pass.cpp | 36 + .../std/containers/unord/unord.set/rehash.pass.cpp | 90 ++ .../containers/unord/unord.set/reserve.pass.cpp | 90 ++ .../unord/unord.set/swap_member.pass.cpp | 571 +++++++ .../std/containers/unord/unord.set/types.pass.cpp | 69 + .../unord.set/unord.set.cnstr/allocator.pass.cpp | 109 ++ .../unord.set/unord.set.cnstr/assign_copy.pass.cpp | 184 +++ .../unord.set/unord.set.cnstr/assign_init.pass.cpp | 97 ++ .../unord.set/unord.set.cnstr/assign_move.pass.cpp | 225 +++ .../unord/unord.set/unord.set.cnstr/copy.pass.cpp | 147 ++ .../unord.set/unord.set.cnstr/copy_alloc.pass.cpp | 107 ++ .../unord.set/unord.set.cnstr/default.pass.cpp | 74 + .../unord.set.cnstr/default_noexcept.pass.cpp | 70 + .../unord.set.cnstr/dtor_noexcept.pass.cpp | 67 + .../unord/unord.set/unord.set.cnstr/init.pass.cpp | 163 ++ .../unord.set/unord.set.cnstr/init_size.pass.cpp | 97 ++ .../unord.set.cnstr/init_size_hash.pass.cpp | 100 ++ .../unord.set.cnstr/init_size_hash_equal.pass.cpp | 102 ++ .../init_size_hash_equal_allocator.pass.cpp | 104 ++ .../unord/unord.set/unord.set.cnstr/move.pass.cpp | 194 +++ .../unord.set/unord.set.cnstr/move_alloc.pass.cpp | 156 ++ .../unord.set.cnstr/move_assign_noexcept.pass.cpp | 69 + .../unord.set.cnstr/move_noexcept.pass.cpp | 66 + .../unord/unord.set/unord.set.cnstr/range.pass.cpp | 168 ++ .../unord.set/unord.set.cnstr/range_size.pass.cpp | 101 ++ .../unord.set.cnstr/range_size_hash.pass.cpp | 104 ++ .../unord.set.cnstr/range_size_hash_equal.pass.cpp | 106 ++ .../range_size_hash_equal_allocator.pass.cpp | 109 ++ .../unord/unord.set/unord.set.cnstr/size.fail.cpp | 45 + .../unord/unord.set/unord.set.cnstr/size.pass.cpp | 65 + .../unord.set/unord.set.cnstr/size_hash.pass.cpp | 69 + .../unord.set.cnstr/size_hash_equal.pass.cpp | 71 + .../size_hash_equal_allocator.pass.cpp | 73 + .../unord.set/unord.set.swap/db_swap_1.pass.cpp | 43 + .../unord.set.swap/swap_noexcept.pass.cpp | 73 + .../unord.set.swap/swap_non_member.pass.cpp | 571 +++++++ .../containers/unord/unord.set/version.pass.cpp | 20 + 953 files changed, 87700 insertions(+) create mode 100644 libcxx/test/std/containers/Copyable.h create mode 100644 libcxx/test/std/containers/Emplaceable.h create mode 100644 libcxx/test/std/containers/MoveOnly.h create mode 100644 libcxx/test/std/containers/NotConstructible.h create mode 100644 libcxx/test/std/containers/associative/map/compare.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.access/at.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.access/empty.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.access/index_key.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.access/index_rv_key.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.access/index_tuple.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.access/iterator.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.access/max_size.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.access/size.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/assign_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/compare.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/compare_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/copy.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/copy_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/copy_assign.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/default.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/default_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/default_recursive.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/dtor_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/initializer_list_compare.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/initializer_list_compare_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/iter_iter_comp.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/iter_iter_comp_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/move.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/move_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/move_assign.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/move_assign_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.cons/move_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.modifiers/clear.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.modifiers/emplace.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.modifiers/emplace_hint.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.modifiers/erase_iter.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.modifiers/erase_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.modifiers/erase_key.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.modifiers/insert_cv.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.modifiers/insert_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.modifiers/insert_iter_cv.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.modifiers/insert_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.modifiers/insert_rv.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.ops/count.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.ops/equal_range.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.ops/find.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.ops/lower_bound.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.ops/upper_bound.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.special/member_swap.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.special/non_member_swap.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/map.special/swap_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/types.pass.cpp create mode 100644 libcxx/test/std/containers/associative/map/version.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/empty.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/iterator.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/max_size.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/assign_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/compare.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/compare_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/copy.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/copy_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/copy_assign.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/default.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/default_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/dtor_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/initializer_list_compare.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/initializer_list_compare_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/iter_iter_comp.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/iter_iter_comp_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/move.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/move_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/move_assign.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/move_assign_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.cons/move_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.modifiers/clear.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.modifiers/emplace.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.modifiers/emplace_hint.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.modifiers/erase_iter.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.modifiers/erase_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.modifiers/erase_key.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_cv.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_cv.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_rv.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_rv.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.ops/count.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.ops/equal_range.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.ops/find.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.ops/lower_bound.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.ops/upper_bound.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.special/member_swap.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.special/non_member_swap.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/multimap.special/swap_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/scary.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/size.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multimap/types.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/clear.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/count.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/emplace.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/emplace_hint.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/empty.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/equal_range.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/erase_iter.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/erase_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/erase_key.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/find.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/insert_cv.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/insert_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/insert_iter_cv.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/insert_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/insert_iter_rv.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/insert_rv.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/iterator.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/lower_bound.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/max_size.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/assign_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/compare.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/compare_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/copy.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/copy_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/copy_assign.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/default.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/default_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/dtor_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/initializer_list_compare.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/initializer_list_compare_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/iter_iter_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/iter_iter_comp.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/move.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/move_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/move_assign.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/move_assign_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.cons/move_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.special/member_swap.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.special/non_member_swap.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/multiset.special/swap_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/scary.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/size.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/types.pass.cpp create mode 100644 libcxx/test/std/containers/associative/multiset/upper_bound.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/clear.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/count.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/emplace.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/emplace_hint.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/empty.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/equal_range.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/erase_iter.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/erase_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/erase_key.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/find.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/insert_cv.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/insert_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/insert_iter_cv.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/insert_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/insert_iter_rv.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/insert_rv.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/iterator.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/lower_bound.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/max_size.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/compare.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/compare_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/copy.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/copy_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/copy_assign.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/default.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/default_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/dtor_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/initializer_list_compare.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/initializer_list_compare_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/iter_iter_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/iter_iter_comp.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/move.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/move_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/move_assign.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/move_assign_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.cons/move_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.special/member_swap.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.special/non_member_swap.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/set.special/swap_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/size.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/types.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/upper_bound.pass.cpp create mode 100644 libcxx/test/std/containers/associative/set/version.pass.cpp create mode 100644 libcxx/test/std/containers/associative/tree_balance_after_insert.pass.cpp create mode 100644 libcxx/test/std/containers/associative/tree_left_rotate.pass.cpp create mode 100644 libcxx/test/std/containers/associative/tree_remove.pass.cpp create mode 100644 libcxx/test/std/containers/associative/tree_right_rotate.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/nothing_to_do.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_cont_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_rcont_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_copy_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_move_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/assign_copy.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/assign_move.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_comp.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_comp_container.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_comp_rcontainer.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_copy.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_default.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp_cont.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp_rcont.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_move.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/default_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/dtor_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/move_assign_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/move_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/emplace.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/empty.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/pop.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/push.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/push_rvalue.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/size.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/swap.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/top.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.special/swap.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.special/swap_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/priority.queue/types.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_container_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_queue_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_rcontainer_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_rqueue_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_container.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_copy.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_default.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_move.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_rcontainer.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.cons/default_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.cons/dtor_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.cons/move_assign_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.cons/move_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.defn/assign_copy.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.defn/assign_move.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.defn/back.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.defn/back_const.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.defn/emplace.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.defn/empty.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.defn/front.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.defn/front_const.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.defn/pop.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.defn/push.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.defn/push_rv.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.defn/size.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.defn/swap.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.defn/types.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.ops/eq.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.ops/lt.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.special/swap.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/queue.special/swap_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/queue/version.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_container_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_copy_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_rcontainer_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_rqueue_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_container.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_copy.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_default.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_move.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_rcontainer.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.cons/default_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.cons/dtor_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.cons/move_assign_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.cons/move_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.defn/assign_copy.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.defn/assign_move.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.defn/emplace.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.defn/empty.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.defn/pop.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.defn/push.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.defn/push_rv.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.defn/size.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.defn/swap.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.defn/top.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.defn/top_const.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.defn/types.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.ops/eq.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.ops/lt.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.special/swap.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/stack.special/swap_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/container.adaptors/stack/version.pass.cpp create mode 100644 libcxx/test/std/containers/container.requirements/associative.reqmts/associative.reqmts.except/nothing_to_do.pass.cpp create mode 100644 libcxx/test/std/containers/container.requirements/associative.reqmts/nothing_to_do.pass.cpp create mode 100644 libcxx/test/std/containers/container.requirements/container.requirements.dataraces/nothing_to_do.pass.cpp create mode 100644 libcxx/test/std/containers/container.requirements/container.requirements.general/nothing_to_do.pass.cpp create mode 100644 libcxx/test/std/containers/container.requirements/nothing_to_do.pass.cpp create mode 100644 libcxx/test/std/containers/container.requirements/sequence.reqmts/nothing_to_do.pass.cpp create mode 100644 libcxx/test/std/containers/container.requirements/unord.req/nothing_to_do.pass.cpp create mode 100644 libcxx/test/std/containers/container.requirements/unord.req/unord.req.except/nothing_to_do.pass.cpp create mode 100644 libcxx/test/std/containers/containers.general/nothing_to_do.pass.cpp create mode 100644 libcxx/test/std/containers/nothing_to_do.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/array.cons/default.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/array.data/data.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/array.data/data_const.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/array.fill/fill.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/array.size/size.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/array.swap/swap.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/array.tuple/get.fail.cpp create mode 100644 libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/array.tuple/tuple_element.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/array.tuple/tuple_size.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/array.zero/tested_elsewhere.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/at.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/begin.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/front_back.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/indexing.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/iterators.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/types.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/array/version.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.capacity/access.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.capacity/resize_size.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.capacity/resize_size_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.capacity/shrink_to_fit.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/assign_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/copy.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/copy_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/default.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/default_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/dtor_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/initializer_list_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/move.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/move_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/move_assign.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/move_assign_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/move_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/op_equal.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/op_equal_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/size.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/size_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.cons/size_value_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace_back.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace_front.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/erase_iter.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/erase_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_iter_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/pop_back.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/pop_front.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_rvalue.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_rvalue.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.special/copy.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.special/copy_backward.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.special/move.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.special/move_backward.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.special/swap.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/deque.special/swap_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/iterators.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/types.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/deque/version.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/dynarray/dynarray.cons/alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/dynarray/dynarray.cons/default.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/dynarray/dynarray.data/default.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/dynarray/dynarray.mutate/default.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/dynarray/dynarray.overview/at.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/dynarray/dynarray.overview/begin_end.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/dynarray/dynarray.overview/capacity.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/dynarray/dynarray.overview/front_back.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/dynarray/dynarray.overview/indexing.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/dynarray/dynarray.traits/default.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/dynarray/dynarray.zero/default.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/dynarray/nothing_to_do.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.access/front.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/alloc.fail.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_copy.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_init.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_move.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_op_init.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_size_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/copy.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/copy_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default_recursive.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/dtor_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/init.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/init_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_assign_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/range.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/range_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size.fail.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size_value_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.iter/before_begin.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.iter/iterators.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/clear.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/emplace_after.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/emplace_front.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_many.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_one.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_const.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_init.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_range.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_rv.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_size_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/pop_front.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_const.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_exception_safety.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_rv.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/resize_size.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/resize_size_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_pred.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove_if.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/reverse.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort_pred.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_range.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/unique.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/unique_pred.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/equal.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/member_swap.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/non_member_swap.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/relational.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/swap_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/max_size.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/types.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/forwardlist/version.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/db_back.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/db_cback.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/db_cfront.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/db_front.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/db_iterators_6.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/db_iterators_7.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/db_iterators_8.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/db_iterators_9.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/iterators.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.capacity/resize_size.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.capacity/resize_size_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/assign_copy.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/assign_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/assign_move.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/copy.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/copy_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/default.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/default_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/default_stack_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/dtor_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/initializer_list_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/move.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/move_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/move_assign_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/move_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/op_equal_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/size_type.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.cons/size_value_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/clear.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/emplace.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/emplace_back.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/emplace_front.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_db1.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_db2.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db1.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db2.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db3.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db4.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_rvalue.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/pop_back.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/pop_front.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/push_back.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/push_back_exception_safety.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/push_back_rvalue.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/push_front.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/push_front_exception_safety.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.modifiers/push_front_rvalue.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.ops/merge.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.ops/merge_comp.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.ops/remove.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.ops/remove_if.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.ops/reverse.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.ops/sort.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.ops/sort_comp.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.ops/unique.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.ops/unique_pred.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.special/db_swap_1.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.special/swap.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/list.special/swap_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/types.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/list/version.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/nothing_to_do.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/assign_copy.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/assign_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/assign_move.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/capacity.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/construct_default.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/construct_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/construct_iter_iter_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/construct_size.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/construct_size_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/construct_size_value_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/copy.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/copy_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/default_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/dtor_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/emplace.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/emplace_back.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/erase_iter.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/erase_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/find.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/initializer_list_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/insert_iter_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/insert_iter_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/iterators.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/move.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/move_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/move_assign_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/move_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/op_equal_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/push_back.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/reserve.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/resize_size.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/resize_size_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/shrink_to_fit.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/swap.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/swap_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/types.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector.bool/vector_bool.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/asan.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/asan_throw.pass.cc create mode 100644 libcxx/test/std/containers/sequences/vector/const_value_type.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/db_back.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/db_cback.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/db_cfront.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/db_cindex.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/db_front.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/db_index.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/db_iterators_2.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/db_iterators_3.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/db_iterators_4.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/db_iterators_5.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/db_iterators_6.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/db_iterators_7.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/db_iterators_8.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/iterators.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/types.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.capacity/capacity.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.capacity/reserve.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.capacity/resize_size.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.capacity/shrink_to_fit.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.capacity/swap.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/assign_copy.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/assign_move.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/construct_default.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/construct_size.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/construct_size_value_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/copy.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/copy_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/default.recursive.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/default_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/dtor_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/initializer_list_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/move.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/move_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/move_assign_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/move_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.cons/op_equal_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.data/data.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.data/data_const.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace_back.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace_extra.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db1.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db2.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db1.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db2.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db3.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db4.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_initializer_list.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/pop_back.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.special/db_swap_1.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.special/swap.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/vector.special/swap_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/sequences/vector/version.pass.cpp create mode 100644 libcxx/test/std/containers/stack_allocator.h create mode 100644 libcxx/test/std/containers/test_compare.h create mode 100644 libcxx/test/std/containers/test_hash.h create mode 100644 libcxx/test/std/containers/unord/next_prime.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/bucket.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/bucket_count.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/bucket_size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/compare.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/count.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/db_iterators_7.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/db_iterators_8.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/db_local_iterators_7.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/db_local_iterators_8.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/eq.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/equal_range_const.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/equal_range_non_const.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/find_const.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/find_non_const.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/iterators.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/load_factor.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/local_iterators.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/max_bucket_count.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/max_load_factor.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/max_size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/rehash.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/reserve.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/swap_member.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/types.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/allocator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_copy.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_init.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_move.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/copy.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/copy_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/default.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/default_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/dtor_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init_size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init_size_hash.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init_size_hash_equal.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init_size_hash_equal_allocator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move_assign_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range_size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range_size_hash.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range_size_hash_equal.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range_size_hash_equal_allocator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size.fail.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size_hash.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size_hash_equal.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size_hash_equal_allocator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.elem/index.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.elem/index_tuple.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.swap/db_swap_1.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.swap/swap_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unord.map.swap/swap_non_member.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/clear.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/emplace.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/emplace_hint.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_const_iter.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_db1.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_db2.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db1.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db2.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db3.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db4.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_key.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_range.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_const_lvalue.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_hint_const_lvalue.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_hint_rvalue.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_init.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_range.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_rvalue.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.map/version.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/bucket.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/bucket_count.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/bucket_size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/count.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/db_iterators_7.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/db_iterators_8.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/db_local_iterators_7.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/db_local_iterators_8.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/eq.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/equal_range_const.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/equal_range_non_const.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/find_const.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/find_non_const.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/iterators.fail.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/iterators.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/load_factor.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/local_iterators.fail.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/local_iterators.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/max_bucket_count.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/max_load_factor.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/max_size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/rehash.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/reserve.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/scary.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/swap_member.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/types.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/allocator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_copy.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_init.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_move.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/copy.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/copy_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/default.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/default_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/dtor_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init_size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init_size_hash.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init_size_hash_equal.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init_size_hash_equal_allocator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_assign_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range_size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range_size_hash.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range_size_hash_equal.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range_size_hash_equal_allocator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size.fail.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size_hash.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size_hash_equal.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size_hash_equal_allocator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/clear.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/emplace.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/emplace_hint.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_const_iter.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_db1.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_db2.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db1.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db2.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db3.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db4.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_key.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_range.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_const_lvalue.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_const_lvalue.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_rvalue.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_init.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_range.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_rvalue.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.swap/db_swap_1.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_non_member.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/bucket.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/bucket_count.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/bucket_size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/clear.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/count.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/db_iterators_7.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/db_iterators_8.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/db_local_iterators_7.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/db_local_iterators_8.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/emplace.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/emplace_hint.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/eq.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/equal_range_const.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/equal_range_non_const.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/erase_const_iter.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/erase_iter_db1.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/erase_iter_db2.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/erase_iter_iter_db1.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/erase_iter_iter_db2.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/erase_iter_iter_db3.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/erase_iter_iter_db4.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/erase_key.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/erase_range.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/find_const.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/find_non_const.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/insert_const_lvalue.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/insert_hint_const_lvalue.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/insert_hint_rvalue.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/insert_init.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/insert_range.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/insert_rvalue.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/iterators.fail.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/iterators.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/load_factor.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/local_iterators.fail.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/local_iterators.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/max_bucket_count.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/max_load_factor.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/max_size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/rehash.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/reserve.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/scary.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/swap_member.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/types.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/allocator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_copy.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_init.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_move.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/default.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/default_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/dtor_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash_equal.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash_equal_allocator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_assign_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash_equal.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash_equal_allocator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size.fail.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash_equal.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash_equal_allocator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.swap/db_swap_1.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_non_member.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/bucket.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/bucket_count.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/bucket_size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/clear.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/count.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/db_iterators_7.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/db_iterators_8.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/db_local_iterators_7.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/db_local_iterators_8.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/emplace.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/emplace_hint.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/eq.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/equal_range_const.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/equal_range_non_const.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/erase_const_iter.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/erase_iter_db1.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/erase_iter_db2.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/erase_iter_iter_db1.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/erase_iter_iter_db2.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/erase_iter_iter_db3.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/erase_iter_iter_db4.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/erase_key.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/erase_range.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/find_const.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/find_non_const.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/insert_const_lvalue.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/insert_hint_const_lvalue.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/insert_hint_rvalue.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/insert_init.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/insert_range.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/insert_rvalue.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/iterators.fail.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/iterators.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/load_factor.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/local_iterators.fail.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/local_iterators.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/max_bucket_count.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/max_load_factor.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/max_size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/rehash.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/reserve.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/swap_member.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/types.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/allocator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_copy.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_init.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_move.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/copy.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/copy_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/default.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/default_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/dtor_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init_size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init_size_hash.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init_size_hash_equal.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init_size_hash_equal_allocator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move_alloc.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move_assign_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range_size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range_size_hash.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range_size_hash_equal.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range_size_hash_equal_allocator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size.fail.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size_hash.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size_hash_equal.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size_hash_equal_allocator.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.swap/db_swap_1.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.swap/swap_noexcept.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/unord.set.swap/swap_non_member.pass.cpp create mode 100644 libcxx/test/std/containers/unord/unord.set/version.pass.cpp (limited to 'libcxx/test/std/containers') diff --git a/libcxx/test/std/containers/Copyable.h b/libcxx/test/std/containers/Copyable.h new file mode 100644 index 00000000000..9542c7e8516 --- /dev/null +++ b/libcxx/test/std/containers/Copyable.h @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef COPYABLE_H +#define COPYABLE_H + +class Copyable +{ +public: +}; + +#endif // COPYABLE_H diff --git a/libcxx/test/std/containers/Emplaceable.h b/libcxx/test/std/containers/Emplaceable.h new file mode 100644 index 00000000000..34dd326203b --- /dev/null +++ b/libcxx/test/std/containers/Emplaceable.h @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef EMPLACEABLE_H +#define EMPLACEABLE_H + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +class Emplaceable +{ + Emplaceable(const Emplaceable&); + Emplaceable& operator=(const Emplaceable&); + + int int_; + double double_; +public: + Emplaceable() : int_(0), double_(0) {} + Emplaceable(int i, double d) : int_(i), double_(d) {} + Emplaceable(Emplaceable&& x) + : int_(x.int_), double_(x.double_) + {x.int_ = 0; x.double_ = 0;} + Emplaceable& operator=(Emplaceable&& x) + {int_ = x.int_; x.int_ = 0; + double_ = x.double_; x.double_ = 0; + return *this;} + + bool operator==(const Emplaceable& x) const + {return int_ == x.int_ && double_ == x.double_;} + bool operator<(const Emplaceable& x) const + {return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);} + + int get() const {return int_;} +}; + +namespace std { + +template <> +struct hash + : public std::unary_function +{ + std::size_t operator()(const Emplaceable& x) const {return x.get();} +}; + +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#endif // EMPLACEABLE_H diff --git a/libcxx/test/std/containers/MoveOnly.h b/libcxx/test/std/containers/MoveOnly.h new file mode 100644 index 00000000000..e4d9f649560 --- /dev/null +++ b/libcxx/test/std/containers/MoveOnly.h @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef MOVEONLY_H +#define MOVEONLY_H + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#include +#include + +class MoveOnly +{ + MoveOnly(const MoveOnly&); + MoveOnly& operator=(const MoveOnly&); + + int data_; +public: + MoveOnly(int data = 1) : data_(data) {} + MoveOnly(MoveOnly&& x) + : data_(x.data_) {x.data_ = 0;} + MoveOnly& operator=(MoveOnly&& x) + {data_ = x.data_; x.data_ = 0; return *this;} + + int get() const {return data_;} + + bool operator==(const MoveOnly& x) const {return data_ == x.data_;} + bool operator< (const MoveOnly& x) const {return data_ < x.data_;} +}; + +namespace std { + +template <> +struct hash + : public std::unary_function +{ + std::size_t operator()(const MoveOnly& x) const {return x.get();} +}; + +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#endif // MOVEONLY_H diff --git a/libcxx/test/std/containers/NotConstructible.h b/libcxx/test/std/containers/NotConstructible.h new file mode 100644 index 00000000000..ac8b98ef99f --- /dev/null +++ b/libcxx/test/std/containers/NotConstructible.h @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef NOTCONSTRUCTIBLE_H +#define NOTCONSTRUCTIBLE_H + +#include + +class NotConstructible +{ + NotConstructible(const NotConstructible&); + NotConstructible& operator=(const NotConstructible&); +public: +}; + +inline +bool +operator==(const NotConstructible&, const NotConstructible&) +{return true;} + +namespace std +{ + +template <> +struct hash + : public std::unary_function +{ + std::size_t operator()(const NotConstructible&) const {return 0;} +}; + +} + +#endif // NOTCONSTRUCTIBLE_H diff --git a/libcxx/test/std/containers/associative/map/compare.pass.cpp b/libcxx/test/std/containers/associative/map/compare.pass.cpp new file mode 100644 index 00000000000..aa4d5999ff4 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/compare.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , +// class Allocator = allocator>> +// class map + +// http://llvm.org/bugs/show_bug.cgi?id=16538 +// http://llvm.org/bugs/show_bug.cgi?id=16549 + +#include + +struct Key { + template Key(const T&) {} + bool operator< (const Key&) const { return false; } +}; + +int +main() +{ + std::map::iterator it = std::map().find(Key(0)); + std::pair::iterator, bool> result = + std::map().insert(std::make_pair(Key(0), 0)); +} diff --git a/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp new file mode 100644 index 00000000000..86b1e3d2dfa --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.access/at.pass.cpp @@ -0,0 +1,154 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// mapped_type& at(const key_type& k); +// const mapped_type& at(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::pair V; + V ar[] = + { + V(1, 1.5), + V(2, 2.5), + V(3, 3.5), + V(4, 4.5), + V(5, 5.5), + V(7, 7.5), + V(8, 8.5), + }; + std::map m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 7); + assert(m.at(1) == 1.5); + m.at(1) = -1.5; + assert(m.at(1) == -1.5); + assert(m.at(2) == 2.5); + assert(m.at(3) == 3.5); + assert(m.at(4) == 4.5); + assert(m.at(5) == 5.5); + try + { + m.at(6); + assert(false); + } + catch (std::out_of_range&) + { + } + assert(m.at(7) == 7.5); + assert(m.at(8) == 8.5); + assert(m.size() == 7); + } + { + typedef std::pair V; + V ar[] = + { + V(1, 1.5), + V(2, 2.5), + V(3, 3.5), + V(4, 4.5), + V(5, 5.5), + V(7, 7.5), + V(8, 8.5), + }; + const std::map m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 7); + assert(m.at(1) == 1.5); + assert(m.at(2) == 2.5); + assert(m.at(3) == 3.5); + assert(m.at(4) == 4.5); + assert(m.at(5) == 5.5); + try + { + m.at(6); + assert(false); + } + catch (std::out_of_range&) + { + } + assert(m.at(7) == 7.5); + assert(m.at(8) == 8.5); + assert(m.size() == 7); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + V ar[] = + { + V(1, 1.5), + V(2, 2.5), + V(3, 3.5), + V(4, 4.5), + V(5, 5.5), + V(7, 7.5), + V(8, 8.5), + }; + std::map, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 7); + assert(m.at(1) == 1.5); + m.at(1) = -1.5; + assert(m.at(1) == -1.5); + assert(m.at(2) == 2.5); + assert(m.at(3) == 3.5); + assert(m.at(4) == 4.5); + assert(m.at(5) == 5.5); + try + { + m.at(6); + assert(false); + } + catch (std::out_of_range&) + { + } + assert(m.at(7) == 7.5); + assert(m.at(8) == 8.5); + assert(m.size() == 7); + } + { + typedef std::pair V; + V ar[] = + { + V(1, 1.5), + V(2, 2.5), + V(3, 3.5), + V(4, 4.5), + V(5, 5.5), + V(7, 7.5), + V(8, 8.5), + }; + const std::map, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 7); + assert(m.at(1) == 1.5); + assert(m.at(2) == 2.5); + assert(m.at(3) == 3.5); + assert(m.at(4) == 4.5); + assert(m.at(5) == 5.5); + try + { + m.at(6); + assert(false); + } + catch (std::out_of_range&) + { + } + assert(m.at(7) == 7.5); + assert(m.at(8) == 8.5); + assert(m.size() == 7); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.access/empty.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/empty.pass.cpp new file mode 100644 index 00000000000..b11e94c8042 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.access/empty.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// bool empty() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::map M; + M m; + assert(m.empty()); + m.insert(M::value_type(1, 1.5)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); + } +#if __cplusplus >= 201103L + { + typedef std::map, min_allocator>> M; + M m; + assert(m.empty()); + m.insert(M::value_type(1, 1.5)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.access/index_key.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/index_key.pass.cpp new file mode 100644 index 00000000000..ab1144c60af --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.access/index_key.pass.cpp @@ -0,0 +1,105 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// mapped_type& operator[](const key_type& k); + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + { + typedef std::pair V; + V ar[] = + { + V(1, 1.5), + V(2, 2.5), + V(3, 3.5), + V(4, 4.5), + V(5, 5.5), + V(7, 7.5), + V(8, 8.5), + }; + std::map m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 7); + assert(m[1] == 1.5); + assert(m.size() == 7); + m[1] = -1.5; + assert(m[1] == -1.5); + assert(m.size() == 7); + assert(m[6] == 0); + assert(m.size() == 8); + m[6] = 6.5; + assert(m[6] == 6.5); + assert(m.size() == 8); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + V ar[] = + { + V(1, 1.5), + V(2, 2.5), + V(3, 3.5), + V(4, 4.5), + V(5, 5.5), + V(7, 7.5), + V(8, 8.5), + }; + std::map, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 7); + assert(m[1] == 1.5); + assert(m.size() == 7); + const int i = 1; + m[i] = -1.5; + assert(m[1] == -1.5); + assert(m.size() == 7); + assert(m[6] == 0); + assert(m.size() == 8); + m[6] = 6.5; + assert(m[6] == 6.5); + assert(m.size() == 8); + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair V; + V ar[] = + { + V(1, 1.5), + V(2, 2.5), + V(3, 3.5), + V(4, 4.5), + V(5, 5.5), + V(7, 7.5), + V(8, 8.5), + }; + std::map> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + + assert(m.size() == 7); + assert(m[1] == 1.5); + assert(m.size() == 7); + m[1] = -1.5; + assert(m[1] == -1.5); + assert(m.size() == 7); + assert(m[6] == 0); + assert(m.size() == 8); + m[6] = 6.5; + assert(m[6] == 6.5); + assert(m.size() == 8); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.access/index_rv_key.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/index_rv_key.pass.cpp new file mode 100644 index 00000000000..a58d50d8499 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.access/index_rv_key.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// mapped_type& operator[](key_type&& k); + +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::pair V; + std::map m; + assert(m.size() == 0); + assert(m[1] == 0.0); + assert(m.size() == 1); + m[1] = -1.5; + assert(m[1] == -1.5); + assert(m.size() == 1); + assert(m[6] == 0); + assert(m.size() == 2); + m[6] = 6.5; + assert(m[6] == 6.5); + assert(m.size() == 2); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::pair V; + std::map, min_allocator> m; + assert(m.size() == 0); + assert(m[1] == 0.0); + assert(m.size() == 1); + m[1] = -1.5; + assert(m[1] == -1.5); + assert(m.size() == 1); + assert(m[6] == 0); + assert(m.size() == 2); + m[6] = 6.5; + assert(m[6] == 6.5); + assert(m.size() == 2); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.access/index_tuple.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/index_tuple.pass.cpp new file mode 100644 index 00000000000..9a00829eadd --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.access/index_tuple.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// mapped_type& operator[](const key_type& k); + +// http://llvm.org/bugs/show_bug.cgi?id=16542 + +#include + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +#include + +#endif + +int main() +{ +#ifndef _LIBCPP_HAS_NO_VARIADICS + using namespace std; + map, size_t> m; + m[make_tuple(2,3)]=7; +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.access/iterator.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/iterator.pass.cpp new file mode 100644 index 00000000000..552e87d8fc8 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.access/iterator.pass.cpp @@ -0,0 +1,227 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// iterator begin(); +// const_iterator begin() const; +// iterator end(); +// const_iterator end() const; +// +// reverse_iterator rbegin(); +// const_reverse_iterator rbegin() const; +// reverse_iterator rend(); +// const_reverse_iterator rend() const; +// +// const_iterator cbegin() const; +// const_iterator cend() const; +// const_reverse_iterator crbegin() const; +// const_reverse_iterator crend() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + V(4, 1), + V(4, 1.5), + V(4, 2), + V(5, 1), + V(5, 1.5), + V(5, 2), + V(6, 1), + V(6, 1.5), + V(6, 2), + V(7, 1), + V(7, 1.5), + V(7, 2), + V(8, 1), + V(8, 1.5), + V(8, 2) + }; + std::map m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + std::map::iterator i; + i = m.begin(); + std::map::const_iterator k = i; + assert(i == k); + for (int j = 1; j <= m.size(); ++j, ++i) + { + assert(i->first == j); + assert(i->second == 1); + i->second = 2.5; + assert(i->second == 2.5); + } + } + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + V(4, 1), + V(4, 1.5), + V(4, 2), + V(5, 1), + V(5, 1.5), + V(5, 2), + V(6, 1), + V(6, 1.5), + V(6, 2), + V(7, 1), + V(7, 1.5), + V(7, 2), + V(8, 1), + V(8, 1.5), + V(8, 2) + }; + const std::map m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.cbegin(), m.cend()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + assert(std::distance(m.crbegin(), m.crend()) == m.size()); + std::map::const_iterator i; + i = m.begin(); + for (int j = 1; j <= m.size(); ++j, ++i) + { + assert(i->first == j); + assert(i->second == 1); + } + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + V(4, 1), + V(4, 1.5), + V(4, 2), + V(5, 1), + V(5, 1.5), + V(5, 2), + V(6, 1), + V(6, 1.5), + V(6, 2), + V(7, 1), + V(7, 1.5), + V(7, 2), + V(8, 1), + V(8, 1.5), + V(8, 2) + }; + std::map, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + std::map, min_allocator>::iterator i; + i = m.begin(); + std::map, min_allocator>::const_iterator k = i; + assert(i == k); + for (int j = 1; j <= m.size(); ++j, ++i) + { + assert(i->first == j); + assert(i->second == 1); + i->second = 2.5; + assert(i->second == 2.5); + } + } + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + V(4, 1), + V(4, 1.5), + V(4, 2), + V(5, 1), + V(5, 1.5), + V(5, 2), + V(6, 1), + V(6, 1.5), + V(6, 2), + V(7, 1), + V(7, 1.5), + V(7, 2), + V(8, 1), + V(8, 1.5), + V(8, 2) + }; + const std::map, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.cbegin(), m.cend()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + assert(std::distance(m.crbegin(), m.crend()) == m.size()); + std::map, min_allocator>::const_iterator i; + i = m.begin(); + for (int j = 1; j <= m.size(); ++j, ++i) + { + assert(i->first == j); + assert(i->second == 1); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + typedef std::map C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.access/max_size.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/max_size.pass.cpp new file mode 100644 index 00000000000..551120d331e --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.access/max_size.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// size_type max_size() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::map M; + M m; + assert(m.max_size() != 0); + } +#if __cplusplus >= 201103L + { + typedef std::map, min_allocator>> M; + M m; + assert(m.max_size() != 0); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.access/size.pass.cpp b/libcxx/test/std/containers/associative/map/map.access/size.pass.cpp new file mode 100644 index 00000000000..07c12322a46 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.access/size.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// size_type size() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::map M; + M m; + assert(m.size() == 0); + m.insert(M::value_type(2, 1.5)); + assert(m.size() == 1); + m.insert(M::value_type(1, 1.5)); + assert(m.size() == 2); + m.insert(M::value_type(3, 1.5)); + assert(m.size() == 3); + m.erase(m.begin()); + assert(m.size() == 2); + m.erase(m.begin()); + assert(m.size() == 1); + m.erase(m.begin()); + assert(m.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::map, min_allocator>> M; + M m; + assert(m.size() == 0); + m.insert(M::value_type(2, 1.5)); + assert(m.size() == 1); + m.insert(M::value_type(1, 1.5)); + assert(m.size() == 2); + m.insert(M::value_type(3, 1.5)); + assert(m.size() == 3); + m.erase(m.begin()); + assert(m.size() == 2); + m.erase(m.begin()); + assert(m.size() == 1); + m.erase(m.begin()); + assert(m.size() == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/alloc.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/alloc.pass.cpp new file mode 100644 index 00000000000..2292c47ef74 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/alloc.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// explicit map(const allocator_type& a); + +#include +#include + +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::less C; + typedef test_allocator > A; + std::map m(A(5)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.get_allocator() == A(5)); + } +#if __cplusplus >= 201103L + { + typedef std::less C; + typedef min_allocator > A; + std::map m(A{}); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.get_allocator() == A()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..482d1acff84 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// map& operator=(initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::pair V; + std::map m = + { + {20, 1}, + }; + m = + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }; + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + std::map, min_allocator> m = + { + {20, 1}, + }; + m = + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }; + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/compare.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/compare.pass.cpp new file mode 100644 index 00000000000..5a213c8e8b8 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/compare.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// explicit map(const key_compare& comp); + +#include +#include + +#include "../../../test_compare.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_compare > C; + std::map m(C(3)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(3)); + } +#if __cplusplus >= 201103L + { + typedef test_compare > C; + std::map>> m(C(3)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(3)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/compare_alloc.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/compare_alloc.pass.cpp new file mode 100644 index 00000000000..56b3c3315e0 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/compare_alloc.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// map(const key_compare& comp, const allocator_type& a); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_compare > C; + typedef test_allocator > A; + std::map m(C(4), A(5)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(4)); + assert(m.get_allocator() == A(5)); + } +#if __cplusplus >= 201103L + { + typedef test_compare > C; + typedef min_allocator > A; + std::map m(C(4), A()); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(4)); + assert(m.get_allocator() == A()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/copy.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/copy.pass.cpp new file mode 100644 index 00000000000..be527413308 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/copy.pass.cpp @@ -0,0 +1,131 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// map(const map& m); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef test_allocator A; + std::map mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::map m = mo; + assert(m.get_allocator() == A(7)); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == V(1, 1)); + assert(*next(mo.begin()) == V(2, 1)); + assert(*next(mo.begin(), 2) == V(3, 1)); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef other_allocator A; + std::map mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::map m = mo; + assert(m.get_allocator() == A(-2)); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == V(1, 1)); + assert(*next(mo.begin()) == V(2, 1)); + assert(*next(mo.begin(), 2) == V(3, 1)); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef min_allocator A; + std::map mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::map m = mo; + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == V(1, 1)); + assert(*next(mo.begin()) == V(2, 1)); + assert(*next(mo.begin(), 2) == V(3, 1)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/copy_alloc.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..fcbe5976d6d --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/copy_alloc.pass.cpp @@ -0,0 +1,95 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// map(const map& m, const allocator_type& a); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef test_allocator A; + std::map mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::map m(mo, A(3)); + assert(m.get_allocator() == A(3)); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == V(1, 1)); + assert(*next(mo.begin()) == V(2, 1)); + assert(*next(mo.begin(), 2) == V(3, 1)); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef min_allocator A; + std::map mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::map m(mo, A()); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == V(1, 1)); + assert(*next(mo.begin()) == V(2, 1)); + assert(*next(mo.begin(), 2) == V(3, 1)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/copy_assign.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/copy_assign.pass.cpp new file mode 100644 index 00000000000..a1bcb30f429 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/copy_assign.pass.cpp @@ -0,0 +1,182 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// map& operator=(const map& m); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2) + }; + typedef test_compare > C; + typedef test_allocator A; + std::map mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2)); + std::map m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7)); + m = mo; + assert(m.get_allocator() == A(7)); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A(2)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == V(1, 1)); + assert(*next(mo.begin()) == V(2, 1)); + assert(*next(mo.begin(), 2) == V(3, 1)); + } + { + typedef std::pair V; + const V ar[] = + { + V(1, 1), + V(2, 1), + V(3, 1), + }; + std::map m(ar, ar+sizeof(ar)/sizeof(ar[0])); + std::map *p = &m; + m = *p; + + assert(m.size() == 3); + assert(std::equal(m.begin(), m.end(), ar)); + } + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2) + }; + typedef test_compare > C; + typedef other_allocator A; + std::map mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2)); + std::map m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7)); + m = mo; + assert(m.get_allocator() == A(2)); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A(2)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == V(1, 1)); + assert(*next(mo.begin()) == V(2, 1)); + assert(*next(mo.begin(), 2) == V(3, 1)); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2) + }; + typedef test_compare > C; + typedef min_allocator A; + std::map mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::map m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A()); + m = mo; + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == V(1, 1)); + assert(*next(mo.begin()) == V(2, 1)); + assert(*next(mo.begin(), 2) == V(3, 1)); + } + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2) + }; + typedef test_compare > C; + typedef min_allocator A; + std::map mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::map m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A()); + m = mo; + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == V(1, 1)); + assert(*next(mo.begin()) == V(2, 1)); + assert(*next(mo.begin(), 2) == V(3, 1)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/default.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/default.pass.cpp new file mode 100644 index 00000000000..1832a32fffb --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/default.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// map(); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + std::map m; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#if __cplusplus >= 201103L + { + std::map, min_allocator>> m; + assert(m.empty()); + assert(m.begin() == m.end()); + } + { + std::map m = {}; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/default_noexcept.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/default_noexcept.pass.cpp new file mode 100644 index 00000000000..6c6b6140f0f --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/default_noexcept.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// map() +// noexcept( +// is_nothrow_default_constructible::value && +// is_nothrow_default_constructible::value && +// is_nothrow_copy_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp(); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::map C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::map, test_allocator> C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::map, other_allocator> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::map> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/default_recursive.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/default_recursive.pass.cpp new file mode 100644 index 00000000000..8b393d3c91c --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/default_recursive.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// map(); + +#include + +#if !__has_feature(cxx_noexcept) + +struct X +{ + std::map m; +}; + +#endif + +int main() +{ +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..c60f2e7e8ba --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// ~map() // implied noexcept; + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template +struct some_comp +{ + typedef T value_type; + ~some_comp() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::map C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::map, test_allocator> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::map, other_allocator> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::map> C; + static_assert(!std::is_nothrow_destructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..196943653a1 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/initializer_list.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// map(initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::pair V; + std::map m = + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }; + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + std::map, min_allocator> m = + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }; + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/initializer_list_compare.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/initializer_list_compare.pass.cpp new file mode 100644 index 00000000000..08f8a529f03 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/initializer_list_compare.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// map(initializer_list il, const key_compare& comp); + +#include +#include +#include "../../../test_compare.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::pair V; + typedef test_compare > C; + std::map m({ + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }, C(3)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + assert(m.key_comp() == C(3)); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + typedef test_compare > C; + std::map>> m({ + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }, C(3)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + assert(m.key_comp() == C(3)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/initializer_list_compare_alloc.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/initializer_list_compare_alloc.pass.cpp new file mode 100644 index 00000000000..765428a631e --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/initializer_list_compare_alloc.pass.cpp @@ -0,0 +1,100 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// map(initializer_list il, const key_compare& comp, const allocator_type& a); + +#include +#include +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::pair V; + typedef test_compare > C; + typedef test_allocator > A; + std::map m({ + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }, C(3), A(6)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + assert(m.key_comp() == C(3)); + assert(m.get_allocator() == A(6)); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + typedef test_compare > C; + typedef min_allocator > A; + std::map m({ + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }, C(3), A()); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + assert(m.key_comp() == C(3)); + assert(m.get_allocator() == A()); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair V; + typedef min_allocator A; + typedef test_compare > C; + typedef std::map M; + A a; + M m ({ {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }, a); + + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + assert(m.get_allocator() == a); + } +#endif +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/iter_iter.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/iter_iter.pass.cpp new file mode 100644 index 00000000000..c1029af6889 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/iter_iter.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// template +// map(InputIterator first, InputIterator last); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + std::map m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + std::map, min_allocator>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/iter_iter_comp.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/iter_iter_comp.pass.cpp new file mode 100644 index 00000000000..837fa8c6cde --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/iter_iter_comp.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// template +// map(InputIterator first, InputIterator last, const key_compare& comp); + +#include +#include + +#include "../../../test_compare.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + std::map m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5)); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + std::map>> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5)); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/iter_iter_comp_alloc.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/iter_iter_comp_alloc.pass.cpp new file mode 100644 index 00000000000..67fb5d64476 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/iter_iter_comp_alloc.pass.cpp @@ -0,0 +1,108 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// template +// map(InputIterator first, InputIterator last, +// const key_compare& comp, const allocator_type& a); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef test_allocator A; + std::map m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + assert(m.get_allocator() == A(7)); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef min_allocator A; + std::map m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef std::pair V; + typedef min_allocator A; + typedef test_compare > C; + A a; + std::map m(ar, ar+sizeof(ar)/sizeof(ar[0]), a ); + + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + assert(m.get_allocator() == a); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/move.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/move.pass.cpp new file mode 100644 index 00000000000..c06f2ee5021 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/move.pass.cpp @@ -0,0 +1,120 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// map(map&& m); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + typedef std::pair V; + { + typedef test_compare > C; + typedef test_allocator A; + std::map mo(C(5), A(7)); + std::map m = std::move(mo); + assert(m.get_allocator() == A(7)); + assert(m.key_comp() == C(5)); + assert(m.size() == 0); + assert(distance(m.begin(), m.end()) == 0); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } + { + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef test_allocator A; + std::map mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::map m = std::move(mo); + assert(m.get_allocator() == A(7)); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } +#if __cplusplus >= 201103L + { + typedef test_compare > C; + typedef min_allocator A; + std::map mo(C(5), A()); + std::map m = std::move(mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 0); + assert(distance(m.begin(), m.end()) == 0); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } + { + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef min_allocator A; + std::map mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::map m = std::move(mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/move_alloc.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..1845e88b7a5 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/move_alloc.pass.cpp @@ -0,0 +1,186 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// map(map&& m, const allocator_type& a); + +#include +#include + +#include "../../../MoveOnly.h" +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::pair V; + typedef std::pair VC; + typedef test_compare > C; + typedef test_allocator A; + typedef std::map M; + typedef std::move_iterator I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(std::move(m1), A(7)); + assert(m3 == m2); + assert(m3.get_allocator() == A(7)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } + { + typedef std::pair V; + typedef std::pair VC; + typedef test_compare > C; + typedef test_allocator A; + typedef std::map M; + typedef std::move_iterator I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(std::move(m1), A(5)); + assert(m3 == m2); + assert(m3.get_allocator() == A(5)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } + { + typedef std::pair V; + typedef std::pair VC; + typedef test_compare > C; + typedef other_allocator A; + typedef std::map M; + typedef std::move_iterator I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(std::move(m1), A(5)); + assert(m3 == m2); + assert(m3.get_allocator() == A(5)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + typedef std::pair VC; + typedef test_compare > C; + typedef min_allocator A; + typedef std::map M; + typedef std::move_iterator I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A()); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A()); + M m3(std::move(m1), A()); + assert(m3 == m2); + assert(m3.get_allocator() == A()); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/move_assign.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/move_assign.pass.cpp new file mode 100644 index 00000000000..6d285fce000 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/move_assign.pass.cpp @@ -0,0 +1,190 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// map& operator=(map&& m); + +#include +#include + +#include "../../../MoveOnly.h" +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::pair V; + typedef std::pair VC; + typedef test_compare > C; + typedef test_allocator A; + typedef std::map M; + typedef std::move_iterator I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(C(3), A(7)); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A(7)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } + { + typedef std::pair V; + typedef std::pair VC; + typedef test_compare > C; + typedef test_allocator A; + typedef std::map M; + typedef std::move_iterator I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(C(3), A(5)); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A(5)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } + { + typedef std::pair V; + typedef std::pair VC; + typedef test_compare > C; + typedef other_allocator A; + typedef std::map M; + typedef std::move_iterator I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(C(3), A(5)); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A(7)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + typedef std::pair VC; + typedef test_compare > C; + typedef min_allocator A; + typedef std::map M; + typedef std::move_iterator I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A()); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A()); + M m3(C(3), A()); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A()); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..d12f9a9784f --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// map& operator=(map&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable::value && +// is_nothrow_move_assignable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp& operator=(const some_comp&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::map C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::map, test_allocator> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::map, other_allocator> C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::map> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.cons/move_noexcept.pass.cpp b/libcxx/test/std/containers/associative/map/map.cons/move_noexcept.pass.cpp new file mode 100644 index 00000000000..6de4b67b326 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.cons/move_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// map(map&&) +// noexcept(is_nothrow_move_constructible::value && +// is_nothrow_move_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp(const some_comp&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::map C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::map, test_allocator> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::map, other_allocator> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::map> C; + static_assert(!std::is_nothrow_move_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/clear.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/clear.pass.cpp new file mode 100644 index 00000000000..c37499df307 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.modifiers/clear.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// void clear(); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::map M; + typedef std::pair P; + P ar[] = + { + P(1, 1.5), + P(2, 2.5), + P(3, 3.5), + P(4, 4.5), + P(5, 5.5), + P(6, 6.5), + P(7, 7.5), + P(8, 8.5), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + m.clear(); + assert(m.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::map, min_allocator>> M; + typedef std::pair P; + P ar[] = + { + P(1, 1.5), + P(2, 2.5), + P(3, 3.5), + P(4, 4.5), + P(5, 5.5), + P(6, 6.5), + P(7, 7.5), + P(8, 8.5), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + m.clear(); + assert(m.size() == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/emplace.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/emplace.pass.cpp new file mode 100644 index 00000000000..81846c6647c --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.modifiers/emplace.pass.cpp @@ -0,0 +1,165 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// template +// pair emplace(Args&&... args); + +#include +#include +#include + +#include "../../../Emplaceable.h" +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::map M; + typedef std::pair R; + M m; + assert(DefaultOnly::count == 0); + R r = m.emplace(); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 0); + assert(m.begin()->second == DefaultOnly()); + assert(DefaultOnly::count == 1); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r.second); + assert(r.first == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(!r.second); + assert(r.first == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + } + assert(DefaultOnly::count == 0); + { + typedef std::map M; + typedef std::pair R; + M m; + R r = m.emplace(std::piecewise_construct, std::forward_as_tuple(2), + std::forward_as_tuple()); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(!r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + } + { + typedef std::map M; + typedef std::pair R; + M m; + R r = m.emplace(M::value_type(2, 3.5)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 3.5); + } +#if __cplusplus >= 201103L + { + typedef std::map, min_allocator>> M; + typedef std::pair R; + M m; + assert(DefaultOnly::count == 0); + R r = m.emplace(); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 0); + assert(m.begin()->second == DefaultOnly()); + assert(DefaultOnly::count == 1); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r.second); + assert(r.first == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(!r.second); + assert(r.first == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + } + assert(DefaultOnly::count == 0); + { + typedef std::map, min_allocator>> M; + typedef std::pair R; + M m; + R r = m.emplace(std::piecewise_construct, std::forward_as_tuple(2), + std::forward_as_tuple()); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(!r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + } + { + typedef std::map, min_allocator>> M; + typedef std::pair R; + M m; + R r = m.emplace(M::value_type(2, 3.5)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 3.5); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/emplace_hint.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/emplace_hint.pass.cpp new file mode 100644 index 00000000000..15f74b17e78 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.modifiers/emplace_hint.pass.cpp @@ -0,0 +1,160 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// template +// iterator emplace_hint(const_iterator position, Args&&... args); + +#include +#include + +#include "../../../Emplaceable.h" +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::map M; + typedef M::iterator R; + M m; + assert(DefaultOnly::count == 0); + R r = m.emplace_hint(m.end()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 0); + assert(m.begin()->second == DefaultOnly()); + assert(DefaultOnly::count == 1); + r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + } + assert(DefaultOnly::count == 0); + { + typedef std::map M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(2), + std::forward_as_tuple()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + } + { + typedef std::map M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.end(), M::value_type(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 3.5); + } +#if __cplusplus >= 201103L + { + typedef std::map, min_allocator>> M; + typedef M::iterator R; + M m; + assert(DefaultOnly::count == 0); + R r = m.emplace_hint(m.end()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 0); + assert(m.begin()->second == DefaultOnly()); + assert(DefaultOnly::count == 1); + r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + } + assert(DefaultOnly::count == 0); + { + typedef std::map, min_allocator>> M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(2), + std::forward_as_tuple()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + } + { + typedef std::map, min_allocator>> M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.end(), M::value_type(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 3.5); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/erase_iter.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/erase_iter.pass.cpp new file mode 100644 index 00000000000..05fb988e991 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.modifiers/erase_iter.pass.cpp @@ -0,0 +1,237 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// iterator erase(const_iterator position); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::map M; + typedef std::pair P; + typedef M::iterator I; + P ar[] = + { + P(1, 1.5), + P(2, 2.5), + P(3, 3.5), + P(4, 4.5), + P(5, 5.5), + P(6, 6.5), + P(7, 7.5), + P(8, 8.5), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(next(m.cbegin(), 3)); + assert(m.size() == 7); + assert(i == next(m.begin(), 3)); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1.5); + assert(next(m.begin())->first == 2); + assert(next(m.begin())->second == 2.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 3.5); + assert(next(m.begin(), 3)->first == 5); + assert(next(m.begin(), 3)->second == 5.5); + assert(next(m.begin(), 4)->first == 6); + assert(next(m.begin(), 4)->second == 6.5); + assert(next(m.begin(), 5)->first == 7); + assert(next(m.begin(), 5)->second == 7.5); + assert(next(m.begin(), 6)->first == 8); + assert(next(m.begin(), 6)->second == 8.5); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 6); + assert(i == m.begin()); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 3); + assert(next(m.begin())->second == 3.5); + assert(next(m.begin(), 2)->first == 5); + assert(next(m.begin(), 2)->second == 5.5); + assert(next(m.begin(), 3)->first == 6); + assert(next(m.begin(), 3)->second == 6.5); + assert(next(m.begin(), 4)->first == 7); + assert(next(m.begin(), 4)->second == 7.5); + assert(next(m.begin(), 5)->first == 8); + assert(next(m.begin(), 5)->second == 8.5); + + i = m.erase(next(m.cbegin(), 5)); + assert(m.size() == 5); + assert(i == m.end()); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 3); + assert(next(m.begin())->second == 3.5); + assert(next(m.begin(), 2)->first == 5); + assert(next(m.begin(), 2)->second == 5.5); + assert(next(m.begin(), 3)->first == 6); + assert(next(m.begin(), 3)->second == 6.5); + assert(next(m.begin(), 4)->first == 7); + assert(next(m.begin(), 4)->second == 7.5); + + i = m.erase(next(m.cbegin(), 1)); + assert(m.size() == 4); + assert(i == next(m.begin())); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 5); + assert(next(m.begin())->second == 5.5); + assert(next(m.begin(), 2)->first == 6); + assert(next(m.begin(), 2)->second == 6.5); + assert(next(m.begin(), 3)->first == 7); + assert(next(m.begin(), 3)->second == 7.5); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 3); + assert(i == next(m.begin(), 2)); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 5); + assert(next(m.begin())->second == 5.5); + assert(next(m.begin(), 2)->first == 7); + assert(next(m.begin(), 2)->second == 7.5); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 2); + assert(i == next(m.begin(), 2)); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 5); + assert(next(m.begin())->second == 5.5); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 1); + assert(i == next(m.begin(), 0)); + assert(m.begin()->first == 5); + assert(m.begin()->second == 5.5); + + i = m.erase(m.cbegin()); + assert(m.size() == 0); + assert(i == m.begin()); + assert(i == m.end()); + } +#if __cplusplus >= 201103L + { + typedef std::map, min_allocator>> M; + typedef std::pair P; + typedef M::iterator I; + P ar[] = + { + P(1, 1.5), + P(2, 2.5), + P(3, 3.5), + P(4, 4.5), + P(5, 5.5), + P(6, 6.5), + P(7, 7.5), + P(8, 8.5), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(next(m.cbegin(), 3)); + assert(m.size() == 7); + assert(i == next(m.begin(), 3)); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1.5); + assert(next(m.begin())->first == 2); + assert(next(m.begin())->second == 2.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 3.5); + assert(next(m.begin(), 3)->first == 5); + assert(next(m.begin(), 3)->second == 5.5); + assert(next(m.begin(), 4)->first == 6); + assert(next(m.begin(), 4)->second == 6.5); + assert(next(m.begin(), 5)->first == 7); + assert(next(m.begin(), 5)->second == 7.5); + assert(next(m.begin(), 6)->first == 8); + assert(next(m.begin(), 6)->second == 8.5); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 6); + assert(i == m.begin()); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 3); + assert(next(m.begin())->second == 3.5); + assert(next(m.begin(), 2)->first == 5); + assert(next(m.begin(), 2)->second == 5.5); + assert(next(m.begin(), 3)->first == 6); + assert(next(m.begin(), 3)->second == 6.5); + assert(next(m.begin(), 4)->first == 7); + assert(next(m.begin(), 4)->second == 7.5); + assert(next(m.begin(), 5)->first == 8); + assert(next(m.begin(), 5)->second == 8.5); + + i = m.erase(next(m.cbegin(), 5)); + assert(m.size() == 5); + assert(i == m.end()); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 3); + assert(next(m.begin())->second == 3.5); + assert(next(m.begin(), 2)->first == 5); + assert(next(m.begin(), 2)->second == 5.5); + assert(next(m.begin(), 3)->first == 6); + assert(next(m.begin(), 3)->second == 6.5); + assert(next(m.begin(), 4)->first == 7); + assert(next(m.begin(), 4)->second == 7.5); + + i = m.erase(next(m.cbegin(), 1)); + assert(m.size() == 4); + assert(i == next(m.begin())); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 5); + assert(next(m.begin())->second == 5.5); + assert(next(m.begin(), 2)->first == 6); + assert(next(m.begin(), 2)->second == 6.5); + assert(next(m.begin(), 3)->first == 7); + assert(next(m.begin(), 3)->second == 7.5); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 3); + assert(i == next(m.begin(), 2)); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 5); + assert(next(m.begin())->second == 5.5); + assert(next(m.begin(), 2)->first == 7); + assert(next(m.begin(), 2)->second == 7.5); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 2); + assert(i == next(m.begin(), 2)); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 5); + assert(next(m.begin())->second == 5.5); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 1); + assert(i == next(m.begin(), 0)); + assert(m.begin()->first == 5); + assert(m.begin()->second == 5.5); + + i = m.erase(m.cbegin()); + assert(m.size() == 0); + assert(i == m.begin()); + assert(i == m.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/erase_iter_iter.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..1b49956d8a5 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.modifiers/erase_iter_iter.pass.cpp @@ -0,0 +1,157 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// iterator erase(const_iterator first, const_iterator last); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::map M; + typedef std::pair P; + typedef M::iterator I; + P ar[] = + { + P(1, 1.5), + P(2, 2.5), + P(3, 3.5), + P(4, 4.5), + P(5, 5.5), + P(6, 6.5), + P(7, 7.5), + P(8, 8.5), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(m.cbegin(), m.cbegin()); + assert(m.size() == 8); + assert(i == m.begin()); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1.5); + assert(next(m.begin())->first == 2); + assert(next(m.begin())->second == 2.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 3.5); + assert(next(m.begin(), 3)->first == 4); + assert(next(m.begin(), 3)->second == 4.5); + assert(next(m.begin(), 4)->first == 5); + assert(next(m.begin(), 4)->second == 5.5); + assert(next(m.begin(), 5)->first == 6); + assert(next(m.begin(), 5)->second == 6.5); + assert(next(m.begin(), 6)->first == 7); + assert(next(m.begin(), 6)->second == 7.5); + assert(next(m.begin(), 7)->first == 8); + assert(next(m.begin(), 7)->second == 8.5); + + i = m.erase(m.cbegin(), next(m.cbegin(), 2)); + assert(m.size() == 6); + assert(i == m.begin()); + assert(next(m.begin(), 0)->first == 3); + assert(next(m.begin(), 0)->second == 3.5); + assert(next(m.begin(), 1)->first == 4); + assert(next(m.begin(), 1)->second == 4.5); + assert(next(m.begin(), 2)->first == 5); + assert(next(m.begin(), 2)->second == 5.5); + assert(next(m.begin(), 3)->first == 6); + assert(next(m.begin(), 3)->second == 6.5); + assert(next(m.begin(), 4)->first == 7); + assert(next(m.begin(), 4)->second == 7.5); + assert(next(m.begin(), 5)->first == 8); + assert(next(m.begin(), 5)->second == 8.5); + + i = m.erase(next(m.cbegin(), 2), next(m.cbegin(), 6)); + assert(m.size() == 2); + assert(i == next(m.begin(), 2)); + assert(next(m.begin(), 0)->first == 3); + assert(next(m.begin(), 0)->second == 3.5); + assert(next(m.begin(), 1)->first == 4); + assert(next(m.begin(), 1)->second == 4.5); + + i = m.erase(m.cbegin(), m.cend()); + assert(m.size() == 0); + assert(i == m.begin()); + assert(i == m.end()); + } +#if __cplusplus >= 201103L + { + typedef std::map, min_allocator>> M; + typedef std::pair P; + typedef M::iterator I; + P ar[] = + { + P(1, 1.5), + P(2, 2.5), + P(3, 3.5), + P(4, 4.5), + P(5, 5.5), + P(6, 6.5), + P(7, 7.5), + P(8, 8.5), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(m.cbegin(), m.cbegin()); + assert(m.size() == 8); + assert(i == m.begin()); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1.5); + assert(next(m.begin())->first == 2); + assert(next(m.begin())->second == 2.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 3.5); + assert(next(m.begin(), 3)->first == 4); + assert(next(m.begin(), 3)->second == 4.5); + assert(next(m.begin(), 4)->first == 5); + assert(next(m.begin(), 4)->second == 5.5); + assert(next(m.begin(), 5)->first == 6); + assert(next(m.begin(), 5)->second == 6.5); + assert(next(m.begin(), 6)->first == 7); + assert(next(m.begin(), 6)->second == 7.5); + assert(next(m.begin(), 7)->first == 8); + assert(next(m.begin(), 7)->second == 8.5); + + i = m.erase(m.cbegin(), next(m.cbegin(), 2)); + assert(m.size() == 6); + assert(i == m.begin()); + assert(next(m.begin(), 0)->first == 3); + assert(next(m.begin(), 0)->second == 3.5); + assert(next(m.begin(), 1)->first == 4); + assert(next(m.begin(), 1)->second == 4.5); + assert(next(m.begin(), 2)->first == 5); + assert(next(m.begin(), 2)->second == 5.5); + assert(next(m.begin(), 3)->first == 6); + assert(next(m.begin(), 3)->second == 6.5); + assert(next(m.begin(), 4)->first == 7); + assert(next(m.begin(), 4)->second == 7.5); + assert(next(m.begin(), 5)->first == 8); + assert(next(m.begin(), 5)->second == 8.5); + + i = m.erase(next(m.cbegin(), 2), next(m.cbegin(), 6)); + assert(m.size() == 2); + assert(i == next(m.begin(), 2)); + assert(next(m.begin(), 0)->first == 3); + assert(next(m.begin(), 0)->second == 3.5); + assert(next(m.begin(), 1)->first == 4); + assert(next(m.begin(), 1)->second == 4.5); + + i = m.erase(m.cbegin(), m.cend()); + assert(m.size() == 0); + assert(i == m.begin()); + assert(i == m.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/erase_key.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/erase_key.pass.cpp new file mode 100644 index 00000000000..e41f5129140 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.modifiers/erase_key.pass.cpp @@ -0,0 +1,275 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// size_type erase(const key_type& k); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::map M; + typedef std::pair P; + typedef M::size_type R; + P ar[] = + { + P(1, 1.5), + P(2, 2.5), + P(3, 3.5), + P(4, 4.5), + P(5, 5.5), + P(6, 6.5), + P(7, 7.5), + P(8, 8.5), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + R s = m.erase(9); + assert(s == 0); + assert(m.size() == 8); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1.5); + assert(next(m.begin())->first == 2); + assert(next(m.begin())->second == 2.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 3.5); + assert(next(m.begin(), 3)->first == 4); + assert(next(m.begin(), 3)->second == 4.5); + assert(next(m.begin(), 4)->first == 5); + assert(next(m.begin(), 4)->second == 5.5); + assert(next(m.begin(), 5)->first == 6); + assert(next(m.begin(), 5)->second == 6.5); + assert(next(m.begin(), 6)->first == 7); + assert(next(m.begin(), 6)->second == 7.5); + assert(next(m.begin(), 7)->first == 8); + assert(next(m.begin(), 7)->second == 8.5); + + s = m.erase(4); + assert(m.size() == 7); + assert(s == 1); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1.5); + assert(next(m.begin())->first == 2); + assert(next(m.begin())->second == 2.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 3.5); + assert(next(m.begin(), 3)->first == 5); + assert(next(m.begin(), 3)->second == 5.5); + assert(next(m.begin(), 4)->first == 6); + assert(next(m.begin(), 4)->second == 6.5); + assert(next(m.begin(), 5)->first == 7); + assert(next(m.begin(), 5)->second == 7.5); + assert(next(m.begin(), 6)->first == 8); + assert(next(m.begin(), 6)->second == 8.5); + + s = m.erase(1); + assert(m.size() == 6); + assert(s == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 3); + assert(next(m.begin())->second == 3.5); + assert(next(m.begin(), 2)->first == 5); + assert(next(m.begin(), 2)->second == 5.5); + assert(next(m.begin(), 3)->first == 6); + assert(next(m.begin(), 3)->second == 6.5); + assert(next(m.begin(), 4)->first == 7); + assert(next(m.begin(), 4)->second == 7.5); + assert(next(m.begin(), 5)->first == 8); + assert(next(m.begin(), 5)->second == 8.5); + + s = m.erase(8); + assert(m.size() == 5); + assert(s == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 3); + assert(next(m.begin())->second == 3.5); + assert(next(m.begin(), 2)->first == 5); + assert(next(m.begin(), 2)->second == 5.5); + assert(next(m.begin(), 3)->first == 6); + assert(next(m.begin(), 3)->second == 6.5); + assert(next(m.begin(), 4)->first == 7); + assert(next(m.begin(), 4)->second == 7.5); + + s = m.erase(3); + assert(m.size() == 4); + assert(s == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 5); + assert(next(m.begin())->second == 5.5); + assert(next(m.begin(), 2)->first == 6); + assert(next(m.begin(), 2)->second == 6.5); + assert(next(m.begin(), 3)->first == 7); + assert(next(m.begin(), 3)->second == 7.5); + + s = m.erase(6); + assert(m.size() == 3); + assert(s == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 5); + assert(next(m.begin())->second == 5.5); + assert(next(m.begin(), 2)->first == 7); + assert(next(m.begin(), 2)->second == 7.5); + + s = m.erase(7); + assert(m.size() == 2); + assert(s == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 5); + assert(next(m.begin())->second == 5.5); + + s = m.erase(2); + assert(m.size() == 1); + assert(s == 1); + assert(m.begin()->first == 5); + assert(m.begin()->second == 5.5); + + s = m.erase(5); + assert(m.size() == 0); + assert(s == 1); + } +#if __cplusplus >= 201103L + { + typedef std::map, min_allocator>> M; + typedef std::pair P; + typedef M::size_type R; + P ar[] = + { + P(1, 1.5), + P(2, 2.5), + P(3, 3.5), + P(4, 4.5), + P(5, 5.5), + P(6, 6.5), + P(7, 7.5), + P(8, 8.5), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + R s = m.erase(9); + assert(s == 0); + assert(m.size() == 8); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1.5); + assert(next(m.begin())->first == 2); + assert(next(m.begin())->second == 2.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 3.5); + assert(next(m.begin(), 3)->first == 4); + assert(next(m.begin(), 3)->second == 4.5); + assert(next(m.begin(), 4)->first == 5); + assert(next(m.begin(), 4)->second == 5.5); + assert(next(m.begin(), 5)->first == 6); + assert(next(m.begin(), 5)->second == 6.5); + assert(next(m.begin(), 6)->first == 7); + assert(next(m.begin(), 6)->second == 7.5); + assert(next(m.begin(), 7)->first == 8); + assert(next(m.begin(), 7)->second == 8.5); + + s = m.erase(4); + assert(m.size() == 7); + assert(s == 1); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1.5); + assert(next(m.begin())->first == 2); + assert(next(m.begin())->second == 2.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 3.5); + assert(next(m.begin(), 3)->first == 5); + assert(next(m.begin(), 3)->second == 5.5); + assert(next(m.begin(), 4)->first == 6); + assert(next(m.begin(), 4)->second == 6.5); + assert(next(m.begin(), 5)->first == 7); + assert(next(m.begin(), 5)->second == 7.5); + assert(next(m.begin(), 6)->first == 8); + assert(next(m.begin(), 6)->second == 8.5); + + s = m.erase(1); + assert(m.size() == 6); + assert(s == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 3); + assert(next(m.begin())->second == 3.5); + assert(next(m.begin(), 2)->first == 5); + assert(next(m.begin(), 2)->second == 5.5); + assert(next(m.begin(), 3)->first == 6); + assert(next(m.begin(), 3)->second == 6.5); + assert(next(m.begin(), 4)->first == 7); + assert(next(m.begin(), 4)->second == 7.5); + assert(next(m.begin(), 5)->first == 8); + assert(next(m.begin(), 5)->second == 8.5); + + s = m.erase(8); + assert(m.size() == 5); + assert(s == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 3); + assert(next(m.begin())->second == 3.5); + assert(next(m.begin(), 2)->first == 5); + assert(next(m.begin(), 2)->second == 5.5); + assert(next(m.begin(), 3)->first == 6); + assert(next(m.begin(), 3)->second == 6.5); + assert(next(m.begin(), 4)->first == 7); + assert(next(m.begin(), 4)->second == 7.5); + + s = m.erase(3); + assert(m.size() == 4); + assert(s == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 5); + assert(next(m.begin())->second == 5.5); + assert(next(m.begin(), 2)->first == 6); + assert(next(m.begin(), 2)->second == 6.5); + assert(next(m.begin(), 3)->first == 7); + assert(next(m.begin(), 3)->second == 7.5); + + s = m.erase(6); + assert(m.size() == 3); + assert(s == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 5); + assert(next(m.begin())->second == 5.5); + assert(next(m.begin(), 2)->first == 7); + assert(next(m.begin(), 2)->second == 7.5); + + s = m.erase(7); + assert(m.size() == 2); + assert(s == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 5); + assert(next(m.begin())->second == 5.5); + + s = m.erase(2); + assert(m.size() == 1); + assert(s == 1); + assert(m.begin()->first == 5); + assert(m.begin()->second == 5.5); + + s = m.erase(5); + assert(m.size() == 0); + assert(s == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/insert_cv.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/insert_cv.pass.cpp new file mode 100644 index 00000000000..3d28242fd32 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.modifiers/insert_cv.pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// pair insert(const value_type& v); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::map M; + typedef std::pair R; + M m; + R r = m.insert(M::value_type(2, 2.5)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(r.first->first == 2); + assert(r.first->second == 2.5); + + r = m.insert(M::value_type(1, 1.5)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(r.first->first == 1); + assert(r.first->second == 1.5); + + r = m.insert(M::value_type(3, 3.5)); + assert(r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(r.first->first == 3); + assert(r.first->second == 3.5); + + r = m.insert(M::value_type(3, 3.5)); + assert(!r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(r.first->first == 3); + assert(r.first->second == 3.5); + } +#if __cplusplus >= 201103L + { + typedef std::map, min_allocator>> M; + typedef std::pair R; + M m; + R r = m.insert(M::value_type(2, 2.5)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(r.first->first == 2); + assert(r.first->second == 2.5); + + r = m.insert(M::value_type(1, 1.5)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(r.first->first == 1); + assert(r.first->second == 1.5); + + r = m.insert(M::value_type(3, 3.5)); + assert(r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(r.first->first == 3); + assert(r.first->second == 3.5); + + r = m.insert(M::value_type(3, 3.5)); + assert(!r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(r.first->first == 3); + assert(r.first->second == 3.5); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/insert_initializer_list.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/insert_initializer_list.pass.cpp new file mode 100644 index 00000000000..ab325ed45bf --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.modifiers/insert_initializer_list.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// void insert(initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::pair V; + std::map m = + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }; + m.insert({ + {2, 1}, + {2, 1.5}, + {2, 2}, + }); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + std::map, min_allocator> m = + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }; + m.insert({ + {2, 1}, + {2, 1.5}, + {2, 2}, + }); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/insert_iter_cv.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/insert_iter_cv.pass.cpp new file mode 100644 index 00000000000..278db4631a8 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.modifiers/insert_iter_cv.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// iterator insert(const_iterator position, const value_type& v); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::map M; + typedef M::iterator R; + M m; + R r = m.insert(m.end(), M::value_type(2, 2.5)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2.5); + + r = m.insert(m.end(), M::value_type(1, 1.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1.5); + + r = m.insert(m.end(), M::value_type(3, 3.5)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3.5); + + r = m.insert(m.end(), M::value_type(3, 3.5)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3.5); + } +#if __cplusplus >= 201103L + { + typedef std::map, min_allocator>> M; + typedef M::iterator R; + M m; + R r = m.insert(m.end(), M::value_type(2, 2.5)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2.5); + + r = m.insert(m.end(), M::value_type(1, 1.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1.5); + + r = m.insert(m.end(), M::value_type(3, 3.5)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3.5); + + r = m.insert(m.end(), M::value_type(3, 3.5)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3.5); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/insert_iter_iter.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/insert_iter_iter.pass.cpp new file mode 100644 index 00000000000..964738b4a68 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.modifiers/insert_iter_iter.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// template +// void insert(InputIterator first, InputIterator last); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::map M; + typedef std::pair P; + P ar[] = + { + P(1, 1), + P(1, 1.5), + P(1, 2), + P(2, 1), + P(2, 1.5), + P(2, 2), + P(3, 1), + P(3, 1.5), + P(3, 2), + }; + M m; + m.insert(input_iterator(ar), input_iterator(ar + sizeof(ar)/sizeof(ar[0]))); + assert(m.size() == 3); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1); + assert(next(m.begin())->first == 2); + assert(next(m.begin())->second == 1); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 1); + } +#if __cplusplus >= 201103L + { + typedef std::map, min_allocator>> M; + typedef std::pair P; + P ar[] = + { + P(1, 1), + P(1, 1.5), + P(1, 2), + P(2, 1), + P(2, 1.5), + P(2, 2), + P(3, 1), + P(3, 1.5), + P(3, 2), + }; + M m; + m.insert(input_iterator(ar), input_iterator(ar + sizeof(ar)/sizeof(ar[0]))); + assert(m.size() == 3); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1); + assert(next(m.begin())->first == 2); + assert(next(m.begin())->second == 1); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp new file mode 100644 index 00000000000..22164202932 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// template +// iterator insert(const_iterator position, P&& p); + +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::map M; + typedef std::pair P; + typedef M::iterator R; + M m; + R r = m.insert(m.end(), P(2, 2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2); + + r = m.insert(m.end(), P(1, 1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1); + + r = m.insert(m.end(), P(3, 3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3); + + r = m.insert(m.end(), P(3, 3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3); + } +#if __cplusplus >= 201103L + { + typedef std::map, min_allocator>> M; + typedef std::pair P; + typedef M::iterator R; + M m; + R r = m.insert(m.end(), P(2, 2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2); + + r = m.insert(m.end(), P(1, 1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1); + + r = m.insert(m.end(), P(3, 3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3); + + r = m.insert(m.end(), P(3, 3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/insert_rv.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/insert_rv.pass.cpp new file mode 100644 index 00000000000..fea88957a70 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.modifiers/insert_rv.pass.cpp @@ -0,0 +1,93 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// template +// pair insert(P&& p); + +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::map M; + typedef std::pair R; + M m; + R r = m.insert(M::value_type(2, 2)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(r.first->first == 2); + assert(r.first->second == 2); + + r = m.insert(M::value_type(1, 1)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(r.first->first == 1); + assert(r.first->second == 1); + + r = m.insert(M::value_type(3, 3)); + assert(r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(r.first->first == 3); + assert(r.first->second == 3); + + r = m.insert(M::value_type(3, 3)); + assert(!r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(r.first->first == 3); + assert(r.first->second == 3); + } +#if __cplusplus >= 201103L + { + typedef std::map, min_allocator>> M; + typedef std::pair R; + M m; + R r = m.insert(M::value_type(2, 2)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(r.first->first == 2); + assert(r.first->second == 2); + + r = m.insert(M::value_type(1, 1)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(r.first->first == 1); + assert(r.first->second == 1); + + r = m.insert(M::value_type(3, 3)); + assert(r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(r.first->first == 3); + assert(r.first->second == 3); + + r = m.insert(M::value_type(3, 3)); + assert(!r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(r.first->first == 3); + assert(r.first->second == 3); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/map/map.ops/count.pass.cpp b/libcxx/test/std/containers/associative/map/map.ops/count.pass.cpp new file mode 100644 index 00000000000..9668055b8bc --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.ops/count.pass.cpp @@ -0,0 +1,173 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// size_type count(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + { + typedef std::pair V; + typedef std::map M; + { + typedef M::size_type R; + V ar[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.count(5); + assert(r == 1); + r = m.count(6); + assert(r == 1); + r = m.count(7); + assert(r == 1); + r = m.count(8); + assert(r == 1); + r = m.count(9); + assert(r == 1); + r = m.count(10); + assert(r == 1); + r = m.count(11); + assert(r == 1); + r = m.count(12); + assert(r == 1); + r = m.count(4); + assert(r == 0); + } + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + typedef std::map, min_allocator> M; + { + typedef M::size_type R; + V ar[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.count(5); + assert(r == 1); + r = m.count(6); + assert(r == 1); + r = m.count(7); + assert(r == 1); + r = m.count(8); + assert(r == 1); + r = m.count(9); + assert(r == 1); + r = m.count(10); + assert(r == 1); + r = m.count(11); + assert(r == 1); + r = m.count(12); + assert(r == 1); + r = m.count(4); + assert(r == 0); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair V; + typedef std::map> M; + typedef M::size_type R; + + V ar[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.count(5); + assert(r == 1); + r = m.count(6); + assert(r == 1); + r = m.count(7); + assert(r == 1); + r = m.count(8); + assert(r == 1); + r = m.count(9); + assert(r == 1); + r = m.count(10); + assert(r == 1); + r = m.count(11); + assert(r == 1); + r = m.count(12); + assert(r == 1); + r = m.count(4); + assert(r == 0); + } + + { + typedef PrivateConstructor PC; + typedef std::map> M; + typedef M::size_type R; + + M m; + m [ PC::make(5) ] = 5; + m [ PC::make(6) ] = 6; + m [ PC::make(7) ] = 7; + m [ PC::make(8) ] = 8; + m [ PC::make(9) ] = 9; + m [ PC::make(10) ] = 10; + m [ PC::make(11) ] = 11; + m [ PC::make(12) ] = 12; + + R r = m.count(5); + assert(r == 1); + r = m.count(6); + assert(r == 1); + r = m.count(7); + assert(r == 1); + r = m.count(8); + assert(r == 1); + r = m.count(9); + assert(r == 1); + r = m.count(10); + assert(r == 1); + r = m.count(11); + assert(r == 1); + r = m.count(12); + assert(r == 1); + r = m.count(4); + assert(r == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.ops/equal_range.pass.cpp b/libcxx/test/std/containers/associative/map/map.ops/equal_range.pass.cpp new file mode 100644 index 00000000000..dff751c3724 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.ops/equal_range.pass.cpp @@ -0,0 +1,437 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// pair equal_range(const key_type& k); +// pair equal_range(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + { + typedef std::pair V; + typedef std::map M; + { + typedef std::pair R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(11); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(13); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(15); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(17); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(19); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 8)); + r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(12); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(14); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(16); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(18); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(20); + assert(r.first == next(m.begin(), 8)); + assert(r.second == next(m.begin(), 8)); + } + { + typedef std::pair R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(11); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(13); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(15); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(17); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(19); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 8)); + r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(12); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(14); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(16); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(18); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(20); + assert(r.first == next(m.begin(), 8)); + assert(r.second == next(m.begin(), 8)); + } + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + typedef std::map, min_allocator> M; + { + typedef std::pair R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(11); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(13); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(15); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(17); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(19); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 8)); + r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(12); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(14); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(16); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(18); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(20); + assert(r.first == next(m.begin(), 8)); + assert(r.second == next(m.begin(), 8)); + } + { + typedef std::pair R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(11); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(13); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(15); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(17); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(19); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 8)); + r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(12); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(14); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(16); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(18); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(20); + assert(r.first == next(m.begin(), 8)); + assert(r.second == next(m.begin(), 8)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair V; + typedef std::map> M; + typedef std::pair R; + + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(11); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(13); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(15); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(17); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(19); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 8)); + r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(12); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(14); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(16); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(18); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(20); + assert(r.first == next(m.begin(), 8)); + assert(r.second == next(m.begin(), 8)); + } + { + typedef PrivateConstructor PC; + typedef std::map> M; + typedef std::pair R; + + M m; + m [ PC::make(5) ] = 5; + m [ PC::make(7) ] = 6; + m [ PC::make(9) ] = 7; + m [ PC::make(11) ] = 8; + m [ PC::make(13) ] = 9; + m [ PC::make(15) ] = 10; + m [ PC::make(17) ] = 11; + m [ PC::make(19) ] = 12; + + R r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(11); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(13); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(15); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(17); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(19); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 8)); + r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(12); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(14); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(16); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(18); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(20); + assert(r.first == next(m.begin(), 8)); + assert(r.second == next(m.begin(), 8)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.ops/find.pass.cpp b/libcxx/test/std/containers/associative/map/map.ops/find.pass.cpp new file mode 100644 index 00000000000..a7578449f5b --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.ops/find.pass.cpp @@ -0,0 +1,240 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + { + typedef std::pair V; + typedef std::map M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + typedef std::map, min_allocator> M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair V; + typedef std::map> M; + typedef M::iterator R; + + V ar[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + + { + typedef PrivateConstructor PC; + typedef std::map> M; + typedef M::iterator R; + + M m; + m [ PC::make(5) ] = 5; + m [ PC::make(6) ] = 6; + m [ PC::make(7) ] = 7; + m [ PC::make(8) ] = 8; + m [ PC::make(9) ] = 9; + m [ PC::make(10) ] = 10; + m [ PC::make(11) ] = 11; + m [ PC::make(12) ] = 12; + + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.ops/lower_bound.pass.cpp b/libcxx/test/std/containers/associative/map/map.ops/lower_bound.pass.cpp new file mode 100644 index 00000000000..87b84eef070 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.ops/lower_bound.pass.cpp @@ -0,0 +1,336 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + { + typedef std::pair V; + typedef std::map M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + typedef std::map, min_allocator> M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair V; + typedef std::map> M; + typedef M::iterator R; + + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } + + { + typedef PrivateConstructor PC; + typedef std::map> M; + typedef M::iterator R; + + M m; + m [ PC::make(5) ] = 5; + m [ PC::make(7) ] = 6; + m [ PC::make(9) ] = 7; + m [ PC::make(11) ] = 8; + m [ PC::make(13) ] = 9; + m [ PC::make(15) ] = 10; + m [ PC::make(17) ] = 11; + m [ PC::make(19) ] = 12; + + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.ops/upper_bound.pass.cpp b/libcxx/test/std/containers/associative/map/map.ops/upper_bound.pass.cpp new file mode 100644 index 00000000000..037ceb962cd --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.ops/upper_bound.pass.cpp @@ -0,0 +1,335 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + { + typedef std::pair V; + typedef std::map M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + typedef std::map, min_allocator> M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair V; + typedef std::map> M; + typedef M::iterator R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } + + { + typedef PrivateConstructor PC; + typedef std::map> M; + typedef M::iterator R; + + M m; + m [ PC::make(5) ] = 5; + m [ PC::make(7) ] = 6; + m [ PC::make(9) ] = 7; + m [ PC::make(11) ] = 8; + m [ PC::make(13) ] = 9; + m [ PC::make(15) ] = 10; + m [ PC::make(17) ] = 11; + m [ PC::make(19) ] = 12; + + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.special/member_swap.pass.cpp b/libcxx/test/std/containers/associative/map/map.special/member_swap.pass.cpp new file mode 100644 index 00000000000..4f7bd5154ed --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.special/member_swap.pass.cpp @@ -0,0 +1,201 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// void swap(map& m); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::pair V; + typedef std::map M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + typedef std::map, min_allocator> M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.special/non_member_swap.pass.cpp b/libcxx/test/std/containers/associative/map/map.special/non_member_swap.pass.cpp new file mode 100644 index 00000000000..57588e6ff16 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.special/non_member_swap.pass.cpp @@ -0,0 +1,306 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map + +// template +// void +// swap(map& x, map& y); + +#include +#include +#include "test_allocator.h" +#include "../../../test_compare.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::pair V; + typedef std::map M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + typedef test_allocator A; + typedef test_compare > C; + typedef std::map M; + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A(1)); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A(2)); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + assert(m1.key_comp() == C(2)); + assert(m1.get_allocator() == A(1)); + assert(m2.key_comp() == C(1)); + assert(m2.get_allocator() == A(2)); + } + { + typedef other_allocator A; + typedef test_compare > C; + typedef std::map M; + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A(1)); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A(2)); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + assert(m1.key_comp() == C(2)); + assert(m1.get_allocator() == A(2)); + assert(m2.key_comp() == C(1)); + assert(m2.get_allocator() == A(1)); + } + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + typedef std::map, min_allocator> M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + typedef min_allocator A; + typedef test_compare > C; + typedef std::map M; + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A()); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A()); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + assert(m1.key_comp() == C(2)); + assert(m1.get_allocator() == A()); + assert(m2.key_comp() == C(1)); + assert(m2.get_allocator() == A()); + } + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/map.special/swap_noexcept.pass.cpp b/libcxx/test/std/containers/associative/map/map.special/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..b8b78635166 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/map.special/swap_noexcept.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(map& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + + some_comp() {} + some_comp(const some_comp&) {} + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::map C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::map, test_allocator> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::map, other_allocator> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::map> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/types.pass.cpp b/libcxx/test/std/containers/associative/map/types.pass.cpp new file mode 100644 index 00000000000..d117deff693 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/types.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , +// class Allocator = allocator>> +// class map +// { +// public: +// // types: +// typedef Key key_type; +// typedef T mapped_type; +// typedef pair value_type; +// typedef Compare key_compare; +// typedef Allocator allocator_type; +// typedef typename allocator_type::reference reference; +// typedef typename allocator_type::const_reference const_reference; +// typedef typename allocator_type::pointer pointer; +// typedef typename allocator_type::const_pointer const_pointer; +// typedef typename allocator_type::size_type size_type; +// typedef typename allocator_type::difference_type difference_type; +// ... +// }; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::map C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same > >::value), ""); + static_assert((std::is_same&>::value), ""); + static_assert((std::is_same&>::value), ""); + static_assert((std::is_same*>::value), ""); + static_assert((std::is_same*>::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + } +#if __cplusplus >= 201103L + { + typedef std::map, min_allocator>> C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same > >::value), ""); + static_assert((std::is_same&>::value), ""); + static_assert((std::is_same&>::value), ""); + static_assert((std::is_same>>::value), ""); + static_assert((std::is_same>>::value), ""); +// min_allocator doesn't have a size_type, so one gets synthesized + static_assert((std::is_same::type>::value), ""); + static_assert((std::is_same::value), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/map/version.pass.cpp b/libcxx/test/std/containers/associative/map/version.pass.cpp new file mode 100644 index 00000000000..b2e3fa43e78 --- /dev/null +++ b/libcxx/test/std/containers/associative/map/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +#include + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/std/containers/associative/multimap/empty.pass.cpp b/libcxx/test/std/containers/associative/multimap/empty.pass.cpp new file mode 100644 index 00000000000..2384960d10d --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/empty.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// bool empty() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multimap M; + M m; + assert(m.empty()); + m.insert(M::value_type(1, 1.5)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + M m; + assert(m.empty()); + m.insert(M::value_type(1, 1.5)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/iterator.pass.cpp b/libcxx/test/std/containers/associative/multimap/iterator.pass.cpp new file mode 100644 index 00000000000..2763129acc2 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/iterator.pass.cpp @@ -0,0 +1,231 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// iterator begin(); +// const_iterator begin() const; +// iterator end(); +// const_iterator end() const; +// +// reverse_iterator rbegin(); +// const_reverse_iterator rbegin() const; +// reverse_iterator rend(); +// const_reverse_iterator rend() const; +// +// const_iterator cbegin() const; +// const_iterator cend() const; +// const_reverse_iterator crbegin() const; +// const_reverse_iterator crend() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + V(4, 1), + V(4, 1.5), + V(4, 2), + V(5, 1), + V(5, 1.5), + V(5, 2), + V(6, 1), + V(6, 1.5), + V(6, 2), + V(7, 1), + V(7, 1.5), + V(7, 2), + V(8, 1), + V(8, 1.5), + V(8, 2) + }; + std::multimap m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + std::multimap::iterator i; + i = m.begin(); + std::multimap::const_iterator k = i; + assert(i == k); + for (int j = 1; j <= 8; ++j) + for (double d = 1; d <= 2; d += .5, ++i) + { + assert(i->first == j); + assert(i->second == d); + i->second = 2.5; + assert(i->second == 2.5); + } + } + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + V(4, 1), + V(4, 1.5), + V(4, 2), + V(5, 1), + V(5, 1.5), + V(5, 2), + V(6, 1), + V(6, 1.5), + V(6, 2), + V(7, 1), + V(7, 1.5), + V(7, 2), + V(8, 1), + V(8, 1.5), + V(8, 2) + }; + const std::multimap m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.cbegin(), m.cend()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + assert(std::distance(m.crbegin(), m.crend()) == m.size()); + std::multimap::const_iterator i; + i = m.begin(); + for (int j = 1; j <= 8; ++j) + for (double d = 1; d <= 2; d += .5, ++i) + { + assert(i->first == j); + assert(i->second == d); + } + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + V(4, 1), + V(4, 1.5), + V(4, 2), + V(5, 1), + V(5, 1.5), + V(5, 2), + V(6, 1), + V(6, 1.5), + V(6, 2), + V(7, 1), + V(7, 1.5), + V(7, 2), + V(8, 1), + V(8, 1.5), + V(8, 2) + }; + std::multimap, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + std::multimap, min_allocator>::iterator i; + i = m.begin(); + std::multimap, min_allocator>::const_iterator k = i; + assert(i == k); + for (int j = 1; j <= 8; ++j) + for (double d = 1; d <= 2; d += .5, ++i) + { + assert(i->first == j); + assert(i->second == d); + i->second = 2.5; + assert(i->second == 2.5); + } + } + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + V(4, 1), + V(4, 1.5), + V(4, 2), + V(5, 1), + V(5, 1.5), + V(5, 2), + V(6, 1), + V(6, 1.5), + V(6, 2), + V(7, 1), + V(7, 1.5), + V(7, 2), + V(8, 1), + V(8, 1.5), + V(8, 2) + }; + const std::multimap, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.cbegin(), m.cend()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + assert(std::distance(m.crbegin(), m.crend()) == m.size()); + std::multimap, min_allocator>::const_iterator i; + i = m.begin(); + for (int j = 1; j <= 8; ++j) + for (double d = 1; d <= 2; d += .5, ++i) + { + assert(i->first == j); + assert(i->second == d); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + typedef std::multimap C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/max_size.pass.cpp b/libcxx/test/std/containers/associative/multimap/max_size.pass.cpp new file mode 100644 index 00000000000..ccd8b10638c --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/max_size.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// size_type max_size() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multimap M; + M m; + assert(m.max_size() != 0); + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + M m; + assert(m.max_size() != 0); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/alloc.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/alloc.pass.cpp new file mode 100644 index 00000000000..87bf0447e5b --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/alloc.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// explicit multimap(const allocator_type& a); + +#include +#include + +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::less C; + typedef test_allocator > A; + std::multimap m(A(5)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.get_allocator() == A(5)); + } +#if __cplusplus >= 201103L + { + typedef std::less C; + typedef min_allocator > A; + std::multimap m(A{}); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.get_allocator() == A()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..0c899183252 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// multimap& operator=(initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::multimap C; + typedef C::value_type V; + C m = {{20, 1}}; + m = + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }; + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + C::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(1, 2)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(2, 2)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 1.5)); + assert(*++i == V(3, 2)); + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> C; + typedef C::value_type V; + C m = {{20, 1}}; + m = + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }; + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + C::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(1, 2)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(2, 2)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 1.5)); + assert(*++i == V(3, 2)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/compare.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/compare.pass.cpp new file mode 100644 index 00000000000..9a4e0f987fd --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/compare.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// explicit multimap(const key_compare& comp); + +#include +#include + +#include "../../../test_compare.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_compare > C; + std::multimap m(C(3)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(3)); + } +#if __cplusplus >= 201103L + { + typedef test_compare > C; + std::multimap>> m(C(3)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(3)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/compare_alloc.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/compare_alloc.pass.cpp new file mode 100644 index 00000000000..1224884939c --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/compare_alloc.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// multimap(const key_compare& comp, const allocator_type& a); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_compare > C; + typedef test_allocator > A; + std::multimap m(C(4), A(5)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(4)); + assert(m.get_allocator() == A(5)); + } +#if __cplusplus >= 201103L + { + typedef test_compare > C; + typedef min_allocator > A; + std::multimap m(C(4), A()); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(4)); + assert(m.get_allocator() == A()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/copy.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/copy.pass.cpp new file mode 100644 index 00000000000..3d6626eaadb --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/copy.pass.cpp @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// multimap(const multimap& m); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef test_allocator A; + std::multimap mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::multimap m = mo; + assert(m == mo); + assert(m.get_allocator() == A(7)); + assert(m.key_comp() == C(5)); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef other_allocator A; + std::multimap mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::multimap m = mo; + assert(m == mo); + assert(m.get_allocator() == A(-2)); + assert(m.key_comp() == C(5)); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef min_allocator A; + std::multimap mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::multimap m = mo; + assert(m == mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/copy_alloc.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..22594e32d71 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/copy_alloc.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// multimap(const multimap& m, const allocator_type& a); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef test_allocator A; + std::multimap mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::multimap m(mo, A(3)); + assert(m == mo); + assert(m.get_allocator() == A(3)); + assert(m.key_comp() == C(5)); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef min_allocator A; + std::multimap mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::multimap m(mo, A()); + assert(m == mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/copy_assign.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/copy_assign.pass.cpp new file mode 100644 index 00000000000..2bdc4d6a70a --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/copy_assign.pass.cpp @@ -0,0 +1,125 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// multimap& operator=(const multimap& m); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef test_allocator A; + std::multimap mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2)); + std::multimap m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7)); + m = mo; + assert(m == mo); + assert(m.get_allocator() == A(7)); + assert(m.key_comp() == C(5)); + + assert(mo.get_allocator() == A(2)); + assert(mo.key_comp() == C(5)); + } + { + typedef std::pair V; + const V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + std::multimap m(ar, ar+sizeof(ar)/sizeof(ar[0])); + std::multimap *p = &m; + m = *p; + assert(m.size() == sizeof(ar)/sizeof(ar[0])); + assert(std::equal(m.begin(), m.end(), ar)); + } + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef other_allocator A; + std::multimap mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2)); + std::multimap m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7)); + m = mo; + assert(m == mo); + assert(m.get_allocator() == A(2)); + assert(m.key_comp() == C(5)); + + assert(mo.get_allocator() == A(2)); + assert(mo.key_comp() == C(5)); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef min_allocator A; + std::multimap mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::multimap m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A()); + m = mo; + assert(m == mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/default.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/default.pass.cpp new file mode 100644 index 00000000000..1c3ab8ce6c4 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/default.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// multimap(); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + std::multimap m; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#if __cplusplus >= 201103L + { + std::multimap, min_allocator>> m; + assert(m.empty()); + assert(m.begin() == m.end()); + } + { + std::multimap m = {}; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/default_noexcept.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/default_noexcept.pass.cpp new file mode 100644 index 00000000000..315efd15276 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/default_noexcept.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// multimap() +// noexcept( +// is_nothrow_default_constructible::value && +// is_nothrow_default_constructible::value && +// is_nothrow_copy_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp(); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multimap C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::multimap, test_allocator> C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::multimap, other_allocator> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::multimap> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..50d8f42a9ab --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// ~multimap() // implied noexcept; + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template +struct some_comp +{ + typedef T value_type; + ~some_comp() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multimap C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::multimap, test_allocator> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::multimap, other_allocator> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::multimap> C; + static_assert(!std::is_nothrow_destructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..937a202a55e --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/initializer_list.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// multimap(initializer_list il, const key_compare& comp = key_compare()); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::multimap C; + typedef C::value_type V; + C m = + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }; + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + C::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(1, 2)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(2, 2)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 1.5)); + assert(*++i == V(3, 2)); + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> C; + typedef C::value_type V; + C m = + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }; + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + C::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(1, 2)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(2, 2)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 1.5)); + assert(*++i == V(3, 2)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/initializer_list_compare.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/initializer_list_compare.pass.cpp new file mode 100644 index 00000000000..e6677039c90 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/initializer_list_compare.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// multimap(initializer_list il, const key_compare& comp = key_compare()); + +#include +#include +#include "../../../test_compare.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef test_compare > Cmp; + typedef std::multimap C; + typedef C::value_type V; + C m( + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }, + Cmp(4) + ); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + C::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(1, 2)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(2, 2)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 1.5)); + assert(*++i == V(3, 2)); + assert(m.key_comp() == Cmp(4)); + } +#if __cplusplus >= 201103L + { + typedef test_compare > Cmp; + typedef std::multimap>> C; + typedef C::value_type V; + C m( + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }, + Cmp(4) + ); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + C::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(1, 2)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(2, 2)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 1.5)); + assert(*++i == V(3, 2)); + assert(m.key_comp() == Cmp(4)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/initializer_list_compare_alloc.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/initializer_list_compare_alloc.pass.cpp new file mode 100644 index 00000000000..0e73f72793e --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/initializer_list_compare_alloc.pass.cpp @@ -0,0 +1,129 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// multimap(initializer_list il, const key_compare& comp, const allocator_type& a); + +#include +#include +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef test_compare > Cmp; + typedef test_allocator > A; + typedef std::multimap C; + typedef C::value_type V; + C m( + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }, + Cmp(4), A(5) + ); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + C::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(1, 2)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(2, 2)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 1.5)); + assert(*++i == V(3, 2)); + assert(m.key_comp() == Cmp(4)); + assert(m.get_allocator() == A(5)); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#if __cplusplus >= 201103L + { + typedef test_compare > Cmp; + typedef min_allocator > A; + typedef std::multimap C; + typedef C::value_type V; + C m( + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }, + Cmp(4), A() + ); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + C::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(1, 2)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(2, 2)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 1.5)); + assert(*++i == V(3, 2)); + assert(m.key_comp() == Cmp(4)); + assert(m.get_allocator() == A()); + } +#if _LIBCPP_STD_VER > 11 + { + typedef test_compare > C; + typedef std::pair V; + typedef min_allocator A; + typedef std::multimap M; + A a; + M m ({ {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }, a); + + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + M::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(1, 2)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(2, 2)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 1.5)); + assert(*++i == V(3, 2)); + assert(m.get_allocator() == a); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/iter_iter.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/iter_iter.pass.cpp new file mode 100644 index 00000000000..fa062e2be0b --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/iter_iter.pass.cpp @@ -0,0 +1,112 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// template +// multimap(InputIterator first, InputIterator last); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + std::multimap m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(1, 1.5)); + assert(*next(m.begin(), 2) == V(1, 2)); + assert(*next(m.begin(), 3) == V(2, 1)); + assert(*next(m.begin(), 4) == V(2, 1.5)); + assert(*next(m.begin(), 5) == V(2, 2)); + assert(*next(m.begin(), 6) == V(3, 1)); + assert(*next(m.begin(), 7) == V(3, 1.5)); + assert(*next(m.begin(), 8) == V(3, 2)); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + std::multimap, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(1, 1.5)); + assert(*next(m.begin(), 2) == V(1, 2)); + assert(*next(m.begin(), 3) == V(2, 1)); + assert(*next(m.begin(), 4) == V(2, 1.5)); + assert(*next(m.begin(), 5) == V(2, 2)); + assert(*next(m.begin(), 6) == V(3, 1)); + assert(*next(m.begin(), 7) == V(3, 1.5)); + assert(*next(m.begin(), 8) == V(3, 2)); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef min_allocator> A; + A a; + std::multimap, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), a); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(1, 1.5)); + assert(*next(m.begin(), 2) == V(1, 2)); + assert(*next(m.begin(), 3) == V(2, 1)); + assert(*next(m.begin(), 4) == V(2, 1.5)); + assert(*next(m.begin(), 5) == V(2, 2)); + assert(*next(m.begin(), 6) == V(3, 1)); + assert(*next(m.begin(), 7) == V(3, 1.5)); + assert(*next(m.begin(), 8) == V(3, 2)); + assert(m.get_allocator() == a); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/iter_iter_comp.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/iter_iter_comp.pass.cpp new file mode 100644 index 00000000000..d6de59428dd --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/iter_iter_comp.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// template +// multimap(InputIterator first, InputIterator last, +// const key_compare& comp); + +#include +#include + +#include "../../../test_compare.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + std::multimap m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5)); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(1, 1.5)); + assert(*next(m.begin(), 2) == V(1, 2)); + assert(*next(m.begin(), 3) == V(2, 1)); + assert(*next(m.begin(), 4) == V(2, 1.5)); + assert(*next(m.begin(), 5) == V(2, 2)); + assert(*next(m.begin(), 6) == V(3, 1)); + assert(*next(m.begin(), 7) == V(3, 1.5)); + assert(*next(m.begin(), 8) == V(3, 2)); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + std::multimap> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5)); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(1, 1.5)); + assert(*next(m.begin(), 2) == V(1, 2)); + assert(*next(m.begin(), 3) == V(2, 1)); + assert(*next(m.begin(), 4) == V(2, 1.5)); + assert(*next(m.begin(), 5) == V(2, 2)); + assert(*next(m.begin(), 6) == V(3, 1)); + assert(*next(m.begin(), 7) == V(3, 1.5)); + assert(*next(m.begin(), 8) == V(3, 2)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/iter_iter_comp_alloc.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/iter_iter_comp_alloc.pass.cpp new file mode 100644 index 00000000000..259fbd145ff --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/iter_iter_comp_alloc.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// template +// multimap(InputIterator first, InputIterator last, +// const key_compare& comp, const allocator_type& a); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef test_allocator A; + std::multimap m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + assert(m.get_allocator() == A(7)); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(1, 1.5)); + assert(*next(m.begin(), 2) == V(1, 2)); + assert(*next(m.begin(), 3) == V(2, 1)); + assert(*next(m.begin(), 4) == V(2, 1.5)); + assert(*next(m.begin(), 5) == V(2, 2)); + assert(*next(m.begin(), 6) == V(3, 1)); + assert(*next(m.begin(), 7) == V(3, 1.5)); + assert(*next(m.begin(), 8) == V(3, 2)); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef min_allocator A; + std::multimap m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(1, 1.5)); + assert(*next(m.begin(), 2) == V(1, 2)); + assert(*next(m.begin(), 3) == V(2, 1)); + assert(*next(m.begin(), 4) == V(2, 1.5)); + assert(*next(m.begin(), 5) == V(2, 2)); + assert(*next(m.begin(), 6) == V(3, 1)); + assert(*next(m.begin(), 7) == V(3, 1.5)); + assert(*next(m.begin(), 8) == V(3, 2)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/move.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/move.pass.cpp new file mode 100644 index 00000000000..aed08867c3c --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/move.pass.cpp @@ -0,0 +1,132 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// multimap(multimap&& m); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + typedef std::pair V; + { + typedef test_compare > C; + typedef test_allocator A; + std::multimap mo(C(5), A(7)); + std::multimap m = std::move(mo); + assert(m.get_allocator() == A(7)); + assert(m.key_comp() == C(5)); + assert(m.size() == 0); + assert(distance(m.begin(), m.end()) == 0); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } + { + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef test_allocator A; + std::multimap mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::multimap m = std::move(mo); + assert(m.get_allocator() == A(7)); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(1, 1.5)); + assert(*next(m.begin(), 2) == V(1, 2)); + assert(*next(m.begin(), 3) == V(2, 1)); + assert(*next(m.begin(), 4) == V(2, 1.5)); + assert(*next(m.begin(), 5) == V(2, 2)); + assert(*next(m.begin(), 6) == V(3, 1)); + assert(*next(m.begin(), 7) == V(3, 1.5)); + assert(*next(m.begin(), 8) == V(3, 2)); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } +#if __cplusplus >= 201103L + { + typedef test_compare > C; + typedef min_allocator A; + std::multimap mo(C(5), A()); + std::multimap m = std::move(mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 0); + assert(distance(m.begin(), m.end()) == 0); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } + { + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare > C; + typedef min_allocator A; + std::multimap mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::multimap m = std::move(mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(1, 1.5)); + assert(*next(m.begin(), 2) == V(1, 2)); + assert(*next(m.begin(), 3) == V(2, 1)); + assert(*next(m.begin(), 4) == V(2, 1.5)); + assert(*next(m.begin(), 5) == V(2, 2)); + assert(*next(m.begin(), 6) == V(3, 1)); + assert(*next(m.begin(), 7) == V(3, 1.5)); + assert(*next(m.begin(), 8) == V(3, 2)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/move_alloc.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..651993a769f --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/move_alloc.pass.cpp @@ -0,0 +1,186 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// multimap(multimap&& m, const allocator_type& a); + +#include +#include + +#include "../../../MoveOnly.h" +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::pair V; + typedef std::pair VC; + typedef test_compare > C; + typedef test_allocator A; + typedef std::multimap M; + typedef std::move_iterator I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(std::move(m1), A(7)); + assert(m3 == m2); + assert(m3.get_allocator() == A(7)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } + { + typedef std::pair V; + typedef std::pair VC; + typedef test_compare > C; + typedef test_allocator A; + typedef std::multimap M; + typedef std::move_iterator I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(std::move(m1), A(5)); + assert(m3 == m2); + assert(m3.get_allocator() == A(5)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } + { + typedef std::pair V; + typedef std::pair VC; + typedef test_compare > C; + typedef other_allocator A; + typedef std::multimap M; + typedef std::move_iterator I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(std::move(m1), A(5)); + assert(m3 == m2); + assert(m3.get_allocator() == A(5)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + typedef std::pair VC; + typedef test_compare > C; + typedef min_allocator A; + typedef std::multimap M; + typedef std::move_iterator I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A()); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A()); + M m3(std::move(m1), A()); + assert(m3 == m2); + assert(m3.get_allocator() == A()); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/move_assign.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/move_assign.pass.cpp new file mode 100644 index 00000000000..496e5357279 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/move_assign.pass.cpp @@ -0,0 +1,190 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// multimap& operator=(multimap&& m); + +#include +#include + +#include "../../../MoveOnly.h" +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::pair V; + typedef std::pair VC; + typedef test_compare > C; + typedef test_allocator A; + typedef std::multimap M; + typedef std::move_iterator I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(C(3), A(7)); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A(7)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } + { + typedef std::pair V; + typedef std::pair VC; + typedef test_compare > C; + typedef test_allocator A; + typedef std::multimap M; + typedef std::move_iterator I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(C(3), A(5)); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A(5)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } + { + typedef std::pair V; + typedef std::pair VC; + typedef test_compare > C; + typedef other_allocator A; + typedef std::multimap M; + typedef std::move_iterator I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(C(3), A(5)); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A(7)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#if __cplusplus >= 201103L + { + typedef std::pair V; + typedef std::pair VC; + typedef test_compare > C; + typedef min_allocator A; + typedef std::multimap M; + typedef std::move_iterator I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A()); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A()); + M m3(C(3), A()); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A()); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..b2488180c5e --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// multimap& operator=(multimap&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable::value && +// is_nothrow_move_assignable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp& operator=(const some_comp&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multimap C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::multimap, test_allocator> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::multimap, other_allocator> C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::multimap> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.cons/move_noexcept.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.cons/move_noexcept.pass.cpp new file mode 100644 index 00000000000..84316a1ea06 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.cons/move_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// multimap(multimap&&) +// noexcept(is_nothrow_move_constructible::value && +// is_nothrow_move_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp(const some_comp&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multimap C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::multimap, test_allocator> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::multimap, other_allocator> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::multimap> C; + static_assert(!std::is_nothrow_move_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/clear.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/clear.pass.cpp new file mode 100644 index 00000000000..fe9b8c8ba12 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/clear.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// void clear(); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multimap M; + typedef std::pair P; + P ar[] = + { + P(1, 1.5), + P(2, 2.5), + P(3, 3.5), + P(4, 4.5), + P(5, 5.5), + P(6, 6.5), + P(7, 7.5), + P(8, 8.5), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + m.clear(); + assert(m.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + typedef std::pair P; + P ar[] = + { + P(1, 1.5), + P(2, 2.5), + P(3, 3.5), + P(4, 4.5), + P(5, 5.5), + P(6, 6.5), + P(7, 7.5), + P(8, 8.5), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + m.clear(); + assert(m.size() == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/emplace.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/emplace.pass.cpp new file mode 100644 index 00000000000..03da4af5937 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/emplace.pass.cpp @@ -0,0 +1,150 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// template +// iterator emplace(Args&&... args); + +#include +#include + +#include "../../../Emplaceable.h" +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::multimap M; + typedef M::iterator R; + M m; + assert(DefaultOnly::count == 0); + R r = m.emplace(); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 0); + assert(m.begin()->second == DefaultOnly()); + assert(DefaultOnly::count == 1); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin(), 2)); + assert(m.size() == 3); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == DefaultOnly()); + assert(DefaultOnly::count == 3); + } + assert(DefaultOnly::count == 0); + { + typedef std::multimap M; + typedef M::iterator R; + M m; + R r = m.emplace(std::piecewise_construct, std::forward_as_tuple(2), + std::forward_as_tuple()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(3, 3.5)); + assert(r == next(m.begin())); + assert(m.size() == 3); + assert(r->first == 1); + assert(r->second == Emplaceable(3, 3.5)); + } + { + typedef std::multimap M; + typedef M::iterator R; + M m; + R r = m.emplace(M::value_type(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 3.5); + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + typedef M::iterator R; + M m; + assert(DefaultOnly::count == 0); + R r = m.emplace(); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 0); + assert(m.begin()->second == DefaultOnly()); + assert(DefaultOnly::count == 1); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin(), 2)); + assert(m.size() == 3); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == DefaultOnly()); + assert(DefaultOnly::count == 3); + } + assert(DefaultOnly::count == 0); + { + typedef std::multimap, min_allocator>> M; + typedef M::iterator R; + M m; + R r = m.emplace(std::piecewise_construct, std::forward_as_tuple(2), + std::forward_as_tuple()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(3, 3.5)); + assert(r == next(m.begin())); + assert(m.size() == 3); + assert(r->first == 1); + assert(r->second == Emplaceable(3, 3.5)); + } + { + typedef std::multimap, min_allocator>> M; + typedef M::iterator R; + M m; + R r = m.emplace(M::value_type(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 3.5); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/emplace_hint.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/emplace_hint.pass.cpp new file mode 100644 index 00000000000..846d5999a17 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/emplace_hint.pass.cpp @@ -0,0 +1,160 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// template +// iterator emplace_hint(const_iterator position, Args&&... args); + +#include +#include + +#include "../../../Emplaceable.h" +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::multimap M; + typedef M::iterator R; + M m; + assert(DefaultOnly::count == 0); + R r = m.emplace_hint(m.cend()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 0); + assert(m.begin()->second == DefaultOnly()); + assert(DefaultOnly::count == 1); + r = m.emplace_hint(m.cend(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace_hint(m.cend(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin(), 2)); + assert(m.size() == 3); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == DefaultOnly()); + assert(DefaultOnly::count == 3); + } + assert(DefaultOnly::count == 0); + { + typedef std::multimap M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.cend(), std::piecewise_construct, + std::forward_as_tuple(2), + std::forward_as_tuple()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace_hint(m.cbegin(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace_hint(m.cbegin(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(3, 3.5)); + assert(r == m.begin()); + assert(m.size() == 3); + assert(r->first == 1); + assert(r->second == Emplaceable(3, 3.5)); + } + { + typedef std::multimap M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.cend(), M::value_type(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 3.5); + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + typedef M::iterator R; + M m; + assert(DefaultOnly::count == 0); + R r = m.emplace_hint(m.cend()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 0); + assert(m.begin()->second == DefaultOnly()); + assert(DefaultOnly::count == 1); + r = m.emplace_hint(m.cend(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace_hint(m.cend(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin(), 2)); + assert(m.size() == 3); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == DefaultOnly()); + assert(DefaultOnly::count == 3); + } + assert(DefaultOnly::count == 0); + { + typedef std::multimap, min_allocator>> M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.cend(), std::piecewise_construct, + std::forward_as_tuple(2), + std::forward_as_tuple()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace_hint(m.cbegin(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace_hint(m.cbegin(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(3, 3.5)); + assert(r == m.begin()); + assert(m.size() == 3); + assert(r->first == 1); + assert(r->second == Emplaceable(3, 3.5)); + } + { + typedef std::multimap, min_allocator>> M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.cend(), M::value_type(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 3.5); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/erase_iter.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/erase_iter.pass.cpp new file mode 100644 index 00000000000..d91295b48c6 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/erase_iter.pass.cpp @@ -0,0 +1,279 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// iterator erase(const_iterator position); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multimap M; + typedef std::pair P; + typedef M::iterator I; + P ar[] = + { + P(1, 1), + P(1, 1.5), + P(1, 2), + P(2, 1), + P(2, 1.5), + P(2, 2), + P(3, 1), + P(3, 1.5), + P(3, 2), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 9); + I i = m.erase(next(m.cbegin(), 3)); + assert(m.size() == 8); + assert(i == next(m.begin(), 3)); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == 1.5); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == 2); + assert(next(m.begin(), 3)->first == 2); + assert(next(m.begin(), 3)->second == 1.5); + assert(next(m.begin(), 4)->first == 2); + assert(next(m.begin(), 4)->second == 2); + assert(next(m.begin(), 5)->first == 3); + assert(next(m.begin(), 5)->second == 1); + assert(next(m.begin(), 6)->first == 3); + assert(next(m.begin(), 6)->second == 1.5); + assert(next(m.begin(), 7)->first == 3); + assert(next(m.begin(), 7)->second == 2); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 7); + assert(i == m.begin()); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1.5); + assert(next(m.begin(), 1)->first == 1); + assert(next(m.begin(), 1)->second == 2); + assert(next(m.begin(), 2)->first == 2); + assert(next(m.begin(), 2)->second == 1.5); + assert(next(m.begin(), 3)->first == 2); + assert(next(m.begin(), 3)->second == 2); + assert(next(m.begin(), 4)->first == 3); + assert(next(m.begin(), 4)->second == 1); + assert(next(m.begin(), 5)->first == 3); + assert(next(m.begin(), 5)->second == 1.5); + assert(next(m.begin(), 6)->first == 3); + assert(next(m.begin(), 6)->second == 2); + + i = m.erase(next(m.cbegin(), 5)); + assert(m.size() == 6); + assert(i == prev(m.end())); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1.5); + assert(next(m.begin(), 1)->first == 1); + assert(next(m.begin(), 1)->second == 2); + assert(next(m.begin(), 2)->first == 2); + assert(next(m.begin(), 2)->second == 1.5); + assert(next(m.begin(), 3)->first == 2); + assert(next(m.begin(), 3)->second == 2); + assert(next(m.begin(), 4)->first == 3); + assert(next(m.begin(), 4)->second == 1); + assert(next(m.begin(), 5)->first == 3); + assert(next(m.begin(), 5)->second == 2); + + i = m.erase(next(m.cbegin(), 1)); + assert(m.size() == 5); + assert(i == next(m.begin())); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1.5); + assert(next(m.begin(), 1)->first == 2); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 2); + assert(next(m.begin(), 2)->second == 2); + assert(next(m.begin(), 3)->first == 3); + assert(next(m.begin(), 3)->second == 1); + assert(next(m.begin(), 4)->first == 3); + assert(next(m.begin(), 4)->second == 2); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 4); + assert(i == next(m.begin(), 2)); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1.5); + assert(next(m.begin(), 1)->first == 2); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 1); + assert(next(m.begin(), 3)->first == 3); + assert(next(m.begin(), 3)->second == 2); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 3); + assert(i == next(m.begin(), 2)); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1.5); + assert(next(m.begin(), 1)->first == 2); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 2); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 2); + assert(i == next(m.begin(), 0)); + assert(next(m.begin(), 0)->first == 2); + assert(next(m.begin(), 0)->second == 1.5); + assert(next(m.begin(), 1)->first == 3); + assert(next(m.begin(), 1)->second == 2); + + i = m.erase(next(m.cbegin(), 1)); + assert(m.size() == 1); + assert(i == m.end()); + assert(next(m.begin(), 0)->first == 2); + assert(next(m.begin(), 0)->second == 1.5); + + i = m.erase(m.cbegin()); + assert(m.size() == 0); + assert(i == m.begin()); + assert(i == m.end()); + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + typedef std::pair P; + typedef M::iterator I; + P ar[] = + { + P(1, 1), + P(1, 1.5), + P(1, 2), + P(2, 1), + P(2, 1.5), + P(2, 2), + P(3, 1), + P(3, 1.5), + P(3, 2), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 9); + I i = m.erase(next(m.cbegin(), 3)); + assert(m.size() == 8); + assert(i == next(m.begin(), 3)); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == 1.5); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == 2); + assert(next(m.begin(), 3)->first == 2); + assert(next(m.begin(), 3)->second == 1.5); + assert(next(m.begin(), 4)->first == 2); + assert(next(m.begin(), 4)->second == 2); + assert(next(m.begin(), 5)->first == 3); + assert(next(m.begin(), 5)->second == 1); + assert(next(m.begin(), 6)->first == 3); + assert(next(m.begin(), 6)->second == 1.5); + assert(next(m.begin(), 7)->first == 3); + assert(next(m.begin(), 7)->second == 2); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 7); + assert(i == m.begin()); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1.5); + assert(next(m.begin(), 1)->first == 1); + assert(next(m.begin(), 1)->second == 2); + assert(next(m.begin(), 2)->first == 2); + assert(next(m.begin(), 2)->second == 1.5); + assert(next(m.begin(), 3)->first == 2); + assert(next(m.begin(), 3)->second == 2); + assert(next(m.begin(), 4)->first == 3); + assert(next(m.begin(), 4)->second == 1); + assert(next(m.begin(), 5)->first == 3); + assert(next(m.begin(), 5)->second == 1.5); + assert(next(m.begin(), 6)->first == 3); + assert(next(m.begin(), 6)->second == 2); + + i = m.erase(next(m.cbegin(), 5)); + assert(m.size() == 6); + assert(i == prev(m.end())); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1.5); + assert(next(m.begin(), 1)->first == 1); + assert(next(m.begin(), 1)->second == 2); + assert(next(m.begin(), 2)->first == 2); + assert(next(m.begin(), 2)->second == 1.5); + assert(next(m.begin(), 3)->first == 2); + assert(next(m.begin(), 3)->second == 2); + assert(next(m.begin(), 4)->first == 3); + assert(next(m.begin(), 4)->second == 1); + assert(next(m.begin(), 5)->first == 3); + assert(next(m.begin(), 5)->second == 2); + + i = m.erase(next(m.cbegin(), 1)); + assert(m.size() == 5); + assert(i == next(m.begin())); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1.5); + assert(next(m.begin(), 1)->first == 2); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 2); + assert(next(m.begin(), 2)->second == 2); + assert(next(m.begin(), 3)->first == 3); + assert(next(m.begin(), 3)->second == 1); + assert(next(m.begin(), 4)->first == 3); + assert(next(m.begin(), 4)->second == 2); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 4); + assert(i == next(m.begin(), 2)); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1.5); + assert(next(m.begin(), 1)->first == 2); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 1); + assert(next(m.begin(), 3)->first == 3); + assert(next(m.begin(), 3)->second == 2); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 3); + assert(i == next(m.begin(), 2)); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1.5); + assert(next(m.begin(), 1)->first == 2); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 2); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 2); + assert(i == next(m.begin(), 0)); + assert(next(m.begin(), 0)->first == 2); + assert(next(m.begin(), 0)->second == 1.5); + assert(next(m.begin(), 1)->first == 3); + assert(next(m.begin(), 1)->second == 2); + + i = m.erase(next(m.cbegin(), 1)); + assert(m.size() == 1); + assert(i == m.end()); + assert(next(m.begin(), 0)->first == 2); + assert(next(m.begin(), 0)->second == 1.5); + + i = m.erase(m.cbegin()); + assert(m.size() == 0); + assert(i == m.begin()); + assert(i == m.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/erase_iter_iter.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..4d378949311 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/erase_iter_iter.pass.cpp @@ -0,0 +1,157 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// iterator erase(const_iterator first, const_iterator last); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multimap M; + typedef std::pair P; + typedef M::iterator I; + P ar[] = + { + P(1, 1.5), + P(2, 2.5), + P(3, 3.5), + P(4, 4.5), + P(5, 5.5), + P(6, 6.5), + P(7, 7.5), + P(8, 8.5), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(m.cbegin(), m.cbegin()); + assert(m.size() == 8); + assert(i == m.begin()); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1.5); + assert(next(m.begin())->first == 2); + assert(next(m.begin())->second == 2.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 3.5); + assert(next(m.begin(), 3)->first == 4); + assert(next(m.begin(), 3)->second == 4.5); + assert(next(m.begin(), 4)->first == 5); + assert(next(m.begin(), 4)->second == 5.5); + assert(next(m.begin(), 5)->first == 6); + assert(next(m.begin(), 5)->second == 6.5); + assert(next(m.begin(), 6)->first == 7); + assert(next(m.begin(), 6)->second == 7.5); + assert(next(m.begin(), 7)->first == 8); + assert(next(m.begin(), 7)->second == 8.5); + + i = m.erase(m.cbegin(), next(m.cbegin(), 2)); + assert(m.size() == 6); + assert(i == m.begin()); + assert(next(m.begin(), 0)->first == 3); + assert(next(m.begin(), 0)->second == 3.5); + assert(next(m.begin(), 1)->first == 4); + assert(next(m.begin(), 1)->second == 4.5); + assert(next(m.begin(), 2)->first == 5); + assert(next(m.begin(), 2)->second == 5.5); + assert(next(m.begin(), 3)->first == 6); + assert(next(m.begin(), 3)->second == 6.5); + assert(next(m.begin(), 4)->first == 7); + assert(next(m.begin(), 4)->second == 7.5); + assert(next(m.begin(), 5)->first == 8); + assert(next(m.begin(), 5)->second == 8.5); + + i = m.erase(next(m.cbegin(), 2), next(m.cbegin(), 6)); + assert(m.size() == 2); + assert(i == next(m.begin(), 2)); + assert(next(m.begin(), 0)->first == 3); + assert(next(m.begin(), 0)->second == 3.5); + assert(next(m.begin(), 1)->first == 4); + assert(next(m.begin(), 1)->second == 4.5); + + i = m.erase(m.cbegin(), m.cend()); + assert(m.size() == 0); + assert(i == m.begin()); + assert(i == m.end()); + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + typedef std::pair P; + typedef M::iterator I; + P ar[] = + { + P(1, 1.5), + P(2, 2.5), + P(3, 3.5), + P(4, 4.5), + P(5, 5.5), + P(6, 6.5), + P(7, 7.5), + P(8, 8.5), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(m.cbegin(), m.cbegin()); + assert(m.size() == 8); + assert(i == m.begin()); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1.5); + assert(next(m.begin())->first == 2); + assert(next(m.begin())->second == 2.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 3.5); + assert(next(m.begin(), 3)->first == 4); + assert(next(m.begin(), 3)->second == 4.5); + assert(next(m.begin(), 4)->first == 5); + assert(next(m.begin(), 4)->second == 5.5); + assert(next(m.begin(), 5)->first == 6); + assert(next(m.begin(), 5)->second == 6.5); + assert(next(m.begin(), 6)->first == 7); + assert(next(m.begin(), 6)->second == 7.5); + assert(next(m.begin(), 7)->first == 8); + assert(next(m.begin(), 7)->second == 8.5); + + i = m.erase(m.cbegin(), next(m.cbegin(), 2)); + assert(m.size() == 6); + assert(i == m.begin()); + assert(next(m.begin(), 0)->first == 3); + assert(next(m.begin(), 0)->second == 3.5); + assert(next(m.begin(), 1)->first == 4); + assert(next(m.begin(), 1)->second == 4.5); + assert(next(m.begin(), 2)->first == 5); + assert(next(m.begin(), 2)->second == 5.5); + assert(next(m.begin(), 3)->first == 6); + assert(next(m.begin(), 3)->second == 6.5); + assert(next(m.begin(), 4)->first == 7); + assert(next(m.begin(), 4)->second == 7.5); + assert(next(m.begin(), 5)->first == 8); + assert(next(m.begin(), 5)->second == 8.5); + + i = m.erase(next(m.cbegin(), 2), next(m.cbegin(), 6)); + assert(m.size() == 2); + assert(i == next(m.begin(), 2)); + assert(next(m.begin(), 0)->first == 3); + assert(next(m.begin(), 0)->second == 3.5); + assert(next(m.begin(), 1)->first == 4); + assert(next(m.begin(), 1)->second == 4.5); + + i = m.erase(m.cbegin(), m.cend()); + assert(m.size() == 0); + assert(i == m.begin()); + assert(i == m.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/erase_key.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/erase_key.pass.cpp new file mode 100644 index 00000000000..33821d3e359 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/erase_key.pass.cpp @@ -0,0 +1,153 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// size_type erase(const key_type& k); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multimap M; + typedef std::pair P; + typedef M::size_type I; + P ar[] = + { + P(1, 1), + P(1, 1.5), + P(1, 2), + P(2, 1), + P(2, 1.5), + P(2, 2), + P(3, 1), + P(3, 1.5), + P(3, 2), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 9); + I i = m.erase(2); + assert(m.size() == 6); + assert(i == 3); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1); + assert(next(m.begin(), 1)->first == 1); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == 2); + assert(next(m.begin(), 3)->first == 3); + assert(next(m.begin(), 3)->second == 1); + assert(next(m.begin(), 4)->first == 3); + assert(next(m.begin(), 4)->second == 1.5); + assert(next(m.begin(), 5)->first == 3); + assert(next(m.begin(), 5)->second == 2); + + i = m.erase(2); + assert(m.size() == 6); + assert(i == 0); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1); + assert(next(m.begin(), 1)->first == 1); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == 2); + assert(next(m.begin(), 3)->first == 3); + assert(next(m.begin(), 3)->second == 1); + assert(next(m.begin(), 4)->first == 3); + assert(next(m.begin(), 4)->second == 1.5); + assert(next(m.begin(), 5)->first == 3); + assert(next(m.begin(), 5)->second == 2); + + i = m.erase(3); + assert(i == 3); + assert(m.size() == 3); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1); + assert(next(m.begin(), 1)->first == 1); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == 2); + + i = m.erase(1); + assert(m.size() == 0); + assert(i == 3); + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + typedef std::pair P; + typedef M::size_type I; + P ar[] = + { + P(1, 1), + P(1, 1.5), + P(1, 2), + P(2, 1), + P(2, 1.5), + P(2, 2), + P(3, 1), + P(3, 1.5), + P(3, 2), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 9); + I i = m.erase(2); + assert(m.size() == 6); + assert(i == 3); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1); + assert(next(m.begin(), 1)->first == 1); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == 2); + assert(next(m.begin(), 3)->first == 3); + assert(next(m.begin(), 3)->second == 1); + assert(next(m.begin(), 4)->first == 3); + assert(next(m.begin(), 4)->second == 1.5); + assert(next(m.begin(), 5)->first == 3); + assert(next(m.begin(), 5)->second == 2); + + i = m.erase(2); + assert(m.size() == 6); + assert(i == 0); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1); + assert(next(m.begin(), 1)->first == 1); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == 2); + assert(next(m.begin(), 3)->first == 3); + assert(next(m.begin(), 3)->second == 1); + assert(next(m.begin(), 4)->first == 3); + assert(next(m.begin(), 4)->second == 1.5); + assert(next(m.begin(), 5)->first == 3); + assert(next(m.begin(), 5)->second == 2); + + i = m.erase(3); + assert(i == 3); + assert(m.size() == 3); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1); + assert(next(m.begin(), 1)->first == 1); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == 2); + + i = m.erase(1); + assert(m.size() == 0); + assert(i == 3); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_cv.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_cv.pass.cpp new file mode 100644 index 00000000000..d9afc9d0fdf --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_cv.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// iterator insert(const value_type& v); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multimap M; + typedef M::iterator R; + M m; + R r = m.insert(M::value_type(2, 2.5)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2.5); + + r = m.insert(M::value_type(1, 1.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1.5); + + r = m.insert(M::value_type(3, 3.5)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3.5); + + r = m.insert(M::value_type(3, 3.5)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(r->first == 3); + assert(r->second == 3.5); + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + typedef M::iterator R; + M m; + R r = m.insert(M::value_type(2, 2.5)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2.5); + + r = m.insert(M::value_type(1, 1.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1.5); + + r = m.insert(M::value_type(3, 3.5)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3.5); + + r = m.insert(M::value_type(3, 3.5)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(r->first == 3); + assert(r->second == 3.5); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_initializer_list.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_initializer_list.pass.cpp new file mode 100644 index 00000000000..5e1a1d4125e --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_initializer_list.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// void insert(initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::multimap C; + typedef C::value_type V; + C m = + { + {1, 1}, + {1, 2}, + {2, 1}, + {2, 2}, + {3, 1}, + {3, 2} + }; + m.insert( + { + {1, 1.5}, + {2, 1.5}, + {3, 1.5}, + } + ); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + C::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 2)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 2)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 2)); + assert(*++i == V(3, 1.5)); + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> C; + typedef C::value_type V; + C m = + { + {1, 1}, + {1, 2}, + {2, 1}, + {2, 2}, + {3, 1}, + {3, 2} + }; + m.insert( + { + {1, 1.5}, + {2, 1.5}, + {3, 1.5}, + } + ); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + C::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 2)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 2)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 2)); + assert(*++i == V(3, 1.5)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_cv.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_cv.pass.cpp new file mode 100644 index 00000000000..b83c802c04c --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_cv.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// iterator insert(const_iterator position, const value_type& v); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multimap M; + typedef M::iterator R; + M m; + R r = m.insert(m.end(), M::value_type(2, 2.5)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2.5); + + r = m.insert(m.end(), M::value_type(1, 1.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1.5); + + r = m.insert(m.end(), M::value_type(3, 3.5)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3.5); + + r = m.insert(prev(m.end()), M::value_type(3, 4.5)); + assert(r == prev(m.end(), 2)); + assert(m.size() == 4); + assert(r->first == 3); + assert(r->second == 4.5); + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + typedef M::iterator R; + M m; + R r = m.insert(m.end(), M::value_type(2, 2.5)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2.5); + + r = m.insert(m.end(), M::value_type(1, 1.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1.5); + + r = m.insert(m.end(), M::value_type(3, 3.5)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3.5); + + r = m.insert(prev(m.end()), M::value_type(3, 4.5)); + assert(r == prev(m.end(), 2)); + assert(m.size() == 4); + assert(r->first == 3); + assert(r->second == 4.5); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_iter.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_iter.pass.cpp new file mode 100644 index 00000000000..70ff7ef6d6b --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_iter.pass.cpp @@ -0,0 +1,101 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// template +// void insert(InputIterator first, InputIterator last); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::multimap M; + typedef std::pair P; + P ar[] = + { + P(1, 1), + P(1, 1.5), + P(1, 2), + P(2, 1), + P(2, 1.5), + P(2, 2), + P(3, 1), + P(3, 1.5), + P(3, 2), + }; + M m; + m.insert(input_iterator(ar), input_iterator(ar + sizeof(ar)/sizeof(ar[0]))); + assert(m.size() == 9); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == 1.5); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == 2); + assert(next(m.begin(), 3)->first == 2); + assert(next(m.begin(), 3)->second == 1); + assert(next(m.begin(), 4)->first == 2); + assert(next(m.begin(), 4)->second == 1.5); + assert(next(m.begin(), 5)->first == 2); + assert(next(m.begin(), 5)->second == 2); + assert(next(m.begin(), 6)->first == 3); + assert(next(m.begin(), 6)->second == 1); + assert(next(m.begin(), 7)->first == 3); + assert(next(m.begin(), 7)->second == 1.5); + assert(next(m.begin(), 8)->first == 3); + assert(next(m.begin(), 8)->second == 2); + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + typedef std::pair P; + P ar[] = + { + P(1, 1), + P(1, 1.5), + P(1, 2), + P(2, 1), + P(2, 1.5), + P(2, 2), + P(3, 1), + P(3, 1.5), + P(3, 2), + }; + M m; + m.insert(input_iterator(ar), input_iterator(ar + sizeof(ar)/sizeof(ar[0]))); + assert(m.size() == 9); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == 1.5); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == 2); + assert(next(m.begin(), 3)->first == 2); + assert(next(m.begin(), 3)->second == 1); + assert(next(m.begin(), 4)->first == 2); + assert(next(m.begin(), 4)->second == 1.5); + assert(next(m.begin(), 5)->first == 2); + assert(next(m.begin(), 5)->second == 2); + assert(next(m.begin(), 6)->first == 3); + assert(next(m.begin(), 6)->second == 1); + assert(next(m.begin(), 7)->first == 3); + assert(next(m.begin(), 7)->second == 1.5); + assert(next(m.begin(), 8)->first == 3); + assert(next(m.begin(), 8)->second == 2); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_rv.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_rv.pass.cpp new file mode 100644 index 00000000000..60ca7d4a5b4 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_rv.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// template +// iterator insert(const_iterator position, P&& p); + +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::multimap M; + typedef std::pair P; + typedef M::iterator R; + M m; + R r = m.insert(m.cend(), P(2, 2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2); + + r = m.insert(m.cend(), P(1, 1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1); + + r = m.insert(m.cend(), P(3, 3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3); + + r = m.insert(m.cend(), P(3, 2)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(r->first == 3); + assert(r->second == 2); + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + typedef std::pair P; + typedef M::iterator R; + M m; + R r = m.insert(m.cend(), P(2, 2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2); + + r = m.insert(m.cend(), P(1, 1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1); + + r = m.insert(m.cend(), P(3, 3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3); + + r = m.insert(m.cend(), P(3, 2)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(r->first == 3); + assert(r->second == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_rv.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_rv.pass.cpp new file mode 100644 index 00000000000..2f198f8f7c2 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_rv.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// template +// iterator insert(P&& p); + +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::multimap M; + typedef M::iterator R; + M m; + R r = m.insert(M::value_type(2, 2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2); + + r = m.insert(M::value_type(1, 1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1); + + r = m.insert(M::value_type(3, 3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3); + + r = m.insert(M::value_type(3, 3)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(r->first == 3); + assert(r->second == 3); + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + typedef M::iterator R; + M m; + R r = m.insert(M::value_type(2, 2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2); + + r = m.insert(M::value_type(1, 1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1); + + r = m.insert(M::value_type(3, 3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3); + + r = m.insert(M::value_type(3, 3)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(r->first == 3); + assert(r->second == 3); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.ops/count.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.ops/count.pass.cpp new file mode 100644 index 00000000000..2f172d11d67 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.ops/count.pass.cpp @@ -0,0 +1,159 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// size_type count(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + typedef std::pair V; + { + typedef std::multimap M; + { + typedef M::size_type R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.count(4); + assert(r == 0); + r = m.count(5); + assert(r == 3); + r = m.count(6); + assert(r == 0); + r = m.count(7); + assert(r == 3); + r = m.count(8); + assert(r == 0); + r = m.count(9); + assert(r == 3); + r = m.count(10); + assert(r == 0); + } + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + { + typedef M::size_type R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.count(4); + assert(r == 0); + r = m.count(5); + assert(r == 3); + r = m.count(6); + assert(r == 0); + r = m.count(7); + assert(r == 3); + r = m.count(8); + assert(r == 0); + r = m.count(9); + assert(r == 3); + r = m.count(10); + assert(r == 0); + } + } +#endif + +#if _LIBCPP_STD_VER > 11 + { + typedef std::multimap> M; + typedef M::size_type R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.count(4); + assert(r == 0); + r = m.count(5); + assert(r == 3); + r = m.count(6); + assert(r == 0); + r = m.count(7); + assert(r == 3); + r = m.count(8); + assert(r == 0); + r = m.count(9); + assert(r == 3); + r = m.count(10); + assert(r == 0); + } + + { + typedef PrivateConstructor PC; + typedef std::multimap> M; + typedef M::size_type R; + + M m; + m.insert ( std::make_pair ( PC::make(5), 1 )); + m.insert ( std::make_pair ( PC::make(5), 2 )); + m.insert ( std::make_pair ( PC::make(5), 3 )); + m.insert ( std::make_pair ( PC::make(7), 1 )); + m.insert ( std::make_pair ( PC::make(7), 2 )); + m.insert ( std::make_pair ( PC::make(7), 3 )); + m.insert ( std::make_pair ( PC::make(9), 1 )); + m.insert ( std::make_pair ( PC::make(9), 2 )); + m.insert ( std::make_pair ( PC::make(9), 3 )); + + R r = m.count(4); + assert(r == 0); + r = m.count(5); + assert(r == 3); + r = m.count(6); + assert(r == 0); + r = m.count(7); + assert(r == 3); + r = m.count(8); + assert(r == 0); + r = m.count(9); + assert(r == 3); + r = m.count(10); + assert(r == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.ops/equal_range.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.ops/equal_range.pass.cpp new file mode 100644 index 00000000000..a408796d1fb --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.ops/equal_range.pass.cpp @@ -0,0 +1,264 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// pair equal_range(const key_type& k); +// pair equal_range(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + typedef std::pair V; + { + typedef std::multimap M; + { + typedef std::pair R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(4); + assert(r.first == m.begin()); + assert(r.second == m.begin()); + r = m.equal_range(5); + assert(r.first == m.begin()); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(10); + assert(r.first == m.end()); + assert(r.second == m.end()); + } + { + typedef std::pair R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(4); + assert(r.first == m.begin()); + assert(r.second == m.begin()); + r = m.equal_range(5); + assert(r.first == m.begin()); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(10); + assert(r.first == m.end()); + assert(r.second == m.end()); + } + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + { + typedef std::pair R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(4); + assert(r.first == m.begin()); + assert(r.second == m.begin()); + r = m.equal_range(5); + assert(r.first == m.begin()); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(10); + assert(r.first == m.end()); + assert(r.second == m.end()); + } + { + typedef std::pair R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(4); + assert(r.first == m.begin()); + assert(r.second == m.begin()); + r = m.equal_range(5); + assert(r.first == m.begin()); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(10); + assert(r.first == m.end()); + assert(r.second == m.end()); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair V; + typedef std::multimap> M; + + typedef std::pair R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(4); + assert(r.first == m.begin()); + assert(r.second == m.begin()); + r = m.equal_range(5); + assert(r.first == m.begin()); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(10); + assert(r.first == m.end()); + assert(r.second == m.end()); + } + + { + typedef PrivateConstructor PC; + typedef std::multimap> M; + typedef std::pair R; + + M m; + m.insert ( std::make_pair ( PC::make(5), 1 )); + m.insert ( std::make_pair ( PC::make(5), 2 )); + m.insert ( std::make_pair ( PC::make(5), 3 )); + m.insert ( std::make_pair ( PC::make(7), 1 )); + m.insert ( std::make_pair ( PC::make(7), 2 )); + m.insert ( std::make_pair ( PC::make(7), 3 )); + m.insert ( std::make_pair ( PC::make(9), 1 )); + m.insert ( std::make_pair ( PC::make(9), 2 )); + m.insert ( std::make_pair ( PC::make(9), 3 )); + +// assert(m.size() == 9); + R r = m.equal_range(4); + assert(r.first == m.begin()); + assert(r.second == m.begin()); + r = m.equal_range(5); + assert(r.first == m.begin()); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(10); + assert(r.first == m.end()); + assert(r.second == m.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.ops/find.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.ops/find.pass.cpp new file mode 100644 index 00000000000..fb5afa241ca --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.ops/find.pass.cpp @@ -0,0 +1,209 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + typedef std::pair V; + { + typedef std::multimap M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == m.end()); + r = m.find(7); + assert(r == next(m.begin(), 3)); + r = m.find(8); + assert(r == m.end()); + r = m.find(9); + assert(r == next(m.begin(), 6)); + r = m.find(10); + assert(r == m.end()); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == m.end()); + r = m.find(7); + assert(r == next(m.begin(), 3)); + r = m.find(8); + assert(r == m.end()); + r = m.find(9); + assert(r == next(m.begin(), 6)); + r = m.find(10); + assert(r == m.end()); + } + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == m.end()); + r = m.find(7); + assert(r == next(m.begin(), 3)); + r = m.find(8); + assert(r == m.end()); + r = m.find(9); + assert(r == next(m.begin(), 6)); + r = m.find(10); + assert(r == m.end()); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == m.end()); + r = m.find(7); + assert(r == next(m.begin(), 3)); + r = m.find(8); + assert(r == m.end()); + r = m.find(9); + assert(r == next(m.begin(), 6)); + r = m.find(10); + assert(r == m.end()); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair V; + typedef std::multimap> M; + typedef M::iterator R; + + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == m.end()); + r = m.find(7); + assert(r == next(m.begin(), 3)); + r = m.find(8); + assert(r == m.end()); + r = m.find(9); + assert(r == next(m.begin(), 6)); + r = m.find(10); + assert(r == m.end()); + } + + { + typedef PrivateConstructor PC; + typedef std::multimap> M; + typedef M::iterator R; + + M m; + m.insert ( std::make_pair ( PC::make(5), 1 )); + m.insert ( std::make_pair ( PC::make(5), 2 )); + m.insert ( std::make_pair ( PC::make(5), 3 )); + m.insert ( std::make_pair ( PC::make(7), 1 )); + m.insert ( std::make_pair ( PC::make(7), 2 )); + m.insert ( std::make_pair ( PC::make(7), 3 )); + m.insert ( std::make_pair ( PC::make(9), 1 )); + m.insert ( std::make_pair ( PC::make(9), 2 )); + m.insert ( std::make_pair ( PC::make(9), 3 )); + + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == m.end()); + r = m.find(7); + assert(r == next(m.begin(), 3)); + r = m.find(8); + assert(r == m.end()); + r = m.find(9); + assert(r == next(m.begin(), 6)); + r = m.find(10); + assert(r == m.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.ops/lower_bound.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.ops/lower_bound.pass.cpp new file mode 100644 index 00000000000..49cf6de853c --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.ops/lower_bound.pass.cpp @@ -0,0 +1,221 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + typedef std::pair V; + { + typedef std::multimap M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(4); + assert(r == m.begin()); + r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(10); + assert(r == m.end()); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(4); + assert(r == m.begin()); + r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(10); + assert(r == m.end()); + } + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(4); + assert(r == m.begin()); + r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(10); + assert(r == m.end()); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(4); + assert(r == m.begin()); + r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(10); + assert(r == m.end()); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair V; + typedef std::multimap> M; + typedef M::iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(4); + assert(r == m.begin()); + r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(10); + assert(r == m.end()); + } + + { + typedef PrivateConstructor PC; + typedef std::multimap> M; + typedef M::iterator R; + + M m; + m.insert ( std::make_pair ( PC::make(5), 1 )); + m.insert ( std::make_pair ( PC::make(5), 2 )); + m.insert ( std::make_pair ( PC::make(5), 3 )); + m.insert ( std::make_pair ( PC::make(7), 1 )); + m.insert ( std::make_pair ( PC::make(7), 2 )); + m.insert ( std::make_pair ( PC::make(7), 3 )); + m.insert ( std::make_pair ( PC::make(9), 1 )); + m.insert ( std::make_pair ( PC::make(9), 2 )); + m.insert ( std::make_pair ( PC::make(9), 3 )); + + R r = m.lower_bound(4); + assert(r == m.begin()); + r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(10); + assert(r == m.end()); + } + +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.ops/upper_bound.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.ops/upper_bound.pass.cpp new file mode 100644 index 00000000000..1920647705f --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.ops/upper_bound.pass.cpp @@ -0,0 +1,221 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + typedef std::pair V; + { + typedef std::multimap M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(4); + assert(r == m.begin()); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(10); + assert(r == m.end()); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(4); + assert(r == m.begin()); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(10); + assert(r == m.end()); + } + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(4); + assert(r == m.begin()); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(10); + assert(r == m.end()); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(4); + assert(r == m.begin()); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(10); + assert(r == m.end()); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair V; + typedef std::multimap> M; + typedef M::iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(4); + assert(r == m.begin()); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(10); + assert(r == m.end()); + } + + { + typedef PrivateConstructor PC; + typedef std::multimap> M; + typedef M::iterator R; + + M m; + m.insert ( std::make_pair ( PC::make(5), 1 )); + m.insert ( std::make_pair ( PC::make(5), 2 )); + m.insert ( std::make_pair ( PC::make(5), 3 )); + m.insert ( std::make_pair ( PC::make(7), 1 )); + m.insert ( std::make_pair ( PC::make(7), 2 )); + m.insert ( std::make_pair ( PC::make(7), 3 )); + m.insert ( std::make_pair ( PC::make(9), 1 )); + m.insert ( std::make_pair ( PC::make(9), 2 )); + m.insert ( std::make_pair ( PC::make(9), 3 )); + + R r = m.upper_bound(4); + assert(r == m.begin()); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(10); + assert(r == m.end()); + } + +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.special/member_swap.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.special/member_swap.pass.cpp new file mode 100644 index 00000000000..c8f30aa7c71 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.special/member_swap.pass.cpp @@ -0,0 +1,200 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// void swap(multimap& m); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + typedef std::pair V; + { + typedef std::multimap M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.special/non_member_swap.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.special/non_member_swap.pass.cpp new file mode 100644 index 00000000000..effec2be092 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.special/non_member_swap.pass.cpp @@ -0,0 +1,305 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// template +// void +// swap(multimap& x, multimap& y); + +#include +#include +#include "test_allocator.h" +#include "../../../test_compare.h" +#include "min_allocator.h" + +int main() +{ + typedef std::pair V; + { + typedef std::multimap M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + typedef test_allocator A; + typedef test_compare > C; + typedef std::multimap M; + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A(1)); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A(2)); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + assert(m1.key_comp() == C(2)); + assert(m1.get_allocator() == A(1)); + assert(m2.key_comp() == C(1)); + assert(m2.get_allocator() == A(2)); + } + { + typedef other_allocator A; + typedef test_compare > C; + typedef std::multimap M; + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A(1)); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A(2)); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + assert(m1.key_comp() == C(2)); + assert(m1.get_allocator() == A(2)); + assert(m2.key_comp() == C(1)); + assert(m2.get_allocator() == A(1)); + } + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + typedef min_allocator A; + typedef test_compare > C; + typedef std::multimap M; + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A()); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A()); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + assert(m1.key_comp() == C(2)); + assert(m1.get_allocator() == A()); + assert(m2.key_comp() == C(1)); + assert(m2.get_allocator() == A()); + } + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/multimap.special/swap_noexcept.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.special/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..687c44385da --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/multimap.special/swap_noexcept.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(multimap& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + + some_comp() {} + some_comp(const some_comp&) {} + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multimap C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::multimap, test_allocator> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::multimap, other_allocator> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::multimap> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/scary.pass.cpp b/libcxx/test/std/containers/associative/multimap/scary.pass.cpp new file mode 100644 index 00000000000..b99d9bc2df9 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/scary.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class map class multimap + +// Extension: SCARY/N2913 iterator compatibility between map and multimap + +#include + +int main() +{ + typedef std::map M1; + typedef std::multimap M2; + M2::iterator i; + M1::iterator j = i; +} diff --git a/libcxx/test/std/containers/associative/multimap/size.pass.cpp b/libcxx/test/std/containers/associative/multimap/size.pass.cpp new file mode 100644 index 00000000000..ac71d4c95b6 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/size.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multimap + +// size_type size() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multimap M; + M m; + assert(m.size() == 0); + m.insert(M::value_type(2, 1.5)); + assert(m.size() == 1); + m.insert(M::value_type(1, 1.5)); + assert(m.size() == 2); + m.insert(M::value_type(3, 1.5)); + assert(m.size() == 3); + m.erase(m.begin()); + assert(m.size() == 2); + m.erase(m.begin()); + assert(m.size() == 1); + m.erase(m.begin()); + assert(m.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> M; + M m; + assert(m.size() == 0); + m.insert(M::value_type(2, 1.5)); + assert(m.size() == 1); + m.insert(M::value_type(1, 1.5)); + assert(m.size() == 2); + m.insert(M::value_type(3, 1.5)); + assert(m.size() == 3); + m.erase(m.begin()); + assert(m.size() == 2); + m.erase(m.begin()); + assert(m.size() == 1); + m.erase(m.begin()); + assert(m.size() == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multimap/types.pass.cpp b/libcxx/test/std/containers/associative/multimap/types.pass.cpp new file mode 100644 index 00000000000..a0f4db056a8 --- /dev/null +++ b/libcxx/test/std/containers/associative/multimap/types.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , +// class Allocator = allocator>> +// class multimap +// { +// public: +// // types: +// typedef Key key_type; +// typedef T mapped_type; +// typedef pair value_type; +// typedef Compare key_compare; +// typedef Allocator allocator_type; +// typedef typename allocator_type::reference reference; +// typedef typename allocator_type::const_reference const_reference; +// typedef typename allocator_type::pointer pointer; +// typedef typename allocator_type::const_pointer const_pointer; +// typedef typename allocator_type::size_type size_type; +// typedef typename allocator_type::difference_type difference_type; +// ... +// }; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multimap C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same > >::value), ""); + static_assert((std::is_same&>::value), ""); + static_assert((std::is_same&>::value), ""); + static_assert((std::is_same*>::value), ""); + static_assert((std::is_same*>::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + } +#if __cplusplus >= 201103L + { + typedef std::multimap, min_allocator>> C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same > >::value), ""); + static_assert((std::is_same&>::value), ""); + static_assert((std::is_same&>::value), ""); + static_assert((std::is_same>>::value), ""); + static_assert((std::is_same>>::value), ""); +// min_allocator doesn't have a size_type, so one gets synthesized + static_assert((std::is_same::type>::value), ""); + static_assert((std::is_same::value), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/clear.pass.cpp b/libcxx/test/std/containers/associative/multiset/clear.pass.cpp new file mode 100644 index 00000000000..3069de5a300 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/clear.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// void clear(); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multiset M; + typedef int V; + V ar[] = + { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + m.clear(); + assert(m.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::multiset, min_allocator> M; + typedef int V; + V ar[] = + { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + m.clear(); + assert(m.size() == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/count.pass.cpp b/libcxx/test/std/containers/associative/multiset/count.pass.cpp new file mode 100644 index 00000000000..93bd6f80eaa --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/count.pass.cpp @@ -0,0 +1,160 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// size_type count(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + { + typedef int V; + typedef std::multiset M; + { + typedef M::size_type R; + V ar[] = + { + 5, + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.count(4); + assert(r == 0); + r = m.count(5); + assert(r == 4); + r = m.count(6); + assert(r == 0); + r = m.count(7); + assert(r == 3); + r = m.count(8); + assert(r == 0); + r = m.count(9); + assert(r == 2); + r = m.count(10); + assert(r == 0); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::multiset, min_allocator> M; + { + typedef M::size_type R; + V ar[] = + { + 5, + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.count(4); + assert(r == 0); + r = m.count(5); + assert(r == 4); + r = m.count(6); + assert(r == 0); + r = m.count(7); + assert(r == 3); + r = m.count(8); + assert(r == 0); + r = m.count(9); + assert(r == 2); + r = m.count(10); + assert(r == 0); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::multiset> M; + typedef M::size_type R; + V ar[] = + { + 5, + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.count(4); + assert(r == 0); + r = m.count(5); + assert(r == 4); + r = m.count(6); + assert(r == 0); + r = m.count(7); + assert(r == 3); + r = m.count(8); + assert(r == 0); + r = m.count(9); + assert(r == 2); + r = m.count(10); + assert(r == 0); + } + + { + typedef PrivateConstructor V; + typedef std::multiset> M; + typedef M::size_type R; + + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 9 )); + + R r = m.count(4); + assert(r == 0); + r = m.count(5); + assert(r == 4); + r = m.count(6); + assert(r == 0); + r = m.count(7); + assert(r == 3); + r = m.count(8); + assert(r == 0); + r = m.count(9); + assert(r == 2); + r = m.count(10); + assert(r == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/emplace.pass.cpp b/libcxx/test/std/containers/associative/multiset/emplace.pass.cpp new file mode 100644 index 00000000000..450ee6cd35a --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/emplace.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// template +// iterator emplace(Args&&... args); + +#include +#include + +#include "../../Emplaceable.h" +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::multiset M; + typedef M::iterator R; + M m; + assert(DefaultOnly::count == 0); + R r = m.emplace(); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*m.begin() == DefaultOnly()); + assert(DefaultOnly::count == 1); + + r = m.emplace(); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(*m.begin() == DefaultOnly()); + assert(DefaultOnly::count == 2); + } + assert(DefaultOnly::count == 0); + { + typedef std::multiset M; + typedef M::iterator R; + M m; + R r = m.emplace(); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*m.begin() == Emplaceable()); + r = m.emplace(2, 3.5); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(*r == Emplaceable(2, 3.5)); + r = m.emplace(2, 3.5); + assert(r == next(m.begin(), 2)); + assert(m.size() == 3); + assert(*r == Emplaceable(2, 3.5)); + } + { + typedef std::multiset M; + typedef M::iterator R; + M m; + R r = m.emplace(M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + } +#if __cplusplus >= 201103L + { + typedef std::multiset, min_allocator> M; + typedef M::iterator R; + M m; + R r = m.emplace(M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/multiset/emplace_hint.pass.cpp b/libcxx/test/std/containers/associative/multiset/emplace_hint.pass.cpp new file mode 100644 index 00000000000..194adf761c4 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/emplace_hint.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// template +// iterator emplace_hint(const_iterator position, Args&&... args); + +#include +#include + +#include "../../Emplaceable.h" +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::multiset M; + typedef M::iterator R; + M m; + assert(DefaultOnly::count == 0); + R r = m.emplace_hint(m.cend()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*m.begin() == DefaultOnly()); + assert(DefaultOnly::count == 1); + + r = m.emplace_hint(m.cbegin()); + assert(r == m.begin()); + assert(m.size() == 2); + assert(*m.begin() == DefaultOnly()); + assert(DefaultOnly::count == 2); + } + assert(DefaultOnly::count == 0); + { + typedef std::multiset M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.cend()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*m.begin() == Emplaceable()); + r = m.emplace_hint(m.cend(), 2, 3.5); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(*r == Emplaceable(2, 3.5)); + r = m.emplace_hint(m.cbegin(), 2, 3.5); + assert(r == next(m.begin())); + assert(m.size() == 3); + assert(*r == Emplaceable(2, 3.5)); + } + { + typedef std::multiset M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.cend(), M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + } +#if __cplusplus >= 201103L + { + typedef std::multiset, min_allocator> M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.cend(), M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/multiset/empty.pass.cpp b/libcxx/test/std/containers/associative/multiset/empty.pass.cpp new file mode 100644 index 00000000000..32aef90d418 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/empty.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// bool empty() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multiset M; + M m; + assert(m.empty()); + m.insert(M::value_type(1)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); + } +#if __cplusplus >= 201103L + { + typedef std::multiset, min_allocator> M; + M m; + assert(m.empty()); + m.insert(M::value_type(1)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/equal_range.pass.cpp b/libcxx/test/std/containers/associative/multiset/equal_range.pass.cpp new file mode 100644 index 00000000000..8c69d0c61ec --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/equal_range.pass.cpp @@ -0,0 +1,263 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// pair equal_range(const key_type& k); +// pair equal_range(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + { + typedef int V; + typedef std::multiset M; + { + typedef std::pair R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 9)); + assert(r.second == next(m.begin(), 9)); + } + { + typedef std::pair R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 9)); + assert(r.second == next(m.begin(), 9)); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::multiset, min_allocator> M; + { + typedef std::pair R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 9)); + assert(r.second == next(m.begin(), 9)); + } + { + typedef std::pair R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 9)); + assert(r.second == next(m.begin(), 9)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::multiset> M; + typedef std::pair R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 9)); + assert(r.second == next(m.begin(), 9)); + } + + { + typedef PrivateConstructor V; + typedef std::multiset> M; + typedef std::pair R; + + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 9 )); + + R r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 9)); + assert(r.second == next(m.begin(), 9)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/erase_iter.pass.cpp b/libcxx/test/std/containers/associative/multiset/erase_iter.pass.cpp new file mode 100644 index 00000000000..b6656668d40 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/erase_iter.pass.cpp @@ -0,0 +1,181 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// iterator erase(const_iterator position); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multiset M; + typedef int V; + typedef M::iterator I; + V ar[] = + { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(next(m.cbegin(), 3)); + assert(m.size() == 7); + assert(i == next(m.begin(), 3)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 5); + assert(*next(m.begin(), 4) == 6); + assert(*next(m.begin(), 5) == 7); + assert(*next(m.begin(), 6) == 8); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 6); + assert(i == m.begin()); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 5); + assert(*next(m.begin(), 3) == 6); + assert(*next(m.begin(), 4) == 7); + assert(*next(m.begin(), 5) == 8); + + i = m.erase(next(m.cbegin(), 5)); + assert(m.size() == 5); + assert(i == m.end()); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 5); + assert(*next(m.begin(), 3) == 6); + assert(*next(m.begin(), 4) == 7); + + i = m.erase(next(m.cbegin(), 1)); + assert(m.size() == 4); + assert(i == next(m.begin())); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + assert(*next(m.begin(), 2) == 6); + assert(*next(m.begin(), 3) == 7); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 3); + assert(i == next(m.begin(), 2)); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + assert(*next(m.begin(), 2) == 7); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 2); + assert(i == next(m.begin(), 2)); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 1); + assert(i == next(m.begin(), 0)); + assert(*next(m.begin(), 0) == 5); + + i = m.erase(m.cbegin()); + assert(m.size() == 0); + assert(i == m.begin()); + assert(i == m.end()); + } +#if __cplusplus >= 201103L + { + typedef std::multiset, min_allocator> M; + typedef int V; + typedef M::iterator I; + V ar[] = + { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(next(m.cbegin(), 3)); + assert(m.size() == 7); + assert(i == next(m.begin(), 3)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 5); + assert(*next(m.begin(), 4) == 6); + assert(*next(m.begin(), 5) == 7); + assert(*next(m.begin(), 6) == 8); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 6); + assert(i == m.begin()); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 5); + assert(*next(m.begin(), 3) == 6); + assert(*next(m.begin(), 4) == 7); + assert(*next(m.begin(), 5) == 8); + + i = m.erase(next(m.cbegin(), 5)); + assert(m.size() == 5); + assert(i == m.end()); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 5); + assert(*next(m.begin(), 3) == 6); + assert(*next(m.begin(), 4) == 7); + + i = m.erase(next(m.cbegin(), 1)); + assert(m.size() == 4); + assert(i == next(m.begin())); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + assert(*next(m.begin(), 2) == 6); + assert(*next(m.begin(), 3) == 7); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 3); + assert(i == next(m.begin(), 2)); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + assert(*next(m.begin(), 2) == 7); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 2); + assert(i == next(m.begin(), 2)); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 1); + assert(i == next(m.begin(), 0)); + assert(*next(m.begin(), 0) == 5); + + i = m.erase(m.cbegin()); + assert(m.size() == 0); + assert(i == m.begin()); + assert(i == m.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/erase_iter_iter.pass.cpp b/libcxx/test/std/containers/associative/multiset/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..e1d7090d816 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/erase_iter_iter.pass.cpp @@ -0,0 +1,141 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// iterator erase(const_iterator first, const_iterator last); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multiset M; + typedef int V; + typedef M::iterator I; + V ar[] = + { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(next(m.cbegin(), 5), next(m.cbegin(), 5)); + assert(m.size() == 8); + assert(i == next(m.begin(), 5)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 4); + assert(*next(m.begin(), 4) == 5); + assert(*next(m.begin(), 5) == 6); + assert(*next(m.begin(), 6) == 7); + assert(*next(m.begin(), 7) == 8); + + i = m.erase(next(m.cbegin(), 3), next(m.cbegin(), 4)); + assert(m.size() == 7); + assert(i == next(m.begin(), 3)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 5); + assert(*next(m.begin(), 4) == 6); + assert(*next(m.begin(), 5) == 7); + assert(*next(m.begin(), 6) == 8); + + i = m.erase(next(m.cbegin(), 2), next(m.cbegin(), 5)); + assert(m.size() == 4); + assert(i == next(m.begin(), 2)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 7); + assert(*next(m.begin(), 3) == 8); + + i = m.erase(next(m.cbegin(), 0), next(m.cbegin(), 2)); + assert(m.size() == 2); + assert(i == next(m.begin(), 0)); + assert(*next(m.begin(), 0) == 7); + assert(*next(m.begin(), 1) == 8); + + i = m.erase(m.cbegin(), m.cend()); + assert(m.size() == 0); + assert(i == m.end()); + } +#if __cplusplus >= 201103L + { + typedef std::multiset, min_allocator> M; + typedef int V; + typedef M::iterator I; + V ar[] = + { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(next(m.cbegin(), 5), next(m.cbegin(), 5)); + assert(m.size() == 8); + assert(i == next(m.begin(), 5)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 4); + assert(*next(m.begin(), 4) == 5); + assert(*next(m.begin(), 5) == 6); + assert(*next(m.begin(), 6) == 7); + assert(*next(m.begin(), 7) == 8); + + i = m.erase(next(m.cbegin(), 3), next(m.cbegin(), 4)); + assert(m.size() == 7); + assert(i == next(m.begin(), 3)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 5); + assert(*next(m.begin(), 4) == 6); + assert(*next(m.begin(), 5) == 7); + assert(*next(m.begin(), 6) == 8); + + i = m.erase(next(m.cbegin(), 2), next(m.cbegin(), 5)); + assert(m.size() == 4); + assert(i == next(m.begin(), 2)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 7); + assert(*next(m.begin(), 3) == 8); + + i = m.erase(next(m.cbegin(), 0), next(m.cbegin(), 2)); + assert(m.size() == 2); + assert(i == next(m.begin(), 0)); + assert(*next(m.begin(), 0) == 7); + assert(*next(m.begin(), 1) == 8); + + i = m.erase(m.cbegin(), m.cend()); + assert(m.size() == 0); + assert(i == m.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/erase_key.pass.cpp b/libcxx/test/std/containers/associative/multiset/erase_key.pass.cpp new file mode 100644 index 00000000000..e9bce1e1b64 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/erase_key.pass.cpp @@ -0,0 +1,129 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// size_type erase(const key_type& k); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multiset M; + typedef int V; + typedef M::size_type I; + V ar[] = + { + 3, + 3, + 3, + 5, + 5, + 5, + 7, + 7, + 7 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 9); + I i = m.erase(6); + assert(m.size() == 9); + assert(i == 0); + assert(*next(m.begin(), 0) == 3); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 5); + assert(*next(m.begin(), 4) == 5); + assert(*next(m.begin(), 5) == 5); + assert(*next(m.begin(), 6) == 7); + assert(*next(m.begin(), 7) == 7); + assert(*next(m.begin(), 8) == 7); + + i = m.erase(5); + assert(m.size() == 6); + assert(i == 3); + assert(*next(m.begin(), 0) == 3); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 7); + assert(*next(m.begin(), 4) == 7); + assert(*next(m.begin(), 5) == 7); + + i = m.erase(3); + assert(m.size() == 3); + assert(i == 3); + assert(*next(m.begin(), 0) == 7); + assert(*next(m.begin(), 1) == 7); + assert(*next(m.begin(), 2) == 7); + + i = m.erase(7); + assert(m.size() == 0); + assert(i == 3); + } +#if __cplusplus >= 201103L + { + typedef std::multiset, min_allocator> M; + typedef int V; + typedef M::size_type I; + V ar[] = + { + 3, + 3, + 3, + 5, + 5, + 5, + 7, + 7, + 7 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 9); + I i = m.erase(6); + assert(m.size() == 9); + assert(i == 0); + assert(*next(m.begin(), 0) == 3); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 5); + assert(*next(m.begin(), 4) == 5); + assert(*next(m.begin(), 5) == 5); + assert(*next(m.begin(), 6) == 7); + assert(*next(m.begin(), 7) == 7); + assert(*next(m.begin(), 8) == 7); + + i = m.erase(5); + assert(m.size() == 6); + assert(i == 3); + assert(*next(m.begin(), 0) == 3); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 7); + assert(*next(m.begin(), 4) == 7); + assert(*next(m.begin(), 5) == 7); + + i = m.erase(3); + assert(m.size() == 3); + assert(i == 3); + assert(*next(m.begin(), 0) == 7); + assert(*next(m.begin(), 1) == 7); + assert(*next(m.begin(), 2) == 7); + + i = m.erase(7); + assert(m.size() == 0); + assert(i == 3); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/find.pass.cpp b/libcxx/test/std/containers/associative/multiset/find.pass.cpp new file mode 100644 index 00000000000..364460a6ca3 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/find.pass.cpp @@ -0,0 +1,240 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + { + typedef int V; + typedef std::multiset M; + { + typedef M::iterator R; + V ar[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::multiset, min_allocator> M; + { + typedef M::iterator R; + V ar[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::multiset> M; + typedef M::iterator R; + + V ar[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + + { + typedef PrivateConstructor V; + typedef std::multiset> M; + typedef M::iterator R; + + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 6 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 8 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 10 )); + m.insert ( V::make ( 11 )); + m.insert ( V::make ( 12 )); + + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/insert_cv.pass.cpp b/libcxx/test/std/containers/associative/multiset/insert_cv.pass.cpp new file mode 100644 index 00000000000..179715753ab --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/insert_cv.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// iterator insert(const value_type& v); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multiset M; + typedef M::iterator R; + M m; + R r = m.insert(M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + + r = m.insert(M::value_type(1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(*r == 1); + + r = m.insert(M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + + r = m.insert(M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(*r == 3); + } +#if __cplusplus >= 201103L + { + typedef std::multiset, min_allocator> M; + typedef M::iterator R; + M m; + R r = m.insert(M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + + r = m.insert(M::value_type(1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(*r == 1); + + r = m.insert(M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + + r = m.insert(M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(*r == 3); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/insert_initializer_list.pass.cpp b/libcxx/test/std/containers/associative/multiset/insert_initializer_list.pass.cpp new file mode 100644 index 00000000000..7e923f2516d --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/insert_initializer_list.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// void insert(initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::multiset C; + typedef C::value_type V; + C m = {10, 8}; + m.insert({1, 2, 3, 4, 5, 6}); + assert(m.size() == 8); + assert(distance(m.begin(), m.end()) == m.size()); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + assert(*++i == V(8)); + assert(*++i == V(10)); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#if __cplusplus >= 201103L + { + typedef std::multiset, min_allocator> C; + typedef C::value_type V; + C m = {10, 8}; + m.insert({1, 2, 3, 4, 5, 6}); + assert(m.size() == 8); + assert(distance(m.begin(), m.end()) == m.size()); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + assert(*++i == V(8)); + assert(*++i == V(10)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/insert_iter_cv.pass.cpp b/libcxx/test/std/containers/associative/multiset/insert_iter_cv.pass.cpp new file mode 100644 index 00000000000..7d204024c21 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/insert_iter_cv.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// iterator insert(const_iterator position, const value_type& v); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multiset M; + typedef M::iterator R; + M m; + R r = m.insert(m.cend(), M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + + r = m.insert(m.cend(), M::value_type(1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(*r == 1); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(*r == 3); + } +#if __cplusplus >= 201103L + { + typedef std::multiset, min_allocator> M; + typedef M::iterator R; + M m; + R r = m.insert(m.cend(), M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + + r = m.insert(m.cend(), M::value_type(1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(*r == 1); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(*r == 3); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/insert_iter_iter.pass.cpp b/libcxx/test/std/containers/associative/multiset/insert_iter_iter.pass.cpp new file mode 100644 index 00000000000..189c4549866 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/insert_iter_iter.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// template +// void insert(InputIterator first, InputIterator last); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::multiset M; + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + M m; + m.insert(input_iterator(ar), + input_iterator(ar + sizeof(ar)/sizeof(ar[0]))); + assert(m.size() == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); + } +#if __cplusplus >= 201103L + { + typedef std::multiset, min_allocator> M; + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + M m; + m.insert(input_iterator(ar), + input_iterator(ar + sizeof(ar)/sizeof(ar[0]))); + assert(m.size() == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/insert_iter_rv.pass.cpp b/libcxx/test/std/containers/associative/multiset/insert_iter_rv.pass.cpp new file mode 100644 index 00000000000..342c6fd53d7 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/insert_iter_rv.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// iterator insert(const_iterator position, value_type&& v); + +#include +#include + +#include "../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::multiset M; + typedef M::iterator R; + M m; + R r = m.insert(m.cend(), M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + + r = m.insert(m.cend(), M::value_type(1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(*r == 1); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(*r == 3); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::multiset, min_allocator> M; + typedef M::iterator R; + M m; + R r = m.insert(m.cend(), M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + + r = m.insert(m.cend(), M::value_type(1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(*r == 1); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(*r == 3); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/insert_rv.pass.cpp b/libcxx/test/std/containers/associative/multiset/insert_rv.pass.cpp new file mode 100644 index 00000000000..1030e0886eb --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/insert_rv.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// iterator insert(value_type&& v); + +#include +#include + +#include "../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::multiset M; + typedef M::iterator R; + M m; + R r = m.insert(M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + + r = m.insert(M::value_type(1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(*r == 1); + + r = m.insert(M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + + r = m.insert(M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(*r == 3); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::multiset, min_allocator> M; + typedef M::iterator R; + M m; + R r = m.insert(M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + + r = m.insert(M::value_type(1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(*r == 1); + + r = m.insert(M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + + r = m.insert(M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(*r == 3); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/iterator.pass.cpp b/libcxx/test/std/containers/associative/multiset/iterator.pass.cpp new file mode 100644 index 00000000000..d1f0ecfd6aa --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/iterator.pass.cpp @@ -0,0 +1,215 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// iterator begin(); +// const_iterator begin() const; +// iterator end(); +// const_iterator end() const; +// +// reverse_iterator rbegin(); +// const_reverse_iterator rbegin() const; +// reverse_iterator rend(); +// const_reverse_iterator rend() const; +// +// const_iterator cbegin() const; +// const_iterator cend() const; +// const_reverse_iterator crbegin() const; +// const_reverse_iterator crend() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3, + 4, + 4, + 4, + 5, + 5, + 5, + 6, + 6, + 6, + 7, + 7, + 7, + 8, + 8, + 8 + }; + std::multiset m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + std::multiset::iterator i; + i = m.begin(); + std::multiset::const_iterator k = i; + assert(i == k); + for (int j = 1; j <= 8; ++j) + for (int k = 0; k < 3; ++k, ++i) + assert(*i == j); + } + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3, + 4, + 4, + 4, + 5, + 5, + 5, + 6, + 6, + 6, + 7, + 7, + 7, + 8, + 8, + 8 + }; + const std::multiset m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.cbegin(), m.cend()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + assert(std::distance(m.crbegin(), m.crend()) == m.size()); + std::multiset::const_iterator i; + i = m.begin(); + for (int j = 1; j <= 8; ++j) + for (int k = 0; k < 3; ++k, ++i) + assert(*i == j); + } +#if __cplusplus >= 201103L + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3, + 4, + 4, + 4, + 5, + 5, + 5, + 6, + 6, + 6, + 7, + 7, + 7, + 8, + 8, + 8 + }; + std::multiset, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + std::multiset, min_allocator>::iterator i; + i = m.begin(); + std::multiset, min_allocator>::const_iterator k = i; + assert(i == k); + for (int j = 1; j <= 8; ++j) + for (int k = 0; k < 3; ++k, ++i) + assert(*i == j); + } + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3, + 4, + 4, + 4, + 5, + 5, + 5, + 6, + 6, + 6, + 7, + 7, + 7, + 8, + 8, + 8 + }; + const std::multiset, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.cbegin(), m.cend()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + assert(std::distance(m.crbegin(), m.crend()) == m.size()); + std::multiset, min_allocator>::const_iterator i; + i = m.begin(); + for (int j = 1; j <= 8; ++j) + for (int k = 0; k < 3; ++k, ++i) + assert(*i == j); + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + typedef std::multiset C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/lower_bound.pass.cpp b/libcxx/test/std/containers/associative/multiset/lower_bound.pass.cpp new file mode 100644 index 00000000000..e466791d935 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/lower_bound.pass.cpp @@ -0,0 +1,223 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + { + typedef int V; + typedef std::multiset M; + { + typedef M::iterator R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(5); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 9)); + } + { + typedef M::const_iterator R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(5); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 9)); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::multiset, min_allocator> M; + { + typedef M::iterator R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(5); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 9)); + } + { + typedef M::const_iterator R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(5); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 9)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::multiset> M; + + typedef M::iterator R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + + R r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(5); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 9)); + } + + { + typedef PrivateConstructor V; + typedef std::multiset> M; + typedef M::iterator R; + + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 9 )); + + R r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(5); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 9)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/max_size.pass.cpp b/libcxx/test/std/containers/associative/multiset/max_size.pass.cpp new file mode 100644 index 00000000000..5524f771b34 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/max_size.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// size_type max_size() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multiset M; + M m; + assert(m.max_size() != 0); + } +#if __cplusplus >= 201103L + { + typedef std::multiset, min_allocator> M; + M m; + assert(m.max_size() != 0); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/alloc.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/alloc.pass.cpp new file mode 100644 index 00000000000..0a7572275af --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/alloc.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// multiset(const allocator_type& a); + +#include +#include + +#include "test_allocator.h" + +int main() +{ + typedef std::less C; + typedef test_allocator A; + std::multiset m(A(5)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.get_allocator() == A(5)); +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..7d76581d6d8 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// multiset& operator=(initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::multiset C; + typedef C::value_type V; + C m = {10, 8}; + m = {1, 2, 3, 4, 5, 6}; + assert(m.size() == 6); + assert(distance(m.begin(), m.end()) == 6); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#if __cplusplus >= 201103L + { + typedef std::multiset, min_allocator> C; + typedef C::value_type V; + C m = {10, 8}; + m = {1, 2, 3, 4, 5, 6}; + assert(m.size() == 6); + assert(distance(m.begin(), m.end()) == 6); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/compare.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/compare.pass.cpp new file mode 100644 index 00000000000..84038ca1e14 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/compare.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// explicit multiset(const value_compare& comp); + +#include +#include + +#include "../../../test_compare.h" + +int main() +{ + typedef test_compare > C; + std::multiset m(C(3)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(3)); +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/compare_alloc.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/compare_alloc.pass.cpp new file mode 100644 index 00000000000..76c9f8b2a8a --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/compare_alloc.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// multiset(const value_compare& comp, const allocator_type& a); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" + +int main() +{ + typedef test_compare > C; + typedef test_allocator A; + std::multiset m(C(4), A(5)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(4)); + assert(m.get_allocator() == A(5)); +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/copy.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/copy.pass.cpp new file mode 100644 index 00000000000..dde36287210 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/copy.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// multiset(const multiset& m); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" + +int main() +{ + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare > C; + typedef test_allocator A; + std::multiset mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::multiset m = mo; + assert(m.get_allocator() == A(7)); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 9); + assert(distance(mo.begin(), mo.end()) == 9); + assert(*next(mo.begin(), 0) == 1); + assert(*next(mo.begin(), 1) == 1); + assert(*next(mo.begin(), 2) == 1); + assert(*next(mo.begin(), 3) == 2); + assert(*next(mo.begin(), 4) == 2); + assert(*next(mo.begin(), 5) == 2); + assert(*next(mo.begin(), 6) == 3); + assert(*next(mo.begin(), 7) == 3); + assert(*next(mo.begin(), 8) == 3); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare > C; + typedef other_allocator A; + std::multiset mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::multiset m = mo; + assert(m.get_allocator() == A(-2)); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 9); + assert(distance(mo.begin(), mo.end()) == 9); + assert(*next(mo.begin(), 0) == 1); + assert(*next(mo.begin(), 1) == 1); + assert(*next(mo.begin(), 2) == 1); + assert(*next(mo.begin(), 3) == 2); + assert(*next(mo.begin(), 4) == 2); + assert(*next(mo.begin(), 5) == 2); + assert(*next(mo.begin(), 6) == 3); + assert(*next(mo.begin(), 7) == 3); + assert(*next(mo.begin(), 8) == 3); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/copy_alloc.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..04a769e7332 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/copy_alloc.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// multiset(const multiset& m, const allocator_type& a); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" + +int main() +{ + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare > C; + typedef test_allocator A; + std::multiset mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::multiset m(mo, A(3)); + assert(m.get_allocator() == A(3)); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 9); + assert(distance(mo.begin(), mo.end()) == 9); + assert(*next(mo.begin(), 0) == 1); + assert(*next(mo.begin(), 1) == 1); + assert(*next(mo.begin(), 2) == 1); + assert(*next(mo.begin(), 3) == 2); + assert(*next(mo.begin(), 4) == 2); + assert(*next(mo.begin(), 5) == 2); + assert(*next(mo.begin(), 6) == 3); + assert(*next(mo.begin(), 7) == 3); + assert(*next(mo.begin(), 8) == 3); +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/copy_assign.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/copy_assign.pass.cpp new file mode 100644 index 00000000000..cca636325ff --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/copy_assign.pass.cpp @@ -0,0 +1,138 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// multiset& operator=(const multiset& s); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" + +int main() +{ + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare > C; + typedef test_allocator A; + std::multiset mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2)); + std::multiset m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7)); + m = mo; + assert(m.get_allocator() == A(7)); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); + + assert(mo.get_allocator() == A(2)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 9); + assert(distance(mo.begin(), mo.end()) == 9); + assert(*next(mo.begin(), 0) == 1); + assert(*next(mo.begin(), 1) == 1); + assert(*next(mo.begin(), 2) == 1); + assert(*next(mo.begin(), 3) == 2); + assert(*next(mo.begin(), 4) == 2); + assert(*next(mo.begin(), 5) == 2); + assert(*next(mo.begin(), 6) == 3); + assert(*next(mo.begin(), 7) == 3); + assert(*next(mo.begin(), 8) == 3); + } + { + typedef int V; + const V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + std::multiset m(ar, ar+sizeof(ar)/sizeof(ar[0])); + std::multiset *p = &m; + m = *p; + assert(m.size() == 9); + assert(std::equal(m.begin(), m.end(), ar)); + } + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare > C; + typedef other_allocator A; + std::multiset mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2)); + std::multiset m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7)); + m = mo; + assert(m.get_allocator() == A(2)); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); + + assert(mo.get_allocator() == A(2)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 9); + assert(distance(mo.begin(), mo.end()) == 9); + assert(*next(mo.begin(), 0) == 1); + assert(*next(mo.begin(), 1) == 1); + assert(*next(mo.begin(), 2) == 1); + assert(*next(mo.begin(), 3) == 2); + assert(*next(mo.begin(), 4) == 2); + assert(*next(mo.begin(), 5) == 2); + assert(*next(mo.begin(), 6) == 3); + assert(*next(mo.begin(), 7) == 3); + assert(*next(mo.begin(), 8) == 3); + } +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/default.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/default.pass.cpp new file mode 100644 index 00000000000..5bb0312f012 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/default.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// multiset(); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + std::multiset m; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#if __cplusplus >= 201103L + { + std::multiset, min_allocator> m; + assert(m.empty()); + assert(m.begin() == m.end()); + } + { + std::multiset m = {}; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/default_noexcept.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/default_noexcept.pass.cpp new file mode 100644 index 00000000000..a0bdb0786c2 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/default_noexcept.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// multiset() +// noexcept( +// is_nothrow_default_constructible::value && +// is_nothrow_default_constructible::value && +// is_nothrow_copy_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp(); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multiset C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::multiset, test_allocator> C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::multiset, other_allocator> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::multiset> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..658af1a89de --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// ~multiset() // implied noexcept; + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template +struct some_comp +{ + typedef T value_type; + ~some_comp() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multiset C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::multiset, test_allocator> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::multiset, other_allocator> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::multiset> C; + static_assert(!std::is_nothrow_destructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..dadafec7c3b --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/initializer_list.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// multiset(initializer_list il, const key_compare& comp = key_compare()); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::multiset C; + typedef C::value_type V; + C m = {1, 2, 3, 4, 5, 6}; + assert(m.size() == 6); + assert(distance(m.begin(), m.end()) == 6); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#if __cplusplus >= 201103L + { + typedef std::multiset, min_allocator> C; + typedef C::value_type V; + C m = {1, 2, 3, 4, 5, 6}; + assert(m.size() == 6); + assert(distance(m.begin(), m.end()) == 6); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::multiset, min_allocator> C; + typedef C::value_type V; + min_allocator a; + C m ({1, 2, 3, 4, 5, 6}, a); + assert(m.size() == 6); + assert(distance(m.begin(), m.end()) == 6); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + assert(m.get_allocator() == a); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/initializer_list_compare.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/initializer_list_compare.pass.cpp new file mode 100644 index 00000000000..c67657aff8a --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/initializer_list_compare.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// multiset(initializer_list il, const key_compare& comp = key_compare()); + +#include +#include +#include "../../../test_compare.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + typedef test_compare > Cmp; + typedef std::multiset C; + typedef C::value_type V; + C m({1, 2, 3, 4, 5, 6}, Cmp(10)); + assert(m.size() == 6); + assert(distance(m.begin(), m.end()) == 6); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + assert(m.key_comp() == Cmp(10)); +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/initializer_list_compare_alloc.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/initializer_list_compare_alloc.pass.cpp new file mode 100644 index 00000000000..83114893a1b --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/initializer_list_compare_alloc.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// multiset(initializer_list il, const key_compare& comp, const allocator_type& a); + +#include +#include +#include "../../../test_compare.h" +#include "test_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + typedef test_compare > Cmp; + typedef test_allocator A; + typedef std::multiset C; + typedef C::value_type V; + C m({1, 2, 3, 4, 5, 6}, Cmp(10), A(4)); + assert(m.size() == 6); + assert(distance(m.begin(), m.end()) == 6); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + assert(m.key_comp() == Cmp(10)); + assert(m.get_allocator() == A(4)); +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/iter_iter.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/iter_iter.pass.cpp new file mode 100644 index 00000000000..f6c1fd76de1 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/iter_iter.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// template +// multiset(InputIterator first, InputIterator last); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + std::multiset m(input_iterator(ar), + input_iterator(ar+sizeof(ar)/sizeof(ar[0]))); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); + } +#if __cplusplus >= 201103L + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + std::multiset, min_allocator> m(input_iterator(ar), + input_iterator(ar+sizeof(ar)/sizeof(ar[0]))); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/iter_iter_alloc.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/iter_iter_alloc.pass.cpp new file mode 100644 index 00000000000..4ed00c7124c --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/iter_iter_alloc.pass.cpp @@ -0,0 +1,92 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// template +// multiset(InputIterator first, InputIterator last, +// const value_compare& comp, const allocator_type& a); + +#include +#include + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "test_allocator.h" + +int main() +{ + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare > C; + typedef test_allocator A; + std::multiset m(input_iterator(ar), + input_iterator(ar+sizeof(ar)/sizeof(ar[0])), + C(5), A(7)); + assert(m.value_comp() == C(5)); + assert(m.get_allocator() == A(7)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_allocator A; + typedef test_compare > C; + A a; + std::multiset m(ar, ar+sizeof(ar)/sizeof(ar[0]), a); + + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); + assert(m.get_allocator() == a); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/iter_iter_comp.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/iter_iter_comp.pass.cpp new file mode 100644 index 00000000000..0bbaaf12eab --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/iter_iter_comp.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// template +// multiset(InputIterator first, InputIterator last, const value_compare& comp); + +#include +#include + +#include "test_iterators.h" +#include "../../../test_compare.h" + +int main() +{ + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare > C; + std::multiset m(input_iterator(ar), + input_iterator(ar+sizeof(ar)/sizeof(ar[0])), C(5)); + assert(m.value_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/move.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/move.pass.cpp new file mode 100644 index 00000000000..40321cd247e --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/move.pass.cpp @@ -0,0 +1,119 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// multiset(multiset&& s); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef int V; + typedef test_compare > C; + typedef test_allocator A; + std::multiset mo(C(5), A(7)); + std::multiset m = std::move(mo); + assert(m.get_allocator() == A(7)); + assert(m.key_comp() == C(5)); + assert(m.size() == 0); + assert(distance(m.begin(), m.end()) == 0); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare > C; + typedef test_allocator A; + std::multiset mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::multiset m = std::move(mo); + assert(m.get_allocator() == A(7)); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare > C; + typedef min_allocator A; + std::multiset mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::multiset m = std::move(mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/move_alloc.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..1a0b065f8b9 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/move_alloc.pass.cpp @@ -0,0 +1,141 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// multiset(multiset&& s, const allocator_type& a); + +#include +#include + +#include "../../../MoveOnly.h" +#include "../../../test_compare.h" +#include "test_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef MoveOnly V; + typedef test_compare > C; + typedef test_allocator A; + typedef std::multiset M; + typedef std::move_iterator I; + V a1[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(std::move(m1), A(7)); + assert(m3 == m2); + assert(m3.get_allocator() == A(7)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } + { + typedef MoveOnly V; + typedef test_compare > C; + typedef test_allocator A; + typedef std::multiset M; + typedef std::move_iterator I; + V a1[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(std::move(m1), A(5)); + assert(m3 == m2); + assert(m3.get_allocator() == A(5)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } + { + typedef MoveOnly V; + typedef test_compare > C; + typedef other_allocator A; + typedef std::multiset M; + typedef std::move_iterator I; + V a1[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(std::move(m1), A(5)); + assert(m3 == m2); + assert(m3.get_allocator() == A(5)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/move_assign.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/move_assign.pass.cpp new file mode 100644 index 00000000000..0b0ce44cb8d --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/move_assign.pass.cpp @@ -0,0 +1,186 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// multiset& operator=(multiset&& s); + +#include +#include + +#include "../../../MoveOnly.h" +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef MoveOnly V; + typedef test_compare > C; + typedef test_allocator A; + typedef std::multiset M; + typedef std::move_iterator I; + V a1[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(C(3), A(7)); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A(7)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } + { + typedef MoveOnly V; + typedef test_compare > C; + typedef test_allocator A; + typedef std::multiset M; + typedef std::move_iterator I; + V a1[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(C(3), A(5)); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A(5)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } + { + typedef MoveOnly V; + typedef test_compare > C; + typedef other_allocator A; + typedef std::multiset M; + typedef std::move_iterator I; + V a1[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(C(3), A(5)); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A(7)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef MoveOnly V; + typedef test_compare > C; + typedef min_allocator A; + typedef std::multiset M; + typedef std::move_iterator I; + V a1[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A()); + V a2[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A()); + M m3(C(3), A()); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A()); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..cef3f202487 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// multiset& operator=(multiset&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable::value && +// is_nothrow_move_assignable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp& operator=(const some_comp&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multiset C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::multiset, test_allocator> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::multiset, other_allocator> C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::multiset> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.cons/move_noexcept.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.cons/move_noexcept.pass.cpp new file mode 100644 index 00000000000..e18f3f5f1bf --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.cons/move_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// multiset(multiset&&) +// noexcept(is_nothrow_move_constructible::value && +// is_nothrow_move_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp(const some_comp&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multiset C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::multiset, test_allocator> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::multiset, other_allocator> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::multiset> C; + static_assert(!std::is_nothrow_move_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.special/member_swap.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.special/member_swap.pass.cpp new file mode 100644 index 00000000000..ce906896b9a --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.special/member_swap.pass.cpp @@ -0,0 +1,201 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// void swap(multiset& m); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int V; + typedef std::multiset M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::multiset, min_allocator> M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.special/non_member_swap.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.special/non_member_swap.pass.cpp new file mode 100644 index 00000000000..222985a08f7 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.special/non_member_swap.pass.cpp @@ -0,0 +1,177 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// void swap(multiset& m); + +#include +#include +#include "test_allocator.h" +#include "../../../test_compare.h" + +int main() +{ + typedef int V; + typedef std::multiset M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + typedef test_allocator A; + typedef test_compare > C; + typedef std::set M; + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A(1)); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A(2)); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + assert(m1.key_comp() == C(2)); + assert(m1.get_allocator() == A(1)); + assert(m2.key_comp() == C(1)); + assert(m2.get_allocator() == A(2)); + } + { + typedef other_allocator A; + typedef test_compare > C; + typedef std::set M; + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A(1)); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A(2)); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + assert(m1.key_comp() == C(2)); + assert(m1.get_allocator() == A(2)); + assert(m2.key_comp() == C(1)); + assert(m2.get_allocator() == A(1)); + } +} diff --git a/libcxx/test/std/containers/associative/multiset/multiset.special/swap_noexcept.pass.cpp b/libcxx/test/std/containers/associative/multiset/multiset.special/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..531fe801a16 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/multiset.special/swap_noexcept.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(multiset& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + + some_comp() {} + some_comp(const some_comp&) {} + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multiset C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::multiset, test_allocator> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::multiset, other_allocator> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::multiset> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/scary.pass.cpp b/libcxx/test/std/containers/associative/multiset/scary.pass.cpp new file mode 100644 index 00000000000..f5ee32714e8 --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/scary.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set class multiset + +// Extension: SCARY/N2913 iterator compatibility between set and multiset + +#include + +int main() +{ + typedef std::set M1; + typedef std::multiset M2; + M2::iterator i; + M1::iterator j = i; +} diff --git a/libcxx/test/std/containers/associative/multiset/size.pass.cpp b/libcxx/test/std/containers/associative/multiset/size.pass.cpp new file mode 100644 index 00000000000..68099b566df --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/size.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// size_type size() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multiset M; + M m; + assert(m.size() == 0); + m.insert(M::value_type(2)); + assert(m.size() == 1); + m.insert(M::value_type(1)); + assert(m.size() == 2); + m.insert(M::value_type(2)); + assert(m.size() == 3); + m.erase(m.begin()); + assert(m.size() == 2); + m.erase(m.begin()); + assert(m.size() == 1); + m.erase(m.begin()); + assert(m.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::multiset, min_allocator> M; + M m; + assert(m.size() == 0); + m.insert(M::value_type(2)); + assert(m.size() == 1); + m.insert(M::value_type(1)); + assert(m.size() == 2); + m.insert(M::value_type(2)); + assert(m.size() == 3); + m.erase(m.begin()); + assert(m.size() == 2); + m.erase(m.begin()); + assert(m.size() == 1); + m.erase(m.begin()); + assert(m.size() == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/types.pass.cpp b/libcxx/test/std/containers/associative/multiset/types.pass.cpp new file mode 100644 index 00000000000..e1e3ad9100c --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/types.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , +// class Allocator = allocator> +// class multiset +// { +// public: +// // types: +// typedef Key key_type; +// typedef key_type value_type; +// typedef Compare key_compare; +// typedef key_compare value_compare; +// typedef Allocator allocator_type; +// typedef typename allocator_type::reference reference; +// typedef typename allocator_type::const_reference const_reference; +// typedef typename allocator_type::pointer pointer; +// typedef typename allocator_type::const_pointer const_pointer; +// typedef typename allocator_type::size_type size_type; +// typedef typename allocator_type::difference_type difference_type; +// ... +// }; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multiset C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + } +#if __cplusplus >= 201103L + { + typedef std::multiset, min_allocator> C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same>::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same>::value), ""); + static_assert((std::is_same>::value), ""); +// min_allocator doesn't have a size_type, so one gets synthesized + static_assert((std::is_same::type>::value), ""); + static_assert((std::is_same::value), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/multiset/upper_bound.pass.cpp b/libcxx/test/std/containers/associative/multiset/upper_bound.pass.cpp new file mode 100644 index 00000000000..7ad3d6ced3d --- /dev/null +++ b/libcxx/test/std/containers/associative/multiset/upper_bound.pass.cpp @@ -0,0 +1,222 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class multiset + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + { + typedef int V; + typedef std::multiset M; + { + typedef M::iterator R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 9)); + } + { + typedef M::const_iterator R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 9)); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::multiset, min_allocator> M; + { + typedef M::iterator R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 9)); + } + { + typedef M::const_iterator R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 9)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::multiset> M; + + typedef M::iterator R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 9)); + } + + { + typedef PrivateConstructor V; + typedef std::multiset> M; + + typedef M::iterator R; + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 9 )); + + R r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 9)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/clear.pass.cpp b/libcxx/test/std/containers/associative/set/clear.pass.cpp new file mode 100644 index 00000000000..4439ad3b1e4 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/clear.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// void clear(); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::set M; + typedef int V; + V ar[] = + { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + m.clear(); + assert(m.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::set, min_allocator> M; + typedef int V; + V ar[] = + { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + m.clear(); + assert(m.size() == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/count.pass.cpp b/libcxx/test/std/containers/associative/set/count.pass.cpp new file mode 100644 index 00000000000..32fe0b8bcee --- /dev/null +++ b/libcxx/test/std/containers/associative/set/count.pass.cpp @@ -0,0 +1,168 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// size_type count(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + { + typedef int V; + typedef std::set M; + typedef M::size_type R; + V ar[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.count(5); + assert(r == 1); + r = m.count(6); + assert(r == 1); + r = m.count(7); + assert(r == 1); + r = m.count(8); + assert(r == 1); + r = m.count(9); + assert(r == 1); + r = m.count(10); + assert(r == 1); + r = m.count(11); + assert(r == 1); + r = m.count(12); + assert(r == 1); + r = m.count(4); + assert(r == 0); + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::set, min_allocator> M; + typedef M::size_type R; + V ar[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.count(5); + assert(r == 1); + r = m.count(6); + assert(r == 1); + r = m.count(7); + assert(r == 1); + r = m.count(8); + assert(r == 1); + r = m.count(9); + assert(r == 1); + r = m.count(10); + assert(r == 1); + r = m.count(11); + assert(r == 1); + r = m.count(12); + assert(r == 1); + r = m.count(4); + assert(r == 0); + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::set> M; + typedef M::size_type R; + V ar[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.count(5); + assert(r == 1); + r = m.count(6); + assert(r == 1); + r = m.count(7); + assert(r == 1); + r = m.count(8); + assert(r == 1); + r = m.count(9); + assert(r == 1); + r = m.count(10); + assert(r == 1); + r = m.count(11); + assert(r == 1); + r = m.count(12); + assert(r == 1); + r = m.count(4); + assert(r == 0); + } + { + typedef PrivateConstructor V; + typedef std::set> M; + typedef M::size_type R; + + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 6 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 8 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 10 )); + m.insert ( V::make ( 11 )); + m.insert ( V::make ( 12 )); + + R r = m.count(5); + assert(r == 1); + r = m.count(6); + assert(r == 1); + r = m.count(7); + assert(r == 1); + r = m.count(8); + assert(r == 1); + r = m.count(9); + assert(r == 1); + r = m.count(10); + assert(r == 1); + r = m.count(11); + assert(r == 1); + r = m.count(12); + assert(r == 1); + r = m.count(4); + assert(r == 0); + } +#endif + +} diff --git a/libcxx/test/std/containers/associative/set/emplace.pass.cpp b/libcxx/test/std/containers/associative/set/emplace.pass.cpp new file mode 100644 index 00000000000..5ebab4d24b9 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/emplace.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// template +// pair emplace(Args&&... args); + +#include +#include + +#include "../../Emplaceable.h" +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::set M; + typedef std::pair R; + M m; + assert(DefaultOnly::count == 0); + R r = m.emplace(); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(*m.begin() == DefaultOnly()); + assert(DefaultOnly::count == 1); + + r = m.emplace(); + assert(!r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(*m.begin() == DefaultOnly()); + assert(DefaultOnly::count == 1); + } + assert(DefaultOnly::count == 0); + { + typedef std::set M; + typedef std::pair R; + M m; + R r = m.emplace(); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(*m.begin() == Emplaceable()); + r = m.emplace(2, 3.5); + assert(r.second); + assert(r.first == next(m.begin())); + assert(m.size() == 2); + assert(*r.first == Emplaceable(2, 3.5)); + r = m.emplace(2, 3.5); + assert(!r.second); + assert(r.first == next(m.begin())); + assert(m.size() == 2); + assert(*r.first == Emplaceable(2, 3.5)); + } + { + typedef std::set M; + typedef std::pair R; + M m; + R r = m.emplace(M::value_type(2)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(*r.first == 2); + } +#if __cplusplus >= 201103L + { + typedef std::set, min_allocator> M; + typedef std::pair R; + M m; + R r = m.emplace(M::value_type(2)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(*r.first == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/set/emplace_hint.pass.cpp b/libcxx/test/std/containers/associative/set/emplace_hint.pass.cpp new file mode 100644 index 00000000000..5fdeb4ffef3 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/emplace_hint.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// template +// iterator emplace_hint(const_iterator position, Args&&... args); + +#include +#include + +#include "../../Emplaceable.h" +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::set M; + typedef M::iterator R; + M m; + assert(DefaultOnly::count == 0); + R r = m.emplace_hint(m.cend()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*m.begin() == DefaultOnly()); + assert(DefaultOnly::count == 1); + + r = m.emplace_hint(m.cbegin()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*m.begin() == DefaultOnly()); + assert(DefaultOnly::count == 1); + } + assert(DefaultOnly::count == 0); + { + typedef std::set M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.cend()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*m.begin() == Emplaceable()); + r = m.emplace_hint(m.cend(), 2, 3.5); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(*r == Emplaceable(2, 3.5)); + r = m.emplace_hint(m.cbegin(), 2, 3.5); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(*r == Emplaceable(2, 3.5)); + } + { + typedef std::set M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.cend(), M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + } +#if __cplusplus >= 201103L + { + typedef std::set, min_allocator> M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.cend(), M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/set/empty.pass.cpp b/libcxx/test/std/containers/associative/set/empty.pass.cpp new file mode 100644 index 00000000000..eb1080263f4 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/empty.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// bool empty() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::set M; + M m; + assert(m.empty()); + m.insert(M::value_type(1)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); + } +#if __cplusplus >= 201103L + { + typedef std::set, min_allocator> M; + M m; + assert(m.empty()); + m.insert(M::value_type(1)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/equal_range.pass.cpp b/libcxx/test/std/containers/associative/set/equal_range.pass.cpp new file mode 100644 index 00000000000..8a180ef4924 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/equal_range.pass.cpp @@ -0,0 +1,370 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// pair equal_range(const key_type& k); +// pair equal_range(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + { + typedef int V; + typedef std::set M; + { + typedef std::pair R; + V ar[] = + { + 5, + 7, + 9, + 11, + 13, + 15, + 17, + 19 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(11); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(13); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(15); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(17); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(19); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 8)); + r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(12); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(14); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(16); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(18); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(20); + assert(r.first == next(m.begin(), 8)); + assert(r.second == next(m.begin(), 8)); + } + { + typedef std::pair R; + V ar[] = + { + 5, + 7, + 9, + 11, + 13, + 15, + 17, + 19 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(11); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(13); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(15); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(17); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(19); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 8)); + r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(12); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(14); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(16); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(18); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(20); + assert(r.first == next(m.begin(), 8)); + assert(r.second == next(m.begin(), 8)); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::set, min_allocator> M; + typedef std::pair R; + V ar[] = + { + 5, + 7, + 9, + 11, + 13, + 15, + 17, + 19 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(11); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(13); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(15); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(17); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(19); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 8)); + r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(12); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(14); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(16); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(18); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(20); + assert(r.first == next(m.begin(), 8)); + assert(r.second == next(m.begin(), 8)); + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::set> M; + { + typedef std::pair R; + V ar[] = + { + 5, + 7, + 9, + 11, + 13, + 15, + 17, + 19 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(11); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(13); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(15); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(17); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(19); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 8)); + r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(12); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(14); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(16); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(18); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(20); + assert(r.first == next(m.begin(), 8)); + assert(r.second == next(m.begin(), 8)); + } + } + { + typedef PrivateConstructor V; + typedef std::set> M; + typedef std::pair R; + + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 11 )); + m.insert ( V::make ( 13 )); + m.insert ( V::make ( 15 )); + m.insert ( V::make ( 17 )); + m.insert ( V::make ( 19 )); + + R r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(11); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(13); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(15); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(17); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(19); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 8)); + r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(12); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(14); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(16); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(18); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(20); + assert(r.first == next(m.begin(), 8)); + assert(r.second == next(m.begin(), 8)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/erase_iter.pass.cpp b/libcxx/test/std/containers/associative/set/erase_iter.pass.cpp new file mode 100644 index 00000000000..21666c36401 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/erase_iter.pass.cpp @@ -0,0 +1,181 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// iterator erase(const_iterator position); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::set M; + typedef int V; + typedef M::iterator I; + V ar[] = + { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(next(m.cbegin(), 3)); + assert(m.size() == 7); + assert(i == next(m.begin(), 3)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 5); + assert(*next(m.begin(), 4) == 6); + assert(*next(m.begin(), 5) == 7); + assert(*next(m.begin(), 6) == 8); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 6); + assert(i == m.begin()); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 5); + assert(*next(m.begin(), 3) == 6); + assert(*next(m.begin(), 4) == 7); + assert(*next(m.begin(), 5) == 8); + + i = m.erase(next(m.cbegin(), 5)); + assert(m.size() == 5); + assert(i == m.end()); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 5); + assert(*next(m.begin(), 3) == 6); + assert(*next(m.begin(), 4) == 7); + + i = m.erase(next(m.cbegin(), 1)); + assert(m.size() == 4); + assert(i == next(m.begin())); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + assert(*next(m.begin(), 2) == 6); + assert(*next(m.begin(), 3) == 7); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 3); + assert(i == next(m.begin(), 2)); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + assert(*next(m.begin(), 2) == 7); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 2); + assert(i == next(m.begin(), 2)); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 1); + assert(i == next(m.begin(), 0)); + assert(*next(m.begin(), 0) == 5); + + i = m.erase(m.cbegin()); + assert(m.size() == 0); + assert(i == m.begin()); + assert(i == m.end()); + } +#if __cplusplus >= 201103L + { + typedef std::set, min_allocator> M; + typedef int V; + typedef M::iterator I; + V ar[] = + { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(next(m.cbegin(), 3)); + assert(m.size() == 7); + assert(i == next(m.begin(), 3)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 5); + assert(*next(m.begin(), 4) == 6); + assert(*next(m.begin(), 5) == 7); + assert(*next(m.begin(), 6) == 8); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 6); + assert(i == m.begin()); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 5); + assert(*next(m.begin(), 3) == 6); + assert(*next(m.begin(), 4) == 7); + assert(*next(m.begin(), 5) == 8); + + i = m.erase(next(m.cbegin(), 5)); + assert(m.size() == 5); + assert(i == m.end()); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 5); + assert(*next(m.begin(), 3) == 6); + assert(*next(m.begin(), 4) == 7); + + i = m.erase(next(m.cbegin(), 1)); + assert(m.size() == 4); + assert(i == next(m.begin())); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + assert(*next(m.begin(), 2) == 6); + assert(*next(m.begin(), 3) == 7); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 3); + assert(i == next(m.begin(), 2)); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + assert(*next(m.begin(), 2) == 7); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 2); + assert(i == next(m.begin(), 2)); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 1); + assert(i == next(m.begin(), 0)); + assert(*next(m.begin(), 0) == 5); + + i = m.erase(m.cbegin()); + assert(m.size() == 0); + assert(i == m.begin()); + assert(i == m.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/erase_iter_iter.pass.cpp b/libcxx/test/std/containers/associative/set/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..47995031665 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/erase_iter_iter.pass.cpp @@ -0,0 +1,141 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// iterator erase(const_iterator first, const_iterator last); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::set M; + typedef int V; + typedef M::iterator I; + V ar[] = + { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(next(m.cbegin(), 5), next(m.cbegin(), 5)); + assert(m.size() == 8); + assert(i == next(m.begin(), 5)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 4); + assert(*next(m.begin(), 4) == 5); + assert(*next(m.begin(), 5) == 6); + assert(*next(m.begin(), 6) == 7); + assert(*next(m.begin(), 7) == 8); + + i = m.erase(next(m.cbegin(), 3), next(m.cbegin(), 4)); + assert(m.size() == 7); + assert(i == next(m.begin(), 3)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 5); + assert(*next(m.begin(), 4) == 6); + assert(*next(m.begin(), 5) == 7); + assert(*next(m.begin(), 6) == 8); + + i = m.erase(next(m.cbegin(), 2), next(m.cbegin(), 5)); + assert(m.size() == 4); + assert(i == next(m.begin(), 2)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 7); + assert(*next(m.begin(), 3) == 8); + + i = m.erase(next(m.cbegin(), 0), next(m.cbegin(), 2)); + assert(m.size() == 2); + assert(i == next(m.begin(), 0)); + assert(*next(m.begin(), 0) == 7); + assert(*next(m.begin(), 1) == 8); + + i = m.erase(m.cbegin(), m.cend()); + assert(m.size() == 0); + assert(i == m.end()); + } +#if __cplusplus >= 201103L + { + typedef std::set, min_allocator> M; + typedef int V; + typedef M::iterator I; + V ar[] = + { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(next(m.cbegin(), 5), next(m.cbegin(), 5)); + assert(m.size() == 8); + assert(i == next(m.begin(), 5)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 4); + assert(*next(m.begin(), 4) == 5); + assert(*next(m.begin(), 5) == 6); + assert(*next(m.begin(), 6) == 7); + assert(*next(m.begin(), 7) == 8); + + i = m.erase(next(m.cbegin(), 3), next(m.cbegin(), 4)); + assert(m.size() == 7); + assert(i == next(m.begin(), 3)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 5); + assert(*next(m.begin(), 4) == 6); + assert(*next(m.begin(), 5) == 7); + assert(*next(m.begin(), 6) == 8); + + i = m.erase(next(m.cbegin(), 2), next(m.cbegin(), 5)); + assert(m.size() == 4); + assert(i == next(m.begin(), 2)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 7); + assert(*next(m.begin(), 3) == 8); + + i = m.erase(next(m.cbegin(), 0), next(m.cbegin(), 2)); + assert(m.size() == 2); + assert(i == next(m.begin(), 0)); + assert(*next(m.begin(), 0) == 7); + assert(*next(m.begin(), 1) == 8); + + i = m.erase(m.cbegin(), m.cend()); + assert(m.size() == 0); + assert(i == m.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/erase_key.pass.cpp b/libcxx/test/std/containers/associative/set/erase_key.pass.cpp new file mode 100644 index 00000000000..9d92bd70d70 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/erase_key.pass.cpp @@ -0,0 +1,203 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// size_type erase(const key_type& k); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::set M; + typedef int V; + typedef M::size_type I; + V ar[] = + { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(9); + assert(m.size() == 8); + assert(i == 0); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 4); + assert(*next(m.begin(), 4) == 5); + assert(*next(m.begin(), 5) == 6); + assert(*next(m.begin(), 6) == 7); + assert(*next(m.begin(), 7) == 8); + + i = m.erase(4); + assert(m.size() == 7); + assert(i == 1); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 5); + assert(*next(m.begin(), 4) == 6); + assert(*next(m.begin(), 5) == 7); + assert(*next(m.begin(), 6) == 8); + + i = m.erase(1); + assert(m.size() == 6); + assert(i == 1); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 5); + assert(*next(m.begin(), 3) == 6); + assert(*next(m.begin(), 4) == 7); + assert(*next(m.begin(), 5) == 8); + + i = m.erase(8); + assert(m.size() == 5); + assert(i == 1); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 5); + assert(*next(m.begin(), 3) == 6); + assert(*next(m.begin(), 4) == 7); + + i = m.erase(3); + assert(m.size() == 4); + assert(i == 1); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + assert(*next(m.begin(), 2) == 6); + assert(*next(m.begin(), 3) == 7); + + i = m.erase(6); + assert(m.size() == 3); + assert(i == 1); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + assert(*next(m.begin(), 2) == 7); + + i = m.erase(7); + assert(m.size() == 2); + assert(i == 1); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + + i = m.erase(2); + assert(m.size() == 1); + assert(i == 1); + assert(*next(m.begin(), 0) == 5); + + i = m.erase(5); + assert(m.size() == 0); + assert(i == 1); + } +#if __cplusplus >= 201103L + { + typedef std::set, min_allocator> M; + typedef int V; + typedef M::size_type I; + V ar[] = + { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(9); + assert(m.size() == 8); + assert(i == 0); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 4); + assert(*next(m.begin(), 4) == 5); + assert(*next(m.begin(), 5) == 6); + assert(*next(m.begin(), 6) == 7); + assert(*next(m.begin(), 7) == 8); + + i = m.erase(4); + assert(m.size() == 7); + assert(i == 1); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 5); + assert(*next(m.begin(), 4) == 6); + assert(*next(m.begin(), 5) == 7); + assert(*next(m.begin(), 6) == 8); + + i = m.erase(1); + assert(m.size() == 6); + assert(i == 1); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 5); + assert(*next(m.begin(), 3) == 6); + assert(*next(m.begin(), 4) == 7); + assert(*next(m.begin(), 5) == 8); + + i = m.erase(8); + assert(m.size() == 5); + assert(i == 1); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 5); + assert(*next(m.begin(), 3) == 6); + assert(*next(m.begin(), 4) == 7); + + i = m.erase(3); + assert(m.size() == 4); + assert(i == 1); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + assert(*next(m.begin(), 2) == 6); + assert(*next(m.begin(), 3) == 7); + + i = m.erase(6); + assert(m.size() == 3); + assert(i == 1); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + assert(*next(m.begin(), 2) == 7); + + i = m.erase(7); + assert(m.size() == 2); + assert(i == 1); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + + i = m.erase(2); + assert(m.size() == 1); + assert(i == 1); + assert(*next(m.begin(), 0) == 5); + + i = m.erase(5); + assert(m.size() == 0); + assert(i == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/find.pass.cpp b/libcxx/test/std/containers/associative/set/find.pass.cpp new file mode 100644 index 00000000000..d08d2fb1e24 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/find.pass.cpp @@ -0,0 +1,240 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + { + typedef int V; + typedef std::set M; + { + typedef M::iterator R; + V ar[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::set, min_allocator> M; + { + typedef M::iterator R; + V ar[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::set> M; + typedef M::iterator R; + + V ar[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + + { + typedef PrivateConstructor V; + typedef std::set> M; + typedef M::iterator R; + + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 6 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 8 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 10 )); + m.insert ( V::make ( 11 )); + m.insert ( V::make ( 12 )); + + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/insert_cv.pass.cpp b/libcxx/test/std/containers/associative/set/insert_cv.pass.cpp new file mode 100644 index 00000000000..18d5c2e0339 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/insert_cv.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// pair insert(const value_type& v); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::set M; + typedef std::pair R; + M m; + R r = m.insert(M::value_type(2)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(*r.first == 2); + + r = m.insert(M::value_type(1)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(*r.first == 1); + + r = m.insert(M::value_type(3)); + assert(r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(*r.first == 3); + + r = m.insert(M::value_type(3)); + assert(!r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(*r.first == 3); + } +#if __cplusplus >= 201103L + { + typedef std::set, min_allocator> M; + typedef std::pair R; + M m; + R r = m.insert(M::value_type(2)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(*r.first == 2); + + r = m.insert(M::value_type(1)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(*r.first == 1); + + r = m.insert(M::value_type(3)); + assert(r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(*r.first == 3); + + r = m.insert(M::value_type(3)); + assert(!r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(*r.first == 3); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/insert_initializer_list.pass.cpp b/libcxx/test/std/containers/associative/set/insert_initializer_list.pass.cpp new file mode 100644 index 00000000000..fc6d612b2eb --- /dev/null +++ b/libcxx/test/std/containers/associative/set/insert_initializer_list.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// void insert(initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::set C; + typedef C::value_type V; + C m = {10, 8}; + m.insert({1, 2, 3, 4, 5, 6}); + assert(m.size() == 8); + assert(distance(m.begin(), m.end()) == m.size()); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + assert(*++i == V(8)); + assert(*++i == V(10)); + } +#if __cplusplus >= 201103L + { + typedef std::set, min_allocator> C; + typedef C::value_type V; + C m = {10, 8}; + m.insert({1, 2, 3, 4, 5, 6}); + assert(m.size() == 8); + assert(distance(m.begin(), m.end()) == m.size()); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + assert(*++i == V(8)); + assert(*++i == V(10)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/associative/set/insert_iter_cv.pass.cpp b/libcxx/test/std/containers/associative/set/insert_iter_cv.pass.cpp new file mode 100644 index 00000000000..718e720559f --- /dev/null +++ b/libcxx/test/std/containers/associative/set/insert_iter_cv.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// iterator insert(const_iterator position, const value_type& v); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::set M; + typedef M::iterator R; + M m; + R r = m.insert(m.cend(), M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + + r = m.insert(m.cend(), M::value_type(1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(*r == 1); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + } +#if __cplusplus >= 201103L + { + typedef std::set, min_allocator> M; + typedef M::iterator R; + M m; + R r = m.insert(m.cend(), M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + + r = m.insert(m.cend(), M::value_type(1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(*r == 1); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/insert_iter_iter.pass.cpp b/libcxx/test/std/containers/associative/set/insert_iter_iter.pass.cpp new file mode 100644 index 00000000000..ff729a0e7b9 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/insert_iter_iter.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// template +// void insert(InputIterator first, InputIterator last); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::set M; + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + M m; + m.insert(input_iterator(ar), + input_iterator(ar + sizeof(ar)/sizeof(ar[0]))); + assert(m.size() == 3); + assert(*m.begin() == 1); + assert(*next(m.begin()) == 2); + assert(*next(m.begin(), 2) == 3); + } +#if __cplusplus >= 201103L + { + typedef std::set, min_allocator> M; + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + M m; + m.insert(input_iterator(ar), + input_iterator(ar + sizeof(ar)/sizeof(ar[0]))); + assert(m.size() == 3); + assert(*m.begin() == 1); + assert(*next(m.begin()) == 2); + assert(*next(m.begin(), 2) == 3); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/insert_iter_rv.pass.cpp b/libcxx/test/std/containers/associative/set/insert_iter_rv.pass.cpp new file mode 100644 index 00000000000..c149fa3c68e --- /dev/null +++ b/libcxx/test/std/containers/associative/set/insert_iter_rv.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// iterator insert(const_iterator position, value_type&& v); + +#include +#include + +#include "../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::set M; + typedef M::iterator R; + M m; + R r = m.insert(m.cend(), M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + + r = m.insert(m.cend(), M::value_type(1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(*r == 1); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + } +#if __cplusplus >= 201103L + { + typedef std::set, min_allocator> M; + typedef M::iterator R; + M m; + R r = m.insert(m.cend(), M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + + r = m.insert(m.cend(), M::value_type(1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(*r == 1); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/set/insert_rv.pass.cpp b/libcxx/test/std/containers/associative/set/insert_rv.pass.cpp new file mode 100644 index 00000000000..39894514ee9 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/insert_rv.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// pair insert(value_type&& v); + +#include +#include + +#include "../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::set M; + typedef std::pair R; + M m; + R r = m.insert(M::value_type(2)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(*r.first == 2); + + r = m.insert(M::value_type(1)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(*r.first == 1); + + r = m.insert(M::value_type(3)); + assert(r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(*r.first == 3); + + r = m.insert(M::value_type(3)); + assert(!r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(*r.first == 3); + } +#if __cplusplus >= 201103L + { + typedef std::set, min_allocator> M; + typedef std::pair R; + M m; + R r = m.insert(M::value_type(2)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(*r.first == 2); + + r = m.insert(M::value_type(1)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(*r.first == 1); + + r = m.insert(M::value_type(3)); + assert(r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(*r.first == 3); + + r = m.insert(M::value_type(3)); + assert(!r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(*r.first == 3); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/set/iterator.pass.cpp b/libcxx/test/std/containers/associative/set/iterator.pass.cpp new file mode 100644 index 00000000000..ecd950f03a0 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/iterator.pass.cpp @@ -0,0 +1,211 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// iterator begin(); +// const_iterator begin() const; +// iterator end(); +// const_iterator end() const; +// +// reverse_iterator rbegin(); +// const_reverse_iterator rbegin() const; +// reverse_iterator rend(); +// const_reverse_iterator rend() const; +// +// const_iterator cbegin() const; +// const_iterator cend() const; +// const_reverse_iterator crbegin() const; +// const_reverse_iterator crend() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3, + 4, + 4, + 4, + 5, + 5, + 5, + 6, + 6, + 6, + 7, + 7, + 7, + 8, + 8, + 8 + }; + std::set m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + std::set::iterator i; + i = m.begin(); + std::set::const_iterator k = i; + assert(i == k); + for (int j = 1; j <= m.size(); ++j, ++i) + assert(*i == j); + } + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3, + 4, + 4, + 4, + 5, + 5, + 5, + 6, + 6, + 6, + 7, + 7, + 7, + 8, + 8, + 8 + }; + const std::set m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.cbegin(), m.cend()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + assert(std::distance(m.crbegin(), m.crend()) == m.size()); + std::set::const_iterator i; + i = m.begin(); + for (int j = 1; j <= m.size(); ++j, ++i) + assert(*i == j); + } +#if __cplusplus >= 201103L + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3, + 4, + 4, + 4, + 5, + 5, + 5, + 6, + 6, + 6, + 7, + 7, + 7, + 8, + 8, + 8 + }; + std::set, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + std::set, min_allocator>::iterator i; + i = m.begin(); + std::set, min_allocator>::const_iterator k = i; + assert(i == k); + for (int j = 1; j <= m.size(); ++j, ++i) + assert(*i == j); + } + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3, + 4, + 4, + 4, + 5, + 5, + 5, + 6, + 6, + 6, + 7, + 7, + 7, + 8, + 8, + 8 + }; + const std::set, min_allocator> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.cbegin(), m.cend()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + assert(std::distance(m.crbegin(), m.crend()) == m.size()); + std::set, min_allocator>::const_iterator i; + i = m.begin(); + for (int j = 1; j <= m.size(); ++j, ++i) + assert(*i == j); + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + typedef std::set C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/lower_bound.pass.cpp b/libcxx/test/std/containers/associative/set/lower_bound.pass.cpp new file mode 100644 index 00000000000..df202f31a4c --- /dev/null +++ b/libcxx/test/std/containers/associative/set/lower_bound.pass.cpp @@ -0,0 +1,337 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + { + typedef int V; + typedef std::set M; + { + typedef M::iterator R; + V ar[] = + { + 5, + 7, + 9, + 11, + 13, + 15, + 17, + 19 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + 5, + 7, + 9, + 11, + 13, + 15, + 17, + 19 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::set, min_allocator> M; + { + typedef M::iterator R; + V ar[] = + { + 5, + 7, + 9, + 11, + 13, + 15, + 17, + 19 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + 5, + 7, + 9, + 11, + 13, + 15, + 17, + 19 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::set> M; + typedef M::iterator R; + + V ar[] = + { + 5, + 7, + 9, + 11, + 13, + 15, + 17, + 19 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } + + { + typedef PrivateConstructor V; + typedef std::set> M; + typedef M::iterator R; + + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 11 )); + m.insert ( V::make ( 13 )); + m.insert ( V::make ( 15 )); + m.insert ( V::make ( 17 )); + m.insert ( V::make ( 19 )); + + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } +#endif + +} diff --git a/libcxx/test/std/containers/associative/set/max_size.pass.cpp b/libcxx/test/std/containers/associative/set/max_size.pass.cpp new file mode 100644 index 00000000000..cde4397c717 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/max_size.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// size_type max_size() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::set M; + M m; + assert(m.max_size() != 0); + } +#if __cplusplus >= 201103L + { + typedef std::set, min_allocator> M; + M m; + assert(m.max_size() != 0); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/alloc.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/alloc.pass.cpp new file mode 100644 index 00000000000..67433ff88a0 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/alloc.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// set(const allocator_type& a); + +#include +#include + +#include "test_allocator.h" + +int main() +{ + typedef std::less C; + typedef test_allocator A; + std::set m(A(5)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.get_allocator() == A(5)); +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..892ae5a0a79 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// set& operator=(initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::set C; + typedef C::value_type V; + C m = {10, 8}; + m = {1, 2, 3, 4, 5, 6}; + assert(m.size() == 6); + assert(distance(m.begin(), m.end()) == 6); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + } +#if __cplusplus >= 201103L + { + typedef std::set, min_allocator> C; + typedef C::value_type V; + C m = {10, 8}; + m = {1, 2, 3, 4, 5, 6}; + assert(m.size() == 6); + assert(distance(m.begin(), m.end()) == 6); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/compare.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/compare.pass.cpp new file mode 100644 index 00000000000..af94c70671b --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/compare.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// explicit set(const value_compare& comp); + +#include +#include + +#include "../../../test_compare.h" + +int main() +{ + typedef test_compare > C; + std::set m(C(3)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(3)); +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/compare_alloc.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/compare_alloc.pass.cpp new file mode 100644 index 00000000000..22b3328d4d7 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/compare_alloc.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// set(const value_compare& comp, const allocator_type& a); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" + +int main() +{ + typedef test_compare > C; + typedef test_allocator A; + std::set m(C(4), A(5)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(4)); + assert(m.get_allocator() == A(5)); +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/copy.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/copy.pass.cpp new file mode 100644 index 00000000000..a0e34e48de4 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/copy.pass.cpp @@ -0,0 +1,94 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// set(const set& m); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" + +int main() +{ + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare > C; + typedef test_allocator A; + std::set mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::set m = mo; + assert(m.get_allocator() == A(7)); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == 1); + assert(*next(m.begin()) == 2); + assert(*next(m.begin(), 2) == 3); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == 1); + assert(*next(mo.begin()) == 2); + assert(*next(mo.begin(), 2) == 3); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare > C; + typedef other_allocator A; + std::set mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::set m = mo; + assert(m.get_allocator() == A(-2)); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == 1); + assert(*next(m.begin()) == 2); + assert(*next(m.begin(), 2) == 3); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == 1); + assert(*next(mo.begin()) == 2); + assert(*next(mo.begin(), 2) == 3); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/copy_alloc.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..1ad03dc1404 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/copy_alloc.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// set(const set& m, const allocator_type& a); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" + +int main() +{ + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare > C; + typedef test_allocator A; + std::set mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::set m(mo, A(3)); + assert(m.get_allocator() == A(3)); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == 1); + assert(*next(m.begin()) == 2); + assert(*next(m.begin(), 2) == 3); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == 1); + assert(*next(mo.begin()) == 2); + assert(*next(mo.begin(), 2) == 3); +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/copy_assign.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/copy_assign.pass.cpp new file mode 100644 index 00000000000..7f0f0447625 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/copy_assign.pass.cpp @@ -0,0 +1,109 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// set& operator=(const set& s); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" + +int main() +{ + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare > C; + typedef test_allocator A; + std::set mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2)); + std::set m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7)); + m = mo; + assert(m.get_allocator() == A(7)); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == 1); + assert(*next(m.begin()) == 2); + assert(*next(m.begin(), 2) == 3); + + assert(mo.get_allocator() == A(2)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == 1); + assert(*next(mo.begin()) == 2); + assert(*next(mo.begin(), 2) == 3); + } + { + typedef int V; + const V ar[] = + { + 1, + 2, + 3 + }; + std::set m(ar, ar+sizeof(ar)/sizeof(ar[0])); + std::set *p = &m; + m = *p; + + assert(m.size() == 3); + assert(std::equal(m.begin(), m.end(), ar)); + } + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare > C; + typedef other_allocator A; + std::set mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2)); + std::set m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A(7)); + m = mo; + assert(m.get_allocator() == A(2)); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == 1); + assert(*next(m.begin()) == 2); + assert(*next(m.begin(), 2) == 3); + + assert(mo.get_allocator() == A(2)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == 1); + assert(*next(mo.begin()) == 2); + assert(*next(mo.begin(), 2) == 3); + } +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/default.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/default.pass.cpp new file mode 100644 index 00000000000..746a2d17307 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/default.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// set(); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + std::set m; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#if __cplusplus >= 201103L + { + std::set, min_allocator> m; + assert(m.empty()); + assert(m.begin() == m.end()); + } + { + std::set m = {}; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/default_noexcept.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/default_noexcept.pass.cpp new file mode 100644 index 00000000000..4d5754a9e6b --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/default_noexcept.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// set() +// noexcept( +// is_nothrow_default_constructible::value && +// is_nothrow_default_constructible::value && +// is_nothrow_copy_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp(); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::set C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::set, test_allocator> C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::set, other_allocator> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::set> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..25f5425c75a --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// ~set() // implied noexcept; + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template +struct some_comp +{ + typedef T value_type; + ~some_comp() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::set C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::set, test_allocator> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::set, other_allocator> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::set> C; + static_assert(!std::is_nothrow_destructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..2ad538e143f --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/initializer_list.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// set(initializer_list il, const key_compare& comp = key_compare()); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::set C; + typedef C::value_type V; + C m = {1, 2, 3, 4, 5, 6}; + assert(m.size() == 6); + assert(distance(m.begin(), m.end()) == 6); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + } +#if __cplusplus >= 201103L + { + typedef std::set, min_allocator> C; + typedef C::value_type V; + C m = {1, 2, 3, 4, 5, 6}; + assert(m.size() == 6); + assert(distance(m.begin(), m.end()) == 6); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/initializer_list_compare.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/initializer_list_compare.pass.cpp new file mode 100644 index 00000000000..a0afa02cf74 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/initializer_list_compare.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// set(initializer_list il, const key_compare& comp = key_compare()); + +#include +#include +#include "../../../test_compare.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + typedef test_compare > Cmp; + typedef std::set C; + typedef C::value_type V; + C m({1, 2, 3, 4, 5, 6}, Cmp(10)); + assert(m.size() == 6); + assert(distance(m.begin(), m.end()) == 6); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + assert(m.key_comp() == Cmp(10)); +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/initializer_list_compare_alloc.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/initializer_list_compare_alloc.pass.cpp new file mode 100644 index 00000000000..821820a1e0c --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/initializer_list_compare_alloc.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// set(initializer_list il, const key_compare& comp, const allocator_type& a); +// set(initializer_list il, const allocator_type& a); + +#include +#include +#include "../../../test_compare.h" +#include "test_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef test_compare > Cmp; + typedef test_allocator A; + typedef std::set C; + typedef C::value_type V; + C m({1, 2, 3, 4, 5, 6}, Cmp(10), A(4)); + assert(m.size() == 6); + assert(distance(m.begin(), m.end()) == 6); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + assert(m.key_comp() == Cmp(10)); + assert(m.get_allocator() == A(4)); + } +#if _LIBCPP_STD_VER > 11 + { + typedef test_compare > Cmp; + typedef test_allocator A; + typedef std::set C; + typedef C::value_type V; + C m({1, 2, 3, 4, 5, 6}, A(4)); + assert(m.size() == 6); + assert(distance(m.begin(), m.end()) == 6); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + assert(m.get_allocator() == A(4)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/iter_iter.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/iter_iter.pass.cpp new file mode 100644 index 00000000000..7ca7fe14d6c --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/iter_iter.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// template +// set(InputIterator first, InputIterator last); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + std::set m(input_iterator(ar), + input_iterator(ar+sizeof(ar)/sizeof(ar[0]))); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == 1); + assert(*next(m.begin()) == 2); + assert(*next(m.begin(), 2) == 3); + } +#if __cplusplus >= 201103L + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + std::set, min_allocator> m(input_iterator(ar), + input_iterator(ar+sizeof(ar)/sizeof(ar[0]))); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == 1); + assert(*next(m.begin()) == 2); + assert(*next(m.begin(), 2) == 3); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/iter_iter_alloc.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/iter_iter_alloc.pass.cpp new file mode 100644 index 00000000000..5ccb6e5cbcd --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/iter_iter_alloc.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// template +// set(InputIterator first, InputIterator last, +// const value_compare& comp, const allocator_type& a); +// +// template +// set(InputIterator first, InputIterator last, +// const allocator_type& a); + +#include +#include + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "test_allocator.h" + +int main() +{ + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare > C; + typedef test_allocator A; + std::set m(input_iterator(ar), + input_iterator(ar+sizeof(ar)/sizeof(ar[0])), + C(5), A(7)); + assert(m.value_comp() == C(5)); + assert(m.get_allocator() == A(7)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == 1); + assert(*next(m.begin()) == 2); + assert(*next(m.begin(), 2) == 3); +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_allocator A; + typedef test_compare > C; + A a(7); + std::set m(ar, ar+sizeof(ar)/sizeof(ar[0]), a); + + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == 1); + assert(*next(m.begin()) == 2); + assert(*next(m.begin(), 2) == 3); + assert(m.get_allocator() == a); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/iter_iter_comp.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/iter_iter_comp.pass.cpp new file mode 100644 index 00000000000..18bc0839003 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/iter_iter_comp.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// template +// set(InputIterator first, InputIterator last, const value_compare& comp); + +#include +#include + +#include "test_iterators.h" +#include "../../../test_compare.h" + +int main() +{ + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare > C; + std::set m(input_iterator(ar), + input_iterator(ar+sizeof(ar)/sizeof(ar[0])), C(5)); + assert(m.value_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == 1); + assert(*next(m.begin()) == 2); + assert(*next(m.begin(), 2) == 3); +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/move.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/move.pass.cpp new file mode 100644 index 00000000000..4026ec70c3e --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/move.pass.cpp @@ -0,0 +1,107 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// set(set&& s); + +#include +#include + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef int V; + typedef test_compare > C; + typedef test_allocator A; + std::set mo(C(5), A(7)); + std::set m = std::move(mo); + assert(m.get_allocator() == A(7)); + assert(m.key_comp() == C(5)); + assert(m.size() == 0); + assert(distance(m.begin(), m.end()) == 0); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare > C; + typedef test_allocator A; + std::set mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::set m = std::move(mo); + assert(m.get_allocator() == A(7)); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == 1); + assert(*next(m.begin()) == 2); + assert(*next(m.begin(), 2) == 3); + + assert(mo.get_allocator() == A(7)); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } +#if __cplusplus >= 201103L + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare > C; + typedef min_allocator A; + std::set mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::set m = std::move(mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == 1); + assert(*next(m.begin()) == 2); + assert(*next(m.begin(), 2) == 3); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/move_alloc.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..c4617f0b481 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/move_alloc.pass.cpp @@ -0,0 +1,141 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// set(set&& s, const allocator_type& a); + +#include +#include + +#include "../../../MoveOnly.h" +#include "../../../test_compare.h" +#include "test_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef MoveOnly V; + typedef test_compare > C; + typedef test_allocator A; + typedef std::set M; + typedef std::move_iterator I; + V a1[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(std::move(m1), A(7)); + assert(m3 == m2); + assert(m3.get_allocator() == A(7)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } + { + typedef MoveOnly V; + typedef test_compare > C; + typedef test_allocator A; + typedef std::set M; + typedef std::move_iterator I; + V a1[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(std::move(m1), A(5)); + assert(m3 == m2); + assert(m3.get_allocator() == A(5)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } + { + typedef MoveOnly V; + typedef test_compare > C; + typedef other_allocator A; + typedef std::set M; + typedef std::move_iterator I; + V a1[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(std::move(m1), A(5)); + assert(m3 == m2); + assert(m3.get_allocator() == A(5)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/move_assign.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/move_assign.pass.cpp new file mode 100644 index 00000000000..4e08f014ebe --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/move_assign.pass.cpp @@ -0,0 +1,186 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// set& operator=(set&& s); + +#include +#include + +#include "../../../MoveOnly.h" +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef MoveOnly V; + typedef test_compare > C; + typedef test_allocator A; + typedef std::set M; + typedef std::move_iterator I; + V a1[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(C(3), A(7)); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A(7)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } + { + typedef MoveOnly V; + typedef test_compare > C; + typedef test_allocator A; + typedef std::set M; + typedef std::move_iterator I; + V a1[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(C(3), A(5)); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A(5)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } + { + typedef MoveOnly V; + typedef test_compare > C; + typedef other_allocator A; + typedef std::set M; + typedef std::move_iterator I; + V a1[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A(7)); + V a2[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A(7)); + M m3(C(3), A(5)); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A(7)); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#if __cplusplus >= 201103L + { + typedef MoveOnly V; + typedef test_compare > C; + typedef min_allocator A; + typedef std::set M; + typedef std::move_iterator I; + V a1[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A()); + V a2[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A()); + M m3(C(3), A()); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A()); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..17ea74036db --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// set& operator=(set&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable::value && +// is_nothrow_move_assignable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp& operator=(const some_comp&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::set C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::set, test_allocator> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::set, other_allocator> C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::set> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/set.cons/move_noexcept.pass.cpp b/libcxx/test/std/containers/associative/set/set.cons/move_noexcept.pass.cpp new file mode 100644 index 00000000000..7a8ae7bf2b5 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.cons/move_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// set(set&&) +// noexcept(is_nothrow_move_constructible::value && +// is_nothrow_move_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp(const some_comp&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::set C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::set, test_allocator> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::set, other_allocator> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::set> C; + static_assert(!std::is_nothrow_move_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/set.special/member_swap.pass.cpp b/libcxx/test/std/containers/associative/set/set.special/member_swap.pass.cpp new file mode 100644 index 00000000000..f72abd7eb4a --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.special/member_swap.pass.cpp @@ -0,0 +1,201 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// void swap(set& m); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int V; + typedef std::set M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::set, min_allocator> M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/set.special/non_member_swap.pass.cpp b/libcxx/test/std/containers/associative/set/set.special/non_member_swap.pass.cpp new file mode 100644 index 00000000000..c9cffc68a12 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.special/non_member_swap.pass.cpp @@ -0,0 +1,177 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// void swap(set& m); + +#include +#include +#include "test_allocator.h" +#include "../../../test_compare.h" + +int main() +{ + typedef int V; + typedef std::set M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + typedef test_allocator A; + typedef test_compare > C; + typedef std::set M; + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A(1)); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A(2)); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + assert(m1.key_comp() == C(2)); + assert(m1.get_allocator() == A(1)); + assert(m2.key_comp() == C(1)); + assert(m2.get_allocator() == A(2)); + } + { + typedef other_allocator A; + typedef test_compare > C; + typedef std::set M; + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A(1)); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A(2)); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + assert(m1.key_comp() == C(2)); + assert(m1.get_allocator() == A(2)); + assert(m2.key_comp() == C(1)); + assert(m2.get_allocator() == A(1)); + } +} diff --git a/libcxx/test/std/containers/associative/set/set.special/swap_noexcept.pass.cpp b/libcxx/test/std/containers/associative/set/set.special/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..c4f169aa512 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/set.special/swap_noexcept.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(set& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + + some_comp() {} + some_comp(const some_comp&) {} + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::set C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::set, test_allocator> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::set, other_allocator> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::set> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/size.pass.cpp b/libcxx/test/std/containers/associative/set/size.pass.cpp new file mode 100644 index 00000000000..e7865473550 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/size.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// size_type size() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::set M; + M m; + assert(m.size() == 0); + m.insert(M::value_type(2)); + assert(m.size() == 1); + m.insert(M::value_type(1)); + assert(m.size() == 2); + m.insert(M::value_type(3)); + assert(m.size() == 3); + m.erase(m.begin()); + assert(m.size() == 2); + m.erase(m.begin()); + assert(m.size() == 1); + m.erase(m.begin()); + assert(m.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::set, min_allocator> M; + M m; + assert(m.size() == 0); + m.insert(M::value_type(2)); + assert(m.size() == 1); + m.insert(M::value_type(1)); + assert(m.size() == 2); + m.insert(M::value_type(3)); + assert(m.size() == 3); + m.erase(m.begin()); + assert(m.size() == 2); + m.erase(m.begin()); + assert(m.size() == 1); + m.erase(m.begin()); + assert(m.size() == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/types.pass.cpp b/libcxx/test/std/containers/associative/set/types.pass.cpp new file mode 100644 index 00000000000..3362c42aee4 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/types.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , +// class Allocator = allocator> +// class set +// { +// public: +// // types: +// typedef Key key_type; +// typedef key_type value_type; +// typedef Compare key_compare; +// typedef key_compare value_compare; +// typedef Allocator allocator_type; +// typedef typename allocator_type::reference reference; +// typedef typename allocator_type::const_reference const_reference; +// typedef typename allocator_type::pointer pointer; +// typedef typename allocator_type::const_pointer const_pointer; +// typedef typename allocator_type::size_type size_type; +// typedef typename allocator_type::difference_type difference_type; +// ... +// }; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::set C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + } +#if __cplusplus >= 201103L + { + typedef std::set, min_allocator> C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same>::value), ""); + static_assert((std::is_same>::value), ""); +// min_allocator doesn't have a size_type, so one gets synthesized + static_assert((std::is_same::type>::value), ""); + static_assert((std::is_same::value), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/upper_bound.pass.cpp b/libcxx/test/std/containers/associative/set/upper_bound.pass.cpp new file mode 100644 index 00000000000..10a28f06469 --- /dev/null +++ b/libcxx/test/std/containers/associative/set/upper_bound.pass.cpp @@ -0,0 +1,336 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class set + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" +#include "private_constructor.hpp" + +int main() +{ + { + typedef int V; + typedef std::set M; + { + typedef M::iterator R; + V ar[] = + { + 5, + 7, + 9, + 11, + 13, + 15, + 17, + 19 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + 5, + 7, + 9, + 11, + 13, + 15, + 17, + 19 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::set, min_allocator> M; + { + typedef M::iterator R; + V ar[] = + { + 5, + 7, + 9, + 11, + 13, + 15, + 17, + 19 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + 5, + 7, + 9, + 11, + 13, + 15, + 17, + 19 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::set> M; + typedef M::iterator R; + + V ar[] = + { + 5, + 7, + 9, + 11, + 13, + 15, + 17, + 19 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } + + { + typedef PrivateConstructor V; + typedef std::set> M; + typedef M::iterator R; + + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 11 )); + m.insert ( V::make ( 13 )); + m.insert ( V::make ( 15 )); + m.insert ( V::make ( 17 )); + m.insert ( V::make ( 19 )); + + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } +#endif +} diff --git a/libcxx/test/std/containers/associative/set/version.pass.cpp b/libcxx/test/std/containers/associative/set/version.pass.cpp new file mode 100644 index 00000000000..c3c4d926e5c --- /dev/null +++ b/libcxx/test/std/containers/associative/set/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +#include + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/std/containers/associative/tree_balance_after_insert.pass.cpp b/libcxx/test/std/containers/associative/tree_balance_after_insert.pass.cpp new file mode 100644 index 00000000000..b0a3e74cab0 --- /dev/null +++ b/libcxx/test/std/containers/associative/tree_balance_after_insert.pass.cpp @@ -0,0 +1,1616 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Not a portable test + +// Precondition: __root->__is_black_ == true +// template +// void +// __tree_balance_after_insert(_NodePtr __root, _NodePtr __x) + +#include <__tree> +#include + +struct Node +{ + Node* __left_; + Node* __right_; + Node* __parent_; + bool __is_black_; + + Node() : __left_(), __right_(), __parent_(), __is_black_() {} +}; + +void +test1() +{ + { + Node root; + Node a; + Node b; + Node c; + Node d; + + root.__left_ = &c; + + c.__parent_ = &root; + c.__left_ = &b; + c.__right_ = &d; + c.__is_black_ = true; + + b.__parent_ = &c; + b.__left_ = &a; + b.__right_ = 0; + b.__is_black_ = false; + + d.__parent_ = &c; + d.__left_ = 0; + d.__right_ = 0; + d.__is_black_ = false; + + a.__parent_ = &b; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = false; + + std::__tree_balance_after_insert(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__left_ == &c); + + assert(c.__parent_ == &root); + assert(c.__left_ == &b); + assert(c.__right_ == &d); + assert(c.__is_black_ == true); + + assert(b.__parent_ == &c); + assert(b.__left_ == &a); + assert(b.__right_ == 0); + assert(b.__is_black_ == true); + + assert(d.__parent_ == &c); + assert(d.__left_ == 0); + assert(d.__right_ == 0); + assert(d.__is_black_ == true); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + } + { + Node root; + Node a; + Node b; + Node c; + Node d; + + root.__left_ = &c; + + c.__parent_ = &root; + c.__left_ = &b; + c.__right_ = &d; + c.__is_black_ = true; + + b.__parent_ = &c; + b.__left_ = 0; + b.__right_ = &a; + b.__is_black_ = false; + + d.__parent_ = &c; + d.__left_ = 0; + d.__right_ = 0; + d.__is_black_ = false; + + a.__parent_ = &b; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = false; + + std::__tree_balance_after_insert(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__left_ == &c); + + assert(c.__parent_ == &root); + assert(c.__left_ == &b); + assert(c.__right_ == &d); + assert(c.__is_black_ == true); + + assert(b.__parent_ == &c); + assert(b.__left_ == 0); + assert(b.__right_ == &a); + assert(b.__is_black_ == true); + + assert(d.__parent_ == &c); + assert(d.__left_ == 0); + assert(d.__right_ == 0); + assert(d.__is_black_ == true); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + } + { + Node root; + Node a; + Node b; + Node c; + Node d; + + root.__left_ = &c; + + c.__parent_ = &root; + c.__left_ = &b; + c.__right_ = &d; + c.__is_black_ = true; + + b.__parent_ = &c; + b.__left_ = 0; + b.__right_ = 0; + b.__is_black_ = false; + + d.__parent_ = &c; + d.__left_ = &a; + d.__right_ = 0; + d.__is_black_ = false; + + a.__parent_ = &d; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = false; + + std::__tree_balance_after_insert(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__left_ == &c); + + assert(c.__parent_ == &root); + assert(c.__left_ == &b); + assert(c.__right_ == &d); + assert(c.__is_black_ == true); + + assert(b.__parent_ == &c); + assert(b.__left_ == 0); + assert(b.__right_ == 0); + assert(b.__is_black_ == true); + + assert(d.__parent_ == &c); + assert(d.__left_ == &a); + assert(d.__right_ == 0); + assert(d.__is_black_ == true); + + assert(a.__parent_ == &d); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + } + { + Node root; + Node a; + Node b; + Node c; + Node d; + + root.__left_ = &c; + + c.__parent_ = &root; + c.__left_ = &b; + c.__right_ = &d; + c.__is_black_ = true; + + b.__parent_ = &c; + b.__left_ = 0; + b.__right_ = 0; + b.__is_black_ = false; + + d.__parent_ = &c; + d.__left_ = 0; + d.__right_ = &a; + d.__is_black_ = false; + + a.__parent_ = &d; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = false; + + std::__tree_balance_after_insert(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__left_ == &c); + + assert(c.__parent_ == &root); + assert(c.__left_ == &b); + assert(c.__right_ == &d); + assert(c.__is_black_ == true); + + assert(b.__parent_ == &c); + assert(b.__left_ == 0); + assert(b.__right_ == 0); + assert(b.__is_black_ == true); + + assert(d.__parent_ == &c); + assert(d.__left_ == 0); + assert(d.__right_ == &a); + assert(d.__is_black_ == true); + + assert(a.__parent_ == &d); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + } + { + Node root; + Node a; + Node b; + Node c; + Node d; + Node e; + Node f; + Node g; + Node h; + Node i; + + root.__left_ = &c; + + c.__parent_ = &root; + c.__left_ = &b; + c.__right_ = &d; + c.__is_black_ = true; + + b.__parent_ = &c; + b.__left_ = &a; + b.__right_ = &g; + b.__is_black_ = false; + + d.__parent_ = &c; + d.__left_ = &h; + d.__right_ = &i; + d.__is_black_ = false; + + a.__parent_ = &b; + a.__left_ = &e; + a.__right_ = &f; + a.__is_black_ = false; + + e.__parent_ = &a; + e.__is_black_ = true; + + f.__parent_ = &a; + f.__is_black_ = true; + + g.__parent_ = &b; + g.__is_black_ = true; + + h.__parent_ = &d; + h.__is_black_ = true; + + i.__parent_ = &d; + i.__is_black_ = true; + + std::__tree_balance_after_insert(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__left_ == &c); + + assert(c.__parent_ == &root); + assert(c.__left_ == &b); + assert(c.__right_ == &d); + assert(c.__is_black_ == true); + + assert(b.__parent_ == &c); + assert(b.__left_ == &a); + assert(b.__right_ == &g); + assert(b.__is_black_ == true); + + assert(d.__parent_ == &c); + assert(d.__left_ == &h); + assert(d.__right_ == &i); + assert(d.__is_black_ == true); + + assert(a.__parent_ == &b); + assert(a.__left_ == &e); + assert(a.__right_ == &f); + assert(a.__is_black_ == false); + } + { + Node root; + Node a; + Node b; + Node c; + Node d; + Node e; + Node f; + Node g; + Node h; + Node i; + + root.__left_ = &c; + + c.__parent_ = &root; + c.__left_ = &b; + c.__right_ = &d; + c.__is_black_ = true; + + b.__parent_ = &c; + b.__left_ = &g; + b.__right_ = &a; + b.__is_black_ = false; + + d.__parent_ = &c; + d.__left_ = &h; + d.__right_ = &i; + d.__is_black_ = false; + + a.__parent_ = &b; + a.__left_ = &e; + a.__right_ = &f; + a.__is_black_ = false; + + e.__parent_ = &a; + e.__is_black_ = true; + + f.__parent_ = &a; + f.__is_black_ = true; + + g.__parent_ = &b; + g.__is_black_ = true; + + h.__parent_ = &d; + h.__is_black_ = true; + + i.__parent_ = &d; + i.__is_black_ = true; + + std::__tree_balance_after_insert(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__left_ == &c); + + assert(c.__parent_ == &root); + assert(c.__left_ == &b); + assert(c.__right_ == &d); + assert(c.__is_black_ == true); + + assert(b.__parent_ == &c); + assert(b.__left_ == &g); + assert(b.__right_ == &a); + assert(b.__is_black_ == true); + + assert(d.__parent_ == &c); + assert(d.__left_ == &h); + assert(d.__right_ == &i); + assert(d.__is_black_ == true); + + assert(a.__parent_ == &b); + assert(a.__left_ == &e); + assert(a.__right_ == &f); + assert(a.__is_black_ == false); + } + { + Node root; + Node a; + Node b; + Node c; + Node d; + Node e; + Node f; + Node g; + Node h; + Node i; + + root.__left_ = &c; + + c.__parent_ = &root; + c.__left_ = &b; + c.__right_ = &d; + c.__is_black_ = true; + + b.__parent_ = &c; + b.__left_ = &g; + b.__right_ = &h; + b.__is_black_ = false; + + d.__parent_ = &c; + d.__left_ = &a; + d.__right_ = &i; + d.__is_black_ = false; + + a.__parent_ = &d; + a.__left_ = &e; + a.__right_ = &f; + a.__is_black_ = false; + + e.__parent_ = &a; + e.__is_black_ = true; + + f.__parent_ = &a; + f.__is_black_ = true; + + g.__parent_ = &b; + g.__is_black_ = true; + + h.__parent_ = &b; + h.__is_black_ = true; + + i.__parent_ = &d; + i.__is_black_ = true; + + std::__tree_balance_after_insert(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__left_ == &c); + + assert(c.__parent_ == &root); + assert(c.__left_ == &b); + assert(c.__right_ == &d); + assert(c.__is_black_ == true); + + assert(b.__parent_ == &c); + assert(b.__left_ == &g); + assert(b.__right_ == &h); + assert(b.__is_black_ == true); + + assert(d.__parent_ == &c); + assert(d.__left_ == &a); + assert(d.__right_ == &i); + assert(d.__is_black_ == true); + + assert(a.__parent_ == &d); + assert(a.__left_ == &e); + assert(a.__right_ == &f); + assert(a.__is_black_ == false); + } + { + Node root; + Node a; + Node b; + Node c; + Node d; + Node e; + Node f; + Node g; + Node h; + Node i; + + root.__left_ = &c; + + c.__parent_ = &root; + c.__left_ = &b; + c.__right_ = &d; + c.__is_black_ = true; + + b.__parent_ = &c; + b.__left_ = &g; + b.__right_ = &h; + b.__is_black_ = false; + + d.__parent_ = &c; + d.__left_ = &i; + d.__right_ = &a; + d.__is_black_ = false; + + a.__parent_ = &d; + a.__left_ = &e; + a.__right_ = &f; + a.__is_black_ = false; + + e.__parent_ = &a; + e.__is_black_ = true; + + f.__parent_ = &a; + f.__is_black_ = true; + + g.__parent_ = &b; + g.__is_black_ = true; + + h.__parent_ = &b; + h.__is_black_ = true; + + i.__parent_ = &d; + i.__is_black_ = true; + + std::__tree_balance_after_insert(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__left_ == &c); + + assert(c.__parent_ == &root); + assert(c.__left_ == &b); + assert(c.__right_ == &d); + assert(c.__is_black_ == true); + + assert(b.__parent_ == &c); + assert(b.__left_ == &g); + assert(b.__right_ == &h); + assert(b.__is_black_ == true); + + assert(d.__parent_ == &c); + assert(d.__left_ == &i); + assert(d.__right_ == &a); + assert(d.__is_black_ == true); + + assert(a.__parent_ == &d); + assert(a.__left_ == &e); + assert(a.__right_ == &f); + assert(a.__is_black_ == false); + } +} + +void +test2() +{ + { + Node root; + Node a; + Node b; + Node c; + + root.__left_ = &c; + + c.__parent_ = &root; + c.__left_ = &a; + c.__right_ = 0; + c.__is_black_ = true; + + a.__parent_ = &c; + a.__left_ = 0; + a.__right_ = &b; + a.__is_black_ = false; + + b.__parent_ = &a; + b.__left_ = 0; + b.__right_ = 0; + b.__is_black_ = false; + + std::__tree_balance_after_insert(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__left_ == &b); + + assert(c.__parent_ == &b); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == false); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == &c); + assert(b.__is_black_ == true); + } + { + Node root; + Node a; + Node b; + Node c; + + root.__left_ = &a; + + a.__parent_ = &root; + a.__left_ = 0; + a.__right_ = &c; + a.__is_black_ = true; + + c.__parent_ = &a; + c.__left_ = &b; + c.__right_ = 0; + c.__is_black_ = false; + + b.__parent_ = &c; + b.__left_ = 0; + b.__right_ = 0; + b.__is_black_ = false; + + std::__tree_balance_after_insert(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__left_ == &b); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + assert(c.__parent_ == &b); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == &c); + assert(b.__is_black_ == true); + } + { + Node root; + Node a; + Node b; + Node c; + Node d; + Node e; + Node f; + Node g; + + root.__left_ = &c; + + c.__parent_ = &root; + c.__left_ = &a; + c.__right_ = &g; + c.__is_black_ = true; + + a.__parent_ = &c; + a.__left_ = &d; + a.__right_ = &b; + a.__is_black_ = false; + + b.__parent_ = &a; + b.__left_ = &e; + b.__right_ = &f; + b.__is_black_ = false; + + d.__parent_ = &a; + d.__is_black_ = true; + + e.__parent_ = &b; + e.__is_black_ = true; + + f.__parent_ = &b; + f.__is_black_ = true; + + g.__parent_ = &c; + g.__is_black_ = true; + + std::__tree_balance_after_insert(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__left_ == &b); + + assert(c.__parent_ == &b); + assert(c.__left_ == &f); + assert(c.__right_ == &g); + assert(c.__is_black_ == false); + + assert(a.__parent_ == &b); + assert(a.__left_ == &d); + assert(a.__right_ == &e); + assert(a.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == &c); + assert(b.__is_black_ == true); + + assert(d.__parent_ == &a); + assert(d.__is_black_ == true); + + assert(e.__parent_ == &a); + assert(e.__is_black_ == true); + + assert(f.__parent_ == &c); + assert(f.__is_black_ == true); + + assert(g.__parent_ == &c); + assert(g.__is_black_ == true); + } + { + Node root; + Node a; + Node b; + Node c; + Node d; + Node e; + Node f; + Node g; + + root.__left_ = &a; + + a.__parent_ = &root; + a.__left_ = &d; + a.__right_ = &c; + a.__is_black_ = true; + + c.__parent_ = &a; + c.__left_ = &b; + c.__right_ = &g; + c.__is_black_ = false; + + b.__parent_ = &c; + b.__left_ = &e; + b.__right_ = &f; + b.__is_black_ = false; + + d.__parent_ = &a; + d.__is_black_ = true; + + e.__parent_ = &b; + e.__is_black_ = true; + + f.__parent_ = &b; + f.__is_black_ = true; + + g.__parent_ = &c; + g.__is_black_ = true; + + std::__tree_balance_after_insert(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__left_ == &b); + + assert(c.__parent_ == &b); + assert(c.__left_ == &f); + assert(c.__right_ == &g); + assert(c.__is_black_ == false); + + assert(a.__parent_ == &b); + assert(a.__left_ == &d); + assert(a.__right_ == &e); + assert(a.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == &c); + assert(b.__is_black_ == true); + + assert(d.__parent_ == &a); + assert(d.__is_black_ == true); + + assert(e.__parent_ == &a); + assert(e.__is_black_ == true); + + assert(f.__parent_ == &c); + assert(f.__is_black_ == true); + + assert(g.__parent_ == &c); + assert(g.__is_black_ == true); + } +} + +void +test3() +{ + { + Node root; + Node a; + Node b; + Node c; + + root.__left_ = &c; + + c.__parent_ = &root; + c.__left_ = &b; + c.__right_ = 0; + c.__is_black_ = true; + + b.__parent_ = &c; + b.__left_ = &a; + b.__right_ = 0; + b.__is_black_ = false; + + a.__parent_ = &b; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = false; + + std::__tree_balance_after_insert(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__left_ == &b); + + assert(c.__parent_ == &b); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == false); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == &c); + assert(b.__is_black_ == true); + } + { + Node root; + Node a; + Node b; + Node c; + + root.__left_ = &a; + + a.__parent_ = &root; + a.__left_ = 0; + a.__right_ = &b; + a.__is_black_ = true; + + b.__parent_ = &a; + b.__left_ = 0; + b.__right_ = &c; + b.__is_black_ = false; + + c.__parent_ = &b; + c.__left_ = 0; + c.__right_ = 0; + c.__is_black_ = false; + + std::__tree_balance_after_insert(root.__left_, &c); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__left_ == &b); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + assert(c.__parent_ == &b); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == &c); + assert(b.__is_black_ == true); + } + { + Node root; + Node a; + Node b; + Node c; + Node d; + Node e; + Node f; + Node g; + + root.__left_ = &c; + + c.__parent_ = &root; + c.__left_ = &b; + c.__right_ = &g; + c.__is_black_ = true; + + b.__parent_ = &c; + b.__left_ = &a; + b.__right_ = &f; + b.__is_black_ = false; + + a.__parent_ = &b; + a.__left_ = &d; + a.__right_ = &e; + a.__is_black_ = false; + + d.__parent_ = &a; + d.__is_black_ = true; + + e.__parent_ = &a; + e.__is_black_ = true; + + f.__parent_ = &b; + f.__is_black_ = true; + + g.__parent_ = &c; + g.__is_black_ = true; + + std::__tree_balance_after_insert(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__left_ == &b); + + assert(c.__parent_ == &b); + assert(c.__left_ == &f); + assert(c.__right_ == &g); + assert(c.__is_black_ == false); + + assert(a.__parent_ == &b); + assert(a.__left_ == &d); + assert(a.__right_ == &e); + assert(a.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == &c); + assert(b.__is_black_ == true); + + assert(d.__parent_ == &a); + assert(d.__is_black_ == true); + + assert(e.__parent_ == &a); + assert(e.__is_black_ == true); + + assert(f.__parent_ == &c); + assert(f.__is_black_ == true); + + assert(g.__parent_ == &c); + assert(g.__is_black_ == true); + } + { + Node root; + Node a; + Node b; + Node c; + Node d; + Node e; + Node f; + Node g; + + root.__left_ = &a; + + a.__parent_ = &root; + a.__left_ = &d; + a.__right_ = &b; + a.__is_black_ = true; + + b.__parent_ = &a; + b.__left_ = &e; + b.__right_ = &c; + b.__is_black_ = false; + + c.__parent_ = &b; + c.__left_ = &f; + c.__right_ = &g; + c.__is_black_ = false; + + d.__parent_ = &a; + d.__is_black_ = true; + + e.__parent_ = &b; + e.__is_black_ = true; + + f.__parent_ = &c; + f.__is_black_ = true; + + g.__parent_ = &c; + g.__is_black_ = true; + + std::__tree_balance_after_insert(root.__left_, &c); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__left_ == &b); + + assert(c.__parent_ == &b); + assert(c.__left_ == &f); + assert(c.__right_ == &g); + assert(c.__is_black_ == false); + + assert(a.__parent_ == &b); + assert(a.__left_ == &d); + assert(a.__right_ == &e); + assert(a.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == &c); + assert(b.__is_black_ == true); + + assert(d.__parent_ == &a); + assert(d.__is_black_ == true); + + assert(e.__parent_ == &a); + assert(e.__is_black_ == true); + + assert(f.__parent_ == &c); + assert(f.__is_black_ == true); + + assert(g.__parent_ == &c); + assert(g.__is_black_ == true); + } +} + +void +test4() +{ + Node root; + Node a; + Node b; + Node c; + Node d; + Node e; + Node f; + Node g; + Node h; + + root.__left_ = &a; + a.__parent_ = &root; + + std::__tree_balance_after_insert(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &a); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(a.__parent_ == &root); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == true); + + a.__right_ = &b; + b.__parent_ = &a; + + std::__tree_balance_after_insert(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &a); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(a.__parent_ == &root); + assert(a.__left_ == 0); + assert(a.__right_ == &b); + assert(a.__is_black_ == true); + + assert(b.__parent_ == &a); + assert(b.__left_ == 0); + assert(b.__right_ == 0); + assert(b.__is_black_ == false); + + b.__right_ = &c; + c.__parent_ = &b; + + std::__tree_balance_after_insert(root.__left_, &c); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == &c); + assert(b.__is_black_ == true); + + assert(c.__parent_ == &b); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == false); + + c.__right_ = &d; + d.__parent_ = &c; + + std::__tree_balance_after_insert(root.__left_, &d); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == true); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == &c); + assert(b.__is_black_ == true); + + assert(c.__parent_ == &b); + assert(c.__left_ == 0); + assert(c.__right_ == &d); + assert(c.__is_black_ == true); + + assert(d.__parent_ == &c); + assert(d.__left_ == 0); + assert(d.__right_ == 0); + assert(d.__is_black_ == false); + + d.__right_ = &e; + e.__parent_ = &d; + + std::__tree_balance_after_insert(root.__left_, &e); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == &d); + assert(b.__is_black_ == true); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == true); + + assert(d.__parent_ == &b); + assert(d.__left_ == &c); + assert(d.__right_ == &e); + assert(d.__is_black_ == true); + + assert(c.__parent_ == &d); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == false); + + assert(e.__parent_ == &d); + assert(e.__left_ == 0); + assert(e.__right_ == 0); + assert(e.__is_black_ == false); + + e.__right_ = &f; + f.__parent_ = &e; + + std::__tree_balance_after_insert(root.__left_, &f); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == &d); + assert(b.__is_black_ == true); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == true); + + assert(d.__parent_ == &b); + assert(d.__left_ == &c); + assert(d.__right_ == &e); + assert(d.__is_black_ == false); + + assert(c.__parent_ == &d); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == true); + + assert(e.__parent_ == &d); + assert(e.__left_ == 0); + assert(e.__right_ == &f); + assert(e.__is_black_ == true); + + assert(f.__parent_ == &e); + assert(f.__left_ == 0); + assert(f.__right_ == 0); + assert(f.__is_black_ == false); + + f.__right_ = &g; + g.__parent_ = &f; + + std::__tree_balance_after_insert(root.__left_, &g); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == &d); + assert(b.__is_black_ == true); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == true); + + assert(d.__parent_ == &b); + assert(d.__left_ == &c); + assert(d.__right_ == &f); + assert(d.__is_black_ == false); + + assert(c.__parent_ == &d); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == true); + + assert(f.__parent_ == &d); + assert(f.__left_ == &e); + assert(f.__right_ == &g); + assert(f.__is_black_ == true); + + assert(e.__parent_ == &f); + assert(e.__left_ == 0); + assert(e.__right_ == 0); + assert(e.__is_black_ == false); + + assert(g.__parent_ == &f); + assert(g.__left_ == 0); + assert(g.__right_ == 0); + assert(g.__is_black_ == false); + + g.__right_ = &h; + h.__parent_ = &g; + + std::__tree_balance_after_insert(root.__left_, &h); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &d); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(d.__parent_ == &root); + assert(d.__left_ == &b); + assert(d.__right_ == &f); + assert(d.__is_black_ == true); + + assert(b.__parent_ == &d); + assert(b.__left_ == &a); + assert(b.__right_ == &c); + assert(b.__is_black_ == false); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == true); + + assert(c.__parent_ == &b); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == true); + + assert(f.__parent_ == &d); + assert(f.__left_ == &e); + assert(f.__right_ == &g); + assert(f.__is_black_ == false); + + assert(e.__parent_ == &f); + assert(e.__left_ == 0); + assert(e.__right_ == 0); + assert(e.__is_black_ == true); + + assert(g.__parent_ == &f); + assert(g.__left_ == 0); + assert(g.__right_ == &h); + assert(g.__is_black_ == true); + + assert(h.__parent_ == &g); + assert(h.__left_ == 0); + assert(h.__right_ == 0); + assert(h.__is_black_ == false); +} + +void +test5() +{ + Node root; + Node a; + Node b; + Node c; + Node d; + Node e; + Node f; + Node g; + Node h; + + root.__left_ = &h; + h.__parent_ = &root; + + std::__tree_balance_after_insert(root.__left_, &h); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &h); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(h.__parent_ == &root); + assert(h.__left_ == 0); + assert(h.__right_ == 0); + assert(h.__is_black_ == true); + + h.__left_ = &g; + g.__parent_ = &h; + + std::__tree_balance_after_insert(root.__left_, &g); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &h); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(h.__parent_ == &root); + assert(h.__left_ == &g); + assert(h.__right_ == 0); + assert(h.__is_black_ == true); + + assert(g.__parent_ == &h); + assert(g.__left_ == 0); + assert(g.__right_ == 0); + assert(g.__is_black_ == false); + + g.__left_ = &f; + f.__parent_ = &g; + + std::__tree_balance_after_insert(root.__left_, &f); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &g); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(g.__parent_ == &root); + assert(g.__left_ == &f); + assert(g.__right_ == &h); + assert(g.__is_black_ == true); + + assert(f.__parent_ == &g); + assert(f.__left_ == 0); + assert(f.__right_ == 0); + assert(f.__is_black_ == false); + + assert(h.__parent_ == &g); + assert(h.__left_ == 0); + assert(h.__right_ == 0); + assert(h.__is_black_ == false); + + f.__left_ = &e; + e.__parent_ = &f; + + std::__tree_balance_after_insert(root.__left_, &e); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &g); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(g.__parent_ == &root); + assert(g.__left_ == &f); + assert(g.__right_ == &h); + assert(g.__is_black_ == true); + + assert(f.__parent_ == &g); + assert(f.__left_ == &e); + assert(f.__right_ == 0); + assert(f.__is_black_ == true); + + assert(e.__parent_ == &f); + assert(e.__left_ == 0); + assert(e.__right_ == 0); + assert(e.__is_black_ == false); + + assert(h.__parent_ == &g); + assert(h.__left_ == 0); + assert(h.__right_ == 0); + assert(h.__is_black_ == true); + + e.__left_ = &d; + d.__parent_ = &e; + + std::__tree_balance_after_insert(root.__left_, &d); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &g); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(g.__parent_ == &root); + assert(g.__left_ == &e); + assert(g.__right_ == &h); + assert(g.__is_black_ == true); + + assert(e.__parent_ == &g); + assert(e.__left_ == &d); + assert(e.__right_ == &f); + assert(e.__is_black_ == true); + + assert(d.__parent_ == &e); + assert(d.__left_ == 0); + assert(d.__right_ == 0); + assert(d.__is_black_ == false); + + assert(f.__parent_ == &e); + assert(f.__left_ == 0); + assert(f.__right_ == 0); + assert(f.__is_black_ == false); + + assert(h.__parent_ == &g); + assert(h.__left_ == 0); + assert(h.__right_ == 0); + assert(h.__is_black_ == true); + + d.__left_ = &c; + c.__parent_ = &d; + + std::__tree_balance_after_insert(root.__left_, &c); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &g); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(g.__parent_ == &root); + assert(g.__left_ == &e); + assert(g.__right_ == &h); + assert(g.__is_black_ == true); + + assert(e.__parent_ == &g); + assert(e.__left_ == &d); + assert(e.__right_ == &f); + assert(e.__is_black_ == false); + + assert(d.__parent_ == &e); + assert(d.__left_ == &c); + assert(d.__right_ == 0); + assert(d.__is_black_ == true); + + assert(c.__parent_ == &d); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == false); + + assert(f.__parent_ == &e); + assert(f.__left_ == 0); + assert(f.__right_ == 0); + assert(f.__is_black_ == true); + + assert(h.__parent_ == &g); + assert(h.__left_ == 0); + assert(h.__right_ == 0); + assert(h.__is_black_ == true); + + c.__left_ = &b; + b.__parent_ = &c; + + std::__tree_balance_after_insert(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &g); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(g.__parent_ == &root); + assert(g.__left_ == &e); + assert(g.__right_ == &h); + assert(g.__is_black_ == true); + + assert(e.__parent_ == &g); + assert(e.__left_ == &c); + assert(e.__right_ == &f); + assert(e.__is_black_ == false); + + assert(c.__parent_ == &e); + assert(c.__left_ == &b); + assert(c.__right_ == &d); + assert(c.__is_black_ == true); + + assert(b.__parent_ == &c); + assert(b.__left_ == 0); + assert(b.__right_ == 0); + assert(b.__is_black_ == false); + + assert(d.__parent_ == &c); + assert(d.__left_ == 0); + assert(d.__right_ == 0); + assert(d.__is_black_ == false); + + assert(f.__parent_ == &e); + assert(f.__left_ == 0); + assert(f.__right_ == 0); + assert(f.__is_black_ == true); + + assert(h.__parent_ == &g); + assert(h.__left_ == 0); + assert(h.__right_ == 0); + assert(h.__is_black_ == true); + + b.__left_ = &a; + a.__parent_ = &b; + + std::__tree_balance_after_insert(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &e); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(e.__parent_ == &root); + assert(e.__left_ == &c); + assert(e.__right_ == &g); + assert(e.__is_black_ == true); + + assert(c.__parent_ == &e); + assert(c.__left_ == &b); + assert(c.__right_ == &d); + assert(c.__is_black_ == false); + + assert(b.__parent_ == &c); + assert(b.__left_ == &a); + assert(b.__right_ == 0); + assert(b.__is_black_ == true); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + assert(d.__parent_ == &c); + assert(d.__left_ == 0); + assert(d.__right_ == 0); + assert(d.__is_black_ == true); + + assert(g.__parent_ == &e); + assert(g.__left_ == &f); + assert(g.__right_ == &h); + assert(g.__is_black_ == false); + + assert(f.__parent_ == &g); + assert(f.__left_ == 0); + assert(f.__right_ == 0); + assert(f.__is_black_ == true); + + assert(h.__parent_ == &g); + assert(h.__left_ == 0); + assert(h.__right_ == 0); + assert(h.__is_black_ == true); +} + +int main() +{ + test1(); + test2(); + test3(); + test4(); + test5(); +} diff --git a/libcxx/test/std/containers/associative/tree_left_rotate.pass.cpp b/libcxx/test/std/containers/associative/tree_left_rotate.pass.cpp new file mode 100644 index 00000000000..774cbc68798 --- /dev/null +++ b/libcxx/test/std/containers/associative/tree_left_rotate.pass.cpp @@ -0,0 +1,98 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Not a portable test + +// Precondition: __x->__right_ != nullptr +// template +// void +// __tree_left_rotate(_NodePtr __x); + +#include <__tree> +#include + +struct Node +{ + Node* __left_; + Node* __right_; + Node* __parent_; + + Node() : __left_(), __right_(), __parent_() {} +}; + +void +test1() +{ + Node root; + Node x; + Node y; + root.__left_ = &x; + x.__left_ = 0; + x.__right_ = &y; + x.__parent_ = &root; + y.__left_ = 0; + y.__right_ = 0; + y.__parent_ = &x; + std::__tree_left_rotate(&x); + assert(root.__parent_ == 0); + assert(root.__left_ == &y); + assert(root.__right_ == 0); + assert(y.__parent_ == &root); + assert(y.__left_ == &x); + assert(y.__right_ == 0); + assert(x.__parent_ == &y); + assert(x.__left_ == 0); + assert(x.__right_ == 0); +} + +void +test2() +{ + Node root; + Node x; + Node y; + Node a; + Node b; + Node c; + root.__left_ = &x; + x.__left_ = &a; + x.__right_ = &y; + x.__parent_ = &root; + y.__left_ = &b; + y.__right_ = &c; + y.__parent_ = &x; + a.__parent_ = &x; + b.__parent_ = &y; + c.__parent_ = &y; + std::__tree_left_rotate(&x); + assert(root.__parent_ == 0); + assert(root.__left_ == &y); + assert(root.__right_ == 0); + assert(y.__parent_ == &root); + assert(y.__left_ == &x); + assert(y.__right_ == &c); + assert(x.__parent_ == &y); + assert(x.__left_ == &a); + assert(x.__right_ == &b); + assert(a.__parent_ == &x); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(b.__parent_ == &x); + assert(b.__left_ == 0); + assert(b.__right_ == 0); + assert(c.__parent_ == &y); + assert(c.__left_ == 0); + assert(c.__right_ == 0); +} + +int main() +{ + test1(); + test2(); +} diff --git a/libcxx/test/std/containers/associative/tree_remove.pass.cpp b/libcxx/test/std/containers/associative/tree_remove.pass.cpp new file mode 100644 index 00000000000..fb14bd929e9 --- /dev/null +++ b/libcxx/test/std/containers/associative/tree_remove.pass.cpp @@ -0,0 +1,1648 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Not a portable test + +// Returns __tree_next(__z) +// template +// void +// __tree_remove(_NodePtr __root, _NodePtr __z) + +#include <__tree> +#include + +struct Node +{ + Node* __left_; + Node* __right_; + Node* __parent_; + bool __is_black_; + + Node() : __left_(), __right_(), __parent_(), __is_black_() {} +}; + +void +test1() +{ + { + // Left + // Case 1 -> Case 2 -> x is red turned to black + Node root; + Node b; + Node c; + Node d; + Node e; + Node y; + + root.__left_ = &b; + + b.__parent_ = &root; + b.__left_ = &y; + b.__right_ = &d; + b.__is_black_ = true; + + y.__parent_ = &b; + y.__left_ = 0; + y.__right_ = 0; + y.__is_black_ = true; + + d.__parent_ = &b; + d.__left_ = &c; + d.__right_ = &e; + d.__is_black_ = false; + + c.__parent_ = &d; + c.__left_ = 0; + c.__right_ = 0; + c.__is_black_ = true; + + e.__parent_ = &d; + e.__left_ = 0; + e.__right_ = 0; + e.__is_black_ = true; + + std::__tree_remove(root.__left_, &y); + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &d); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(d.__parent_ == &root); + assert(d.__left_ == &b); + assert(d.__right_ == &e); + assert(d.__is_black_ == true); + + assert(b.__parent_ == &d); + assert(b.__left_ == 0); + assert(b.__right_ == &c); + assert(b.__is_black_ == true); + + assert(c.__parent_ == &b); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == false); + + assert(e.__parent_ == &d); + assert(e.__left_ == 0); + assert(e.__right_ == 0); + assert(e.__is_black_ == true); + } + { + // Right + // Case 1 -> Case 2 -> x is red turned to black + Node root; + Node b; + Node c; + Node d; + Node e; + Node y; + + root.__left_ = &b; + + b.__parent_ = &root; + b.__right_ = &y; + b.__left_ = &d; + b.__is_black_ = true; + + y.__parent_ = &b; + y.__right_ = 0; + y.__left_ = 0; + y.__is_black_ = true; + + d.__parent_ = &b; + d.__right_ = &c; + d.__left_ = &e; + d.__is_black_ = false; + + c.__parent_ = &d; + c.__right_ = 0; + c.__left_ = 0; + c.__is_black_ = true; + + e.__parent_ = &d; + e.__right_ = 0; + e.__left_ = 0; + e.__is_black_ = true; + + std::__tree_remove(root.__left_, &y); + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &d); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(d.__parent_ == &root); + assert(d.__right_ == &b); + assert(d.__left_ == &e); + assert(d.__is_black_ == true); + + assert(b.__parent_ == &d); + assert(b.__right_ == 0); + assert(b.__left_ == &c); + assert(b.__is_black_ == true); + + assert(c.__parent_ == &b); + assert(c.__right_ == 0); + assert(c.__left_ == 0); + assert(c.__is_black_ == false); + + assert(e.__parent_ == &d); + assert(e.__right_ == 0); + assert(e.__left_ == 0); + assert(e.__is_black_ == true); + } + { + // Left + // Case 1 -> Case 3 -> Case 4 + Node root; + Node b; + Node c; + Node d; + Node e; + Node f; + Node y; + + root.__left_ = &b; + + b.__parent_ = &root; + b.__left_ = &y; + b.__right_ = &d; + b.__is_black_ = true; + + y.__parent_ = &b; + y.__left_ = 0; + y.__right_ = 0; + y.__is_black_ = true; + + d.__parent_ = &b; + d.__left_ = &c; + d.__right_ = &e; + d.__is_black_ = false; + + c.__parent_ = &d; + c.__left_ = &f; + c.__right_ = 0; + c.__is_black_ = true; + + e.__parent_ = &d; + e.__left_ = 0; + e.__right_ = 0; + e.__is_black_ = true; + + f.__parent_ = &c; + f.__left_ = 0; + f.__right_ = 0; + f.__is_black_ = false; + + std::__tree_remove(root.__left_, &y); + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &d); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(d.__parent_ == &root); + assert(d.__left_ == &f); + assert(d.__right_ == &e); + assert(d.__is_black_ == true); + + assert(f.__parent_ == &d); + assert(f.__left_ == &b); + assert(f.__right_ == &c); + assert(f.__is_black_ == false); + + assert(b.__parent_ == &f); + assert(b.__left_ == 0); + assert(b.__right_ == 0); + assert(b.__is_black_ == true); + + assert(c.__parent_ == &f); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == true); + + assert(e.__parent_ == &d); + assert(e.__left_ == 0); + assert(e.__right_ == 0); + assert(e.__is_black_ == true); + } + { + // Right + // Case 1 -> Case 3 -> Case 4 + Node root; + Node b; + Node c; + Node d; + Node e; + Node f; + Node y; + + root.__left_ = &b; + + b.__parent_ = &root; + b.__right_ = &y; + b.__left_ = &d; + b.__is_black_ = true; + + y.__parent_ = &b; + y.__right_ = 0; + y.__left_ = 0; + y.__is_black_ = true; + + d.__parent_ = &b; + d.__right_ = &c; + d.__left_ = &e; + d.__is_black_ = false; + + c.__parent_ = &d; + c.__right_ = &f; + c.__left_ = 0; + c.__is_black_ = true; + + e.__parent_ = &d; + e.__right_ = 0; + e.__left_ = 0; + e.__is_black_ = true; + + f.__parent_ = &c; + f.__right_ = 0; + f.__left_ = 0; + f.__is_black_ = false; + + std::__tree_remove(root.__left_, &y); + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &d); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(d.__parent_ == &root); + assert(d.__right_ == &f); + assert(d.__left_ == &e); + assert(d.__is_black_ == true); + + assert(f.__parent_ == &d); + assert(f.__right_ == &b); + assert(f.__left_ == &c); + assert(f.__is_black_ == false); + + assert(b.__parent_ == &f); + assert(b.__right_ == 0); + assert(b.__left_ == 0); + assert(b.__is_black_ == true); + + assert(c.__parent_ == &f); + assert(c.__right_ == 0); + assert(c.__left_ == 0); + assert(c.__is_black_ == true); + + assert(e.__parent_ == &d); + assert(e.__right_ == 0); + assert(e.__left_ == 0); + assert(e.__is_black_ == true); + } +} + +void +test2() +{ + { + Node root; + Node a; + Node b; + Node c; + + root.__left_ = &b; + + b.__parent_ = &root; + b.__left_ = &a; + b.__right_ = &c; + b.__is_black_ = true; + + a.__parent_ = &b; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = true; + + c.__parent_ = &b; + c.__left_ = 0; + c.__right_ = 0; + c.__is_black_ = true; + + std::__tree_remove(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == 0); + assert(b.__right_ == &c); + assert(b.__is_black_ == true); + + assert(c.__parent_ == &b); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == false); + + std::__tree_remove(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &c); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(c.__parent_ == &root); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == true); + + std::__tree_remove(root.__left_, &c); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == 0); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + } + { + Node root; + Node a; + Node b; + Node c; + + root.__left_ = &b; + + b.__parent_ = &root; + b.__left_ = &a; + b.__right_ = &c; + b.__is_black_ = true; + + a.__parent_ = &b; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = false; + + c.__parent_ = &b; + c.__left_ = 0; + c.__right_ = 0; + c.__is_black_ = false; + + std::__tree_remove(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == 0); + assert(b.__right_ == &c); + assert(b.__is_black_ == true); + + assert(c.__parent_ == &b); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == false); + + std::__tree_remove(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &c); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(c.__parent_ == &root); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == true); + + std::__tree_remove(root.__left_, &c); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == 0); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + } + { + Node root; + Node a; + Node b; + Node c; + + root.__left_ = &b; + + b.__parent_ = &root; + b.__left_ = &a; + b.__right_ = &c; + b.__is_black_ = true; + + a.__parent_ = &b; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = true; + + c.__parent_ = &b; + c.__left_ = 0; + c.__right_ = 0; + c.__is_black_ = true; + + std::__tree_remove(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == 0); + assert(b.__right_ == &c); + assert(b.__is_black_ == true); + + assert(c.__parent_ == &b); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == false); + + std::__tree_remove(root.__left_, &c); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == 0); + assert(b.__right_ == 0); + assert(b.__is_black_ == true); + + std::__tree_remove(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == 0); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + } + { + Node root; + Node a; + Node b; + Node c; + + root.__left_ = &b; + + b.__parent_ = &root; + b.__left_ = &a; + b.__right_ = &c; + b.__is_black_ = true; + + a.__parent_ = &b; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = false; + + c.__parent_ = &b; + c.__left_ = 0; + c.__right_ = 0; + c.__is_black_ = false; + + std::__tree_remove(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == 0); + assert(b.__right_ == &c); + assert(b.__is_black_ == true); + + assert(c.__parent_ == &b); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == false); + + std::__tree_remove(root.__left_, &c); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == 0); + assert(b.__right_ == 0); + assert(b.__is_black_ == true); + + std::__tree_remove(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == 0); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + } + { + Node root; + Node a; + Node b; + Node c; + + root.__left_ = &b; + + b.__parent_ = &root; + b.__left_ = &a; + b.__right_ = &c; + b.__is_black_ = true; + + a.__parent_ = &b; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = true; + + c.__parent_ = &b; + c.__left_ = 0; + c.__right_ = 0; + c.__is_black_ = true; + + std::__tree_remove(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &c); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(a.__parent_ == &c); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + assert(c.__parent_ == &root); + assert(c.__left_ == &a); + assert(c.__right_ == 0); + assert(c.__is_black_ == true); + + std::__tree_remove(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &c); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(c.__parent_ == &root); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == true); + + std::__tree_remove(root.__left_, &c); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == 0); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + } + { + Node root; + Node a; + Node b; + Node c; + + root.__left_ = &b; + + b.__parent_ = &root; + b.__left_ = &a; + b.__right_ = &c; + b.__is_black_ = true; + + a.__parent_ = &b; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = false; + + c.__parent_ = &b; + c.__left_ = 0; + c.__right_ = 0; + c.__is_black_ = false; + + std::__tree_remove(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &c); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(a.__parent_ == &c); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + assert(c.__parent_ == &root); + assert(c.__left_ == &a); + assert(c.__right_ == 0); + assert(c.__is_black_ == true); + + std::__tree_remove(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &c); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(c.__parent_ == &root); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == true); + + std::__tree_remove(root.__left_, &c); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == 0); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + } + { + Node root; + Node a; + Node b; + Node c; + + root.__left_ = &b; + + b.__parent_ = &root; + b.__left_ = &a; + b.__right_ = &c; + b.__is_black_ = true; + + a.__parent_ = &b; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = true; + + c.__parent_ = &b; + c.__left_ = 0; + c.__right_ = 0; + c.__is_black_ = true; + + std::__tree_remove(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &c); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(a.__parent_ == &c); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + assert(c.__parent_ == &root); + assert(c.__left_ == &a); + assert(c.__right_ == 0); + assert(c.__is_black_ == true); + + std::__tree_remove(root.__left_, &c); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &a); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(a.__parent_ == &root); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == true); + + std::__tree_remove(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == 0); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + } + { + Node root; + Node a; + Node b; + Node c; + + root.__left_ = &b; + + b.__parent_ = &root; + b.__left_ = &a; + b.__right_ = &c; + b.__is_black_ = true; + + a.__parent_ = &b; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = false; + + c.__parent_ = &b; + c.__left_ = 0; + c.__right_ = 0; + c.__is_black_ = false; + + std::__tree_remove(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &c); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(a.__parent_ == &c); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + assert(c.__parent_ == &root); + assert(c.__left_ == &a); + assert(c.__right_ == 0); + assert(c.__is_black_ == true); + + std::__tree_remove(root.__left_, &c); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &a); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(a.__parent_ == &root); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == true); + + std::__tree_remove(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == 0); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + } + { + Node root; + Node a; + Node b; + Node c; + + root.__left_ = &b; + + b.__parent_ = &root; + b.__left_ = &a; + b.__right_ = &c; + b.__is_black_ = true; + + a.__parent_ = &b; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = true; + + c.__parent_ = &b; + c.__left_ = 0; + c.__right_ = 0; + c.__is_black_ = true; + + std::__tree_remove(root.__left_, &c); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == 0); + assert(b.__is_black_ == true); + + std::__tree_remove(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &a); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(a.__parent_ == &root); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == true); + + std::__tree_remove(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == 0); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + } + { + Node root; + Node a; + Node b; + Node c; + + root.__left_ = &b; + + b.__parent_ = &root; + b.__left_ = &a; + b.__right_ = &c; + b.__is_black_ = true; + + a.__parent_ = &b; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = false; + + c.__parent_ = &b; + c.__left_ = 0; + c.__right_ = 0; + c.__is_black_ = false; + + std::__tree_remove(root.__left_, &c); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == 0); + assert(b.__is_black_ == true); + + std::__tree_remove(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &a); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(a.__parent_ == &root); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == true); + + std::__tree_remove(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == 0); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + } + { + Node root; + Node a; + Node b; + Node c; + + root.__left_ = &b; + + b.__parent_ = &root; + b.__left_ = &a; + b.__right_ = &c; + b.__is_black_ = true; + + a.__parent_ = &b; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = true; + + c.__parent_ = &b; + c.__left_ = 0; + c.__right_ = 0; + c.__is_black_ = true; + + std::__tree_remove(root.__left_, &c); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == 0); + assert(b.__is_black_ == true); + + std::__tree_remove(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == 0); + assert(b.__right_ == 0); + assert(b.__is_black_ == true); + + std::__tree_remove(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == 0); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + } + { + Node root; + Node a; + Node b; + Node c; + + root.__left_ = &b; + + b.__parent_ = &root; + b.__left_ = &a; + b.__right_ = &c; + b.__is_black_ = true; + + a.__parent_ = &b; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = false; + + c.__parent_ = &b; + c.__left_ = 0; + c.__right_ = 0; + c.__is_black_ = false; + + std::__tree_remove(root.__left_, &c); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == 0); + assert(b.__is_black_ == true); + + std::__tree_remove(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == 0); + assert(b.__right_ == 0); + assert(b.__is_black_ == true); + + std::__tree_remove(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == 0); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + } +} + +void +test3() +{ + Node root; + Node a; + Node b; + Node c; + Node d; + Node e; + Node f; + Node g; + Node h; + + root.__left_ = &e; + + e.__parent_ = &root; + e.__left_ = &c; + e.__right_ = &g; + e.__is_black_ = true; + + c.__parent_ = &e; + c.__left_ = &b; + c.__right_ = &d; + c.__is_black_ = false; + + g.__parent_ = &e; + g.__left_ = &f; + g.__right_ = &h; + g.__is_black_ = false; + + b.__parent_ = &c; + b.__left_ = &a; + b.__right_ = 0; + b.__is_black_ = true; + + d.__parent_ = &c; + d.__left_ = 0; + d.__right_ = 0; + d.__is_black_ = true; + + f.__parent_ = &g; + f.__left_ = 0; + f.__right_ = 0; + f.__is_black_ = true; + + h.__parent_ = &g; + h.__left_ = 0; + h.__right_ = 0; + h.__is_black_ = true; + + a.__parent_ = &b; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = false; + + assert(std::__tree_invariant(root.__left_)); + + std::__tree_remove(root.__left_, &h); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &e); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(e.__parent_ == &root); + assert(e.__left_ == &c); + assert(e.__right_ == &g); + assert(e.__is_black_ == true); + + assert(c.__parent_ == &e); + assert(c.__left_ == &b); + assert(c.__right_ == &d); + assert(c.__is_black_ == false); + + assert(g.__parent_ == &e); + assert(g.__left_ == &f); + assert(g.__right_ == 0); + assert(g.__is_black_ == true); + + assert(b.__parent_ == &c); + assert(b.__left_ == &a); + assert(b.__right_ == 0); + assert(b.__is_black_ == true); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + assert(d.__parent_ == &c); + assert(d.__left_ == 0); + assert(d.__right_ == 0); + assert(d.__is_black_ == true); + + assert(f.__parent_ == &g); + assert(f.__left_ == 0); + assert(f.__right_ == 0); + assert(f.__is_black_ == false); + + std::__tree_remove(root.__left_, &g); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &e); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(e.__parent_ == &root); + assert(e.__left_ == &c); + assert(e.__right_ == &f); + assert(e.__is_black_ == true); + + assert(c.__parent_ == &e); + assert(c.__left_ == &b); + assert(c.__right_ == &d); + assert(c.__is_black_ == false); + + assert(b.__parent_ == &c); + assert(b.__left_ == &a); + assert(b.__right_ == 0); + assert(b.__is_black_ == true); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + assert(d.__parent_ == &c); + assert(d.__left_ == 0); + assert(d.__right_ == 0); + assert(d.__is_black_ == true); + + assert(f.__parent_ == &e); + assert(f.__left_ == 0); + assert(f.__right_ == 0); + assert(f.__is_black_ == true); + + std::__tree_remove(root.__left_, &f); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &c); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(c.__parent_ == &root); + assert(c.__left_ == &b); + assert(c.__right_ == &e); + assert(c.__is_black_ == true); + + assert(b.__parent_ == &c); + assert(b.__left_ == &a); + assert(b.__right_ == 0); + assert(b.__is_black_ == true); + + assert(e.__parent_ == &c); + assert(e.__left_ == &d); + assert(e.__right_ == 0); + assert(e.__is_black_ == true); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + assert(d.__parent_ == &e); + assert(d.__left_ == 0); + assert(d.__right_ == 0); + assert(d.__is_black_ == false); + + std::__tree_remove(root.__left_, &e); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &c); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(c.__parent_ == &root); + assert(c.__left_ == &b); + assert(c.__right_ == &d); + assert(c.__is_black_ == true); + + assert(b.__parent_ == &c); + assert(b.__left_ == &a); + assert(b.__right_ == 0); + assert(b.__is_black_ == true); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + assert(d.__parent_ == &c); + assert(d.__left_ == 0); + assert(d.__right_ == 0); + assert(d.__is_black_ == true); + + std::__tree_remove(root.__left_, &d); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == &c); + assert(b.__is_black_ == true); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == true); + + assert(c.__parent_ == &b); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == true); + + std::__tree_remove(root.__left_, &c); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &b); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(b.__parent_ == &root); + assert(b.__left_ == &a); + assert(b.__right_ == 0); + assert(b.__is_black_ == true); + + assert(a.__parent_ == &b); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == false); + + std::__tree_remove(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &a); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(a.__parent_ == &root); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(a.__is_black_ == true); + + std::__tree_remove(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == 0); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); +} + +void +test4() +{ + Node root; + Node a; + Node b; + Node c; + Node d; + Node e; + Node f; + Node g; + Node h; + + root.__left_ = &d; + + d.__parent_ = &root; + d.__left_ = &b; + d.__right_ = &f; + d.__is_black_ = true; + + b.__parent_ = &d; + b.__left_ = &a; + b.__right_ = &c; + b.__is_black_ = false; + + f.__parent_ = &d; + f.__left_ = &e; + f.__right_ = &g; + f.__is_black_ = false; + + a.__parent_ = &b; + a.__left_ = 0; + a.__right_ = 0; + a.__is_black_ = true; + + c.__parent_ = &b; + c.__left_ = 0; + c.__right_ = 0; + c.__is_black_ = true; + + e.__parent_ = &f; + e.__left_ = 0; + e.__right_ = 0; + e.__is_black_ = true; + + g.__parent_ = &f; + g.__left_ = 0; + g.__right_ = &h; + g.__is_black_ = true; + + h.__parent_ = &g; + h.__left_ = 0; + h.__right_ = 0; + h.__is_black_ = false; + + assert(std::__tree_invariant(root.__left_)); + + std::__tree_remove(root.__left_, &a); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &d); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(d.__parent_ == &root); + assert(d.__left_ == &b); + assert(d.__right_ == &f); + assert(d.__is_black_ == true); + + assert(b.__parent_ == &d); + assert(b.__left_ == 0); + assert(b.__right_ == &c); + assert(b.__is_black_ == true); + + assert(f.__parent_ == &d); + assert(f.__left_ == &e); + assert(f.__right_ == &g); + assert(f.__is_black_ == false); + + assert(c.__parent_ == &b); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == false); + + assert(e.__parent_ == &f); + assert(e.__left_ == 0); + assert(e.__right_ == 0); + assert(e.__is_black_ == true); + + assert(g.__parent_ == &f); + assert(g.__left_ == 0); + assert(g.__right_ == &h); + assert(g.__is_black_ == true); + + assert(h.__parent_ == &g); + assert(h.__left_ == 0); + assert(h.__right_ == 0); + assert(h.__is_black_ == false); + + std::__tree_remove(root.__left_, &b); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &d); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(d.__parent_ == &root); + assert(d.__left_ == &c); + assert(d.__right_ == &f); + assert(d.__is_black_ == true); + + assert(c.__parent_ == &d); + assert(c.__left_ == 0); + assert(c.__right_ == 0); + assert(c.__is_black_ == true); + + assert(f.__parent_ == &d); + assert(f.__left_ == &e); + assert(f.__right_ == &g); + assert(f.__is_black_ == false); + + assert(e.__parent_ == &f); + assert(e.__left_ == 0); + assert(e.__right_ == 0); + assert(e.__is_black_ == true); + + assert(g.__parent_ == &f); + assert(g.__left_ == 0); + assert(g.__right_ == &h); + assert(g.__is_black_ == true); + + assert(h.__parent_ == &g); + assert(h.__left_ == 0); + assert(h.__right_ == 0); + assert(h.__is_black_ == false); + + std::__tree_remove(root.__left_, &c); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &f); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(f.__parent_ == &root); + assert(f.__left_ == &d); + assert(f.__right_ == &g); + assert(f.__is_black_ == true); + + assert(d.__parent_ == &f); + assert(d.__left_ == 0); + assert(d.__right_ == &e); + assert(d.__is_black_ == true); + + assert(g.__parent_ == &f); + assert(g.__left_ == 0); + assert(g.__right_ == &h); + assert(g.__is_black_ == true); + + assert(e.__parent_ == &d); + assert(e.__left_ == 0); + assert(e.__right_ == 0); + assert(e.__is_black_ == false); + + assert(h.__parent_ == &g); + assert(h.__left_ == 0); + assert(h.__right_ == 0); + assert(h.__is_black_ == false); + + std::__tree_remove(root.__left_, &d); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &f); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(f.__parent_ == &root); + assert(f.__left_ == &e); + assert(f.__right_ == &g); + assert(f.__is_black_ == true); + + assert(e.__parent_ == &f); + assert(e.__left_ == 0); + assert(e.__right_ == 0); + assert(e.__is_black_ == true); + + assert(g.__parent_ == &f); + assert(g.__left_ == 0); + assert(g.__right_ == &h); + assert(g.__is_black_ == true); + + assert(h.__parent_ == &g); + assert(h.__left_ == 0); + assert(h.__right_ == 0); + assert(h.__is_black_ == false); + + std::__tree_remove(root.__left_, &e); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &g); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(g.__parent_ == &root); + assert(g.__left_ == &f); + assert(g.__right_ == &h); + assert(g.__is_black_ == true); + + assert(f.__parent_ == &g); + assert(f.__left_ == 0); + assert(f.__right_ == 0); + assert(f.__is_black_ == true); + + assert(h.__parent_ == &g); + assert(h.__left_ == 0); + assert(h.__right_ == 0); + assert(h.__is_black_ == true); + + std::__tree_remove(root.__left_, &f); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &g); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(g.__parent_ == &root); + assert(g.__left_ == 0); + assert(g.__right_ == &h); + assert(g.__is_black_ == true); + + assert(h.__parent_ == &g); + assert(h.__left_ == 0); + assert(h.__right_ == 0); + assert(h.__is_black_ == false); + + std::__tree_remove(root.__left_, &g); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == &h); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); + + assert(h.__parent_ == &root); + assert(h.__left_ == 0); + assert(h.__right_ == 0); + assert(h.__is_black_ == true); + + std::__tree_remove(root.__left_, &h); + + assert(std::__tree_invariant(root.__left_)); + + assert(root.__parent_ == 0); + assert(root.__left_ == 0); + assert(root.__right_ == 0); + assert(root.__is_black_ == false); +} + +int main() +{ + test1(); + test2(); + test3(); + test4(); +} diff --git a/libcxx/test/std/containers/associative/tree_right_rotate.pass.cpp b/libcxx/test/std/containers/associative/tree_right_rotate.pass.cpp new file mode 100644 index 00000000000..06ec7b88945 --- /dev/null +++ b/libcxx/test/std/containers/associative/tree_right_rotate.pass.cpp @@ -0,0 +1,98 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Not a portable test + +// Precondition: __x->__left_ != nullptr +// template +// void +// __tree_right_rotate(_NodePtr __x); + +#include <__tree> +#include + +struct Node +{ + Node* __left_; + Node* __right_; + Node* __parent_; + + Node() : __left_(), __right_(), __parent_() {} +}; + +void +test1() +{ + Node root; + Node x; + Node y; + root.__left_ = &x; + x.__left_ = &y; + x.__right_ = 0; + x.__parent_ = &root; + y.__left_ = 0; + y.__right_ = 0; + y.__parent_ = &x; + std::__tree_right_rotate(&x); + assert(root.__parent_ == 0); + assert(root.__left_ == &y); + assert(root.__right_ == 0); + assert(y.__parent_ == &root); + assert(y.__left_ == 0); + assert(y.__right_ == &x); + assert(x.__parent_ == &y); + assert(x.__left_ == 0); + assert(x.__right_ == 0); +} + +void +test2() +{ + Node root; + Node x; + Node y; + Node a; + Node b; + Node c; + root.__left_ = &x; + x.__left_ = &y; + x.__right_ = &c; + x.__parent_ = &root; + y.__left_ = &a; + y.__right_ = &b; + y.__parent_ = &x; + a.__parent_ = &y; + b.__parent_ = &y; + c.__parent_ = &x; + std::__tree_right_rotate(&x); + assert(root.__parent_ == 0); + assert(root.__left_ == &y); + assert(root.__right_ == 0); + assert(y.__parent_ == &root); + assert(y.__left_ == &a); + assert(y.__right_ == &x); + assert(x.__parent_ == &y); + assert(x.__left_ == &b); + assert(x.__right_ == &c); + assert(a.__parent_ == &y); + assert(a.__left_ == 0); + assert(a.__right_ == 0); + assert(b.__parent_ == &x); + assert(b.__left_ == 0); + assert(b.__right_ == 0); + assert(c.__parent_ == &x); + assert(c.__left_ == 0); + assert(c.__right_ == 0); +} + +int main() +{ + test1(); + test2(); +} diff --git a/libcxx/test/std/containers/container.adaptors/nothing_to_do.pass.cpp b/libcxx/test/std/containers/container.adaptors/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_alloc.pass.cpp new file mode 100644 index 00000000000..b102f117d48 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_alloc.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// explicit priority_queue(const Alloc& a); + +#include +#include + +#include "test_allocator.h" + +template +struct test + : public std::priority_queue > > +{ + typedef std::priority_queue > > base; + typedef typename base::container_type container_type; + typedef typename base::value_compare value_compare; + + explicit test(const test_allocator& a) : base(a) {} + test(const value_compare& comp, const test_allocator& a) + : base(comp, c, a) {} + test(const value_compare& comp, const container_type& c, + const test_allocator& a) : base(comp, c, a) {} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test(const value_compare& comp, container_type&& c, + const test_allocator& a) : base(comp, std::move(c), a) {} + test(test&& q, const test_allocator& a) : base(std::move(q), a) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_allocator get_allocator() {return c.get_allocator();} + + using base::c; +}; + +int main() +{ + test q((test_allocator(3))); + assert(q.c.get_allocator() == test_allocator(3)); + assert(q.c.size() == 0); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_alloc.pass.cpp new file mode 100644 index 00000000000..4d99fc14728 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_alloc.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// priority_queue(const Compare& comp, const Alloc& a); + +#include +#include + +#include "test_allocator.h" + +template +struct test + : public std::priority_queue > > +{ + typedef std::priority_queue > > base; + typedef typename base::container_type container_type; + typedef typename base::value_compare value_compare; + + explicit test(const test_allocator& a) : base(a) {} + test(const value_compare& comp, const test_allocator& a) + : base(comp, a) {} + test(const value_compare& comp, const container_type& c, + const test_allocator& a) : base(comp, c, a) {} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test(const value_compare& comp, container_type&& c, + const test_allocator& a) : base(comp, std::move(c), a) {} + test(test&& q, const test_allocator& a) : base(std::move(q), a) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_allocator get_allocator() {return c.get_allocator();} + + using base::c; +}; + +int main() +{ + test q(std::less(), test_allocator(3)); + assert(q.c.get_allocator() == test_allocator(3)); + assert(q.c.size() == 0); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_cont_alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_cont_alloc.pass.cpp new file mode 100644 index 00000000000..66ca614126f --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_cont_alloc.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// priority_queue(const Compare& comp, const container_type& c, +// const Alloc& a); + +#include +#include + +#include "test_allocator.h" + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +template +struct test + : public std::priority_queue > > +{ + typedef std::priority_queue > > base; + typedef typename base::container_type container_type; + typedef typename base::value_compare value_compare; + + explicit test(const test_allocator& a) : base(a) {} + test(const value_compare& comp, const test_allocator& a) + : base(comp, a) {} + test(const value_compare& comp, const container_type& c, + const test_allocator& a) : base(comp, c, a) {} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test(const value_compare& comp, container_type&& c, + const test_allocator& a) : base(comp, std::move(c), a) {} + test(test&& q, const test_allocator& a) : base(std::move(q), a) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_allocator get_allocator() {return c.get_allocator();} + + using base::c; +}; + +int main() +{ + typedef std::vector > C; + C v = make(5); + test q(std::less(), v, test_allocator(3)); + assert(q.c.get_allocator() == test_allocator(3)); + assert(q.size() == 5); + assert(q.top() == 4); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_rcont_alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_rcont_alloc.pass.cpp new file mode 100644 index 00000000000..643b0c625ab --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_comp_rcont_alloc.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// priority_queue(const Compare& comp, container_type&& c, +// const Alloc& a); + +#include +#include + +#include "test_allocator.h" + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +template +struct test + : public std::priority_queue > > +{ + typedef std::priority_queue > > base; + typedef typename base::container_type container_type; + typedef typename base::value_compare value_compare; + + explicit test(const test_allocator& a) : base(a) {} + test(const value_compare& comp, const test_allocator& a) + : base(comp, a) {} + test(const value_compare& comp, const container_type& c, + const test_allocator& a) : base(comp, c, a) {} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test(const value_compare& comp, container_type&& c, + const test_allocator& a) : base(comp, std::move(c), a) {} + test(test&& q, const test_allocator& a) : base(std::move(q), a) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_allocator get_allocator() {return c.get_allocator();} + + using base::c; +}; + +int main() +{ + typedef std::vector > C; + test q(std::less(), make(5), test_allocator(3)); + assert(q.c.get_allocator() == test_allocator(3)); + assert(q.size() == 5); + assert(q.top() == 4); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_copy_alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_copy_alloc.pass.cpp new file mode 100644 index 00000000000..a5a073c079b --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_copy_alloc.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// priority_queue(const priority_queue& q, const Alloc& a); + +#include +#include + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +#include "test_allocator.h" + +template +struct test + : public std::priority_queue > > +{ + typedef std::priority_queue > > base; + typedef typename base::container_type container_type; + typedef typename base::value_compare value_compare; + + explicit test(const test_allocator& a) : base(a) {} + test(const value_compare& comp, const test_allocator& a) + : base(comp, c, a) {} + test(const value_compare& comp, const container_type& c, + const test_allocator& a) : base(comp, c, a) {} + test(const test& q, const test_allocator& a) : base(q, a) {} + test_allocator get_allocator() {return c.get_allocator();} + + using base::c; +}; + +int main() +{ + test qo(std::less(), + make > >(5), + test_allocator(2)); + test q(qo, test_allocator(6)); + assert(q.size() == 5); + assert(q.c.get_allocator() == test_allocator(6)); + assert(q.top() == int(4)); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_move_alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_move_alloc.pass.cpp new file mode 100644 index 00000000000..d4df36cf2af --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons.alloc/ctor_move_alloc.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// priority_queue(priority_queue&& q, const Alloc& a); + +#include +#include + +#include "../../../MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#include "test_allocator.h" + +template +struct test + : public std::priority_queue > > +{ + typedef std::priority_queue > > base; + typedef typename base::container_type container_type; + typedef typename base::value_compare value_compare; + + explicit test(const test_allocator& a) : base(a) {} + test(const value_compare& comp, const test_allocator& a) + : base(comp, c, a) {} + test(const value_compare& comp, const container_type& c, + const test_allocator& a) : base(comp, c, a) {} + test(const value_compare& comp, container_type&& c, + const test_allocator& a) : base(comp, std::move(c), a) {} + test(test&& q, const test_allocator& a) : base(std::move(q), a) {} + test_allocator get_allocator() {return c.get_allocator();} + + using base::c; +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test qo(std::less(), + make > >(5), + test_allocator(2)); + test q(std::move(qo), test_allocator(6)); + assert(q.size() == 5); + assert(q.c.get_allocator() == test_allocator(6)); + assert(q.top() == MoveOnly(4)); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/assign_copy.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/assign_copy.pass.cpp new file mode 100644 index 00000000000..82e44b414f6 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/assign_copy.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue& operator=(const priority_queue&) = default; + +#include +#include +#include + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::vector v = make >(5); + std::priority_queue, std::greater > qo(std::greater(), v); + std::priority_queue, std::greater > q; + q = qo; + assert(q.size() == 5); + assert(q.top() == 0); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/assign_move.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/assign_move.pass.cpp new file mode 100644 index 00000000000..07726f60b84 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/assign_move.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue& operator=(priority_queue&& q); + +#include +#include + +#include "../../../MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::priority_queue qo(std::less(), make >(5)); + std::priority_queue q; + q = std::move(qo); + assert(q.size() == 5); + assert(q.top() == MoveOnly(4)); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_comp.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_comp.pass.cpp new file mode 100644 index 00000000000..f543b6379f1 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_comp.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// explicit priority_queue(const Compare& comp); + +#include +#include + +#include "../../../stack_allocator.h" + +int main() +{ + std::priority_queue > > q((std::less())); + assert(q.size() == 0); + q.push(1); + q.push(2); + assert(q.size() == 2); + assert(q.top() == 2); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_comp_container.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_comp_container.pass.cpp new file mode 100644 index 00000000000..2c73cbc62c6 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_comp_container.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// explicit priority_queue(const Compare& comp, const container_type& c); + +#include +#include +#include + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::vector v = make >(5); + std::priority_queue, std::greater > q(std::greater(), v); + assert(q.size() == 5); + assert(q.top() == 0); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_comp_rcontainer.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_comp_rcontainer.pass.cpp new file mode 100644 index 00000000000..40e36456f1f --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_comp_rcontainer.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// explicit priority_queue(const Compare& comp, container_type&& c); + +#include +#include + +#include "../../../MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::priority_queue q(std::less(), make >(5)); + assert(q.size() == 5); + assert(q.top() == MoveOnly(4)); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_copy.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_copy.pass.cpp new file mode 100644 index 00000000000..f1129bc1bbc --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_copy.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue(const priority_queue&) = default; + +#include +#include +#include + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::vector v = make >(5); + std::priority_queue, std::greater > qo(std::greater(), v); + std::priority_queue, std::greater > q = qo; + assert(q.size() == 5); + assert(q.top() == 0); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_default.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_default.pass.cpp new file mode 100644 index 00000000000..2bffe80ae11 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_default.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue(); + +#include +#include + +#include "../../../stack_allocator.h" + +int main() +{ + std::priority_queue > > q; + assert(q.size() == 0); + q.push(1); + q.push(2); + assert(q.size() == 2); + assert(q.top() == 2); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter.pass.cpp new file mode 100644 index 00000000000..1aaa8a3c659 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// priority_queue(InputIterator first, InputIterator last); + +#include +#include + +int main() +{ + int a[] = {3, 5, 2, 0, 6, 8, 1}; + int* an = a + sizeof(a)/sizeof(a[0]); + std::priority_queue q(a, an); + assert(q.size() == an - a); + assert(q.top() == 8); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp.pass.cpp new file mode 100644 index 00000000000..17a698c15df --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// priority_queue(InputIterator first, InputIterator last, const Compare& comp); + +#include +#include +#include + +int main() +{ + int a[] = {3, 5, 2, 0, 6, 8, 1}; + int* an = a + sizeof(a)/sizeof(a[0]); + std::priority_queue, std::greater > + q(a, an, std::greater()); + assert(q.size() == an - a); + assert(q.top() == 0); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp_cont.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp_cont.pass.cpp new file mode 100644 index 00000000000..b44d7d38c6f --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp_cont.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// priority_queue(InputIterator first, InputIterator last, +// const Compare& comp, const container_type& c); + +#include +#include + +int main() +{ + int a[] = {3, 5, 2, 0, 6, 8, 1}; + const int n = sizeof(a)/sizeof(a[0]); + std::vector v(a, a+n/2); + std::priority_queue q(a+n/2, a+n, std::less(), v); + assert(q.size() == n); + assert(q.top() == 8); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp_rcont.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp_rcont.pass.cpp new file mode 100644 index 00000000000..b81daf98d8e --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_iter_iter_comp_rcont.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// priority_queue(InputIterator first, InputIterator last, +// const Compare& comp, container_type&& c); + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + int a[] = {3, 5, 2, 0, 6, 8, 1}; + const int n = sizeof(a)/sizeof(a[0]); + std::priority_queue q(a+n/2, a+n, + std::less(), + std::vector(a, a+n/2)); + assert(q.size() == n); + assert(q.top() == MoveOnly(8)); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_move.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_move.pass.cpp new file mode 100644 index 00000000000..ad23f262545 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/ctor_move.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue(priority_queue&& q); + +#include +#include + +#include "../../../MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::priority_queue qo(std::less(), make >(5)); + std::priority_queue q = std::move(qo); + assert(q.size() == 5); + assert(q.top() == MoveOnly(4)); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/default_noexcept.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/default_noexcept.pass.cpp new file mode 100644 index 00000000000..48e075698ad --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/default_noexcept.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue() +// noexcept(is_nothrow_default_constructible::value && +// is_nothrow_default_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::priority_queue C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..80ad8bdb28b --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// ~priority_queue() // implied noexcept; + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::priority_queue C; + static_assert(std::is_nothrow_destructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..7fd01d6dcb6 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue& operator=(priority_queue&& c) +// noexcept(is_nothrow_move_assignable::value && +// is_nothrow_move_assignable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::priority_queue C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/move_noexcept.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/move_noexcept.pass.cpp new file mode 100644 index 00000000000..1e7fcd86b46 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.cons/move_noexcept.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue(priority_queue&&) +// noexcept(is_nothrow_move_constructible::value && +// is_nothrow_move_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::priority_queue C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/emplace.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/emplace.pass.cpp new file mode 100644 index 00000000000..4f14e93f5f5 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/emplace.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue(); + +// template void emplace(Args&&... args); + +#include +#include + +#include "../../../Emplaceable.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::priority_queue q; + q.emplace(1, 2.5); + assert(q.top() == Emplaceable(1, 2.5)); + q.emplace(3, 4.5); + assert(q.top() == Emplaceable(3, 4.5)); + q.emplace(2, 3.5); + assert(q.top() == Emplaceable(3, 4.5)); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/empty.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/empty.pass.cpp new file mode 100644 index 00000000000..f0c914a0427 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/empty.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue(); + +// bool empty() const; + +#include +#include + +int main() +{ + std::priority_queue q; + assert(q.empty()); + q.push(1); + assert(!q.empty()); + q.pop(); + assert(q.empty()); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/pop.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/pop.pass.cpp new file mode 100644 index 00000000000..f41b26f68fb --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/pop.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue(); + +// void pop(); + +#include +#include + +int main() +{ + std::priority_queue q; + q.push(1); + assert(q.top() == 1); + q.push(3); + assert(q.top() == 3); + q.push(2); + assert(q.top() == 3); + q.pop(); + assert(q.top() == 2); + q.pop(); + assert(q.top() == 1); + q.pop(); + assert(q.empty()); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/push.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/push.pass.cpp new file mode 100644 index 00000000000..288e858f93f --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/push.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue(); + +// void push(const value_type& v); + +#include +#include + +int main() +{ + std::priority_queue q; + q.push(1); + assert(q.top() == 1); + q.push(3); + assert(q.top() == 3); + q.push(2); + assert(q.top() == 3); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/push_rvalue.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/push_rvalue.pass.cpp new file mode 100644 index 00000000000..2f737cecd6a --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/push_rvalue.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue(); + +// void push(value_type&& v); + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::priority_queue q; + q.push(1); + assert(q.top() == 1); + q.push(3); + assert(q.top() == 3); + q.push(2); + assert(q.top() == 3); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/size.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/size.pass.cpp new file mode 100644 index 00000000000..0ed579e060b --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/size.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue(); + +// size_type size() const; + +#include +#include + +int main() +{ + std::priority_queue q; + assert(q.size() == 0); + q.push(1); + assert(q.size() == 1); + q.pop(); + assert(q.size() == 0); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/swap.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/swap.pass.cpp new file mode 100644 index 00000000000..397d67fab52 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/swap.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue(); + +// void swap(priority_queue& q); + +#include +#include + +int main() +{ + std::priority_queue q1; + std::priority_queue q2; + q1.push(1); + q1.push(3); + q1.push(2); + q1.swap(q2); + assert(q1.empty()); + assert(q2.size() == 3); + assert(q2.top() == 3); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/top.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/top.pass.cpp new file mode 100644 index 00000000000..eddbb926d20 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.members/top.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue(); + +// const_reference top() const; + +#include +#include + +int main() +{ + std::priority_queue q; + q.push(1); + assert(q.top() == 1); + q.push(3); + assert(q.top() == 3); + q.push(2); + assert(q.top() == 3); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.special/swap.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.special/swap.pass.cpp new file mode 100644 index 00000000000..1a828adde35 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.special/swap.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// priority_queue(); + +// template +// void swap(priority_queue& x, +// priority_queue& y); + +#include +#include + +int main() +{ + std::priority_queue q1; + std::priority_queue q2; + q1.push(1); + q1.push(3); + q1.push(2); + swap(q1, q2); + assert(q1.empty()); + assert(q2.size() == 3); + assert(q2.top() == 3); +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.special/swap_noexcept.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.special/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..e40570a120b --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/priqueue.special/swap_noexcept.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(priority_queue& c) +// noexcept(__is_nothrow_swappable::value && +// __is_nothrow_swappable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::priority_queue C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/container.adaptors/priority.queue/types.pass.cpp b/libcxx/test/std/containers/container.adaptors/priority.queue/types.pass.cpp new file mode 100644 index 00000000000..ade20d47d4e --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/priority.queue/types.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , +// class Compare = less> +// class priority_queue +// { +// public: +// typedef Container container_type; +// typedef typename container_type::value_type value_type; +// typedef typename container_type::reference reference; +// typedef typename container_type::const_reference const_reference; +// typedef typename container_type::size_type size_type; +// +// protected: +// container_type c; +// Compare comp; + +#include +#include +#include + +struct test + : private std::priority_queue +{ + test() + { + c.push_back(1); + assert(comp(1, 2)); + } +}; + +struct C +{ + typedef int value_type; + typedef int& reference; + typedef const int& const_reference; + typedef int size_type; +}; + +int main() +{ + static_assert((std::is_same::container_type, std::vector >::value), ""); + static_assert((std::is_same >::container_type, std::deque >::value), ""); + static_assert((std::is_same >::value_type, int>::value), ""); + static_assert((std::is_same::reference, std::vector::reference>::value), ""); + static_assert((std::is_same::const_reference, std::vector::const_reference>::value), ""); + static_assert((std::is_same::size_type, std::vector::size_type>::value), ""); + static_assert((std::uses_allocator, std::allocator >::value), ""); + static_assert((!std::uses_allocator, std::allocator >::value), ""); + test t; +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_alloc.pass.cpp new file mode 100644 index 00000000000..b3ee758182a --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_alloc.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// explicit queue(const Alloc& a); + +#include +#include + +#include "test_allocator.h" + +struct test + : private std::queue > > +{ + typedef std::queue > > base; + + explicit test(const test_allocator& a) : base(a) {} + test(const container_type& c, const test_allocator& a) : base(c, a) {} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test(container_type&& c, const test_allocator& a) : base(std::move(c), a) {} + test(test&& q, const test_allocator& a) : base(std::move(q), a) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_allocator get_allocator() {return c.get_allocator();} +}; + +int main() +{ + test q(test_allocator(3)); + assert(q.get_allocator() == test_allocator(3)); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_container_alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_container_alloc.pass.cpp new file mode 100644 index 00000000000..16ba1747dd8 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_container_alloc.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// queue(const container_type& c, const Alloc& a); + +#include +#include + +#include "test_allocator.h" + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +typedef std::deque > C; + +struct test + : public std::queue +{ + typedef std::queue base; + + explicit test(const test_allocator& a) : base(a) {} + test(const container_type& c, const test_allocator& a) : base(c, a) {} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test(container_type&& c, const test_allocator& a) : base(std::move(c), a) {} + test(test&& q, const test_allocator& a) : base(std::move(q), a) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_allocator get_allocator() {return c.get_allocator();} +}; + +int main() +{ + C d = make(5); + test q(d, test_allocator(4)); + assert(q.get_allocator() == test_allocator(4)); + assert(q.size() == 5); + for (int i = 0; i < d.size(); ++i) + { + assert(q.front() == d[i]); + q.pop(); + } +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_queue_alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_queue_alloc.pass.cpp new file mode 100644 index 00000000000..70eaa18f9e2 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_queue_alloc.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// queue(const queue& q, const Alloc& a); + +#include +#include + +#include "test_allocator.h" + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +typedef std::deque > C; + +template +struct test + : public std::queue +{ + typedef std::queue base; + typedef test_allocator allocator_type; + typedef typename base::container_type container_type; + + explicit test(const allocator_type& a) : base(a) {} + test(const container_type& c, const allocator_type& a) : base(c, a) {} + test(const test& q, const allocator_type& a) : base(q, a) {} + allocator_type get_allocator() {return this->c.get_allocator();} +}; + +int main() +{ + test q(make(5), test_allocator(4)); + test q2(q, test_allocator(5)); + assert(q2.get_allocator() == test_allocator(5)); + assert(q2.size() == 5); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_rcontainer_alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_rcontainer_alloc.pass.cpp new file mode 100644 index 00000000000..b752238056b --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_rcontainer_alloc.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// queue(const container_type& c, const Alloc& a); + +#include +#include + +#include "test_allocator.h" +#include "../../../MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +typedef std::deque > C; + +template +struct test + : public std::queue +{ + typedef std::queue base; + typedef test_allocator allocator_type; + typedef typename base::container_type container_type; + + explicit test(const allocator_type& a) : base(a) {} + test(const container_type& c, const allocator_type& a) : base(c, a) {} + test(container_type&& c, const allocator_type& a) : base(std::move(c), a) {} + test(test&& q, const allocator_type& a) : base(std::move(q), a) {} + allocator_type get_allocator() {return this->c.get_allocator();} +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test q(make(5), test_allocator(4)); + assert(q.get_allocator() == test_allocator(4)); + assert(q.size() == 5); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_rqueue_alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_rqueue_alloc.pass.cpp new file mode 100644 index 00000000000..11b4ecd3b0a --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons.alloc/ctor_rqueue_alloc.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// queue(queue&& q, const Alloc& a); + +#include +#include + +#include "test_allocator.h" +#include "../../../MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +typedef std::deque > C; + +template +struct test + : public std::queue +{ + typedef std::queue base; + typedef test_allocator allocator_type; + typedef typename base::container_type container_type; + + explicit test(const allocator_type& a) : base(a) {} + test(const container_type& c, const allocator_type& a) : base(c, a) {} + test(container_type&& c, const allocator_type& a) : base(std::move(c), a) {} + test(test&& q, const allocator_type& a) : base(std::move(q), a) {} + allocator_type get_allocator() {return this->c.get_allocator();} +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test q(make(5), test_allocator(4)); + test q2(std::move(q), test_allocator(5)); + assert(q2.get_allocator() == test_allocator(5)); + assert(q2.size() == 5); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_container.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_container.pass.cpp new file mode 100644 index 00000000000..c4ab955c311 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_container.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// explicit queue(const container_type& c); + +#include +#include + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::deque d = make >(5); + std::queue q(d); + assert(q.size() == 5); + for (int i = 0; i < d.size(); ++i) + { + assert(q.front() == d[i]); + q.pop(); + } +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_copy.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_copy.pass.cpp new file mode 100644 index 00000000000..998f849797c --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// queue(const queue&) = default; + +#include +#include + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::queue q(make >(5)); + std::queue q2 = q; + assert(q2 == q); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_default.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_default.pass.cpp new file mode 100644 index 00000000000..e6aadd39dd9 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_default.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// queue(); + +#include +#include + +#include "../../../stack_allocator.h" + +int main() +{ + std::queue > > q; + assert(q.size() == 0); + q.push(1); + q.push(2); + assert(q.size() == 2); + assert(q.front() == 1); + assert(q.back() == 2); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_move.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_move.pass.cpp new file mode 100644 index 00000000000..f168209f83d --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_move.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// queue(queue&& q); + +#include +#include + +#include "../../../MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::queue q(make >(5)); + std::queue q2 = std::move(q); + assert(q2.size() == 5); + assert(q.empty()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_rcontainer.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_rcontainer.pass.cpp new file mode 100644 index 00000000000..2f6c3dab1c6 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/ctor_rcontainer.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// explicit queue(container_type&& c); + +#include +#include + +#include "../../../MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::queue q(make >(5)); + assert(q.size() == 5); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.cons/default_noexcept.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/default_noexcept.pass.cpp new file mode 100644 index 00000000000..874577c7632 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/default_noexcept.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// queue() +// noexcept(is_nothrow_default_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::queue C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.cons/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..1af20ecb04b --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// ~queue() // implied noexcept; + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::queue C; + static_assert(std::is_nothrow_destructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.cons/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..1b45bfa93ee --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// queue& operator=(queue&& c) +// noexcept(is_nothrow_move_assignable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::queue C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.cons/move_noexcept.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/move_noexcept.pass.cpp new file mode 100644 index 00000000000..8fba28fc534 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.cons/move_noexcept.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// queue(queue&&) +// noexcept(is_nothrow_move_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::queue C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.defn/assign_copy.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/assign_copy.pass.cpp new file mode 100644 index 00000000000..e9afa0b8c61 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/assign_copy.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// queue& operator=(const queue& q); + +#include +#include + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::queue q(make >(5)); + std::queue q2; + q2 = q; + assert(q2 == q); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.defn/assign_move.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/assign_move.pass.cpp new file mode 100644 index 00000000000..828c0b78dc6 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/assign_move.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// queue& operator=(queue&& q); + +#include +#include + +#include "../../../MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::queue q(make >(5)); + std::queue q2; + q2 = std::move(q); + assert(q2.size() == 5); + assert(q.empty()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.defn/back.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/back.pass.cpp new file mode 100644 index 00000000000..e91edc28308 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/back.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// reference back(); + +#include +#include + +int main() +{ + std::queue q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + int& ir = q.back(); + assert(ir == 3); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.defn/back_const.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/back_const.pass.cpp new file mode 100644 index 00000000000..f2696e903fe --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/back_const.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// const_reference back() const; + +#include +#include + +int main() +{ + std::queue q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + const std::queue& cqr = q; + const int& cir = cqr.back(); + assert(cir == 3); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.defn/emplace.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/emplace.pass.cpp new file mode 100644 index 00000000000..1d9c08b156b --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/emplace.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template void emplace(Args&&... args); + +#include +#include + +#include "../../../Emplaceable.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::queue q; + q.emplace(1, 2.5); + q.emplace(2, 3.5); + q.emplace(3, 4.5); + assert(q.size() == 3); + assert(q.front() == Emplaceable(1, 2.5)); + assert(q.back() == Emplaceable(3, 4.5)); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.defn/empty.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/empty.pass.cpp new file mode 100644 index 00000000000..deac5fa4d0e --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/empty.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// bool empty() const; + +#include +#include + +int main() +{ + std::queue q; + assert(q.empty()); + q.push(1); + assert(!q.empty()); + q.pop(); + assert(q.empty()); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.defn/front.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/front.pass.cpp new file mode 100644 index 00000000000..4fbbb005386 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/front.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// reference front(); + +#include +#include + +int main() +{ + std::queue q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + int& ir = q.front(); + assert(ir == 1); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.defn/front_const.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/front_const.pass.cpp new file mode 100644 index 00000000000..253a27817eb --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/front_const.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// const_reference front() const; + +#include +#include + +int main() +{ + std::queue q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + const std::queue& cqr = q; + const int& cir = cqr.front(); + assert(cir == 1); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.defn/pop.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/pop.pass.cpp new file mode 100644 index 00000000000..3da2d122f34 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/pop.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void pop(); + +#include +#include + +int main() +{ + std::queue q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + assert(q.size() == 3); + assert(q.front() == 1); + assert(q.back() == 3); + q.pop(); + assert(q.size() == 2); + assert(q.front() == 2); + assert(q.back() == 3); + q.pop(); + assert(q.size() == 1); + assert(q.front() == 3); + assert(q.back() == 3); + q.pop(); + assert(q.size() == 0); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.defn/push.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/push.pass.cpp new file mode 100644 index 00000000000..9d462954c29 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/push.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push(const value_type& v); + +#include +#include + +int main() +{ + std::queue q; + q.push(1); + assert(q.size() == 1); + assert(q.front() == 1); + assert(q.back() == 1); + q.push(2); + assert(q.size() == 2); + assert(q.front() == 1); + assert(q.back() == 2); + q.push(3); + assert(q.size() == 3); + assert(q.front() == 1); + assert(q.back() == 3); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.defn/push_rv.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/push_rv.pass.cpp new file mode 100644 index 00000000000..11883d8cf70 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/push_rv.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push(value_type&& v); + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::queue q; + q.push(MoveOnly(1)); + assert(q.size() == 1); + assert(q.front() == MoveOnly(1)); + assert(q.back() == MoveOnly(1)); + q.push(MoveOnly(2)); + assert(q.size() == 2); + assert(q.front() == MoveOnly(1)); + assert(q.back() == MoveOnly(2)); + q.push(MoveOnly(3)); + assert(q.size() == 3); + assert(q.front() == MoveOnly(1)); + assert(q.back() == MoveOnly(3)); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.defn/size.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/size.pass.cpp new file mode 100644 index 00000000000..1c72408f469 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/size.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// size_type size() const; + +#include +#include + +int main() +{ + std::queue q; + assert(q.size() == 0); + q.push(1); + assert(q.size() == 1); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.defn/swap.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/swap.pass.cpp new file mode 100644 index 00000000000..e0744939748 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/swap.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(queue& q); + +#include +#include + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::queue q1 = make >(5); + std::queue q2 = make >(10); + std::queue q1_save = q1; + std::queue q2_save = q2; + q1.swap(q2); + assert(q1 == q2_save); + assert(q2 == q1_save); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.defn/types.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/types.pass.cpp new file mode 100644 index 00000000000..cc918a36170 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.defn/types.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template > +// class queue +// { +// public: +// typedef Container container_type; +// typedef typename container_type::value_type value_type; +// typedef typename container_type::reference reference; +// typedef typename container_type::const_reference const_reference; +// typedef typename container_type::size_type size_type; +// +// protected: +// container_type c; +// ... +// }; + +#include +#include + +struct test + : private std::queue +{ + test() + { + c.push_back(1); + } +}; + +struct C +{ + typedef int value_type; + typedef int& reference; + typedef const int& const_reference; + typedef int size_type; +}; + +int main() +{ + static_assert((std::is_same::container_type, std::deque >::value), ""); + static_assert((std::is_same >::container_type, std::vector >::value), ""); + static_assert((std::is_same >::value_type, int>::value), ""); + static_assert((std::is_same::reference, std::deque::reference>::value), ""); + static_assert((std::is_same::const_reference, std::deque::const_reference>::value), ""); + static_assert((std::is_same::size_type, std::deque::size_type>::value), ""); + static_assert((std::uses_allocator, std::allocator >::value), ""); + static_assert((!std::uses_allocator, std::allocator >::value), ""); + test t; +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.ops/eq.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.ops/eq.pass.cpp new file mode 100644 index 00000000000..a2ad32fec14 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.ops/eq.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// bool operator==(const queue& x,const queue& y); +// +// template +// bool operator!=(const queue& x,const queue& y); + +#include +#include + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::queue q1 = make >(5); + std::queue q2 = make >(10); + std::queue q1_save = q1; + std::queue q2_save = q2; + assert(q1 == q1_save); + assert(q1 != q2); + assert(q2 == q2_save); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.ops/lt.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.ops/lt.pass.cpp new file mode 100644 index 00000000000..af08cbaca48 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.ops/lt.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// bool operator< (const queue& x,const queue& y); +// +// template +// bool operator> (const queue& x,const queue& y); +// +// template +// bool operator>=(const queue& x,const queue& y); +// +// template +// bool operator<=(const queue& x,const queue& y); + +#include +#include + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::queue q1 = make >(5); + std::queue q2 = make >(10); + assert(q1 < q2); + assert(q2 > q1); + assert(q1 <= q2); + assert(q2 >= q1); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.special/swap.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.special/swap.pass.cpp new file mode 100644 index 00000000000..a3f7c43b792 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.special/swap.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// void swap(queue& x, queue& y); + +#include +#include + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::queue q1 = make >(5); + std::queue q2 = make >(10); + std::queue q1_save = q1; + std::queue q2_save = q2; + swap(q1, q2); + assert(q1 == q2_save); + assert(q2 == q1_save); +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/queue.special/swap_noexcept.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/queue.special/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..5c9b7756b8a --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/queue.special/swap_noexcept.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(queue& c) +// noexcept(__is_nothrow_swappable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::queue C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/container.adaptors/queue/version.pass.cpp b/libcxx/test/std/containers/container.adaptors/queue/version.pass.cpp new file mode 100644 index 00000000000..35b94b33c51 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/queue/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +#include + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_alloc.pass.cpp new file mode 100644 index 00000000000..94899d4f1b5 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_alloc.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// explicit stack(const Alloc& a); + +#include +#include + +#include "test_allocator.h" + +struct test + : private std::stack > > +{ + typedef std::stack > > base; + + explicit test(const test_allocator& a) : base(a) {} + test(const container_type& c, const test_allocator& a) : base(c, a) {} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test(container_type&& c, const test_allocator& a) : base(std::move(c), a) {} + test(test&& q, const test_allocator& a) : base(std::move(q), a) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_allocator get_allocator() {return c.get_allocator();} +}; + +int main() +{ + test q(test_allocator(3)); + assert(q.get_allocator() == test_allocator(3)); +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_container_alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_container_alloc.pass.cpp new file mode 100644 index 00000000000..fe8622751c9 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_container_alloc.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// stack(const container_type& c, const Alloc& a); + +#include +#include + +#include "test_allocator.h" + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +typedef std::deque > C; + +struct test + : public std::stack +{ + typedef std::stack base; + + explicit test(const test_allocator& a) : base(a) {} + test(const container_type& c, const test_allocator& a) : base(c, a) {} +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test(container_type&& c, const test_allocator& a) : base(std::move(c), a) {} + test(test&& q, const test_allocator& a) : base(std::move(q), a) {} +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_allocator get_allocator() {return c.get_allocator();} +}; + +int main() +{ + C d = make(5); + test q(d, test_allocator(4)); + assert(q.get_allocator() == test_allocator(4)); + assert(q.size() == 5); + for (int i = 0; i < d.size(); ++i) + { + assert(q.top() == d[d.size() - i - 1]); + q.pop(); + } +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_copy_alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_copy_alloc.pass.cpp new file mode 100644 index 00000000000..33cb4dd52b3 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_copy_alloc.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// stack(const stack& q, const Alloc& a); + +#include +#include + +#include "test_allocator.h" + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(int(i)); + return c; +} + +typedef std::deque > C; + +template +struct test + : public std::stack +{ + typedef std::stack base; + typedef test_allocator allocator_type; + typedef typename base::container_type container_type; + + explicit test(const allocator_type& a) : base(a) {} + test(const container_type& c, const allocator_type& a) : base(c, a) {} + test(const test& q, const allocator_type& a) : base(q, a) {} + allocator_type get_allocator() {return this->c.get_allocator();} +}; + +int main() +{ + test q(make(5), test_allocator(4)); + test q2(q, test_allocator(5)); + assert(q2.get_allocator() == test_allocator(5)); + assert(q2.size() == 5); +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_rcontainer_alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_rcontainer_alloc.pass.cpp new file mode 100644 index 00000000000..16ba9d76cd0 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_rcontainer_alloc.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// stack(const container_type& c, const Alloc& a); + +#include +#include + +#include "test_allocator.h" +#include "../../../MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +typedef std::deque > C; + +template +struct test + : public std::stack +{ + typedef std::stack base; + typedef test_allocator allocator_type; + typedef typename base::container_type container_type; + + explicit test(const allocator_type& a) : base(a) {} + test(const container_type& c, const allocator_type& a) : base(c, a) {} + test(container_type&& c, const allocator_type& a) : base(std::move(c), a) {} + test(test&& q, const allocator_type& a) : base(std::move(q), a) {} + allocator_type get_allocator() {return this->c.get_allocator();} +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test q(make(5), test_allocator(4)); + assert(q.get_allocator() == test_allocator(4)); + assert(q.size() == 5); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_rqueue_alloc.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_rqueue_alloc.pass.cpp new file mode 100644 index 00000000000..19d968a0854 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons.alloc/ctor_rqueue_alloc.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// stack(stack&& q, const Alloc& a); + +#include +#include + +#include "test_allocator.h" +#include "../../../MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +typedef std::deque > C; + +template +struct test + : public std::stack +{ + typedef std::stack base; + typedef test_allocator allocator_type; + typedef typename base::container_type container_type; + + explicit test(const allocator_type& a) : base(a) {} + test(const container_type& c, const allocator_type& a) : base(c, a) {} + test(container_type&& c, const allocator_type& a) : base(std::move(c), a) {} + test(test&& q, const allocator_type& a) : base(std::move(q), a) {} + allocator_type get_allocator() {return this->c.get_allocator();} +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test q(make(5), test_allocator(4)); + test q2(std::move(q), test_allocator(5)); + assert(q2.get_allocator() == test_allocator(5)); + assert(q2.size() == 5); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_container.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_container.pass.cpp new file mode 100644 index 00000000000..9dc05013e3d --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_container.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// explicit stack(const container_type& c); + +#include +#include + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::deque d = make >(5); + std::stack q(d); + assert(q.size() == 5); + for (int i = 0; i < d.size(); ++i) + { + assert(q.top() == d[d.size() - i - 1]); + q.pop(); + } +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_copy.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_copy.pass.cpp new file mode 100644 index 00000000000..8673e06ce93 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_copy.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// stack(const stack&) = default; + +#include +#include + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::stack q(make >(5)); + std::stack q2 = q; + assert(q2 == q); +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_default.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_default.pass.cpp new file mode 100644 index 00000000000..523cd681189 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_default.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// stack(); + +#include +#include +#include + +#include "../../../stack_allocator.h" + +int main() +{ + std::stack > > q; + assert(q.size() == 0); + q.push(1); + q.push(2); + assert(q.size() == 2); + assert(q.top() == 2); +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_move.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_move.pass.cpp new file mode 100644 index 00000000000..173bfc2fe09 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_move.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// stack(stack&& q); + +#include +#include + +#include "../../../MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::stack q(make >(5)); + std::stack q2 = std::move(q); + assert(q2.size() == 5); + assert(q.empty()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_rcontainer.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_rcontainer.pass.cpp new file mode 100644 index 00000000000..a6c424d9abb --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/ctor_rcontainer.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// explicit stack(container_type&& c); + +#include +#include + +#include "../../../MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::stack q(make >(5)); + assert(q.size() == 5); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.cons/default_noexcept.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/default_noexcept.pass.cpp new file mode 100644 index 00000000000..521d9567758 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/default_noexcept.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// stack() +// noexcept(is_nothrow_default_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::stack C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.cons/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..c502012c8eb --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// ~stack() // implied noexcept; + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::stack C; + static_assert(std::is_nothrow_destructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.cons/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..4952803d042 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// stack& operator=(stack&& c) +// noexcept(is_nothrow_move_assignable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::stack C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.cons/move_noexcept.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/move_noexcept.pass.cpp new file mode 100644 index 00000000000..c9826834311 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.cons/move_noexcept.pass.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// stack(stack&&) +// noexcept(is_nothrow_move_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::stack C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.defn/assign_copy.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/assign_copy.pass.cpp new file mode 100644 index 00000000000..38769e3fb02 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/assign_copy.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// stack& operator=(const stack& q); + +#include +#include + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(i); + return c; +} + +int main() +{ + std::stack q(make >(5)); + std::stack q2; + q2 = q; + assert(q2 == q); +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.defn/assign_move.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/assign_move.pass.cpp new file mode 100644 index 00000000000..5455299058a --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/assign_move.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// stack& operator=(stack&& q); + +#include +#include + +#include "../../../MoveOnly.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push_back(MoveOnly(i)); + return c; +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::stack q(make >(5)); + std::stack q2; + q2 = std::move(q); + assert(q2.size() == 5); + assert(q.empty()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.defn/emplace.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/emplace.pass.cpp new file mode 100644 index 00000000000..3573c220ece --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/emplace.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template void emplace(Args&&... args); + +#include +#include + +#include "../../../Emplaceable.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::stack q; + q.emplace(1, 2.5); + q.emplace(2, 3.5); + q.emplace(3, 4.5); + assert(q.size() == 3); + assert(q.top() == Emplaceable(3, 4.5)); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.defn/empty.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/empty.pass.cpp new file mode 100644 index 00000000000..a4f72817413 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/empty.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// bool empty() const; + +#include +#include + +int main() +{ + std::stack q; + assert(q.empty()); + q.push(1); + assert(!q.empty()); + q.pop(); + assert(q.empty()); +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.defn/pop.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/pop.pass.cpp new file mode 100644 index 00000000000..7ec1bf187ce --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/pop.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void pop(); + +#include +#include + +int main() +{ + std::stack q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + assert(q.size() == 3); + assert(q.top() == 3); + q.pop(); + assert(q.size() == 2); + assert(q.top() == 2); + q.pop(); + assert(q.size() == 1); + assert(q.top() == 1); + q.pop(); + assert(q.size() == 0); +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.defn/push.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/push.pass.cpp new file mode 100644 index 00000000000..6d5c90890d2 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/push.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push(const value_type& v); + +#include +#include + +int main() +{ + std::stack q; + q.push(1); + assert(q.size() == 1); + assert(q.top() == 1); + q.push(2); + assert(q.size() == 2); + assert(q.top() == 2); + q.push(3); + assert(q.size() == 3); + assert(q.top() == 3); +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.defn/push_rv.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/push_rv.pass.cpp new file mode 100644 index 00000000000..c769c5d4749 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/push_rv.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push(value_type&& v); + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + std::stack q; + q.push(MoveOnly(1)); + assert(q.size() == 1); + assert(q.top() == MoveOnly(1)); + q.push(MoveOnly(2)); + assert(q.size() == 2); + assert(q.top() == MoveOnly(2)); + q.push(MoveOnly(3)); + assert(q.size() == 3); + assert(q.top() == MoveOnly(3)); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.defn/size.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/size.pass.cpp new file mode 100644 index 00000000000..2d802472933 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/size.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// size_type size() const; + +#include +#include + +int main() +{ + std::stack q; + assert(q.size() == 0); + q.push(1); + assert(q.size() == 1); +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.defn/swap.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/swap.pass.cpp new file mode 100644 index 00000000000..50a29c48aa2 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/swap.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(stack& q); + +#include +#include + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::stack q1 = make >(5); + std::stack q2 = make >(10); + std::stack q1_save = q1; + std::stack q2_save = q2; + q1.swap(q2); + assert(q1 == q2_save); + assert(q2 == q1_save); +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.defn/top.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/top.pass.cpp new file mode 100644 index 00000000000..6bde162e3eb --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/top.pass.cpp @@ -0,0 +1,26 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// reference top(); + +#include +#include + +int main() +{ + std::stack q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + int& ir = q.top(); + assert(ir == 3); +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.defn/top_const.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/top_const.pass.cpp new file mode 100644 index 00000000000..8e43d05fc68 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/top_const.pass.cpp @@ -0,0 +1,27 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// const_reference top() const; + +#include +#include + +int main() +{ + std::stack q; + assert(q.size() == 0); + q.push(1); + q.push(2); + q.push(3); + const std::stack& cqr = q; + const int& cir = cqr.top(); + assert(cir == 3); +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.defn/types.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/types.pass.cpp new file mode 100644 index 00000000000..afc5ebd5375 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.defn/types.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template > +// class stack +// { +// public: +// typedef Container container_type; +// typedef typename container_type::value_type value_type; +// typedef typename container_type::reference reference; +// typedef typename container_type::const_reference const_reference; +// typedef typename container_type::size_type size_type; +// +// protected: +// container_type c; +// ... +// }; + +#include +#include +#include + +struct test + : private std::stack +{ + test() + { + c.push_back(1); + } +}; + +struct C +{ + typedef int value_type; + typedef int& reference; + typedef const int& const_reference; + typedef int size_type; +}; + +int main() +{ + static_assert((std::is_same::container_type, std::deque >::value), ""); + static_assert((std::is_same >::container_type, std::vector >::value), ""); + static_assert((std::is_same >::value_type, int>::value), ""); + static_assert((std::is_same::reference, std::deque::reference>::value), ""); + static_assert((std::is_same::const_reference, std::deque::const_reference>::value), ""); + static_assert((std::is_same::size_type, std::deque::size_type>::value), ""); + static_assert((std::uses_allocator, std::allocator >::value), ""); + static_assert((!std::uses_allocator, std::allocator >::value), ""); + test t; +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.ops/eq.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.ops/eq.pass.cpp new file mode 100644 index 00000000000..9b041f7f8d1 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.ops/eq.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// bool operator==(const stack& x,const stack& y); +// +// template +// bool operator!=(const stack& x,const stack& y); + +#include +#include + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::stack q1 = make >(5); + std::stack q2 = make >(10); + std::stack q1_save = q1; + std::stack q2_save = q2; + assert(q1 == q1_save); + assert(q1 != q2); + assert(q2 == q2_save); +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.ops/lt.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.ops/lt.pass.cpp new file mode 100644 index 00000000000..beb937d4c12 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.ops/lt.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// bool operator< (const stack& x,const stack& y); +// +// template +// bool operator> (const stack& x,const stack& y); +// +// template +// bool operator>=(const stack& x,const stack& y); +// +// template +// bool operator<=(const stack& x,const stack& y); + +#include +#include + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::stack q1 = make >(5); + std::stack q2 = make >(10); + assert(q1 < q2); + assert(q2 > q1); + assert(q1 <= q2); + assert(q2 >= q1); +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.special/swap.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.special/swap.pass.cpp new file mode 100644 index 00000000000..90371146dc0 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.special/swap.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// void swap(stack& x, stack& y); + +#include +#include + +template +C +make(int n) +{ + C c; + for (int i = 0; i < n; ++i) + c.push(i); + return c; +} + +int main() +{ + std::stack q1 = make >(5); + std::stack q2 = make >(10); + std::stack q1_save = q1; + std::stack q2_save = q2; + swap(q1, q2); + assert(q1 == q2_save); + assert(q2 == q1_save); +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/stack.special/swap_noexcept.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/stack.special/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..d0977f4e3e5 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/stack.special/swap_noexcept.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(stack& c) +// noexcept(__is_nothrow_swappable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::stack C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/container.adaptors/stack/version.pass.cpp b/libcxx/test/std/containers/container.adaptors/stack/version.pass.cpp new file mode 100644 index 00000000000..339d0f4dda8 --- /dev/null +++ b/libcxx/test/std/containers/container.adaptors/stack/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +#include + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/std/containers/container.requirements/associative.reqmts/associative.reqmts.except/nothing_to_do.pass.cpp b/libcxx/test/std/containers/container.requirements/associative.reqmts/associative.reqmts.except/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/containers/container.requirements/associative.reqmts/associative.reqmts.except/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/containers/container.requirements/associative.reqmts/nothing_to_do.pass.cpp b/libcxx/test/std/containers/container.requirements/associative.reqmts/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/containers/container.requirements/associative.reqmts/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/containers/container.requirements/container.requirements.dataraces/nothing_to_do.pass.cpp b/libcxx/test/std/containers/container.requirements/container.requirements.dataraces/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/containers/container.requirements/container.requirements.dataraces/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/containers/container.requirements/container.requirements.general/nothing_to_do.pass.cpp b/libcxx/test/std/containers/container.requirements/container.requirements.general/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/containers/container.requirements/container.requirements.general/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/containers/container.requirements/nothing_to_do.pass.cpp b/libcxx/test/std/containers/container.requirements/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/containers/container.requirements/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/containers/container.requirements/sequence.reqmts/nothing_to_do.pass.cpp b/libcxx/test/std/containers/container.requirements/sequence.reqmts/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/containers/container.requirements/sequence.reqmts/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/containers/container.requirements/unord.req/nothing_to_do.pass.cpp b/libcxx/test/std/containers/container.requirements/unord.req/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/containers/container.requirements/unord.req/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/containers/container.requirements/unord.req/unord.req.except/nothing_to_do.pass.cpp b/libcxx/test/std/containers/container.requirements/unord.req/unord.req.except/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/containers/container.requirements/unord.req/unord.req.except/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/containers/containers.general/nothing_to_do.pass.cpp b/libcxx/test/std/containers/containers.general/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/containers/containers.general/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/containers/nothing_to_do.pass.cpp b/libcxx/test/std/containers/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/containers/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/array/array.cons/default.pass.cpp b/libcxx/test/std/containers/sequences/array/array.cons/default.pass.cpp new file mode 100644 index 00000000000..7bc62b759c3 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.cons/default.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// array(); + +#include +#include + +int main() +{ + { + typedef double T; + typedef std::array C; + C c; + assert(c.size() == 3); + } + { + typedef double T; + typedef std::array C; + C c; + assert(c.size() == 0); + } +} diff --git a/libcxx/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..b9775eef067 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.cons/initializer_list.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Construct with initizializer list + +#include +#include + +int main() +{ + { + typedef double T; + typedef std::array C; + C c = {1, 2, 3.5}; + assert(c.size() == 3); + assert(c[0] == 1); + assert(c[1] == 2); + assert(c[2] == 3.5); + } + { + typedef double T; + typedef std::array C; + C c = {}; + assert(c.size() == 0); + } +} diff --git a/libcxx/test/std/containers/sequences/array/array.data/data.pass.cpp b/libcxx/test/std/containers/sequences/array/array.data/data.pass.cpp new file mode 100644 index 00000000000..08e4fd39d37 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.data/data.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// T *data(); + +#include +#include + +int main() +{ + { + typedef double T; + typedef std::array C; + C c = {1, 2, 3.5}; + T* p = c.data(); + assert(p[0] == 1); + assert(p[1] == 2); + assert(p[2] == 3.5); + } + { + typedef double T; + typedef std::array C; + C c = {}; + T* p = c.data(); + (void)p; // to placate scan-build + } +} diff --git a/libcxx/test/std/containers/sequences/array/array.data/data_const.pass.cpp b/libcxx/test/std/containers/sequences/array/array.data/data_const.pass.cpp new file mode 100644 index 00000000000..8eb9762dcb8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.data/data_const.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// const T* data() const; + +#include +#include + +int main() +{ + { + typedef double T; + typedef std::array C; + const C c = {1, 2, 3.5}; + const T* p = c.data(); + assert(p[0] == 1); + assert(p[1] == 2); + assert(p[2] == 3.5); + } + { + typedef double T; + typedef std::array C; + const C c = {}; + const T* p = c.data(); + (void)p; // to placate scan-build + } +} diff --git a/libcxx/test/std/containers/sequences/array/array.fill/fill.pass.cpp b/libcxx/test/std/containers/sequences/array/array.fill/fill.pass.cpp new file mode 100644 index 00000000000..675f4950062 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.fill/fill.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void fill(const T& u); + +#include +#include + +int main() +{ + { + typedef double T; + typedef std::array C; + C c = {1, 2, 3.5}; + c.fill(5.5); + assert(c.size() == 3); + assert(c[0] == 5.5); + assert(c[1] == 5.5); + assert(c[2] == 5.5); + } + { + typedef double T; + typedef std::array C; + C c = {}; + c.fill(5.5); + assert(c.size() == 0); + } +} diff --git a/libcxx/test/std/containers/sequences/array/array.size/size.pass.cpp b/libcxx/test/std/containers/sequences/array/array.size/size.pass.cpp new file mode 100644 index 00000000000..fe5a0d5c8db --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.size/size.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template constexpr size_type array::size(); + +#include +#include + +int main() +{ + { + typedef double T; + typedef std::array C; + C c = {1, 2, 3.5}; + assert(c.size() == 3); + assert(c.max_size() == 3); + assert(!c.empty()); + } + { + typedef double T; + typedef std::array C; + C c = {}; + assert(c.size() == 0); + assert(c.max_size() == 0); + assert(c.empty()); + } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + typedef double T; + typedef std::array C; + constexpr C c = {1, 2, 3.5}; + static_assert(c.size() == 3, ""); + static_assert(c.max_size() == 3, ""); + static_assert(!c.empty(), ""); + } + { + typedef double T; + typedef std::array C; + constexpr C c = {}; + static_assert(c.size() == 0, ""); + static_assert(c.max_size() == 0, ""); + static_assert(c.empty(), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp b/libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp new file mode 100644 index 00000000000..08e437739ee --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.special/swap.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template void swap(array& x, array& y); + +#include +#include + +int main() +{ + { + typedef double T; + typedef std::array C; + C c1 = {1, 2, 3.5}; + C c2 = {4, 5, 6.5}; + swap(c1, c2); + assert(c1.size() == 3); + assert(c1[0] == 4); + assert(c1[1] == 5); + assert(c1[2] == 6.5); + assert(c2.size() == 3); + assert(c2[0] == 1); + assert(c2[1] == 2); + assert(c2[2] == 3.5); + } + { + typedef double T; + typedef std::array C; + C c1 = {}; + C c2 = {}; + swap(c1, c2); + assert(c1.size() == 0); + assert(c2.size() == 0); + } +} diff --git a/libcxx/test/std/containers/sequences/array/array.swap/swap.pass.cpp b/libcxx/test/std/containers/sequences/array/array.swap/swap.pass.cpp new file mode 100644 index 00000000000..c7a4cb8df38 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.swap/swap.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(array& a); + +#include +#include + +int main() +{ + { + typedef double T; + typedef std::array C; + C c1 = {1, 2, 3.5}; + C c2 = {4, 5, 6.5}; + c1.swap(c2); + assert(c1.size() == 3); + assert(c1[0] == 4); + assert(c1[1] == 5); + assert(c1[2] == 6.5); + assert(c2.size() == 3); + assert(c2[0] == 1); + assert(c2[1] == 2); + assert(c2[2] == 3.5); + } + { + typedef double T; + typedef std::array C; + C c1 = {}; + C c2 = {}; + c1.swap(c2); + assert(c1.size() == 0); + assert(c2.size() == 0); + } +} diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/get.fail.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/get.fail.cpp new file mode 100644 index 00000000000..4f4fbcf93af --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.tuple/get.fail.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template T& get(array& a); + +#include +#include + +int main() +{ + { + typedef double T; + typedef std::array C; + C c = {1, 2, 3.5}; + std::get<3>(c) = 5.5; // Can't get element 3! + } +} diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp new file mode 100644 index 00000000000..d9e242cd420 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.tuple/get.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template T& get(array& a); + +#include +#include + +#if __cplusplus > 201103L +struct S { + std::array a; + int k; + constexpr S() : a{1,2,3}, k(std::get<2>(a)) {} + }; + +constexpr std::array getArr () { return { 3, 4 }; } +#endif + +int main() +{ + { + typedef double T; + typedef std::array C; + C c = {1, 2, 3.5}; + std::get<1>(c) = 5.5; + assert(c[0] == 1); + assert(c[1] == 5.5); + assert(c[2] == 3.5); + } +#if _LIBCPP_STD_VER > 11 + { + typedef double T; + typedef std::array C; + constexpr C c = {1, 2, 3.5}; + static_assert(std::get<0>(c) == 1, ""); + static_assert(std::get<1>(c) == 2, ""); + static_assert(std::get<2>(c) == 3.5, ""); + } + { + static_assert(S().k == 3, ""); + static_assert(std::get<1>(getArr()) == 4, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp new file mode 100644 index 00000000000..1cbdfa4ff39 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.tuple/get_const.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template const T& get(const array& a); + +#include +#include + +int main() +{ + { + typedef double T; + typedef std::array C; + const C c = {1, 2, 3.5}; + assert(std::get<0>(c) == 1); + assert(std::get<1>(c) == 2); + assert(std::get<2>(c) == 3.5); + } +#if _LIBCPP_STD_VER > 11 + { + typedef double T; + typedef std::array C; + constexpr const C c = {1, 2, 3.5}; + static_assert(std::get<0>(c) == 1, ""); + static_assert(std::get<1>(c) == 2, ""); + static_assert(std::get<2>(c) == 3.5, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp new file mode 100644 index 00000000000..869c1ec9c2d --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.tuple/get_rv.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template T&& get(array&& a); + +#include +#include +#include + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unique_ptr T; + typedef std::array C; + C c = {std::unique_ptr(new double(3.5))}; + T t = std::get<0>(std::move(c)); + assert(*t == 3.5); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/tuple_element.pass.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/tuple_element.pass.cpp new file mode 100644 index 00000000000..cd1dad60ade --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.tuple/tuple_element.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// tuple_element >::type + +#include +#include + +int main() +{ + { + typedef double T; + typedef std::array C; + static_assert((std::is_same::type, T>::value), ""); + static_assert((std::is_same::type, T>::value), ""); + static_assert((std::is_same::type, T>::value), ""); + } + { + typedef int T; + typedef std::array C; + static_assert((std::is_same::type, T>::value), ""); + static_assert((std::is_same::type, T>::value), ""); + static_assert((std::is_same::type, T>::value), ""); + } +} diff --git a/libcxx/test/std/containers/sequences/array/array.tuple/tuple_size.pass.cpp b/libcxx/test/std/containers/sequences/array/array.tuple/tuple_size.pass.cpp new file mode 100644 index 00000000000..83394b1e0c9 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.tuple/tuple_size.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// tuple_size >::value + +#include + +int main() +{ + { + typedef double T; + typedef std::array C; + static_assert((std::tuple_size::value == 3), ""); + } + { + typedef double T; + typedef std::array C; + static_assert((std::tuple_size::value == 0), ""); + } +} diff --git a/libcxx/test/std/containers/sequences/array/array.zero/tested_elsewhere.pass.cpp b/libcxx/test/std/containers/sequences/array/array.zero/tested_elsewhere.pass.cpp new file mode 100644 index 00000000000..0aa2f50d8b4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/array.zero/tested_elsewhere.pass.cpp @@ -0,0 +1,18 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// support for zero-sized array + +#include + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/array/at.pass.cpp b/libcxx/test/std/containers/sequences/array/at.pass.cpp new file mode 100644 index 00000000000..b5cf8a5aaa8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/at.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// reference operator[] (size_type) +// const_reference operator[] (size_type); // constexpr in C++14 +// reference at (size_type) +// const_reference at (size_type); // constexpr in C++14 + +#include +#include + +int main() +{ + { + typedef double T; + typedef std::array C; + C c = {1, 2, 3.5}; + C::reference r1 = c.at(0); + assert(r1 == 1); + r1 = 5.5; + assert(c.front() == 5.5); + + C::reference r2 = c.at(2); + assert(r2 == 3.5); + r2 = 7.5; + assert(c.back() == 7.5); + + try { (void) c.at(3); } + catch (const std::out_of_range &) {} + } + { + typedef double T; + typedef std::array C; + const C c = {1, 2, 3.5}; + C::const_reference r1 = c.at(0); + assert(r1 == 1); + + C::const_reference r2 = c.at(2); + assert(r2 == 3.5); + + try { (void) c.at(3); } + catch (const std::out_of_range &) {} + } + +#if _LIBCPP_STD_VER > 11 + { + typedef double T; + typedef std::array C; + constexpr C c = {1, 2, 3.5}; + + constexpr T t1 = c.at(0); + static_assert (t1 == 1, ""); + + constexpr T t2 = c.at(2); + static_assert (t2 == 3.5, ""); + } +#endif + +} diff --git a/libcxx/test/std/containers/sequences/array/begin.pass.cpp b/libcxx/test/std/containers/sequences/array/begin.pass.cpp new file mode 100644 index 00000000000..9cba0d6fceb --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/begin.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator begin(); + +#include +#include + +int main() +{ + { + typedef double T; + typedef std::array C; + C c = {1, 2, 3.5}; + C::iterator i; + i = c.begin(); + assert(*i == 1); + assert(&*i == c.data()); + *i = 5.5; + assert(c[0] == 5.5); + } + { + } +} diff --git a/libcxx/test/std/containers/sequences/array/front_back.pass.cpp b/libcxx/test/std/containers/sequences/array/front_back.pass.cpp new file mode 100644 index 00000000000..45a963b9947 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/front_back.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// reference front(); +// reference back(); +// const_reference front(); // constexpr in C++14 +// const_reference back(); // constexpr in C++14 + +#include +#include + +int main() +{ + { + typedef double T; + typedef std::array C; + C c = {1, 2, 3.5}; + + C::reference r1 = c.front(); + assert(r1 == 1); + r1 = 5.5; + assert(c[0] == 5.5); + + C::reference r2 = c.back(); + assert(r2 == 3.5); + r2 = 7.5; + assert(c[2] == 7.5); + } + { + typedef double T; + typedef std::array C; + const C c = {1, 2, 3.5}; + C::const_reference r1 = c.front(); + assert(r1 == 1); + + C::const_reference r2 = c.back(); + assert(r2 == 3.5); + } + +#if _LIBCPP_STD_VER > 11 + { + typedef double T; + typedef std::array C; + constexpr C c = {1, 2, 3.5}; + + constexpr T t1 = c.front(); + static_assert (t1 == 1, ""); + + constexpr T t2 = c.back(); + static_assert (t2 == 3.5, ""); + } +#endif + +} diff --git a/libcxx/test/std/containers/sequences/array/indexing.pass.cpp b/libcxx/test/std/containers/sequences/array/indexing.pass.cpp new file mode 100644 index 00000000000..e4dda0dc5cf --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/indexing.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// reference operator[] (size_type) +// const_reference operator[] (size_type); // constexpr in C++14 +// reference at (size_type) +// const_reference at (size_type); // constexpr in C++14 + +#include +#include + +int main() +{ + { + typedef double T; + typedef std::array C; + C c = {1, 2, 3.5}; + C::reference r1 = c[0]; + assert(r1 == 1); + r1 = 5.5; + assert(c.front() == 5.5); + + C::reference r2 = c[2]; + assert(r2 == 3.5); + r2 = 7.5; + assert(c.back() == 7.5); + } + { + typedef double T; + typedef std::array C; + const C c = {1, 2, 3.5}; + C::const_reference r1 = c[0]; + assert(r1 == 1); + C::const_reference r2 = c[2]; + assert(r2 == 3.5); + } + +#if _LIBCPP_STD_VER > 11 + { + typedef double T; + typedef std::array C; + constexpr C c = {1, 2, 3.5}; + + constexpr T t1 = c[0]; + static_assert (t1 == 1, ""); + + constexpr T t2 = c[2]; + static_assert (t2 == 3.5, ""); + } +#endif + +} diff --git a/libcxx/test/std/containers/sequences/array/iterators.pass.cpp b/libcxx/test/std/containers/sequences/array/iterators.pass.cpp new file mode 100644 index 00000000000..98997d8c26d --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/iterators.pass.cpp @@ -0,0 +1,110 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator, const_iterator + +#include +#include +#include + +int main() +{ + { + typedef std::array C; + C c; + C::iterator i; + i = c.begin(); + C::const_iterator j; + j = c.cbegin(); + assert(i == j); + } + { + typedef std::array C; + C c; + C::iterator i; + i = c.begin(); + C::const_iterator j; + j = c.cbegin(); + assert(i == j); + } + +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + { + typedef std::array C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + assert ( ii1 == cii ); + + assert ( !(ii1 != ii2 )); + assert ( !(ii1 != cii )); + + C c; + assert ( c.begin() == std::begin(c)); + assert ( c.cbegin() == std::cbegin(c)); + assert ( c.rbegin() == std::rbegin(c)); + assert ( c.crbegin() == std::crbegin(c)); + assert ( c.end() == std::end(c)); + assert ( c.cend() == std::cend(c)); + assert ( c.rend() == std::rend(c)); + assert ( c.crend() == std::crend(c)); + + assert ( std::begin(c) != std::end(c)); + assert ( std::rbegin(c) != std::rend(c)); + assert ( std::cbegin(c) != std::cend(c)); + assert ( std::crbegin(c) != std::crend(c)); + } + { + typedef std::array C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + assert (!(ii1 < cii )); + assert (!(cii < ii1 )); + assert ( (ii1 <= cii )); + assert ( (cii <= ii1 )); + assert (!(ii1 > cii )); + assert (!(cii > ii1 )); + assert ( (ii1 >= cii )); + assert ( (cii >= ii1 )); + assert (cii - ii1 == 0); + assert (ii1 - cii == 0); + + C c; + assert ( c.begin() == std::begin(c)); + assert ( c.cbegin() == std::cbegin(c)); + assert ( c.rbegin() == std::rbegin(c)); + assert ( c.crbegin() == std::crbegin(c)); + assert ( c.end() == std::end(c)); + assert ( c.cend() == std::cend(c)); + assert ( c.rend() == std::rend(c)); + assert ( c.crend() == std::crend(c)); + + assert ( std::begin(c) == std::end(c)); + assert ( std::rbegin(c) == std::rend(c)); + assert ( std::cbegin(c) == std::cend(c)); + assert ( std::crbegin(c) == std::crend(c)); + } + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/array/types.pass.cpp b/libcxx/test/std/containers/sequences/array/types.pass.cpp new file mode 100644 index 00000000000..065ade959d0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/types.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// struct array +// { +// // types: +// typedef T& reference; +// typedef const T& const_reference; +// typedef implementation defined iterator; +// typedef implementation defined const_iterator; +// typedef T value_type; +// typedef T* pointer; +// typedef size_t size_type; +// typedef ptrdiff_t difference_type; +// typedef T value_type; +// typedef std::reverse_iterator reverse_iterator; +// typedef std::reverse_iterator const_reverse_iterator; + +#include +#include +#include + +int main() +{ + { + typedef double T; + typedef std::array C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + } + { + typedef int* T; + typedef std::array C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + } +} diff --git a/libcxx/test/std/containers/sequences/array/version.pass.cpp b/libcxx/test/std/containers/sequences/array/version.pass.cpp new file mode 100644 index 00000000000..b89a8dd8cca --- /dev/null +++ b/libcxx/test/std/containers/sequences/array/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +#include + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.capacity/access.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.capacity/access.pass.cpp new file mode 100644 index 00000000000..77aaf3c131e --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.capacity/access.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// reference operator[](size_type __i); +// const_reference operator[](size_type __i) const; +// +// reference at(size_type __i); +// const_reference at(size_type __i) const; +// +// reference front(); +// const_reference front() const; +// +// reference back(); +// const_reference back() const; + +#include +#include + +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +int main() +{ + { + std::deque c = make >(10); + for (unsigned i = 0; i < 10; ++i) + assert(c[i] == i); + for (unsigned i = 0; i < 10; ++i) + assert(c.at(i) == i); + assert(c.front() == 0); + assert(c.back() == 9); + } + { + const std::deque c = make >(10); + for (unsigned i = 0; i < 10; ++i) + assert(c[i] == i); + for (unsigned i = 0; i < 10; ++i) + assert(c.at(i) == i); + assert(c.front() == 0); + assert(c.back() == 9); + } +#if __cplusplus >= 201103L + { + std::deque> c = make> >(10); + for (unsigned i = 0; i < 10; ++i) + assert(c[i] == i); + for (unsigned i = 0; i < 10; ++i) + assert(c.at(i) == i); + assert(c.front() == 0); + assert(c.back() == 9); + } + { + const std::deque> c = make> >(10); + for (unsigned i = 0; i < 10; ++i) + assert(c[i] == i); + for (unsigned i = 0; i < 10; ++i) + assert(c.at(i) == i); + assert(c.front() == 0); + assert(c.back() == 9); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.capacity/resize_size.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.capacity/resize_size.pass.cpp new file mode 100644 index 00000000000..8f732a06c7c --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.capacity/resize_size.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void resize(size_type n); + +#include +#include + +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void +test(C& c1, int size) +{ + typedef typename C::const_iterator CI; + typename C::size_type c1_osize = c1.size(); + c1.resize(size); + assert(c1.size() == size); + assert(distance(c1.begin(), c1.end()) == c1.size()); + CI i = c1.begin(); + for (int j = 0; j < std::min(c1_osize, c1.size()); ++j, ++i) + assert(*i == j); + for (int j = c1_osize; j < c1.size(); ++j, ++i) + assert(*i == 0); +} + +template +void +testN(int start, int N, int M) +{ + typedef typename C::const_iterator CI; + C c1 = make(N, start); + test(c1, M); +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN >(rng[i], rng[j], rng[k]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN>>(rng[i], rng[j], rng[k]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.capacity/resize_size_value.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.capacity/resize_size_value.pass.cpp new file mode 100644 index 00000000000..1d1522cbcb3 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.capacity/resize_size_value.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void resize(size_type n, const value_type& v); + +#include +#include + +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void +test(C& c1, int size, int x) +{ + typedef typename C::const_iterator CI; + typename C::size_type c1_osize = c1.size(); + c1.resize(size, x); + assert(c1.size() == size); + assert(distance(c1.begin(), c1.end()) == c1.size()); + CI i = c1.begin(); + for (int j = 0; j < std::min(c1_osize, c1.size()); ++j, ++i) + assert(*i == j); + for (int j = c1_osize; j < c1.size(); ++j, ++i) + assert(*i == x); +} + +template +void +testN(int start, int N, int M) +{ + typedef typename C::const_iterator CI; + C c1 = make(N, start); + test(c1, M, -10); +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN >(rng[i], rng[j], rng[k]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN>>(rng[i], rng[j], rng[k]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.capacity/shrink_to_fit.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.capacity/shrink_to_fit.pass.cpp new file mode 100644 index 00000000000..0ac1d5a680c --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.capacity/shrink_to_fit.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void shrink_to_fit(); + +#include +#include + +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void +test(C& c1) +{ + C s = c1; + c1.shrink_to_fit(); + assert(c1 == s); +} + +template +void +testN(int start, int N) +{ + typedef typename C::const_iterator CI; + C c1 = make(N, start); + test(c1); +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN> >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/alloc.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/alloc.pass.cpp new file mode 100644 index 00000000000..841bfd9f8a7 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/alloc.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// explicit deque(const allocator_type& a); + +#include +#include + +#include "test_allocator.h" +#include "../../../NotConstructible.h" +#include "min_allocator.h" + +template +void +test(const Allocator& a) +{ + std::deque d(a); + assert(d.size() == 0); + assert(d.get_allocator() == a); +} + +int main() +{ + test(std::allocator()); + test(test_allocator(3)); +#if __cplusplus >= 201103L + test(min_allocator()); + test(min_allocator{}); +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..c760b437244 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void assign(initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::deque d; + d.assign({3, 4, 5, 6}); + assert(d.size() == 4); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#if __cplusplus >= 201103L + { + std::deque> d; + d.assign({3, 4, 5, 6}); + assert(d.size() == 4); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp new file mode 100644 index 00000000000..6594984fc0d --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/assign_iter_iter.pass.cpp @@ -0,0 +1,109 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// void assign(InputIterator f, InputIterator l); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void +test(C& c1, const C& c2) +{ + std::size_t c1_osize = c1.size(); + c1.assign(c2.begin(), c2.end()); + assert(distance(c1.begin(), c1.end()) == c1.size()); + assert(c1 == c2); +} + +template +void +testN(int start, int N, int M) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + C c1 = make(N, start); + C c2 = make(M); + test(c1, c2); +} + +template +void +testI(C& c1, const C& c2) +{ + typedef typename C::const_iterator CI; + typedef input_iterator ICI; + std::size_t c1_osize = c1.size(); + c1.assign(ICI(c2.begin()), ICI(c2.end())); + assert(distance(c1.begin(), c1.end()) == c1.size()); + assert(c1 == c2); +} + +template +void +testNI(int start, int N, int M) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + C c1 = make(N, start); + C c2 = make(M); + testI(c1, c2); +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN >(rng[i], rng[j], rng[k]); + testNI >(1500, 2000, 1000); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN> >(rng[i], rng[j], rng[k]); + testNI> >(1500, 2000, 1000); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp new file mode 100644 index 00000000000..fd6dd6e4ab6 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/assign_size_value.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void assign(size_type n, const value_type& v); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void +test(C& c1, int size, int v) +{ + typedef typename C::const_iterator CI; + std::size_t c1_osize = c1.size(); + c1.assign(size, v); + assert(c1.size() == size); + assert(distance(c1.begin(), c1.end()) == c1.size()); + for (CI i = c1.begin(); i != c1.end(); ++i) + assert(*i == v); +} + +template +void +testN(int start, int N, int M) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + C c1 = make(N, start); + test(c1, M, -10); +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN >(rng[i], rng[j], rng[k]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN> >(rng[i], rng[j], rng[k]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/copy.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/copy.pass.cpp new file mode 100644 index 00000000000..fa0c1203ede --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/copy.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// deque(const deque&); + +#include +#include +#include "test_allocator.h" +#include "min_allocator.h" + +template +void +test(const C& x) +{ + C c(x); + assert(c == x); +} + +int main() +{ + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + test(std::deque(ab, an)); + } + { + std::deque > v(3, 2, test_allocator(5)); + std::deque > v2 = v; + assert(v2 == v); + assert(v2.get_allocator() == v.get_allocator()); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + std::deque > v(3, 2, other_allocator(5)); + std::deque > v2 = v; + assert(v2 == v); + assert(v2.get_allocator() == other_allocator(-2)); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + test(std::deque>(ab, an)); + } + { + std::deque > v(3, 2, min_allocator()); + std::deque > v2 = v; + assert(v2 == v); + assert(v2.get_allocator() == v.get_allocator()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/copy_alloc.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..efea4948eba --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/copy_alloc.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// deque(const deque& c, const allocator_type& a); + +#include +#include + +#include "test_allocator.h" +#include "min_allocator.h" + +template +void +test(const C& x, const typename C::allocator_type& a) +{ + C c(x, a); + assert(c == x); + assert(c.get_allocator() == a); +} + +int main() +{ + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + test(std::deque >(ab, an, test_allocator(3)), + test_allocator(4)); + } + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + test(std::deque >(ab, an, other_allocator(3)), + other_allocator(4)); + } +#if __cplusplus >= 201103L + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + test(std::deque >(ab, an, min_allocator()), + min_allocator()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/default.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/default.pass.cpp new file mode 100644 index 00000000000..b725dade70b --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/default.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// deque() + +#include +#include + +#include "../../../stack_allocator.h" +#include "../../../NotConstructible.h" +#include "min_allocator.h" + +template +void +test() +{ + std::deque d; + assert(d.size() == 0); +#if __cplusplus >= 201103L + std::deque d1 = {}; + assert(d1.size() == 0); +#endif +} + +int main() +{ + test >(); + test >(); +#if __cplusplus >= 201103L + test >(); + test >(); +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/default_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/default_noexcept.pass.cpp new file mode 100644 index 00000000000..3605a1b636f --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/default_noexcept.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// deque() +// noexcept(is_nothrow_default_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::deque C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::deque> C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::deque> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::deque> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..0f459b2c919 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// ~deque() // implied noexcept; + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); + ~some_alloc() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::deque C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::deque> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::deque> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::deque> C; + static_assert(!std::is_nothrow_destructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..a9e0218e2e0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/initializer_list.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// deque(initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::deque d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#if __cplusplus >= 201103L + { + std::deque> d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/initializer_list_alloc.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/initializer_list_alloc.pass.cpp new file mode 100644 index 00000000000..36c5af60ee3 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/initializer_list_alloc.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// deque(initializer_list il, const Allocator& a = allocator_type()); + +#include +#include + +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::deque> d({3, 4, 5, 6}, test_allocator(3)); + assert(d.get_allocator() == test_allocator(3)); + assert(d.size() == 4); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#if __cplusplus >= 201103L + { + std::deque> d({3, 4, 5, 6}, min_allocator()); + assert(d.get_allocator() == min_allocator()); + assert(d.size() == 4); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter.pass.cpp new file mode 100644 index 00000000000..faadf2b1a1d --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template deque(InputIterator f, InputIterator l); + +#include +#include + +#include "../../../stack_allocator.h" +#include "test_iterators.h" +#include "min_allocator.h" + +template +void +test(InputIterator f, InputIterator l) +{ + typedef typename std::iterator_traits::value_type T; + typedef std::allocator Allocator; + typedef std::deque C; + typedef typename C::const_iterator const_iterator; + C d(f, l); + assert(d.size() == std::distance(f, l)); + assert(distance(d.begin(), d.end()) == d.size()); + for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f) + assert(*i == *f); +} + +template +void +test(InputIterator f, InputIterator l) +{ + typedef typename std::iterator_traits::value_type T; + typedef std::deque C; + typedef typename C::const_iterator const_iterator; + C d(f, l); + assert(d.size() == std::distance(f, l)); + assert(distance(d.begin(), d.end()) == d.size()); + for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f) + assert(*i == *f); +} + +int main() +{ + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + test(input_iterator(ab), input_iterator(an)); + test(forward_iterator(ab), forward_iterator(an)); + test(bidirectional_iterator(ab), bidirectional_iterator(an)); + test(random_access_iterator(ab), random_access_iterator(an)); + test >(ab, an); +#if __cplusplus >= 201103L + test >(ab, an); +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp new file mode 100644 index 00000000000..b8c3e889929 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/iter_iter_alloc.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// deque(InputIterator f, InputIterator l, const allocator_type& a); + +#include +#include + +#include "test_iterators.h" +#include "test_allocator.h" +#include "min_allocator.h" + +template +void +test(InputIterator f, InputIterator l, const Allocator& a) +{ + typedef typename std::iterator_traits::value_type T; + typedef std::deque C; + typedef typename C::const_iterator const_iterator; + C d(f, l, a); + assert(d.get_allocator() == a); + assert(d.size() == std::distance(f, l)); + assert(distance(d.begin(), d.end()) == d.size()); + for (const_iterator i = d.begin(), e = d.end(); i != e; ++i, ++f) + assert(*i == *f); +} + +int main() +{ + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + test(input_iterator(ab), input_iterator(an), test_allocator(3)); + test(forward_iterator(ab), forward_iterator(an), test_allocator(4)); + test(bidirectional_iterator(ab), bidirectional_iterator(an), test_allocator(5)); + test(random_access_iterator(ab), random_access_iterator(an), test_allocator(6)); +#if __cplusplus >= 201103L + test(input_iterator(ab), input_iterator(an), min_allocator()); + test(forward_iterator(ab), forward_iterator(an), min_allocator()); + test(bidirectional_iterator(ab), bidirectional_iterator(an), min_allocator()); + test(random_access_iterator(ab), random_access_iterator(an), min_allocator()); +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/move.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/move.pass.cpp new file mode 100644 index 00000000000..a20ad4cecbd --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/move.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// deque(deque&&); + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef test_allocator A; + std::deque c1(A(1)); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque c2(A(2)); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque c3 = std::move(c1); + assert(c2 == c3); + assert(c1.size() == 0); + assert(c3.get_allocator() == c1.get_allocator()); + } + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef other_allocator A; + std::deque c1(A(1)); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque c2(A(2)); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque c3 = std::move(c1); + assert(c2 == c3); + assert(c1.size() == 0); + assert(c3.get_allocator() == c1.get_allocator()); + } +#if __cplusplus >= 201103L + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef min_allocator A; + std::deque c1(A{}); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque c2(A{}); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque c3 = std::move(c1); + assert(c2 == c3); + assert(c1.size() == 0); + assert(c3.get_allocator() == c1.get_allocator()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/move_alloc.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..0ba4a2da330 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/move_alloc.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// deque(deque&& c, const allocator_type& a); + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef test_allocator A; + std::deque c1(A(1)); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque c2(A(1)); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque c3(std::move(c1), A(3)); + assert(c2 == c3); + assert(c3.get_allocator() == A(3)); + assert(c1.size() != 0); + } + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef test_allocator A; + std::deque c1(A(1)); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque c2(A(1)); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque c3(std::move(c1), A(1)); + assert(c2 == c3); + assert(c3.get_allocator() == A(1)); + assert(c1.size() == 0); + } + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef other_allocator A; + std::deque c1(A(1)); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque c2(A(1)); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque c3(std::move(c1), A(3)); + assert(c2 == c3); + assert(c3.get_allocator() == A(3)); + assert(c1.size() != 0); + } +#if __cplusplus >= 201103L + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef min_allocator A; + std::deque c1(A{}); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque c2(A{}); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque c3(std::move(c1), A()); + assert(c2 == c3); + assert(c3.get_allocator() == A()); + assert(c1.size() == 0); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/move_assign.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/move_assign.pass.cpp new file mode 100644 index 00000000000..bb01dc5c54b --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/move_assign.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// deque& operator=(deque&& c); + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef test_allocator A; + std::deque c1(A(5)); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque c2(A(5)); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque c3(A(5)); + c3 = std::move(c1); + assert(c2 == c3); + assert(c1.size() == 0); + assert(c3.get_allocator() == A(5)); + } + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef test_allocator A; + std::deque c1(A(5)); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque c2(A(5)); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque c3(A(6)); + c3 = std::move(c1); + assert(c2 == c3); + assert(c1.size() != 0); + assert(c3.get_allocator() == A(6)); + } + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef other_allocator A; + std::deque c1(A(5)); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque c2(A(5)); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque c3(A(6)); + c3 = std::move(c1); + assert(c2 == c3); + assert(c1.size() == 0); + assert(c3.get_allocator() == A(5)); + } +#if __cplusplus >= 201103L + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + typedef min_allocator A; + std::deque c1(A{}); + for (int* p = ab; p < an; ++p) + c1.push_back(MoveOnly(*p)); + std::deque c2(A{}); + for (int* p = ab; p < an; ++p) + c2.push_back(MoveOnly(*p)); + std::deque c3(A{}); + c3 = std::move(c1); + assert(c2 == c3); + assert(c1.size() == 0); + assert(c3.get_allocator() == A()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..c2bb40a8b6f --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// deque& operator=(deque&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::deque C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::deque> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::deque> C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::deque> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/move_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/move_noexcept.pass.cpp new file mode 100644 index 00000000000..36f780703c0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/move_noexcept.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// deque(deque&&) +// noexcept(is_nothrow_move_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::deque C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::deque> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::deque> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::deque> C; + static_assert(!std::is_nothrow_move_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/op_equal.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/op_equal.pass.cpp new file mode 100644 index 00000000000..3a6ec8370b8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/op_equal.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// deque& operator=(const deque& c); + +#include +#include +#include "test_allocator.h" +#include "min_allocator.h" + +template +void +test(const C& x) +{ + C c; + c = x; + assert(c == x); +} + +int main() +{ + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + test(std::deque(ab, an)); + } + { + std::deque > l(3, 2, test_allocator(5)); + std::deque > l2(l, test_allocator(3)); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == test_allocator(3)); + } + { + std::deque > l(3, 2, other_allocator(5)); + std::deque > l2(l, other_allocator(3)); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == other_allocator(5)); + } +#if __cplusplus >= 201103L + { + int ab[] = {3, 4, 2, 8, 0, 1, 44, 34, 45, 96, 80, 1, 13, 31, 45}; + int* an = ab + sizeof(ab)/sizeof(ab[0]); + test(std::deque>(ab, an)); + } + { + std::deque > l(3, 2, min_allocator()); + std::deque > l2(l, min_allocator()); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == min_allocator()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/op_equal_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/op_equal_initializer_list.pass.cpp new file mode 100644 index 00000000000..6468e4329bd --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/op_equal_initializer_list.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// deque& operator=(initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::deque d; + d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#if __cplusplus >= 201103L + { + std::deque> d; + d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/size.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/size.pass.cpp new file mode 100644 index 00000000000..d2e324b0e3f --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/size.pass.cpp @@ -0,0 +1,113 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// explicit deque(size_type n); + +#include +#include + +#include "../../../stack_allocator.h" +#include "DefaultOnly.h" +#include "min_allocator.h" + +template +void +test2(unsigned n) +{ +#if _LIBCPP_STD_VER > 11 + typedef std::deque C; + typedef typename C::const_iterator const_iterator; + assert(DefaultOnly::count == 0); + { + C d(n, Allocator()); + assert(DefaultOnly::count == n); + assert(d.size() == n); + assert(distance(d.begin(), d.end()) == d.size()); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + for (const_iterator i = d.begin(), e = d.end(); i != e; ++i) + assert(*i == T()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + } + assert(DefaultOnly::count == 0); +#endif +} + +template +void +test1(unsigned n) +{ + typedef std::deque C; + typedef typename C::const_iterator const_iterator; + assert(DefaultOnly::count == 0); + { + C d(n); + assert(DefaultOnly::count == n); + assert(d.size() == n); + assert(distance(d.begin(), d.end()) == d.size()); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + for (const_iterator i = d.begin(), e = d.end(); i != e; ++i) + assert(*i == T()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + } + assert(DefaultOnly::count == 0); +} + +template +void +test3(unsigned n, Allocator const &alloc = Allocator()) +{ +#if _LIBCPP_STD_VER > 11 + typedef std::deque C; + typedef typename C::const_iterator const_iterator; + { + C d(n, alloc); + assert(d.size() == n); + assert(d.get_allocator() == alloc); + } +#endif +} + +template +void +test(unsigned n) +{ + test1 ( n ); + test2 ( n ); +} + +int main() +{ + test >(0); + test >(1); + test >(10); + test >(1023); + test >(1024); + test >(1025); + test >(2047); + test >(2048); + test >(2049); + test >(4095); + test >(4096); + test >(4097); + + test1 >(4095); + +#if __cplusplus >= 201103L + test >(4095); +#endif + +#if _LIBCPP_STD_VER > 11 + test3> (1023); + test3>(1); + test3> (3); +#endif + +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/size_value.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/size_value.pass.cpp new file mode 100644 index 00000000000..859deba1e1a --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/size_value.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// deque(size_type n, const value_type& v); + +#include +#include + +#include "../../../stack_allocator.h" +#include "min_allocator.h" + +template +void +test(unsigned n, const T& x) +{ + typedef std::deque C; + typedef typename C::const_iterator const_iterator; + C d(n, x); + assert(d.size() == n); + assert(distance(d.begin(), d.end()) == d.size()); + for (const_iterator i = d.begin(), e = d.end(); i != e; ++i) + assert(*i == x); +} + +int main() +{ + test >(0, 5); + test >(1, 10); + test >(10, 11); + test >(1023, -11); + test >(1024, 25); + test >(1025, 0); + test >(2047, 110); + test >(2048, -500); + test >(2049, 654); + test >(4095, 78); + test >(4096, 1165); + test >(4097, 157); + test >(4095, 90); +#if __cplusplus >= 201103L + test >(4095, 90); +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.cons/size_value_alloc.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.cons/size_value_alloc.pass.cpp new file mode 100644 index 00000000000..5693be702de --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.cons/size_value_alloc.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// deque(size_type n, const value_type& v, const allocator_type& a); + +#include +#include + +#include "min_allocator.h" + +template +void +test(unsigned n, const T& x, const Allocator& a) +{ + typedef std::deque C; + typedef typename C::const_iterator const_iterator; + C d(n, x, a); + assert(d.get_allocator() == a); + assert(d.size() == n); + assert(distance(d.begin(), d.end()) == d.size()); + for (const_iterator i = d.begin(), e = d.end(); i != e; ++i) + assert(*i == x); +} + +int main() +{ + { + std::allocator a; + test(0, 5, a); + test(1, 10, a); + test(10, 11, a); + test(1023, -11, a); + test(1024, 25, a); + test(1025, 0, a); + test(2047, 110, a); + test(2048, -500, a); + test(2049, 654, a); + test(4095, 78, a); + test(4096, 1165, a); + test(4097, 157, a); + } +#if __cplusplus >= 201103L + { + min_allocator a; + test(0, 5, a); + test(1, 10, a); + test(10, 11, a); + test(1023, -11, a); + test(1024, 25, a); + test(1025, 0, a); + test(2047, 110, a); + test(2048, -500, a); + test(2049, 654, a); + test(4095, 78, a); + test(4096, 1165, a); + test(4097, 157, a); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace.pass.cpp new file mode 100644 index 00000000000..806f7280332 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace.pass.cpp @@ -0,0 +1,112 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template iterator emplace(const_iterator p, Args&&... args); + +#include +#include + +#include "../../../Emplaceable.h" +#include "min_allocator.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(Emplaceable()); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void +test(int P, C& c1) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + std::size_t c1_osize = c1.size(); + CI i = c1.emplace(c1.begin() + P, Emplaceable(1, 2.5)); + assert(i == c1.begin() + P); + assert(c1.size() == c1_osize + 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + assert(*i == Emplaceable(1, 2.5)); +} + +template +void +testN(int start, int N) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + for (int i = 0; i <= 3; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1); + } + } + for (int i = N/2-1; i <= N/2+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1); + } + } + for (int i = N - 3; i <= N; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1); + } + } +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN> >(rng[i], rng[j]); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace_back.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace_back.pass.cpp new file mode 100644 index 00000000000..aa977eb84bf --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace_back.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template void emplace_back(Args&&... args); + +#include +#include + +#include "../../../Emplaceable.h" +#include "min_allocator.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(Emplaceable()); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void +test(C& c1) +{ + typedef typename C::iterator I; + std::size_t c1_osize = c1.size(); + c1.emplace_back(Emplaceable(1, 2.5)); + assert(c1.size() == c1_osize + 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + I i = c1.end(); + assert(*--i == Emplaceable(1, 2.5)); +} + +template +void +testN(int start, int N) +{ + C c1 = make(N, start); + test(c1); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN> >(rng[i], rng[j]); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace_front.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace_front.pass.cpp new file mode 100644 index 00000000000..cf09d6e19b6 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/emplace_front.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template void emplace_front(Args&&... args); + +#include +#include + +#include "../../../Emplaceable.h" +#include "min_allocator.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(Emplaceable()); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void +test(C& c1) +{ + typedef typename C::iterator I; + std::size_t c1_osize = c1.size(); + c1.emplace_front(Emplaceable(1, 2.5)); + assert(c1.size() == c1_osize + 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + I i = c1.begin(); + assert(*i == Emplaceable(1, 2.5)); +} + +template +void +testN(int start, int N) +{ + C c1 = make(N, start); + test(c1); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN> >(rng[i], rng[j]); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/erase_iter.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/erase_iter.pass.cpp new file mode 100644 index 00000000000..bfab2a3a4fc --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/erase_iter.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator erase(const_iterator p) + +#include +#include + +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void +test(int P, C& c1) +{ + typedef typename C::iterator I; + assert(P < c1.size()); + std::size_t c1_osize = c1.size(); + I i = c1.erase(c1.cbegin() + P); + assert(i == c1.begin() + P); + assert(c1.size() == c1_osize - 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + i = c1.begin(); + int j = 0; + for (; j < P; ++j, ++i) + assert(*i == j); + for (++j; j < c1_osize; ++j, ++i) + assert(*i == j); +} + +template +void +testN(int start, int N) +{ + int pstep = std::max(N / std::max(std::min(N, 10), 1), 1); + for (int p = 0; p < N; p += pstep) + { + C c1 = make(N, start); + test(p, c1); + } +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN> >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/erase_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..6e937ac0c4e --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/erase_iter_iter.pass.cpp @@ -0,0 +1,96 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// REQUIRES: long_tests + +// + +// iterator erase(const_iterator f, const_iterator l) + +#include +#include + +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void +test(int P, C& c1, int size) +{ + typedef typename C::iterator I; + assert(P + size <= c1.size()); + std::size_t c1_osize = c1.size(); + I i = c1.erase(c1.cbegin() + P, c1.cbegin() + (P + size)); + assert(i == c1.begin() + P); + assert(c1.size() == c1_osize - size); + assert(distance(c1.begin(), c1.end()) == c1.size()); + i = c1.begin(); + int j = 0; + for (; j < P; ++j, ++i) + assert(*i == j); + for (j += size; j < c1_osize; ++j, ++i) + assert(*i == j); +} + +template +void +testN(int start, int N) +{ + int pstep = std::max(N / std::max(std::min(N, 10), 1), 1); + for (int p = 0; p <= N; p += pstep) + { + int sstep = std::max((N - p) / std::max(std::min(N - p, 10), 1), 1); + for (int s = 0; s <= N - p; s += sstep) + { + C c1 = make(N, start); + test(p, c1, s); + } + } +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN> >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_iter_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_iter_initializer_list.pass.cpp new file mode 100644 index 00000000000..5f7804023c7 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_iter_initializer_list.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator insert(const_iterator p, initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::deque d(10, 1); + std::deque::iterator i = d.insert(d.cbegin() + 2, {3, 4, 5, 6}); + assert(d.size() == 14); + assert(i == d.begin() + 2); + assert(d[0] == 1); + assert(d[1] == 1); + assert(d[2] == 3); + assert(d[3] == 4); + assert(d[4] == 5); + assert(d[5] == 6); + assert(d[6] == 1); + assert(d[7] == 1); + assert(d[8] == 1); + assert(d[9] == 1); + assert(d[10] == 1); + assert(d[11] == 1); + assert(d[12] == 1); + assert(d[13] == 1); + } + { + std::deque> d(10, 1); + std::deque>::iterator i = d.insert(d.cbegin() + 2, {3, 4, 5, 6}); + assert(d.size() == 14); + assert(i == d.begin() + 2); + assert(d[0] == 1); + assert(d[1] == 1); + assert(d[2] == 3); + assert(d[3] == 4); + assert(d[4] == 5); + assert(d[5] == 6); + assert(d[6] == 1); + assert(d[7] == 1); + assert(d[8] == 1); + assert(d[9] == 1); + assert(d[10] == 1); + assert(d[11] == 1); + assert(d[12] == 1); + assert(d[13] == 1); + } +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp new file mode 100644 index 00000000000..2bc37c34ce4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_iter_iter.pass.cpp @@ -0,0 +1,256 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// REQUIRES: long_tests + +// + +// template +// iterator insert (const_iterator p, InputIterator f, InputIterator l); + +#include +#include + +#include "test_iterators.h" +#include "../../../MoveOnly.h" +#include "../../../stack_allocator.h" +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void +test(int P, C& c1, const C& c2) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + typedef bidirectional_iterator BCI; + std::size_t c1_osize = c1.size(); + CI i = c1.insert(c1.begin() + P, BCI(c2.begin()), BCI(c2.end())); + assert(i == c1.begin() + P); + assert(c1.size() == c1_osize + c2.size()); + assert(distance(c1.begin(), c1.end()) == c1.size()); + i = c1.begin(); + for (int j = 0; j < P; ++j, ++i) + assert(*i == j); + for (int j = 0; j < c2.size(); ++j, ++i) + assert(*i == j); + for (int j = P; j < c1_osize; ++j, ++i) + assert(*i == j); +} + +template +void +testN(int start, int N, int M) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + for (int i = 0; i <= 3; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + test(i, c1, c2); + } + } + for (int i = M-1; i <= M+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + test(i, c1, c2); + } + } + for (int i = N/2-1; i <= N/2+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + test(i, c1, c2); + } + } + for (int i = N - M - 1; i <= N - M + 1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + test(i, c1, c2); + } + } + for (int i = N - M - 1; i <= N - M + 1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + test(i, c1, c2); + } + } + for (int i = N - 3; i <= N; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + test(i, c1, c2); + } + } +} + +template +void +testI(int P, C& c1, const C& c2) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + typedef input_iterator ICI; + std::size_t c1_osize = c1.size(); + CI i = c1.insert(c1.begin() + P, ICI(c2.begin()), ICI(c2.end())); + assert(i == c1.begin() + P); + assert(c1.size() == c1_osize + c2.size()); + assert(distance(c1.begin(), c1.end()) == c1.size()); + i = c1.begin(); + for (int j = 0; j < P; ++j, ++i) + assert(*i == j); + for (int j = 0; j < c2.size(); ++j, ++i) + assert(*i == j); + for (int j = P; j < c1_osize; ++j, ++i) + assert(*i == j); +} + +template +void +testNI(int start, int N, int M) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + for (int i = 0; i <= 3; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + testI(i, c1, c2); + } + } + for (int i = M-1; i <= M+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + testI(i, c1, c2); + } + } + for (int i = N/2-1; i <= N/2+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + testI(i, c1, c2); + } + } + for (int i = N - M - 1; i <= N - M + 1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + testI(i, c1, c2); + } + } + for (int i = N - 3; i <= N; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + C c2 = make(M); + testI(i, c1, c2); + } + } +} + +template +void +test_move() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + C c; + typedef typename C::const_iterator CI; + { + MoveOnly mo(0); + typedef MoveOnly* I; + c.insert(c.end(), std::move_iterator(&mo), std::move_iterator(&mo+1)); + } + int j = 0; + for (CI i = c.begin(); i != c.end(); ++i, ++j) + assert(*i == MoveOnly(j)); + { + MoveOnly mo(1); + typedef input_iterator I; + c.insert(c.end(), std::move_iterator(I(&mo)), std::move_iterator(I(&mo+1))); + } + j = 0; + for (CI i = c.begin(); i != c.end(); ++i, ++j) + assert(*i == MoveOnly(j)); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN >(rng[i], rng[j], rng[k]); + testNI >(1500, 2000, 1000); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + test_move > >(); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN> >(rng[i], rng[j], rng[k]); + testNI >(1500, 2000, 1000); + test_move > >(); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp new file mode 100644 index 00000000000..0bde7d9b7e3 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_rvalue.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator insert (const_iterator p, value_type&& v); + +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(MoveOnly(i)); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void +test(int P, C& c1, int x) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + std::size_t c1_osize = c1.size(); + CI i = c1.insert(c1.begin() + P, MoveOnly(x)); + assert(i == c1.begin() + P); + assert(c1.size() == c1_osize + 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + i = c1.begin(); + for (int j = 0; j < P; ++j, ++i) + assert(*i == MoveOnly(j)); + assert(*i == MoveOnly(x)); + ++i; + for (int j = P; j < c1_osize; ++j, ++i) + assert(*i == MoveOnly(j)); +} + +template +void +testN(int start, int N) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + for (int i = 0; i <= 3; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, -10); + } + } + for (int i = N/2-1; i <= N/2+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, -10); + } + } + for (int i = N - 3; i <= N; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, -10); + } + } +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN> >(rng[i], rng[j]); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp new file mode 100644 index 00000000000..3e7767209e5 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_size_value.pass.cpp @@ -0,0 +1,159 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// REQUIRES: long_tests + +// + +// iterator insert (const_iterator p, size_type n, const value_type& v); + +#include +#include + +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void +test(int P, C& c1, int size, int x) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + std::size_t c1_osize = c1.size(); + CI i = c1.insert(c1.begin() + P, size, x); + assert(i == c1.begin() + P); + assert(c1.size() == c1_osize + size); + assert(distance(c1.begin(), c1.end()) == c1.size()); + i = c1.begin(); + for (int j = 0; j < P; ++j, ++i) + assert(*i == j); + for (int j = 0; j < size; ++j, ++i) + assert(*i == x); + for (int j = P; j < c1_osize; ++j, ++i) + assert(*i == j); +} + +template +void +testN(int start, int N, int M) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + for (int i = 0; i <= 3; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, M, -10); + } + } + for (int i = M-1; i <= M+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, M, -10); + } + } + for (int i = N/2-1; i <= N/2+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, M, -10); + } + } + for (int i = N - M - 1; i <= N - M + 1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, M, -10); + } + } + for (int i = N - 3; i <= N; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, M, -10); + } + } +} + +template +void +self_reference_test() +{ + typedef typename C::const_iterator CI; + for (int i = 0; i < 20; ++i) + { + for (int j = 0; j < 20; ++j) + { + C c = make(20); + CI it = c.cbegin() + i; + CI jt = c.cbegin() + j; + c.insert(it, 5, *jt); + assert(c.size() == 25); + assert(distance(c.begin(), c.end()) == c.size()); + it = c.cbegin(); + for (int k = 0; k < i; ++k, ++it) + assert(*it == k); + for (int k = 0; k < 5; ++k, ++it) + assert(*it == j); + for (int k = i; k < 20; ++k, ++it) + assert(*it == k); + } + } +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN >(rng[i], rng[j], rng[k]); + self_reference_test >(); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN> >(rng[i], rng[j], rng[k]); + self_reference_test> >(); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp new file mode 100644 index 00000000000..97827c1183a --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/insert_value.pass.cpp @@ -0,0 +1,139 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator insert (const_iterator p, const value_type& v); + +#include +#include + +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void +test(int P, C& c1, int x) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + std::size_t c1_osize = c1.size(); + CI i = c1.insert(c1.begin() + P, x); + assert(i == c1.begin() + P); + assert(c1.size() == c1_osize + 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + i = c1.begin(); + for (int j = 0; j < P; ++j, ++i) + assert(*i == j); + assert(*i == x); + ++i; + for (int j = P; j < c1_osize; ++j, ++i) + assert(*i == j); +} + +template +void +testN(int start, int N) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + for (int i = 0; i <= 3; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, -10); + } + } + for (int i = N/2-1; i <= N/2+1; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, -10); + } + } + for (int i = N - 3; i <= N; ++i) + { + if (0 <= i && i <= N) + { + C c1 = make(N, start); + test(i, c1, -10); + } + } +} + +template +void +self_reference_test() +{ + typedef typename C::const_iterator CI; + for (int i = 0; i < 20; ++i) + { + for (int j = 0; j < 20; ++j) + { + C c = make(20); + CI it = c.cbegin() + i; + CI jt = c.cbegin() + j; + c.insert(it, *jt); + assert(c.size() == 21); + assert(distance(c.begin(), c.end()) == c.size()); + it = c.cbegin(); + for (int k = 0; k < i; ++k, ++it) + assert(*it == k); + assert(*it == j); + ++it; + for (int k = i; k < 20; ++k, ++it) + assert(*it == k); + } + } +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN >(rng[i], rng[j]); + self_reference_test >(); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN> >(rng[i], rng[j]); + self_reference_test> >(); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/pop_back.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/pop_back.pass.cpp new file mode 100644 index 00000000000..e642f7132f5 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/pop_back.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void pop_back() + +#include +#include + +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void +test(C& c1) +{ + typedef typename C::iterator I; + std::size_t c1_osize = c1.size(); + c1.pop_back(); + assert(c1.size() == c1_osize - 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + I i = c1.begin(); + for (int j = 0; j < c1.size(); ++j, ++i) + assert(*i == j); +} + +template +void +testN(int start, int N) +{ + if (N != 0) + { + C c1 = make(N, start); + test(c1); + } +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN> >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/pop_front.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/pop_front.pass.cpp new file mode 100644 index 00000000000..e27edf51f79 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/pop_front.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void pop_front() + +#include +#include + +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void +test(C& c1) +{ + typedef typename C::iterator I; + std::size_t c1_osize = c1.size(); + c1.pop_front(); + assert(c1.size() == c1_osize - 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + I i = c1.begin(); + for (int j = 1; j < c1.size(); ++j, ++i) + assert(*i == j); +} + +template +void +testN(int start, int N) +{ + if (N != 0) + { + C c1 = make(N, start); + test(c1); + } +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN> >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back.pass.cpp new file mode 100644 index 00000000000..444ab9ba955 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push_back(const value_type& v); +// void pop_back(); +// void pop_front(); + +#include +#include + +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void test(int size) +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int j = 0; j < N; ++j) + { + C c = make(size, rng[j]); + typename C::const_iterator it = c.begin(); + for (int i = 0; i < size; ++i, ++it) + assert(*it == i); + } +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int j = 0; j < N; ++j) + test >(rng[j]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int j = 0; j < N; ++j) + test> >(rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp new file mode 100644 index 00000000000..3e628791a9f --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_exception_safety.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push_back(const value_type& x); + +#include +#include + +// Flag that makes the copy constructor for CMyClass throw an exception +static bool gCopyConstructorShouldThow = false; + + +class CMyClass { + public: CMyClass(int tag); + public: CMyClass(const CMyClass& iOther); + public: ~CMyClass(); + + bool equal(const CMyClass &rhs) const + { return fTag == rhs.fTag && fMagicValue == rhs.fMagicValue; } + private: + int fMagicValue; + int fTag; + + private: static int kStartedConstructionMagicValue; + private: static int kFinishedConstructionMagicValue; +}; + +// Value for fMagicValue when the constructor has started running, but not yet finished +int CMyClass::kStartedConstructionMagicValue = 0; +// Value for fMagicValue when the constructor has finished running +int CMyClass::kFinishedConstructionMagicValue = 12345; + +CMyClass::CMyClass(int tag) : + fMagicValue(kStartedConstructionMagicValue), fTag(tag) +{ + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::CMyClass(const CMyClass& iOther) : + fMagicValue(kStartedConstructionMagicValue), fTag(iOther.fTag) +{ + // If requested, throw an exception _before_ setting fMagicValue to kFinishedConstructionMagicValue + if (gCopyConstructorShouldThow) { + throw std::exception(); + } + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::~CMyClass() { + // Only instances for which the constructor has finished running should be destructed + assert(fMagicValue == kFinishedConstructionMagicValue); +} + +bool operator==(const CMyClass &lhs, const CMyClass &rhs) { return lhs.equal(rhs); } + +int main() +{ + CMyClass instance(42); + std::deque vec; + + vec.push_back(instance); + std::deque vec2(vec); + + gCopyConstructorShouldThow = true; + try { + vec.push_back(instance); + } + catch (...) { + assert(vec==vec2); + } +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_rvalue.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_rvalue.pass.cpp new file mode 100644 index 00000000000..d6c44391477 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_back_rvalue.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push_back(value_type&& v); +// void pop_back(); +// void pop_front(); + +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(MoveOnly(i)); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void test(int size) +{ + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int j = 0; j < N; ++j) + { + C c = make(size, rng[j]); + typename C::const_iterator it = c.begin(); + for (int i = 0; i < size; ++i, ++it) + assert(*it == MoveOnly(i)); + } +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int j = 0; j < N; ++j) + test >(rng[j]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2046, 2047, 2048, 2049, 4094, 4095, 4096}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int j = 0; j < N; ++j) + test> >(rng[j]); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front.pass.cpp new file mode 100644 index 00000000000..700edd3abdb --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push_front(const value_type& v); + +#include +#include + +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void +test(C& c1, int x) +{ + typedef typename C::iterator I; + std::size_t c1_osize = c1.size(); + c1.push_front(x); + assert(c1.size() == c1_osize + 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + I i = c1.begin(); + assert(*i == x); + ++i; + for (int j = 0; j < c1_osize; ++j, ++i) + assert(*i == j); +} + +template +void +testN(int start, int N) +{ + C c1 = make(N, start); + test(c1, -10); +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN> >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp new file mode 100644 index 00000000000..6ae06db0bca --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_exception_safety.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push_front(const value_type& x); + +#include +#include + +// Flag that makes the copy constructor for CMyClass throw an exception +static bool gCopyConstructorShouldThow = false; + + +class CMyClass { + public: CMyClass(int tag); + public: CMyClass(const CMyClass& iOther); + public: ~CMyClass(); + + bool equal(const CMyClass &rhs) const + { return fTag == rhs.fTag && fMagicValue == rhs.fMagicValue; } + private: + int fMagicValue; + int fTag; + + private: static int kStartedConstructionMagicValue; + private: static int kFinishedConstructionMagicValue; +}; + +// Value for fMagicValue when the constructor has started running, but not yet finished +int CMyClass::kStartedConstructionMagicValue = 0; +// Value for fMagicValue when the constructor has finished running +int CMyClass::kFinishedConstructionMagicValue = 12345; + +CMyClass::CMyClass(int tag) : + fMagicValue(kStartedConstructionMagicValue), fTag(tag) +{ + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::CMyClass(const CMyClass& iOther) : + fMagicValue(kStartedConstructionMagicValue), fTag(iOther.fTag) +{ + // If requested, throw an exception _before_ setting fMagicValue to kFinishedConstructionMagicValue + if (gCopyConstructorShouldThow) { + throw std::exception(); + } + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::~CMyClass() { + // Only instances for which the constructor has finished running should be destructed + assert(fMagicValue == kFinishedConstructionMagicValue); +} + +bool operator==(const CMyClass &lhs, const CMyClass &rhs) { return lhs.equal(rhs); } + +int main() +{ + CMyClass instance(42); + std::deque vec; + + vec.push_front(instance); + std::deque vec2(vec); + + gCopyConstructorShouldThow = true; + try { + vec.push_front(instance); + } + catch (...) { + assert(vec==vec2); + } +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_rvalue.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_rvalue.pass.cpp new file mode 100644 index 00000000000..1670a44aa07 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.modifiers/push_front_rvalue.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push_front(value_type&& v); + +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(MoveOnly(i)); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void +test(C& c1, int x) +{ + typedef typename C::iterator I; + std::size_t c1_osize = c1.size(); + c1.push_front(MoveOnly(x)); + assert(c1.size() == c1_osize + 1); + assert(distance(c1.begin(), c1.end()) == c1.size()); + I i = c1.begin(); + assert(*i == MoveOnly(x)); + ++i; + for (int j = 0; j < c1_osize; ++j, ++i) + assert(*i == MoveOnly(j)); +} + +template +void +testN(int start, int N) +{ + C c1 = make(N, start); + test(c1, -10); +} + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN> >(rng[i], rng[j]); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.special/copy.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.special/copy.pass.cpp new file mode 100644 index 00000000000..7dfb4bc5c2d --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.special/copy.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Optimization for deque::iterators + +// template +// OutputIterator +// copy(InputIterator first, InputIterator last, OutputIterator result); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void testN(int start, int N) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + typedef random_access_iterator RAI; + typedef random_access_iterator RACI; + typedef input_iterator ICI; + C c1 = make(N, start); + C c2 = make(N); + assert(std::copy(c1.cbegin(), c1.cend(), c2.begin()) == c2.end()); + assert(c1 == c2); + assert(std::copy(c2.cbegin(), c2.cend(), c1.begin()) == c1.end()); + assert(c1 == c2); + assert(std::copy(c1.cbegin(), c1.cend(), RAI(c2.begin())) == RAI(c2.end())); + assert(c1 == c2); + assert(std::copy(c2.cbegin(), c2.cend(), RAI(c1.begin())) == RAI(c1.end())); + assert(c1 == c2); + assert(std::copy(RACI(c1.cbegin()), RACI(c1.cend()), c2.begin()) == c2.end()); + assert(c1 == c2); + assert(std::copy(ICI(c2.cbegin()), ICI(c2.cend()), c1.begin()) == c1.end()); + assert(c1 == c2); +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN> >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.special/copy_backward.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.special/copy_backward.pass.cpp new file mode 100644 index 00000000000..b484a865c57 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.special/copy_backward.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Optimization for deque::iterators + +// template +// OutputIterator +// copy_backward(InputIterator first, InputIterator last, OutputIterator result); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void testN(int start, int N) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + typedef random_access_iterator RAI; + typedef random_access_iterator RACI; + C c1 = make(N, start); + C c2 = make(N); + assert(std::copy_backward(c1.cbegin(), c1.cend(), c2.end()) == c2.begin()); + assert(c1 == c2); + assert(std::copy_backward(c2.cbegin(), c2.cend(), c1.end()) == c1.begin()); + assert(c1 == c2); + assert(std::copy_backward(c1.cbegin(), c1.cend(), RAI(c2.end())) == RAI(c2.begin())); + assert(c1 == c2); + assert(std::copy_backward(c2.cbegin(), c2.cend(), RAI(c1.end())) == RAI(c1.begin())); + assert(c1 == c2); + assert(std::copy_backward(RACI(c1.cbegin()), RACI(c1.cend()), c2.end()) == c2.begin()); + assert(c1 == c2); + assert(std::copy_backward(RACI(c2.cbegin()), RACI(c2.cend()), c1.end()) == c1.begin()); + assert(c1 == c2); +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN> >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.special/move.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.special/move.pass.cpp new file mode 100644 index 00000000000..b100ba487ea --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.special/move.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Optimization for deque::iterators + +// template +// OutputIterator +// move(InputIterator first, InputIterator last, OutputIterator result); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void testN(int start, int N) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + typedef random_access_iterator RAI; + typedef random_access_iterator RACI; + C c1 = make(N, start); + C c2 = make(N); + assert(std::move(c1.cbegin(), c1.cend(), c2.begin()) == c2.end()); + assert(c1 == c2); + assert(std::move(c2.cbegin(), c2.cend(), c1.begin()) == c1.end()); + assert(c1 == c2); + assert(std::move(c1.cbegin(), c1.cend(), RAI(c2.begin())) == RAI(c2.end())); + assert(c1 == c2); + assert(std::move(c2.cbegin(), c2.cend(), RAI(c1.begin())) == RAI(c1.end())); + assert(c1 == c2); + assert(std::move(RACI(c1.cbegin()), RACI(c1.cend()), c2.begin()) == c2.end()); + assert(c1 == c2); + assert(std::move(RACI(c2.cbegin()), RACI(c2.cend()), c1.begin()) == c1.end()); + assert(c1 == c2); +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN> >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.special/move_backward.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.special/move_backward.pass.cpp new file mode 100644 index 00000000000..072d7a78a30 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.special/move_backward.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Optimization for deque::iterators + +// template +// OutputIterator +// move_backward(InputIterator first, InputIterator last, OutputIterator result); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void testN(int start, int N) +{ + typedef typename C::iterator I; + typedef typename C::const_iterator CI; + typedef random_access_iterator RAI; + typedef random_access_iterator RACI; + C c1 = make(N, start); + C c2 = make(N); + assert(std::move_backward(c1.cbegin(), c1.cend(), c2.end()) == c2.begin()); + assert(c1 == c2); + assert(std::move_backward(c2.cbegin(), c2.cend(), c1.end()) == c1.begin()); + assert(c1 == c2); + assert(std::move_backward(c1.cbegin(), c1.cend(), RAI(c2.end())) == RAI(c2.begin())); + assert(c1 == c2); + assert(std::move_backward(c2.cbegin(), c2.cend(), RAI(c1.end())) == RAI(c1.begin())); + assert(c1 == c2); + assert(std::move_backward(RACI(c1.cbegin()), RACI(c1.cend()), c2.end()) == c2.begin()); + assert(c1 == c2); + assert(std::move_backward(RACI(c2.cbegin()), RACI(c2.cend()), c1.end()) == c1.begin()); + assert(c1 == c2); +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN >(rng[i], rng[j]); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + testN > >(rng[i], rng[j]); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.special/swap.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.special/swap.pass.cpp new file mode 100644 index 00000000000..808144c9ebe --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.special/swap.pass.cpp @@ -0,0 +1,110 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// void swap(deque& x, deque& y); + +#include +#include +#include "test_allocator.h" +#include "min_allocator.h" + +template +C +make(int size, int start = 0 ) +{ + const int b = 4096 / sizeof(int); + int init = 0; + if (start > 0) + { + init = (start+1) / b + ((start+1) % b != 0); + init *= b; + --init; + } + C c(init, 0); + for (int i = 0; i < init-start; ++i) + c.pop_back(); + for (int i = 0; i < size; ++i) + c.push_back(i); + for (int i = 0; i < start; ++i) + c.pop_front(); + return c; +}; + +template +void testN(int start, int N, int M) +{ + C c1 = make(N, start); + C c2 = make(M); + C c1_save = c1; + C c2_save = c2; + swap(c1, c2); + assert(c1 == c2_save); + assert(c2 == c1_save); +} + +int main() +{ + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN >(rng[i], rng[j], rng[k]); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef test_allocator A; + std::deque c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1)); + std::deque c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2)); + swap(c1, c2); + assert((c1 == std::deque(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A(1)); + assert((c2 == std::deque(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A(2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef other_allocator A; + std::deque c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1)); + std::deque c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2)); + swap(c1, c2); + assert((c1 == std::deque(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A(2)); + assert((c2 == std::deque(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A(1)); + } +#if __cplusplus >= 201103L + { + int rng[] = {0, 1, 2, 3, 1023, 1024, 1025, 2047, 2048, 2049}; + const int N = sizeof(rng)/sizeof(rng[0]); + for (int i = 0; i < N; ++i) + for (int j = 0; j < N; ++j) + for (int k = 0; k < N; ++k) + testN> >(rng[i], rng[j], rng[k]); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef min_allocator A; + std::deque c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A()); + std::deque c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A()); + swap(c1, c2); + assert((c1 == std::deque(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A()); + assert((c2 == std::deque(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/deque.special/swap_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/deque/deque.special/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..d55d719c762 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/deque.special/swap_noexcept.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(deque& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + + some_alloc() {} + some_alloc(const some_alloc&); + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::deque C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::deque> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::deque> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::deque> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/iterators.pass.cpp b/libcxx/test/std/containers/sequences/deque/iterators.pass.cpp new file mode 100644 index 00000000000..8ec491fae4d --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/iterators.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Test nested types and default template args: + +// template > +// class deque; + +// iterator, const_iterator + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::deque C; + C c; + C::iterator i; + i = c.begin(); + C::const_iterator j; + j = c.cbegin(); + assert(i == j); + } +#if __cplusplus >= 201103L + { + typedef std::deque> C; + C c; + C::iterator i; + i = c.begin(); + C::const_iterator j; + j = c.cbegin(); + assert(i == j); + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + std::deque::iterator ii1{}, ii2{}; + std::deque::iterator ii4 = ii1; + std::deque::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + assert (!(ii1 < cii )); + assert (!(cii < ii1 )); + assert ( (ii1 <= cii )); + assert ( (cii <= ii1 )); + assert (!(ii1 > cii )); + assert (!(cii > ii1 )); + assert ( (ii1 >= cii )); + assert ( (cii >= ii1 )); + assert (cii - ii1 == 0); + assert (ii1 - cii == 0); + +// std::deque c; +// assert ( ii1 != c.cbegin()); +// assert ( cii != c.begin()); +// assert ( cii != c.cend()); +// assert ( ii1 != c.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/types.pass.cpp b/libcxx/test/std/containers/sequences/deque/types.pass.cpp new file mode 100644 index 00000000000..da9470d8a6c --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/types.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Test nested types and default template args: + +// template > +// class deque +// { +// public: +// typedef T value_type; +// typedef Allocator allocator_type; +// typedef typename allocator_type::reference reference; +// typedef typename allocator_type::const_reference const_reference; +// typedef implementation-defined iterator; +// typedef implementation-defined const_iterator; +// typedef typename allocator_type::size_type size_type; +// typedef typename allocator_type::difference_type difference_type; +// typedef typename allocator_type::pointer pointer; +// typedef typename allocator_type::const_pointer const_pointer; +// typedef std::reverse_iterator reverse_iterator; +// typedef std::reverse_iterator const_reverse_iterator; +// }; + +#include +#include +#include + +#include "test_allocator.h" +#include "../../Copyable.h" +#include "min_allocator.h" + +template +void +test() +{ + typedef std::deque C; + + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same< + typename std::iterator_traits::iterator_category, + std::random_access_iterator_tag>::value), ""); + static_assert((std::is_same< + typename std::iterator_traits::iterator_category, + std::random_access_iterator_tag>::value), ""); + static_assert((std::is_same< + typename C::reverse_iterator, + std::reverse_iterator >::value), ""); + static_assert((std::is_same< + typename C::const_reverse_iterator, + std::reverse_iterator >::value), ""); +} + +int main() +{ + test >(); + test >(); + test >(); + static_assert((std::is_same::allocator_type, + std::allocator >::value), ""); +#if __cplusplus >= 201103L + { + typedef std::deque> C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same>::value), ""); + static_assert((std::is_same>::value), ""); +// min_allocator doesn't have a size_type, so one gets synthesized + static_assert((std::is_same::type>::value), ""); + static_assert((std::is_same::value), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/deque/version.pass.cpp b/libcxx/test/std/containers/sequences/deque/version.pass.cpp new file mode 100644 index 00000000000..22e663d9bc2 --- /dev/null +++ b/libcxx/test/std/containers/sequences/deque/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +#include + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.cons/alloc.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.cons/alloc.pass.cpp new file mode 100644 index 00000000000..d274bc03088 --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.cons/alloc.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.cons + +// template +// dynarray(size_type c, const Alloc& alloc); +// template +// dynarray(size_type c, const T& v, const Alloc& alloc); +// template +// dynarray(const dynarray& d, const Alloc& alloc); +// template +// dynarray(initializer_list, const Alloc& alloc); + +// ~dynarray(); + + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include +#include + +#include +#include +#include +#include "test_allocator.h" + +using std::experimental::dynarray; + +template +void check_allocator ( const dynarray &dyn, const Allocator &alloc ) { + for ( int i = 0; i < dyn.size (); ++i ) + assert ( dyn[i].get_allocator() == alloc ); +} + +template +void test ( const std::initializer_list &vals, const Allocator &alloc ) { + typedef dynarray dynA; + + dynA d1 ( vals, alloc ); + assert ( d1.size () == vals.size() ); + assert ( std::equal ( vals.begin (), vals.end (), d1.begin (), d1.end ())); + check_allocator ( d1, alloc ); + } + + +template +void test ( const T &val, const Allocator &alloc1, const Allocator &alloc2 ) { + typedef dynarray dynA; + + dynA d1 ( 4, alloc1 ); + assert ( d1.size () == 4 ); + assert ( std::all_of ( d1.begin (), d1.end (), []( const T &item ){ return item == T(); } )); + check_allocator ( d1, alloc1 ); + + dynA d2 ( 7, val, alloc1 ); + assert ( d2.size () == 7 ); + assert ( std::all_of ( d2.begin (), d2.end (), [&val]( const T &item ){ return item == val; } )); + check_allocator ( d2, alloc1 ); + + dynA d3 ( d2, alloc2 ); + assert ( d3.size () == 7 ); + assert ( std::all_of ( d3.begin (), d3.end (), [&val]( const T &item ){ return item == val; } )); + check_allocator ( d3, alloc2 ); + } + +int main() +{ +// This test is waiting on the resolution of LWG issue #2235 +// typedef test_allocator Alloc; +// typedef std::basic_string, Alloc> nstr; +// +// test ( nstr("fourteen"), Alloc(3), Alloc(4) ); +// test ( { nstr("1"), nstr("1"), nstr("2"), nstr("3"), nstr("5"), nstr("8")}, Alloc(6)); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.cons/default.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.cons/default.pass.cpp new file mode 100644 index 00000000000..0effac2fc14 --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.cons/default.pass.cpp @@ -0,0 +1,95 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.cons + +// explicit dynarray(size_type c); +// dynarray(size_type c, const T& v); +// dynarray(initializer_list); +// dynarray(const dynarray& d); + +// ~dynarray(); + + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include +#include + +#include +#include +#include + +using std::experimental::dynarray; + +template +void test ( const std::initializer_list &vals ) { + typedef dynarray dynA; + + dynA d1 ( vals ); + assert ( d1.size () == vals.size() ); + assert ( std::equal ( vals.begin (), vals.end (), d1.begin (), d1.end ())); + } + + +template +void test ( const T &val ) { + typedef dynarray dynA; + + dynA d1 ( 4 ); + assert ( d1.size () == 4 ); + assert ( std::all_of ( d1.begin (), d1.end (), []( const T &item ){ return item == T(); } )); + + dynA d2 ( 7, val ); + assert ( d2.size () == 7 ); + assert ( std::all_of ( d2.begin (), d2.end (), [&val]( const T &item ){ return item == val; } )); + + dynA d3 ( d2 ); + assert ( d3.size () == 7 ); + assert ( std::all_of ( d3.begin (), d3.end (), [&val]( const T &item ){ return item == val; } )); + } + +void test_bad_length () { + try { dynarray ( std::numeric_limits::max() / sizeof ( int ) + 1 ); } + catch ( std::bad_array_length & ) { return ; } + assert ( false ); + } + +void test_bad_alloc () { + try { dynarray ( std::numeric_limits::max() / sizeof ( int ) - 1 ); } + catch ( std::bad_alloc & ) { return ; } + assert ( false ); + } + +int main() +{ +// test ( 14 ); // ints don't get default initialized + test ( 0 ); + test ( 14.0 ); + test> ( std::complex ( 14, 0 )); + test ( "fourteen" ); + + test ( { 1, 1, 2, 3, 5, 8 } ); + test ( { 1., 1., 2., 3., 5., 8. } ); + test ( { std::string("1"), std::string("1"), std::string("2"), std::string("3"), + std::string("5"), std::string("8")} ); + +// Make sure we don't pick up the Allocator version here + dynarray d1 ( 20, 3 ); + assert ( d1.size() == 20 ); + assert ( std::all_of ( d1.begin (), d1.end (), []( long item ){ return item == 3L; } )); + + test_bad_length (); + test_bad_alloc (); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.data/default.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.data/default.pass.cpp new file mode 100644 index 00000000000..b669f25948e --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.data/default.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.data + +// T* data() noexcept; +// const T* data() const noexcept; + + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include +#include + +#include +#include +#include + +using std::experimental::dynarray; + +template +void dyn_test_const ( const dynarray &dyn ) { + const T *data = dyn.data (); + assert ( data != NULL ); + assert ( std::equal ( dyn.begin(), dyn.end(), data )); + } + +template +void dyn_test ( dynarray &dyn ) { + T *data = dyn.data (); + assert ( data != NULL ); + assert ( std::equal ( dyn.begin(), dyn.end(), data )); + } + + + +template +void test ( const T &val ) { + typedef dynarray dynA; + + dynA d1 ( 4 ); + dyn_test ( d1 ); + dyn_test_const ( d1 ); + + dynA d2 ( 7, val ); + dyn_test ( d2 ); + dyn_test_const ( d2 ); + } + +int main() +{ + test ( 14 ); + test ( 14.0 ); + test> ( std::complex ( 14, 0 )); + test ( "fourteen" ); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.mutate/default.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.mutate/default.pass.cpp new file mode 100644 index 00000000000..c57887ddaf9 --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.mutate/default.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.data + +// void fill(const T& v); +// const T* data() const noexcept; + + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include +#include + +#include +#include +#include + +using std::experimental::dynarray; + +template +void test ( const T &val ) { + typedef dynarray dynA; + + dynA d1 ( 4 ); + d1.fill ( val ); + assert ( std::all_of ( d1.begin (), d1.end (), + [&val]( const T &item ){ return item == val; } )); + } + +int main() +{ + test ( 14 ); + test ( 14.0 ); + test> ( std::complex ( 14, 0 )); + test ( "fourteen" ); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/at.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/at.pass.cpp new file mode 100644 index 00000000000..4d77cf73275 --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/at.pass.cpp @@ -0,0 +1,94 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.overview + +// const_reference at(size_type n) const; +// reference at(size_type n); + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include +#include + +#include +#include +#include + +using std::experimental::dynarray; + +template +void dyn_at_fail ( dynarray &dyn, size_t sz ) { + try { dyn.at (sz); } + catch (const std::out_of_range &) { return; } + assert ( false ); + } + +template +void dyn_at_fail_const ( const dynarray &dyn, size_t sz ) { + try { dyn.at (sz); } + catch (const std::out_of_range &) { return; } + assert ( false ); + } + + +template +void dyn_test_const ( const dynarray &dyn, const std::initializer_list &vals ) { + const T *data = dyn.data (); + auto it = vals.begin (); + for ( size_t i = 0; i < dyn.size(); ++i, ++it ) { + assert ( data + i == &dyn.at(i)); + assert ( *it == dyn.at(i)); + } + + dyn_at_fail_const ( dyn, dyn.size ()); + dyn_at_fail_const ( dyn, 2*dyn.size ()); + dyn_at_fail_const ( dyn, size_t (-1)); + } + +template +void dyn_test ( dynarray &dyn, const std::initializer_list &vals ) { + T *data = dyn.data (); + auto it = vals.begin (); + for ( size_t i = 0; i < dyn.size(); ++i, ++it ) { + assert ( data + i == &dyn.at(i)); + assert ( *it == dyn.at(i)); + } + + dyn_at_fail ( dyn, dyn.size ()); + dyn_at_fail ( dyn, 2*dyn.size ()); + dyn_at_fail ( dyn, size_t (-1)); + } + + +template +void test ( std::initializer_list vals ) { + typedef dynarray dynA; + + dynA d1 ( vals ); + dyn_test ( d1, vals ); + dyn_test_const ( d1, vals ); + } + +int main() +{ + test ( { 1, 1, 2, 3, 5, 8 } ); + test ( { 1., 1., 2., 3., 5., 8. } ); + test ( { std::string("1"), std::string("1"), std::string("2"), std::string("3"), + std::string("5"), std::string("8")} ); + + test ( {} ); + test> ( {} ); + test ( {} ); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/begin_end.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/begin_end.pass.cpp new file mode 100644 index 00000000000..695e1aa9f14 --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/begin_end.pass.cpp @@ -0,0 +1,108 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.overview + + +// iterator begin() noexcept; +// const_iterator begin() const noexcept; +// const_iterator cbegin() const noexcept; +// iterator end() noexcept; +// const_iterator end() const noexcept; +// const_iterator cend() const noexcept; +// +// reverse_iterator rbegin() noexcept; +// const_reverse_iterator rbegin() const noexcept; +// const_reverse_iterator crbegin() const noexcept; +// reverse_iterator rend() noexcept; +// const_reverse_iterator rend() const noexcept; +// const_reverse_iterator crend() const noexcept; + + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include +#include + +#include +#include +#include + +using std::experimental::dynarray; + +template +void dyn_test_const ( const dynarray &dyn ) { + const T *data = dyn.data (); + assert ( data == &*dyn.begin ()); + assert ( data == &*dyn.cbegin ()); + + assert ( data + dyn.size() - 1 == &*dyn.rbegin ()); + assert ( data + dyn.size() - 1 == &*dyn.crbegin ()); + + assert ( dyn.size () == std::distance ( dyn.begin(), dyn.end())); + assert ( dyn.size () == std::distance ( dyn.cbegin(), dyn.cend())); + assert ( dyn.size () == std::distance ( dyn.rbegin(), dyn.rend())); + assert ( dyn.size () == std::distance ( dyn.crbegin(), dyn.crend())); + + assert ( dyn.begin () == dyn.cbegin ()); + assert ( &*dyn.begin () == &*dyn.cbegin ()); + assert ( dyn.rbegin () == dyn.crbegin ()); + assert ( &*dyn.rbegin () == &*dyn.crbegin ()); + assert ( dyn.end () == dyn.cend ()); + assert ( dyn.rend () == dyn.crend ()); + } + +template +void dyn_test ( dynarray &dyn ) { + T *data = dyn.data (); + assert ( data == &*dyn.begin ()); + assert ( data == &*dyn.cbegin ()); + + assert ( data + dyn.size() - 1 == &*dyn.rbegin ()); + assert ( data + dyn.size() - 1 == &*dyn.crbegin ()); + + assert ( dyn.size () == std::distance ( dyn.begin(), dyn.end())); + assert ( dyn.size () == std::distance ( dyn.cbegin(), dyn.cend())); + assert ( dyn.size () == std::distance ( dyn.rbegin(), dyn.rend())); + assert ( dyn.size () == std::distance ( dyn.crbegin(), dyn.crend())); + + assert ( dyn.begin () == dyn.cbegin ()); + assert ( &*dyn.begin () == &*dyn.cbegin ()); + assert ( dyn.rbegin () == dyn.crbegin ()); + assert ( &*dyn.rbegin () == &*dyn.crbegin ()); + assert ( dyn.end () == dyn.cend ()); + assert ( dyn.rend () == dyn.crend ()); + } + + +template +void test ( const T &val ) { + typedef dynarray dynA; + + dynA d1 ( 4 ); + dyn_test ( d1 ); + dyn_test_const ( d1 ); + + dynA d2 ( 7, val ); + dyn_test ( d2 ); + dyn_test_const ( d2 ); + } + +int main() +{ + test ( 14 ); + test ( 14.0 ); + test> ( std::complex ( 14, 0 )); + test ( "fourteen" ); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/capacity.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/capacity.pass.cpp new file mode 100644 index 00000000000..6d28eef1b05 --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/capacity.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.overview + +// size_type size() const noexcept; +// size_type max_size() const noexcept; +// bool empty() const noexcept; + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include +#include + +#include +#include +#include + +using std::experimental::dynarray; + +template +void dyn_test ( const dynarray &dyn, size_t sz ) { + assert ( dyn.size () == sz ); + assert ( dyn.max_size () == sz ); + assert ( dyn.empty () == ( sz == 0 )); + } + +template +void test ( std::initializer_list vals ) { + typedef dynarray dynA; + + dynA d1 ( vals ); + dyn_test ( d1, vals.size ()); + } + +int main() +{ + test ( { 1, 1, 2, 3, 5, 8 } ); + test ( { 1., 1., 2., 3., 5., 8. } ); + test ( { std::string("1"), std::string("1"), std::string("2"), std::string("3"), + std::string("5"), std::string("8")} ); + + test ( {} ); + test> ( {} ); + test ( {} ); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/front_back.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/front_back.pass.cpp new file mode 100644 index 00000000000..e82aa64b98b --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/front_back.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.overview + +// reference front(); +// const_reference front() const; +// reference back(); +// const_reference back() const; + + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include +#include + +#include +#include +#include + +using std::experimental::dynarray; + +template +void dyn_test_const ( const dynarray &dyn ) { + const T *data = dyn.data (); + assert ( *data == dyn.front ()); + assert ( *(data + dyn.size() - 1 ) == dyn.back ()); + } + +template +void dyn_test ( dynarray &dyn ) { + T *data = dyn.data (); + assert ( *data == dyn.front ()); + assert ( *(data + dyn.size() - 1 ) == dyn.back ()); + } + + +template +void test ( const T &val ) { + typedef dynarray dynA; + + dynA d1 ( 4 ); + dyn_test ( d1 ); + dyn_test_const ( d1 ); + + dynA d2 ( 7, val ); + dyn_test ( d2 ); + dyn_test_const ( d2 ); + } + +int main() +{ + test ( 14 ); + test ( 14.0 ); + test> ( std::complex ( 14, 0 )); + test ( "fourteen" ); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/indexing.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/indexing.pass.cpp new file mode 100644 index 00000000000..7317a2023cb --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.overview/indexing.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.overview + +// const_reference at(size_type n) const; +// reference at(size_type n); + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include +#include + +#include +#include +#include + +using std::experimental::dynarray; + +template +void dyn_test_const ( const dynarray &dyn, const std::initializer_list &vals ) { + const T *data = dyn.data (); + auto it = vals.begin (); + for ( size_t i = 0; i < dyn.size(); ++i, ++it ) { + assert ( data + i == &dyn[i]); + assert ( *it == dyn[i]); + } + } + +template +void dyn_test ( dynarray &dyn, const std::initializer_list &vals ) { + T *data = dyn.data (); + auto it = vals.begin (); + for ( size_t i = 0; i < dyn.size(); ++i, ++it ) { + assert ( data + i == &dyn[i]); + assert ( *it == dyn[i]); + } + } + + +template +void test ( std::initializer_list vals ) { + typedef dynarray dynA; + + dynA d1 ( vals ); + dyn_test ( d1, vals ); + dyn_test_const ( d1, vals ); + } + +int main() +{ + test ( { 1, 1, 2, 3, 5, 8 } ); + test ( { 1., 1., 2., 3., 5., 8. } ); + test ( { std::string("1"), std::string("1"), std::string("2"), std::string("3"), + std::string("5"), std::string("8")} ); + + test ( {} ); + test> ( {} ); + test ( {} ); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.traits/default.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.traits/default.pass.cpp new file mode 100644 index 00000000000..9b8240d4cd8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.traits/default.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.data + +// template +// struct uses_allocator, Alloc> : true_type { }; + + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include +#include "test_allocator.h" + +using std::experimental::dynarray; + +int main() +{ + static_assert ( std::uses_allocator, test_allocator>::value, "" ); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/dynarray.zero/default.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/dynarray.zero/default.pass.cpp new file mode 100644 index 00000000000..93f3b18f192 --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/dynarray.zero/default.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// dynarray.zero + +// dynarray shall provide support for the special case of construction with a size of zero. +// In the case that the size is zero, begin() == end() == unique value. +// The return value of data() is unspecified. +// The effect of calling front() or back() for a zero-sized dynarray is undefined. + + + +#include <__config> + +#if _LIBCPP_STD_VER > 11 + +#include +#include + +#include +#include +#include + +using std::experimental::dynarray; + +template +void test ( ) { + typedef dynarray dynA; + + dynA d1 ( 0 ); + assert ( d1.size() == 0 ); + assert ( d1.begin() == d1.end ()); + } + +int main() +{ + test (); + test (); + test> (); + test (); +} +#else +int main() {} +#endif diff --git a/libcxx/test/std/containers/sequences/dynarray/nothing_to_do.pass.cpp b/libcxx/test/std/containers/sequences/dynarray/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/containers/sequences/dynarray/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.access/front.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.access/front.pass.cpp new file mode 100644 index 00000000000..2ec9b871332 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.access/front.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// reference front(); +// const_reference front() const; + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + assert(c.front() == 0); + c.front() = 10; + assert(c.front() == 10); + assert(*c.begin() == 10); + } + { + typedef int T; + typedef std::forward_list C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const C c(std::begin(t), std::end(t)); + assert(c.front() == 0); + assert(*c.begin() == 0); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + assert(c.front() == 0); + c.front() = 10; + assert(c.front() == 10); + assert(*c.begin() == 10); + } + { + typedef int T; + typedef std::forward_list> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const C c(std::begin(t), std::end(t)); + assert(c.front() == 0); + assert(*c.begin() == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/alloc.fail.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/alloc.fail.cpp new file mode 100644 index 00000000000..cd4d1ede120 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/alloc.fail.cpp @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// explicit forward_list(const allocator_type& a); + +#include +#include + +#include "test_allocator.h" +#include "../../../NotConstructible.h" + +int main() +{ + { + typedef test_allocator A; + typedef A::value_type T; + typedef std::forward_list C; + C c = A(12); + assert(c.get_allocator() == A(12)); + assert(c.empty()); + } +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/alloc.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/alloc.pass.cpp new file mode 100644 index 00000000000..7aba906ec20 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/alloc.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// explicit forward_list(const allocator_type& a); + +#include +#include + +#include "test_allocator.h" +#include "../../../NotConstructible.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_allocator A; + typedef A::value_type T; + typedef std::forward_list C; + C c(A(12)); + assert(c.get_allocator() == A(12)); + assert(c.empty()); + } +#if __cplusplus >= 201103L + { + typedef min_allocator A; + typedef A::value_type T; + typedef std::forward_list C; + C c(A{}); + assert(c.get_allocator() == A()); + assert(c.empty()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_copy.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_copy.pass.cpp new file mode 100644 index 00000000000..0b9263db989 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_copy.pass.cpp @@ -0,0 +1,146 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// forward_list& operator=(const forward_list& x); + +#include +#include +#include + +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef test_allocator A; + typedef std::forward_list C; + const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const T t1[] = {10, 11, 12, 13}; + C c0(std::begin(t0), std::end(t0), A(10)); + C c1(std::begin(t1), std::end(t1), A(10)); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A(10)); + } + { + typedef int T; + typedef test_allocator A; + typedef std::forward_list C; + const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const T t1[] = {10, 11, 12, 13}; + C c0(std::begin(t0), std::end(t0), A(10)); + C c1(std::begin(t1), std::end(t1), A(11)); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A(11)); + } + { + typedef int T; + typedef test_allocator A; + typedef std::forward_list C; + const T t0[] = {10, 11, 12, 13}; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t0), std::end(t0), A(10)); + C c1(std::begin(t1), std::end(t1), A(10)); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A(10)); + } + { + typedef int T; + typedef test_allocator A; + typedef std::forward_list C; + const T t0[] = {10, 11, 12, 13}; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t0), std::end(t0), A(10)); + C c1(std::begin(t1), std::end(t1), A(11)); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A(11)); + } + + { + typedef int T; + typedef other_allocator A; + typedef std::forward_list C; + const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const T t1[] = {10, 11, 12, 13}; + C c0(std::begin(t0), std::end(t0), A(10)); + C c1(std::begin(t1), std::end(t1), A(10)); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A(10)); + } + { + typedef int T; + typedef other_allocator A; + typedef std::forward_list C; + const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const T t1[] = {10, 11, 12, 13}; + C c0(std::begin(t0), std::end(t0), A(10)); + C c1(std::begin(t1), std::end(t1), A(11)); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A(10)); + } + { + typedef int T; + typedef other_allocator A; + typedef std::forward_list C; + const T t0[] = {10, 11, 12, 13}; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t0), std::end(t0), A(10)); + C c1(std::begin(t1), std::end(t1), A(10)); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A(10)); + } + { + typedef int T; + typedef other_allocator A; + typedef std::forward_list C; + const T t0[] = {10, 11, 12, 13}; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t0), std::end(t0), A(10)); + C c1(std::begin(t1), std::end(t1), A(11)); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A(10)); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef min_allocator A; + typedef std::forward_list C; + const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const T t1[] = {10, 11, 12, 13}; + C c0(std::begin(t0), std::end(t0), A()); + C c1(std::begin(t1), std::end(t1), A()); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A()); + } + { + typedef int T; + typedef min_allocator A; + typedef std::forward_list C; + const T t0[] = {10, 11, 12, 13}; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t0), std::end(t0), A()); + C c1(std::begin(t1), std::end(t1), A()); + c1 = c0; + assert(c1 == c0); + assert(c1.get_allocator() == A()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_init.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_init.pass.cpp new file mode 100644 index 00000000000..e0382a10db4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_init.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void assign(initializer_list il); + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {10, 11, 12, 13}; + C c(std::begin(t1), std::end(t1)); + c.assign({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == n); + assert(n == 10); + } + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t1), std::end(t1)); + c.assign({10, 11, 12, 13}); + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == 10+n); + assert(n == 4); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {10, 11, 12, 13}; + C c(std::begin(t1), std::end(t1)); + c.assign({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}); + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == n); + assert(n == 10); + } + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t1), std::end(t1)); + c.assign({10, 11, 12, 13}); + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == 10+n); + assert(n == 4); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_move.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_move.pass.cpp new file mode 100644 index 00000000000..a3d270f01d9 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_move.pass.cpp @@ -0,0 +1,199 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// forward_list& operator=(forward_list&& x); + +#include +#include +#include + +#include "test_allocator.h" +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef MoveOnly T; + typedef test_allocator A; + typedef std::forward_list C; + T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + T t1[] = {10, 11, 12, 13}; + typedef std::move_iterator I; + C c0(I(std::begin(t0)), I(std::end(t0)), A(10)); + C c1(I(std::begin(t1)), I(std::end(t1)), A(10)); + c1 = std::move(c0); + int n = 0; + for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n) + assert(*i == n); + assert(n == 10); + assert(c1.get_allocator() == A(10)); + assert(c0.empty()); + } + { + typedef MoveOnly T; + typedef test_allocator A; + typedef std::forward_list C; + T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + T t1[] = {10, 11, 12, 13}; + typedef std::move_iterator I; + C c0(I(std::begin(t0)), I(std::end(t0)), A(10)); + C c1(I(std::begin(t1)), I(std::end(t1)), A(11)); + c1 = std::move(c0); + int n = 0; + for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n) + assert(*i == n); + assert(n == 10); + assert(c1.get_allocator() == A(11)); + assert(!c0.empty()); + } + { + typedef MoveOnly T; + typedef test_allocator A; + typedef std::forward_list C; + T t0[] = {10, 11, 12, 13}; + T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator I; + C c0(I(std::begin(t0)), I(std::end(t0)), A(10)); + C c1(I(std::begin(t1)), I(std::end(t1)), A(10)); + c1 = std::move(c0); + int n = 0; + for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n) + assert(*i == 10+n); + assert(n == 4); + assert(c1.get_allocator() == A(10)); + assert(c0.empty()); + } + { + typedef MoveOnly T; + typedef test_allocator A; + typedef std::forward_list C; + T t0[] = {10, 11, 12, 13}; + T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator I; + C c0(I(std::begin(t0)), I(std::end(t0)), A(10)); + C c1(I(std::begin(t1)), I(std::end(t1)), A(11)); + c1 = std::move(c0); + int n = 0; + for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n) + assert(*i == 10+n); + assert(n == 4); + assert(c1.get_allocator() == A(11)); + assert(!c0.empty()); + } + + { + typedef MoveOnly T; + typedef other_allocator A; + typedef std::forward_list C; + T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + T t1[] = {10, 11, 12, 13}; + typedef std::move_iterator I; + C c0(I(std::begin(t0)), I(std::end(t0)), A(10)); + C c1(I(std::begin(t1)), I(std::end(t1)), A(10)); + c1 = std::move(c0); + int n = 0; + for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n) + assert(*i == n); + assert(n == 10); + assert(c1.get_allocator() == A(10)); + assert(c0.empty()); + } + { + typedef MoveOnly T; + typedef other_allocator A; + typedef std::forward_list C; + T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + T t1[] = {10, 11, 12, 13}; + typedef std::move_iterator I; + C c0(I(std::begin(t0)), I(std::end(t0)), A(10)); + C c1(I(std::begin(t1)), I(std::end(t1)), A(11)); + c1 = std::move(c0); + int n = 0; + for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n) + assert(*i == n); + assert(n == 10); + assert(c1.get_allocator() == A(10)); + assert(c0.empty()); + } + { + typedef MoveOnly T; + typedef other_allocator A; + typedef std::forward_list C; + T t0[] = {10, 11, 12, 13}; + T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator I; + C c0(I(std::begin(t0)), I(std::end(t0)), A(10)); + C c1(I(std::begin(t1)), I(std::end(t1)), A(10)); + c1 = std::move(c0); + int n = 0; + for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n) + assert(*i == 10+n); + assert(n == 4); + assert(c1.get_allocator() == A(10)); + assert(c0.empty()); + } + { + typedef MoveOnly T; + typedef other_allocator A; + typedef std::forward_list C; + T t0[] = {10, 11, 12, 13}; + T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator I; + C c0(I(std::begin(t0)), I(std::end(t0)), A(10)); + C c1(I(std::begin(t1)), I(std::end(t1)), A(11)); + c1 = std::move(c0); + int n = 0; + for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n) + assert(*i == 10+n); + assert(n == 4); + assert(c1.get_allocator() == A(10)); + assert(c0.empty()); + } +#if __cplusplus >= 201103L + { + typedef MoveOnly T; + typedef min_allocator A; + typedef std::forward_list C; + T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + T t1[] = {10, 11, 12, 13}; + typedef std::move_iterator I; + C c0(I(std::begin(t0)), I(std::end(t0)), A()); + C c1(I(std::begin(t1)), I(std::end(t1)), A()); + c1 = std::move(c0); + int n = 0; + for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n) + assert(*i == n); + assert(n == 10); + assert(c1.get_allocator() == A()); + assert(c0.empty()); + } + { + typedef MoveOnly T; + typedef min_allocator A; + typedef std::forward_list C; + T t0[] = {10, 11, 12, 13}; + T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator I; + C c0(I(std::begin(t0)), I(std::end(t0)), A()); + C c1(I(std::begin(t1)), I(std::end(t1)), A()); + c1 = std::move(c0); + int n = 0; + for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n) + assert(*i == 10+n); + assert(n == 4); + assert(c1.get_allocator() == A()); + assert(c0.empty()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_op_init.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_op_init.pass.cpp new file mode 100644 index 00000000000..551908fea16 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_op_init.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// forward_list& operator=(initializer_list il); + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {10, 11, 12, 13}; + C c(std::begin(t1), std::end(t1)); + c = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == n); + assert(n == 10); + } + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t1), std::end(t1)); + c = {10, 11, 12, 13}; + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == 10+n); + assert(n == 4); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {10, 11, 12, 13}; + C c(std::begin(t1), std::end(t1)); + c = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == n); + assert(n == 10); + } + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t1), std::end(t1)); + c = {10, 11, 12, 13}; + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == 10+n); + assert(n == 4); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp new file mode 100644 index 00000000000..0b348e6920c --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_range.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// void assign(InputIterator first, InputIterator last); + +#include +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const T t1[] = {10, 11, 12, 13}; + C c(std::begin(t1), std::end(t1)); + typedef input_iterator I; + c.assign(I(std::begin(t0)), I(std::end(t0))); + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == n); + assert(n == 10); + } + { + typedef int T; + typedef std::forward_list C; + const T t0[] = {10, 11, 12, 13}; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t1), std::end(t1)); + typedef input_iterator I; + c.assign(I(std::begin(t0)), I(std::end(t0))); + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == 10+n); + assert(n == 4); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const T t1[] = {10, 11, 12, 13}; + C c(std::begin(t1), std::end(t1)); + typedef input_iterator I; + c.assign(I(std::begin(t0)), I(std::end(t0))); + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == n); + assert(n == 10); + } + { + typedef int T; + typedef std::forward_list> C; + const T t0[] = {10, 11, 12, 13}; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t1), std::end(t1)); + typedef input_iterator I; + c.assign(I(std::begin(t0)), I(std::end(t0))); + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, (void) ++n) + assert(*i == 10+n); + assert(n == 4); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_size_value.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_size_value.pass.cpp new file mode 100644 index 00000000000..ea53e1c3732 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_size_value.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void assign(size_type n, const value_type& v); + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {10, 11, 12, 13}; + C c(std::begin(t1), std::end(t1)); + c.assign(10, 1); + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == 1); + assert(n == 10); + } + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t1), std::end(t1)); + c.assign(4, 10); + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == 10); + assert(n == 4); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {10, 11, 12, 13}; + C c(std::begin(t1), std::end(t1)); + c.assign(10, 1); + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == 1); + assert(n == 10); + } + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t1), std::end(t1)); + c.assign(4, 10); + int n = 0; + for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n) + assert(*i == 10); + assert(n == 4); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/copy.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/copy.pass.cpp new file mode 100644 index 00000000000..2fc53bc3a51 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/copy.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// forward_list(const forward_list& x); + +#include +#include +#include + +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef test_allocator A; + typedef std::forward_list C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t), std::end(t), A(10)); + C c = c0; + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c == c0); + assert(c.get_allocator() == A(10)); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + typedef int T; + typedef other_allocator A; + typedef std::forward_list C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t), std::end(t), A(10)); + C c = c0; + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c == c0); + assert(c.get_allocator() == A(-2)); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + typedef int T; + typedef min_allocator A; + typedef std::forward_list C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t), std::end(t), A()); + C c = c0; + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c == c0); + assert(c.get_allocator() == A()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/copy_alloc.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..bcc24e1cc68 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/copy_alloc.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// forward_list(const forward_list& x, const allocator_type& a); + +#include +#include +#include + +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef test_allocator A; + typedef std::forward_list C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t), std::end(t), A(10)); + C c(c0, A(9)); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c == c0); + assert(c.get_allocator() == A(9)); + } + { + typedef int T; + typedef other_allocator A; + typedef std::forward_list C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t), std::end(t), A(10)); + C c(c0, A(9)); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c == c0); + assert(c.get_allocator() == A(9)); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef min_allocator A; + typedef std::forward_list C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c0(std::begin(t), std::end(t), A()); + C c(c0, A()); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c == c0); + assert(c.get_allocator() == A()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default.pass.cpp new file mode 100644 index 00000000000..38e95fad839 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// forward_list(); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + C c; + assert(c.empty()); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + C c; + assert(c.empty()); + } + { + typedef int T; + typedef std::forward_list C; + C c = {}; + assert(c.empty()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default_noexcept.pass.cpp new file mode 100644 index 00000000000..6b0233d65b6 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default_noexcept.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// forward_list() +// noexcept(is_nothrow_default_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::forward_list C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::forward_list> C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::forward_list> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::forward_list> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default_recursive.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default_recursive.pass.cpp new file mode 100644 index 00000000000..5ff00e6fe52 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/default_recursive.pass.cpp @@ -0,0 +1,25 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class forward_list + +// forward_list(); + +#include + +struct X +{ + std::forward_list q; +}; + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..1f7b05efd66 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// ~forward_list() // implied noexcept; + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); + ~some_alloc() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::forward_list C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::forward_list> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::forward_list> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::forward_list> C; + static_assert(!std::is_nothrow_destructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/init.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/init.pass.cpp new file mode 100644 index 00000000000..5b31c4dad0a --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/init.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// forward_list(initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef int T; + typedef std::forward_list C; + C c = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == 10); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + C c = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == 10); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/init_alloc.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/init_alloc.pass.cpp new file mode 100644 index 00000000000..750486b829f --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/init_alloc.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// forward_list(initializer_list il, const allocator_type& a); + +#include +#include + +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef int T; + typedef test_allocator A; + typedef std::forward_list C; + C c({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, A(14)); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == 10); + assert(c.get_allocator() == A(14)); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef min_allocator A; + typedef std::forward_list C; + C c({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, A()); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == 10); + assert(c.get_allocator() == A()); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move.pass.cpp new file mode 100644 index 00000000000..164801a0b40 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// forward_list(forward_list&& x); + +#include +#include +#include + +#include "test_allocator.h" +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef MoveOnly T; + typedef test_allocator A; + typedef std::forward_list C; + T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator I; + C c0(I(std::begin(t)), I(std::end(t)), A(10)); + C c = std::move(c0); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c0.empty()); + assert(c.get_allocator() == A(10)); + } + { + typedef MoveOnly T; + typedef other_allocator A; + typedef std::forward_list C; + T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator I; + C c0(I(std::begin(t)), I(std::end(t)), A(10)); + C c = std::move(c0); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c0.empty()); + assert(c.get_allocator() == A(10)); + } +#if __cplusplus >= 201103L + { + typedef MoveOnly T; + typedef min_allocator A; + typedef std::forward_list C; + T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator I; + C c0(I(std::begin(t)), I(std::end(t)), A()); + C c = std::move(c0); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c0.empty()); + assert(c.get_allocator() == A()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_alloc.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..ba0cb5d3beb --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_alloc.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// forward_list(forward_list&& x, const allocator_type& a); + +#include +#include +#include + +#include "test_allocator.h" +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef MoveOnly T; + typedef test_allocator A; + typedef std::forward_list C; + T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator I; + C c0(I(std::begin(t)), I(std::end(t)), A(10)); + C c(std::move(c0), A(10)); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c0.empty()); + assert(c.get_allocator() == A(10)); + } + { + typedef MoveOnly T; + typedef test_allocator A; + typedef std::forward_list C; + T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator I; + C c0(I(std::begin(t)), I(std::end(t)), A(10)); + C c(std::move(c0), A(9)); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(!c0.empty()); + assert(c.get_allocator() == A(9)); + } +#if __cplusplus >= 201103L + { + typedef MoveOnly T; + typedef min_allocator A; + typedef std::forward_list C; + T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + typedef std::move_iterator I; + C c0(I(std::begin(t)), I(std::end(t)), A()); + C c(std::move(c0), A()); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c0.empty()); + assert(c.get_allocator() == A()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..cc5b9d54ed3 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// forward_list& operator=(forward_list&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::forward_list C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::forward_list> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::forward_list> C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::forward_list> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_noexcept.pass.cpp new file mode 100644 index 00000000000..3666c7d169d --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/move_noexcept.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// forward_list(forward_list&&) +// noexcept(is_nothrow_move_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::forward_list C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::forward_list> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::forward_list> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::forward_list> C; + static_assert(!std::is_nothrow_move_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/range.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/range.pass.cpp new file mode 100644 index 00000000000..763952439f0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/range.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// forward_list(InputIterator first, InputIterator last); + +#include +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + typedef input_iterator I; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(I(std::begin(t)), I(std::end(t))); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + typedef input_iterator I; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(I(std::begin(t)), I(std::end(t))); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/range_alloc.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/range_alloc.pass.cpp new file mode 100644 index 00000000000..d72c3581022 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/range_alloc.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// forward_list(InputIterator first, InputIterator last, +// const allocator_type& a); + +#include +#include +#include + +#include "test_allocator.h" +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef test_allocator A; + typedef std::forward_list C; + typedef input_iterator I; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(I(std::begin(t)), I(std::end(t)), A(13)); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c.get_allocator() == A(13)); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef min_allocator A; + typedef std::forward_list C; + typedef input_iterator I; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(I(std::begin(t)), I(std::end(t)), A()); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == n); + assert(n == std::end(t) - std::begin(t)); + assert(c.get_allocator() == A()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size.fail.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size.fail.cpp new file mode 100644 index 00000000000..2d963a1be47 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size.fail.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// explicit forward_list(size_type n); + +#include +#include + +#include "DefaultOnly.h" + +int main() +{ + { + typedef DefaultOnly T; + typedef std::forward_list C; + unsigned N = 10; + C c = N; + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(*i == T()); +#else + ; +#endif + assert(n == N); + } +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size.pass.cpp new file mode 100644 index 00000000000..e02dcb4bf69 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// explicit forward_list(size_type n); +// explicit forward_list(size_type n, const Alloc& a); + +#include +#include + +#include "DefaultOnly.h" +#include "min_allocator.h" + +template +void check_allocator(unsigned n, Allocator const &alloc = Allocator()) +{ +#if _LIBCPP_STD_VER > 11 + typedef std::forward_list C; + C d(n, alloc); + assert(d.get_allocator() == alloc); + assert(std::distance(d.begin(), d.end()) == n); +#endif +} + +int main() +{ + { + typedef DefaultOnly T; + typedef std::forward_list C; + unsigned N = 10; + C c(N); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(*i == T()); +#else + ; +#endif + assert(n == N); + } +#if __cplusplus >= 201103L + { + typedef DefaultOnly T; + typedef std::forward_list> C; + unsigned N = 10; + C c(N); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + assert(*i == T()); +#else + ; +#endif + assert(n == N); + check_allocator> ( 0 ); + check_allocator> ( 3 ); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size_value.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size_value.pass.cpp new file mode 100644 index 00000000000..05ab98bb205 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size_value.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// forward_list(size_type n, const value_type& v); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + T v(6); + unsigned N = 10; + C c(N, v); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == v); + assert(n == N); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + T v(6); + unsigned N = 10; + C c(N, v); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == v); + assert(n == N); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size_value_alloc.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size_value_alloc.pass.cpp new file mode 100644 index 00000000000..1d631ab12ba --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/size_value_alloc.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// forward_list(size_type n, const value_type& v, const allocator_type& a); + +#include +#include + +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_allocator A; + typedef A::value_type T; + typedef std::forward_list C; + T v(6); + unsigned N = 10; + C c(N, v, A(12)); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == v); + assert(n == N); + assert(c.get_allocator() == A(12)); + } +#if __cplusplus >= 201103L + { + typedef min_allocator A; + typedef A::value_type T; + typedef std::forward_list C; + T v(6); + unsigned N = 10; + C c(N, v, A()); + unsigned n = 0; + for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n) + assert(*i == v); + assert(n == N); + assert(c.get_allocator() == A()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.iter/before_begin.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.iter/before_begin.pass.cpp new file mode 100644 index 00000000000..083cec2886d --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.iter/before_begin.pass.cpp @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator before_begin(); +// const_iterator before_begin() const; +// const_iterator cbefore_begin() const; + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + C c; + C::iterator i = c.before_begin(); + assert(std::distance(i, c.end()) == 1); + } + { + typedef int T; + typedef std::forward_list C; + const C c; + C::const_iterator i = c.before_begin(); + assert(std::distance(i, c.end()) == 1); + } + { + typedef int T; + typedef std::forward_list C; + const C c; + C::const_iterator i = c.cbefore_begin(); + assert(std::distance(i, c.end()) == 1); + assert(c.cbefore_begin() == c.before_begin()); + } + { + typedef int T; + typedef std::forward_list C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + C::iterator i = c.before_begin(); + assert(std::distance(i, c.end()) == 11); + assert(std::next(c.before_begin()) == c.begin()); + } + { + typedef int T; + typedef std::forward_list C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const C c(std::begin(t), std::end(t)); + C::const_iterator i = c.before_begin(); + assert(std::distance(i, c.end()) == 11); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + C c; + C::iterator i = c.before_begin(); + assert(std::distance(i, c.end()) == 1); + } + { + typedef int T; + typedef std::forward_list> C; + const C c; + C::const_iterator i = c.before_begin(); + assert(std::distance(i, c.end()) == 1); + } + { + typedef int T; + typedef std::forward_list> C; + const C c; + C::const_iterator i = c.cbefore_begin(); + assert(std::distance(i, c.end()) == 1); + assert(c.cbefore_begin() == c.before_begin()); + } + { + typedef int T; + typedef std::forward_list> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + C::iterator i = c.before_begin(); + assert(std::distance(i, c.end()) == 11); + assert(std::next(c.before_begin()) == c.begin()); + } + { + typedef int T; + typedef std::forward_list> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + const C c(std::begin(t), std::end(t)); + C::const_iterator i = c.before_begin(); + assert(std::distance(i, c.end()) == 11); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.iter/iterators.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.iter/iterators.pass.cpp new file mode 100644 index 00000000000..6f3ac548db8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.iter/iterators.pass.cpp @@ -0,0 +1,145 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator begin(); +// iterator end(); +// const_iterator begin() const; +// const_iterator end() const; +// const_iterator cbegin() const; +// const_iterator cend() const; + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + C c; + C::iterator i = c.begin(); + C::iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef int T; + typedef std::forward_list C; + const C c; + C::const_iterator i = c.begin(); + C::const_iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef int T; + typedef std::forward_list C; + C c; + C::const_iterator i = c.cbegin(); + C::const_iterator j = c.cend(); + assert(std::distance(i, j) == 0); + assert(i == j); + assert(i == c.end()); + } + { + typedef int T; + typedef std::forward_list C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + C::iterator i = c.begin(); + assert(*i == 0); + ++i; + assert(*i == 1); + *i = 10; + assert(*i == 10); + assert(std::distance(c.begin(), c.end()) == 10); + } + { + typedef int T; + typedef std::forward_list C; + C::iterator i; + C::const_iterator j; + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + C c; + C::iterator i = c.begin(); + C::iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef int T; + typedef std::forward_list> C; + const C c; + C::const_iterator i = c.begin(); + C::const_iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef int T; + typedef std::forward_list> C; + C c; + C::const_iterator i = c.cbegin(); + C::const_iterator j = c.cend(); + assert(std::distance(i, j) == 0); + assert(i == j); + assert(i == c.end()); + } + { + typedef int T; + typedef std::forward_list> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + C::iterator i = c.begin(); + assert(*i == 0); + ++i; + assert(*i == 1); + *i = 10; + assert(*i == 10); + assert(std::distance(c.begin(), c.end()) == 10); + } + { + typedef int T; + typedef std::forward_list> C; + C::iterator i; + C::const_iterator j; + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + std::forward_list::iterator ii1{}, ii2{}; + std::forward_list::iterator ii4 = ii1; + std::forward_list::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + +// std::forward_list c; +// assert ( ii1 != c.cbegin()); +// assert ( cii != c.begin()); +// assert ( cii != c.cend()); +// assert ( ii1 != c.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/clear.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/clear.pass.cpp new file mode 100644 index 00000000000..2739b49d8eb --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/clear.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void clear(); + +#include +#include + +#include "../../../NotConstructible.h" +#include "min_allocator.h" + +int main() +{ + { + typedef NotConstructible T; + typedef std::forward_list C; + C c; + c.clear(); + assert(distance(c.begin(), c.end()) == 0); + } + { + typedef int T; + typedef std::forward_list C; + const T t[] = {0, 1, 2, 3, 4}; + C c(std::begin(t), std::end(t)); + + c.clear(); + assert(distance(c.begin(), c.end()) == 0); + + c.clear(); + assert(distance(c.begin(), c.end()) == 0); + } +#if __cplusplus >= 201103L + { + typedef NotConstructible T; + typedef std::forward_list> C; + C c; + c.clear(); + assert(distance(c.begin(), c.end()) == 0); + } + { + typedef int T; + typedef std::forward_list> C; + const T t[] = {0, 1, 2, 3, 4}; + C c(std::begin(t), std::end(t)); + + c.clear(); + assert(distance(c.begin(), c.end()) == 0); + + c.clear(); + assert(distance(c.begin(), c.end()) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/emplace_after.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/emplace_after.pass.cpp new file mode 100644 index 00000000000..e305c5b6ab5 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/emplace_after.pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// iterator emplace_after(const_iterator p, Args&&... args); + +#include +#include + +#include "../../../Emplaceable.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef Emplaceable T; + typedef std::forward_list C; + typedef C::iterator I; + C c; + I i = c.emplace_after(c.cbefore_begin()); + assert(i == c.begin()); + assert(c.front() == Emplaceable()); + assert(distance(c.begin(), c.end()) == 1); + + i = c.emplace_after(c.cbegin(), 1, 2.5); + assert(i == next(c.begin())); + assert(c.front() == Emplaceable()); + assert(*next(c.begin()) == Emplaceable(1, 2.5)); + assert(distance(c.begin(), c.end()) == 2); + + i = c.emplace_after(next(c.cbegin()), 2, 3.5); + assert(i == next(c.begin(), 2)); + assert(c.front() == Emplaceable()); + assert(*next(c.begin()) == Emplaceable(1, 2.5)); + assert(*next(c.begin(), 2) == Emplaceable(2, 3.5)); + assert(distance(c.begin(), c.end()) == 3); + + i = c.emplace_after(c.cbegin(), 3, 4.5); + assert(i == next(c.begin())); + assert(c.front() == Emplaceable()); + assert(*next(c.begin(), 1) == Emplaceable(3, 4.5)); + assert(*next(c.begin(), 2) == Emplaceable(1, 2.5)); + assert(*next(c.begin(), 3) == Emplaceable(2, 3.5)); + assert(distance(c.begin(), c.end()) == 4); + } +#if __cplusplus >= 201103L + { + typedef Emplaceable T; + typedef std::forward_list> C; + typedef C::iterator I; + C c; + I i = c.emplace_after(c.cbefore_begin()); + assert(i == c.begin()); + assert(c.front() == Emplaceable()); + assert(distance(c.begin(), c.end()) == 1); + + i = c.emplace_after(c.cbegin(), 1, 2.5); + assert(i == next(c.begin())); + assert(c.front() == Emplaceable()); + assert(*next(c.begin()) == Emplaceable(1, 2.5)); + assert(distance(c.begin(), c.end()) == 2); + + i = c.emplace_after(next(c.cbegin()), 2, 3.5); + assert(i == next(c.begin(), 2)); + assert(c.front() == Emplaceable()); + assert(*next(c.begin()) == Emplaceable(1, 2.5)); + assert(*next(c.begin(), 2) == Emplaceable(2, 3.5)); + assert(distance(c.begin(), c.end()) == 3); + + i = c.emplace_after(c.cbegin(), 3, 4.5); + assert(i == next(c.begin())); + assert(c.front() == Emplaceable()); + assert(*next(c.begin(), 1) == Emplaceable(3, 4.5)); + assert(*next(c.begin(), 2) == Emplaceable(1, 2.5)); + assert(*next(c.begin(), 3) == Emplaceable(2, 3.5)); + assert(distance(c.begin(), c.end()) == 4); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/emplace_front.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/emplace_front.pass.cpp new file mode 100644 index 00000000000..c02337e0562 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/emplace_front.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template void emplace_front(Args&&... args); + +#include +#include + +#include "../../../Emplaceable.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef Emplaceable T; + typedef std::forward_list C; + C c; + c.emplace_front(); + assert(c.front() == Emplaceable()); + assert(distance(c.begin(), c.end()) == 1); + c.emplace_front(1, 2.5); + assert(c.front() == Emplaceable(1, 2.5)); + assert(*next(c.begin()) == Emplaceable()); + assert(distance(c.begin(), c.end()) == 2); + } +#if __cplusplus >= 201103L + { + typedef Emplaceable T; + typedef std::forward_list> C; + C c; + c.emplace_front(); + assert(c.front() == Emplaceable()); + assert(distance(c.begin(), c.end()) == 1); + c.emplace_front(1, 2.5); + assert(c.front() == Emplaceable(1, 2.5)); + assert(*next(c.begin()) == Emplaceable()); + assert(distance(c.begin(), c.end()) == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_many.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_many.pass.cpp new file mode 100644 index 00000000000..bd9b15300ef --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_many.pass.cpp @@ -0,0 +1,155 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator erase_after(const_iterator first, const_iterator last); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + + C::iterator i = c.erase_after(next(c.cbefore_begin(), 4), next(c.cbefore_begin(), 4)); + assert(i == next(c.cbefore_begin(), 4)); + assert(distance(c.begin(), c.end()) == 10); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 3); + assert(*next(c.begin(), 4) == 4); + assert(*next(c.begin(), 5) == 5); + assert(*next(c.begin(), 6) == 6); + assert(*next(c.begin(), 7) == 7); + assert(*next(c.begin(), 8) == 8); + assert(*next(c.begin(), 9) == 9); + + i = c.erase_after(next(c.cbefore_begin(), 2), next(c.cbefore_begin(), 5)); + assert(i == next(c.begin(), 2)); + assert(distance(c.begin(), c.end()) == 8); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 4); + assert(*next(c.begin(), 3) == 5); + assert(*next(c.begin(), 4) == 6); + assert(*next(c.begin(), 5) == 7); + assert(*next(c.begin(), 6) == 8); + assert(*next(c.begin(), 7) == 9); + + i = c.erase_after(next(c.cbefore_begin(), 2), next(c.cbefore_begin(), 3)); + assert(i == next(c.begin(), 2)); + assert(distance(c.begin(), c.end()) == 8); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 4); + assert(*next(c.begin(), 3) == 5); + assert(*next(c.begin(), 4) == 6); + assert(*next(c.begin(), 5) == 7); + assert(*next(c.begin(), 6) == 8); + assert(*next(c.begin(), 7) == 9); + + i = c.erase_after(next(c.cbefore_begin(), 5), next(c.cbefore_begin(), 9)); + assert(i == c.end()); + assert(distance(c.begin(), c.end()) == 5); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 4); + assert(*next(c.begin(), 3) == 5); + assert(*next(c.begin(), 4) == 6); + + i = c.erase_after(next(c.cbefore_begin(), 0), next(c.cbefore_begin(), 2)); + assert(i == c.begin()); + assert(distance(c.begin(), c.end()) == 4); + assert(*next(c.begin(), 0) == 1); + assert(*next(c.begin(), 1) == 4); + assert(*next(c.begin(), 2) == 5); + assert(*next(c.begin(), 3) == 6); + + i = c.erase_after(next(c.cbefore_begin(), 0), next(c.cbefore_begin(), 5)); + assert(i == c.begin()); + assert(i == c.end()); + assert(distance(c.begin(), c.end()) == 0); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + + C::iterator i = c.erase_after(next(c.cbefore_begin(), 4), next(c.cbefore_begin(), 4)); + assert(i == next(c.cbefore_begin(), 4)); + assert(distance(c.begin(), c.end()) == 10); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 3); + assert(*next(c.begin(), 4) == 4); + assert(*next(c.begin(), 5) == 5); + assert(*next(c.begin(), 6) == 6); + assert(*next(c.begin(), 7) == 7); + assert(*next(c.begin(), 8) == 8); + assert(*next(c.begin(), 9) == 9); + + i = c.erase_after(next(c.cbefore_begin(), 2), next(c.cbefore_begin(), 5)); + assert(i == next(c.begin(), 2)); + assert(distance(c.begin(), c.end()) == 8); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 4); + assert(*next(c.begin(), 3) == 5); + assert(*next(c.begin(), 4) == 6); + assert(*next(c.begin(), 5) == 7); + assert(*next(c.begin(), 6) == 8); + assert(*next(c.begin(), 7) == 9); + + i = c.erase_after(next(c.cbefore_begin(), 2), next(c.cbefore_begin(), 3)); + assert(i == next(c.begin(), 2)); + assert(distance(c.begin(), c.end()) == 8); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 4); + assert(*next(c.begin(), 3) == 5); + assert(*next(c.begin(), 4) == 6); + assert(*next(c.begin(), 5) == 7); + assert(*next(c.begin(), 6) == 8); + assert(*next(c.begin(), 7) == 9); + + i = c.erase_after(next(c.cbefore_begin(), 5), next(c.cbefore_begin(), 9)); + assert(i == c.end()); + assert(distance(c.begin(), c.end()) == 5); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 4); + assert(*next(c.begin(), 3) == 5); + assert(*next(c.begin(), 4) == 6); + + i = c.erase_after(next(c.cbefore_begin(), 0), next(c.cbefore_begin(), 2)); + assert(i == c.begin()); + assert(distance(c.begin(), c.end()) == 4); + assert(*next(c.begin(), 0) == 1); + assert(*next(c.begin(), 1) == 4); + assert(*next(c.begin(), 2) == 5); + assert(*next(c.begin(), 3) == 6); + + i = c.erase_after(next(c.cbefore_begin(), 0), next(c.cbefore_begin(), 5)); + assert(i == c.begin()); + assert(i == c.end()); + assert(distance(c.begin(), c.end()) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_one.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_one.pass.cpp new file mode 100644 index 00000000000..4f51498bc65 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/erase_after_one.pass.cpp @@ -0,0 +1,97 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator erase_after(const_iterator p); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + const T t[] = {0, 1, 2, 3, 4}; + C c(std::begin(t), std::end(t)); + + C::iterator i = c.erase_after(next(c.cbefore_begin(), 4)); + assert(i == c.end()); + assert(distance(c.begin(), c.end()) == 4); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 3); + + i = c.erase_after(next(c.cbefore_begin(), 0)); + assert(i == c.begin()); + assert(distance(c.begin(), c.end()) == 3); + assert(*next(c.begin(), 0) == 1); + assert(*next(c.begin(), 1) == 2); + assert(*next(c.begin(), 2) == 3); + + i = c.erase_after(next(c.cbefore_begin(), 1)); + assert(i == next(c.begin())); + assert(distance(c.begin(), c.end()) == 2); + assert(*next(c.begin(), 0) == 1); + assert(*next(c.begin(), 1) == 3); + + i = c.erase_after(next(c.cbefore_begin(), 1)); + assert(i == c.end()); + assert(distance(c.begin(), c.end()) == 1); + assert(*next(c.begin(), 0) == 1); + + i = c.erase_after(next(c.cbefore_begin(), 0)); + assert(i == c.begin()); + assert(i == c.end()); + assert(distance(c.begin(), c.end()) == 0); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + const T t[] = {0, 1, 2, 3, 4}; + C c(std::begin(t), std::end(t)); + + C::iterator i = c.erase_after(next(c.cbefore_begin(), 4)); + assert(i == c.end()); + assert(distance(c.begin(), c.end()) == 4); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 3); + + i = c.erase_after(next(c.cbefore_begin(), 0)); + assert(i == c.begin()); + assert(distance(c.begin(), c.end()) == 3); + assert(*next(c.begin(), 0) == 1); + assert(*next(c.begin(), 1) == 2); + assert(*next(c.begin(), 2) == 3); + + i = c.erase_after(next(c.cbefore_begin(), 1)); + assert(i == next(c.begin())); + assert(distance(c.begin(), c.end()) == 2); + assert(*next(c.begin(), 0) == 1); + assert(*next(c.begin(), 1) == 3); + + i = c.erase_after(next(c.cbefore_begin(), 1)); + assert(i == c.end()); + assert(distance(c.begin(), c.end()) == 1); + assert(*next(c.begin(), 0) == 1); + + i = c.erase_after(next(c.cbefore_begin(), 0)); + assert(i == c.begin()); + assert(i == c.end()); + assert(distance(c.begin(), c.end()) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_const.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_const.pass.cpp new file mode 100644 index 00000000000..ec650b69572 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_const.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator insert_after(const_iterator p, const value_type& v); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + typedef C::iterator I; + C c; + I i = c.insert_after(c.cbefore_begin(), 0); + assert(i == c.begin()); + assert(c.front() == 0); + assert(c.front() == 0); + assert(distance(c.begin(), c.end()) == 1); + + i = c.insert_after(c.cbegin(), 1); + assert(i == next(c.begin())); + assert(c.front() == 0); + assert(*next(c.begin()) == 1); + assert(distance(c.begin(), c.end()) == 2); + + i = c.insert_after(next(c.cbegin()), 2); + assert(i == next(c.begin(), 2)); + assert(c.front() == 0); + assert(*next(c.begin()) == 1); + assert(*next(c.begin(), 2) == 2); + assert(distance(c.begin(), c.end()) == 3); + + i = c.insert_after(c.cbegin(), 3); + assert(i == next(c.begin())); + assert(c.front() == 0); + assert(*next(c.begin(), 1) == 3); + assert(*next(c.begin(), 2) == 1); + assert(*next(c.begin(), 3) == 2); + assert(distance(c.begin(), c.end()) == 4); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + typedef C::iterator I; + C c; + I i = c.insert_after(c.cbefore_begin(), 0); + assert(i == c.begin()); + assert(c.front() == 0); + assert(c.front() == 0); + assert(distance(c.begin(), c.end()) == 1); + + i = c.insert_after(c.cbegin(), 1); + assert(i == next(c.begin())); + assert(c.front() == 0); + assert(*next(c.begin()) == 1); + assert(distance(c.begin(), c.end()) == 2); + + i = c.insert_after(next(c.cbegin()), 2); + assert(i == next(c.begin(), 2)); + assert(c.front() == 0); + assert(*next(c.begin()) == 1); + assert(*next(c.begin(), 2) == 2); + assert(distance(c.begin(), c.end()) == 3); + + i = c.insert_after(c.cbegin(), 3); + assert(i == next(c.begin())); + assert(c.front() == 0); + assert(*next(c.begin(), 1) == 3); + assert(*next(c.begin(), 2) == 1); + assert(*next(c.begin(), 3) == 2); + assert(distance(c.begin(), c.end()) == 4); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_init.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_init.pass.cpp new file mode 100644 index 00000000000..4d301819980 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_init.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator insert_after(const_iterator p, initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef int T; + typedef std::forward_list C; + typedef C::iterator I; + C c; + I i = c.insert_after(c.cbefore_begin(), {}); + assert(i == c.before_begin()); + assert(distance(c.begin(), c.end()) == 0); + + i = c.insert_after(c.cbefore_begin(), {0, 1, 2}); + assert(i == next(c.before_begin(), 3)); + assert(distance(c.begin(), c.end()) == 3); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + + i = c.insert_after(c.begin(), {3, 4}); + assert(i == next(c.begin(), 2)); + assert(distance(c.begin(), c.end()) == 5); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 3); + assert(*next(c.begin(), 2) == 4); + assert(*next(c.begin(), 3) == 1); + assert(*next(c.begin(), 4) == 2); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + typedef C::iterator I; + C c; + I i = c.insert_after(c.cbefore_begin(), {}); + assert(i == c.before_begin()); + assert(distance(c.begin(), c.end()) == 0); + + i = c.insert_after(c.cbefore_begin(), {0, 1, 2}); + assert(i == next(c.before_begin(), 3)); + assert(distance(c.begin(), c.end()) == 3); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + + i = c.insert_after(c.begin(), {3, 4}); + assert(i == next(c.begin(), 2)); + assert(distance(c.begin(), c.end()) == 5); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 3); + assert(*next(c.begin(), 2) == 4); + assert(*next(c.begin(), 3) == 1); + assert(*next(c.begin(), 4) == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_range.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_range.pass.cpp new file mode 100644 index 00000000000..103475f1eda --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_range.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// iterator insert_after(const_iterator p, +// InputIterator first, InputIterator last); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + typedef C::iterator I; + typedef input_iterator J; + C c; + const T t[] = {0, 1, 2, 3, 4}; + I i = c.insert_after(c.cbefore_begin(), J(t), J(t)); + assert(i == c.before_begin()); + assert(distance(c.begin(), c.end()) == 0); + + i = c.insert_after(c.cbefore_begin(), J(t), J(t+3)); + assert(i == next(c.before_begin(), 3)); + assert(distance(c.begin(), c.end()) == 3); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + + i = c.insert_after(c.begin(), J(t+3), J(t+5)); + assert(i == next(c.begin(), 2)); + assert(distance(c.begin(), c.end()) == 5); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 3); + assert(*next(c.begin(), 2) == 4); + assert(*next(c.begin(), 3) == 1); + assert(*next(c.begin(), 4) == 2); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + typedef C::iterator I; + typedef input_iterator J; + C c; + const T t[] = {0, 1, 2, 3, 4}; + I i = c.insert_after(c.cbefore_begin(), J(t), J(t)); + assert(i == c.before_begin()); + assert(distance(c.begin(), c.end()) == 0); + + i = c.insert_after(c.cbefore_begin(), J(t), J(t+3)); + assert(i == next(c.before_begin(), 3)); + assert(distance(c.begin(), c.end()) == 3); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + + i = c.insert_after(c.begin(), J(t+3), J(t+5)); + assert(i == next(c.begin(), 2)); + assert(distance(c.begin(), c.end()) == 5); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 3); + assert(*next(c.begin(), 2) == 4); + assert(*next(c.begin(), 3) == 1); + assert(*next(c.begin(), 4) == 2); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_rv.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_rv.pass.cpp new file mode 100644 index 00000000000..4f0be520c30 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_rv.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator insert_after(const_iterator p, value_type&& v); + +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef MoveOnly T; + typedef std::forward_list C; + typedef C::iterator I; + C c; + I i = c.insert_after(c.cbefore_begin(), 0); + assert(i == c.begin()); + assert(c.front() == 0); + assert(c.front() == 0); + assert(distance(c.begin(), c.end()) == 1); + + i = c.insert_after(c.cbegin(), 1); + assert(i == next(c.begin())); + assert(c.front() == 0); + assert(*next(c.begin()) == 1); + assert(distance(c.begin(), c.end()) == 2); + + i = c.insert_after(next(c.cbegin()), 2); + assert(i == next(c.begin(), 2)); + assert(c.front() == 0); + assert(*next(c.begin()) == 1); + assert(*next(c.begin(), 2) == 2); + assert(distance(c.begin(), c.end()) == 3); + + i = c.insert_after(c.cbegin(), 3); + assert(i == next(c.begin())); + assert(c.front() == 0); + assert(*next(c.begin(), 1) == 3); + assert(*next(c.begin(), 2) == 1); + assert(*next(c.begin(), 3) == 2); + assert(distance(c.begin(), c.end()) == 4); + } +#if __cplusplus >= 201103L + { + typedef MoveOnly T; + typedef std::forward_list> C; + typedef C::iterator I; + C c; + I i = c.insert_after(c.cbefore_begin(), 0); + assert(i == c.begin()); + assert(c.front() == 0); + assert(c.front() == 0); + assert(distance(c.begin(), c.end()) == 1); + + i = c.insert_after(c.cbegin(), 1); + assert(i == next(c.begin())); + assert(c.front() == 0); + assert(*next(c.begin()) == 1); + assert(distance(c.begin(), c.end()) == 2); + + i = c.insert_after(next(c.cbegin()), 2); + assert(i == next(c.begin(), 2)); + assert(c.front() == 0); + assert(*next(c.begin()) == 1); + assert(*next(c.begin(), 2) == 2); + assert(distance(c.begin(), c.end()) == 3); + + i = c.insert_after(c.cbegin(), 3); + assert(i == next(c.begin())); + assert(c.front() == 0); + assert(*next(c.begin(), 1) == 3); + assert(*next(c.begin(), 2) == 1); + assert(*next(c.begin(), 3) == 2); + assert(distance(c.begin(), c.end()) == 4); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_size_value.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_size_value.pass.cpp new file mode 100644 index 00000000000..b2da2ecd3bb --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/insert_after_size_value.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator insert_after(const_iterator p, size_type n, const value_type& v); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + typedef C::iterator I; + C c; + I i = c.insert_after(c.cbefore_begin(), 0, 0); + assert(i == c.before_begin()); + assert(distance(c.begin(), c.end()) == 0); + + i = c.insert_after(c.cbefore_begin(), 3, 3); + assert(i == next(c.before_begin(), 3)); + assert(distance(c.begin(), c.end()) == 3); + assert(*next(c.begin(), 0) == 3); + assert(*next(c.begin(), 1) == 3); + assert(*next(c.begin(), 2) == 3); + + i = c.insert_after(c.begin(), 2, 2); + assert(i == next(c.begin(), 2)); + assert(distance(c.begin(), c.end()) == 5); + assert(*next(c.begin(), 0) == 3); + assert(*next(c.begin(), 1) == 2); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 3); + assert(*next(c.begin(), 4) == 3); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + typedef C::iterator I; + C c; + I i = c.insert_after(c.cbefore_begin(), 0, 0); + assert(i == c.before_begin()); + assert(distance(c.begin(), c.end()) == 0); + + i = c.insert_after(c.cbefore_begin(), 3, 3); + assert(i == next(c.before_begin(), 3)); + assert(distance(c.begin(), c.end()) == 3); + assert(*next(c.begin(), 0) == 3); + assert(*next(c.begin(), 1) == 3); + assert(*next(c.begin(), 2) == 3); + + i = c.insert_after(c.begin(), 2, 2); + assert(i == next(c.begin(), 2)); + assert(distance(c.begin(), c.end()) == 5); + assert(*next(c.begin(), 0) == 3); + assert(*next(c.begin(), 1) == 2); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 3); + assert(*next(c.begin(), 4) == 3); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/pop_front.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/pop_front.pass.cpp new file mode 100644 index 00000000000..276f2c9f8ed --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/pop_front.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void pop_front(); + +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + typedef std::forward_list C; + C c; + c.push_front(1); + c.push_front(3); + c.pop_front(); + assert(distance(c.begin(), c.end()) == 1); + assert(c.front() == 1); + c.pop_front(); + assert(distance(c.begin(), c.end()) == 0); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef MoveOnly T; + typedef std::forward_list C; + C c; + c.push_front(1); + c.push_front(3); + c.pop_front(); + assert(distance(c.begin(), c.end()) == 1); + assert(c.front() == 1); + c.pop_front(); + assert(distance(c.begin(), c.end()) == 0); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + typedef std::forward_list> C; + C c; + c.push_front(1); + c.push_front(3); + c.pop_front(); + assert(distance(c.begin(), c.end()) == 1); + assert(c.front() == 1); + c.pop_front(); + assert(distance(c.begin(), c.end()) == 0); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef MoveOnly T; + typedef std::forward_list> C; + C c; + c.push_front(1); + c.push_front(3); + c.pop_front(); + assert(distance(c.begin(), c.end()) == 1); + assert(c.front() == 1); + c.pop_front(); + assert(distance(c.begin(), c.end()) == 0); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_const.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_const.pass.cpp new file mode 100644 index 00000000000..85958afc1ce --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_const.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push_front(const value_type& v); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + C c; + c.push_front(1); + assert(c.front() == 1); + assert(distance(c.begin(), c.end()) == 1); + c.push_front(3); + assert(c.front() == 3); + assert(*next(c.begin()) == 1); + assert(distance(c.begin(), c.end()) == 2); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + C c; + c.push_front(1); + assert(c.front() == 1); + assert(distance(c.begin(), c.end()) == 1); + c.push_front(3); + assert(c.front() == 3); + assert(*next(c.begin()) == 1); + assert(distance(c.begin(), c.end()) == 2); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_exception_safety.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_exception_safety.pass.cpp new file mode 100644 index 00000000000..43c62eb00cb --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_exception_safety.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push_front(const value_type& x); + +#include +#include + +// Flag that makes the copy constructor for CMyClass throw an exception +static bool gCopyConstructorShouldThow = false; + + +class CMyClass { + public: CMyClass(); + public: CMyClass(const CMyClass& iOther); + public: ~CMyClass(); + + private: int fMagicValue; + + private: static int kStartedConstructionMagicValue; + private: static int kFinishedConstructionMagicValue; +}; + +// Value for fMagicValue when the constructor has started running, but not yet finished +int CMyClass::kStartedConstructionMagicValue = 0; +// Value for fMagicValue when the constructor has finished running +int CMyClass::kFinishedConstructionMagicValue = 12345; + +CMyClass::CMyClass() : + fMagicValue(kStartedConstructionMagicValue) +{ + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::CMyClass(const CMyClass& /*iOther*/) : + fMagicValue(kStartedConstructionMagicValue) +{ + // If requested, throw an exception _before_ setting fMagicValue to kFinishedConstructionMagicValue + if (gCopyConstructorShouldThow) { + throw std::exception(); + } + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::~CMyClass() { + // Only instances for which the constructor has finished running should be destructed + assert(fMagicValue == kFinishedConstructionMagicValue); +} + +int main() +{ + CMyClass instance; + std::forward_list vec; + + vec.push_front(instance); + + gCopyConstructorShouldThow = true; + try { + vec.push_front(instance); + } + catch (...) { + } +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_rv.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_rv.pass.cpp new file mode 100644 index 00000000000..53181ec881e --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/push_front_rv.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push_front(value_type&& v); + +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef MoveOnly T; + typedef std::forward_list C; + C c; + c.push_front(1); + assert(c.front() == 1); + assert(distance(c.begin(), c.end()) == 1); + c.push_front(3); + assert(c.front() == 3); + assert(*next(c.begin()) == 1); + assert(distance(c.begin(), c.end()) == 2); + } +#if __cplusplus >= 201103L + { + typedef MoveOnly T; + typedef std::forward_list> C; + C c; + c.push_front(1); + assert(c.front() == 1); + assert(distance(c.begin(), c.end()) == 1); + c.push_front(3); + assert(c.front() == 3); + assert(*next(c.begin()) == 1); + assert(distance(c.begin(), c.end()) == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/resize_size.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/resize_size.pass.cpp new file mode 100644 index 00000000000..ef7ef82626d --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/resize_size.pass.cpp @@ -0,0 +1,114 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void resize(size_type n); + +#include +#include + +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ + { + typedef DefaultOnly T; + typedef std::forward_list C; + C c; + c.resize(0); + assert(distance(c.begin(), c.end()) == 0); + c.resize(10); + assert(distance(c.begin(), c.end()) == 10); + c.resize(20); + assert(distance(c.begin(), c.end()) == 20); + c.resize(5); + assert(distance(c.begin(), c.end()) == 5); + c.resize(0); + assert(distance(c.begin(), c.end()) == 0); + } + { + typedef int T; + typedef std::forward_list C; + const T t[] = {0, 1, 2, 3, 4}; + C c(std::begin(t), std::end(t)); + + c.resize(3); + assert(distance(c.begin(), c.end()) == 3); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + + c.resize(6); + assert(distance(c.begin(), c.end()) == 6); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 0); + assert(*next(c.begin(), 4) == 0); + assert(*next(c.begin(), 5) == 0); + + c.resize(6); + assert(distance(c.begin(), c.end()) == 6); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 0); + assert(*next(c.begin(), 4) == 0); + assert(*next(c.begin(), 5) == 0); + } +#if __cplusplus >= 201103L + { + typedef DefaultOnly T; + typedef std::forward_list> C; + C c; + c.resize(0); + assert(distance(c.begin(), c.end()) == 0); + c.resize(10); + assert(distance(c.begin(), c.end()) == 10); + c.resize(20); + assert(distance(c.begin(), c.end()) == 20); + c.resize(5); + assert(distance(c.begin(), c.end()) == 5); + c.resize(0); + assert(distance(c.begin(), c.end()) == 0); + } + { + typedef int T; + typedef std::forward_list> C; + const T t[] = {0, 1, 2, 3, 4}; + C c(std::begin(t), std::end(t)); + + c.resize(3); + assert(distance(c.begin(), c.end()) == 3); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + + c.resize(6); + assert(distance(c.begin(), c.end()) == 6); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 0); + assert(*next(c.begin(), 4) == 0); + assert(*next(c.begin(), 5) == 0); + + c.resize(6); + assert(distance(c.begin(), c.end()) == 6); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 0); + assert(*next(c.begin(), 4) == 0); + assert(*next(c.begin(), 5) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/resize_size_value.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/resize_size_value.pass.cpp new file mode 100644 index 00000000000..d4bd6b4e011 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.modifiers/resize_size_value.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void resize(size_type n, const value_type& v); + +#include +#include + +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + const T t[] = {0, 1, 2, 3, 4}; + C c(std::begin(t), std::end(t)); + + c.resize(3, 10); + assert(distance(c.begin(), c.end()) == 3); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + + c.resize(6, 10); + assert(distance(c.begin(), c.end()) == 6); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 10); + assert(*next(c.begin(), 4) == 10); + assert(*next(c.begin(), 5) == 10); + + c.resize(6, 12); + assert(distance(c.begin(), c.end()) == 6); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 10); + assert(*next(c.begin(), 4) == 10); + assert(*next(c.begin(), 5) == 10); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + const T t[] = {0, 1, 2, 3, 4}; + C c(std::begin(t), std::end(t)); + + c.resize(3, 10); + assert(distance(c.begin(), c.end()) == 3); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + + c.resize(6, 10); + assert(distance(c.begin(), c.end()) == 6); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 10); + assert(*next(c.begin(), 4) == 10); + assert(*next(c.begin(), 5) == 10); + + c.resize(6, 12); + assert(distance(c.begin(), c.end()) == 6); + assert(*next(c.begin(), 0) == 0); + assert(*next(c.begin(), 1) == 1); + assert(*next(c.begin(), 2) == 2); + assert(*next(c.begin(), 3) == 10); + assert(*next(c.begin(), 4) == 10); + assert(*next(c.begin(), 5) == 10); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge.pass.cpp new file mode 100644 index 00000000000..3b6f853c84c --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void merge(forward_list&& x); + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {3, 5, 6, 7, 12, 13}; + const T t2[] = {0, 1, 2, 4, 8, 9, 10, 11, 14, 15}; + const T t3[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.merge(c2); + C c3(std::begin(t3), std::end(t3)); + assert(c1 == c3); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {3, 5, 6, 7, 12, 13}; + const T t2[] = {0, 1, 2, 4, 8, 9, 10, 11, 14, 15}; + const T t3[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.merge(c2); + C c3(std::begin(t3), std::end(t3)); + assert(c1 == c3); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_pred.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_pred.pass.cpp new file mode 100644 index 00000000000..7e873bdddd0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/merge_pred.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template void merge(forward_list&& x, Compare comp); + +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {13, 12, 7, 6, 5, 3}; + const T t2[] = {15, 14, 11, 10, 9, 8, 4, 2, 1, 0}; + const T t3[] = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.merge(c2, std::greater()); + C c3(std::begin(t3), std::end(t3)); + assert(c1 == c3); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {13, 12, 7, 6, 5, 3}; + const T t2[] = {15, 14, 11, 10, 9, 8, 4, 2, 1, 0}; + const T t3[] = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.merge(c2, std::greater()); + C c3(std::begin(t3), std::end(t3)); + assert(c1 == c3); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove.pass.cpp new file mode 100644 index 00000000000..18d4cae8cc6 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove.pass.cpp @@ -0,0 +1,155 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void remove(const value_type& v); + +#include +#include +#include + +#include "min_allocator.h" + +struct S { + S(int i) : i_(new int(i)) {} + S(const S &rhs) : i_(new int(*rhs.i_)) {} + S& operator = (const S &rhs) { *i_ = *rhs.i_; return *this; } + ~S () { delete i_; i_ = NULL; } + bool operator == (const S &rhs) const { return *i_ == *rhs.i_; } + int get () const { return *i_; } + int *i_; + }; + + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {0, 5, 5, 0, 0, 0, 5}; + const T t2[] = {5, 5, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.remove(0); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {0, 0, 0, 0}; + C c1(std::begin(t1), std::end(t1)); + C c2; + c1.remove(0); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {5, 5, 5}; + const T t2[] = {5, 5, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.remove(0); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list C; + C c1; + C c2; + c1.remove(0); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {5, 5, 5, 0}; + const T t2[] = {5, 5, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.remove(0); + assert(c1 == c2); + } + { // LWG issue #526 + typedef int T; + typedef std::forward_list C; + int t1[] = {1, 2, 1, 3, 5, 8, 11}; + int t2[] = { 2, 3, 5, 8, 11}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.remove(c1.front()); + assert(c1 == c2); + } + { + typedef S T; + typedef std::forward_list C; + int t1[] = {1, 2, 1, 3, 5, 8, 11, 1}; + int t2[] = { 2, 3, 5, 8, 11 }; + C c; + for(int *ip = std::end(t1); ip != std::begin(t1);) + c.push_front(S(*--ip)); + c.remove(c.front()); + C::const_iterator it = c.begin(); + for(int *ip = std::begin(t2); ip != std::end(t2); ++ip, ++it) { + assert ( it != c.end()); + assert ( *ip == it->get()); + } + assert ( it == c.end ()); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {0, 5, 5, 0, 0, 0, 5}; + const T t2[] = {5, 5, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.remove(0); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {0, 0, 0, 0}; + C c1(std::begin(t1), std::end(t1)); + C c2; + c1.remove(0); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {5, 5, 5}; + const T t2[] = {5, 5, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.remove(0); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list> C; + C c1; + C c2; + c1.remove(0); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {5, 5, 5, 0}; + const T t2[] = {5, 5, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.remove(0); + assert(c1 == c2); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove_if.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove_if.pass.cpp new file mode 100644 index 00000000000..ed408fbd685 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/remove_if.pass.cpp @@ -0,0 +1,155 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template void remove_if(Predicate pred); + +#include +#include +#include + +#include "min_allocator.h" +#include "counting_predicates.hpp" + + +bool g(int i) +{ + return i < 3; +} + +int main() +{ + { + typedef int T; + typedef unary_counting_predicate Predicate; + typedef std::forward_list C; + const T t1[] = {0, 5, 5, 0, 0, 0, 5}; + const T t2[] = {5, 5, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == std::distance(std::begin(t1), std::end(t1))); + } + { + typedef int T; + typedef unary_counting_predicate Predicate; + typedef std::forward_list C; + const T t1[] = {0, 0, 0, 0}; + C c1(std::begin(t1), std::end(t1)); + C c2; + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == std::distance(std::begin(t1), std::end(t1))); + } + { + typedef int T; + typedef unary_counting_predicate Predicate; + typedef std::forward_list C; + const T t1[] = {5, 5, 5}; + const T t2[] = {5, 5, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == std::distance(std::begin(t1), std::end(t1))); + } + { + typedef int T; + typedef unary_counting_predicate Predicate; + typedef std::forward_list C; + C c1; + C c2; + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == 0); + } + { + typedef int T; + typedef unary_counting_predicate Predicate; + typedef std::forward_list C; + const T t1[] = {5, 5, 5, 0}; + const T t2[] = {5, 5, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == std::distance(std::begin(t1), std::end(t1))); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef unary_counting_predicate Predicate; + typedef std::forward_list> C; + const T t1[] = {0, 5, 5, 0, 0, 0, 5}; + const T t2[] = {5, 5, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == std::distance(std::begin(t1), std::end(t1))); + } + { + typedef int T; + typedef unary_counting_predicate Predicate; + typedef std::forward_list> C; + const T t1[] = {0, 0, 0, 0}; + C c1(std::begin(t1), std::end(t1)); + C c2; + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == std::distance(std::begin(t1), std::end(t1))); + } + { + typedef int T; + typedef unary_counting_predicate Predicate; + typedef std::forward_list> C; + const T t1[] = {5, 5, 5}; + const T t2[] = {5, 5, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == std::distance(std::begin(t1), std::end(t1))); + } + { + typedef int T; + typedef unary_counting_predicate Predicate; + typedef std::forward_list> C; + C c1; + C c2; + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == 0); + } + { + typedef int T; + typedef unary_counting_predicate Predicate; + typedef std::forward_list> C; + const T t1[] = {5, 5, 5, 0}; + const T t2[] = {5, 5, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + Predicate cp(g); + c1.remove_if(std::ref(cp)); + assert(c1 == c2); + assert(cp.count() == std::distance(std::begin(t1), std::end(t1))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/reverse.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/reverse.pass.cpp new file mode 100644 index 00000000000..9bf0d03a885 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/reverse.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void reverse(); + +#include +#include +#include +#include + +#include "min_allocator.h" + +template +void test(int N) +{ + C c; + for (int i = 0; i < N; ++i) + c.push_front(i); + c.reverse(); + assert(distance(c.begin(), c.end()) == N); + typename C::const_iterator j = c.begin(); + for (int i = 0; i < N; ++i, ++j) + assert(*j == i); +} + +int main() +{ + for (int i = 0; i < 10; ++i) + test >(i); +#if __cplusplus >= 201103L + for (int i = 0; i < 10; ++i) + test> >(i); +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort.pass.cpp new file mode 100644 index 00000000000..06e40c595ec --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void sort(); + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +template +void test(int N) +{ + typedef typename C::value_type T; + typedef std::vector V; + V v; + for (int i = 0; i < N; ++i) + v.push_back(i); + std::random_shuffle(v.begin(), v.end()); + C c(v.begin(), v.end()); + c.sort(); + assert(distance(c.begin(), c.end()) == N); + typename C::const_iterator j = c.begin(); + for (int i = 0; i < N; ++i, ++j) + assert(*j == i); +} + +int main() +{ + for (int i = 0; i < 40; ++i) + test >(i); +#if __cplusplus >= 201103L + for (int i = 0; i < 40; ++i) + test> >(i); +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort_pred.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort_pred.pass.cpp new file mode 100644 index 00000000000..8b6ca39b2aa --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/sort_pred.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template void sort(Compare comp); + +#include +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +template +void test(int N) +{ + typedef typename C::value_type T; + typedef std::vector V; + V v; + for (int i = 0; i < N; ++i) + v.push_back(i); + std::random_shuffle(v.begin(), v.end()); + C c(v.begin(), v.end()); + c.sort(std::greater()); + assert(distance(c.begin(), c.end()) == N); + typename C::const_iterator j = c.begin(); + for (int i = 0; i < N; ++i, ++j) + assert(*j == N-1-i); +} + +int main() +{ + for (int i = 0; i < 40; ++i) + test >(i); +#if __cplusplus >= 201103L + for (int i = 0; i < 40; ++i) + test> >(i); +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp new file mode 100644 index 00000000000..51da651970c --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_flist.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void splice_after(const_iterator p, forward_list&& x); + +#include +#include +#include + +#include "min_allocator.h" + +typedef int T; +const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7}; +const T t2[] = {10, 11, 12, 13, 14, 15}; +const int size_t1 = std::end(t1) - std::begin(t1); +const int size_t2 = std::end(t2) - std::begin(t2); + +template +void +testd(const C& c, int p, int l) +{ + typename C::const_iterator i = c.begin(); + int n1 = 0; + for (; n1 < p; ++n1, ++i) + assert(*i == t1[n1]); + for (int n2 = 0; n2 < l; ++n2, ++i) + assert(*i == t2[n2]); + for (; n1 < size_t1; ++n1, ++i) + assert(*i == t1[n1]); + assert(distance(c.begin(), c.end()) == size_t1 + l); +} + +int main() +{ + { + // splicing different containers + typedef std::forward_list C; + for (int l = 0; l <= size_t2; ++l) + { + for (int p = 0; p <= size_t1; ++p) + { + C c1(std::begin(t1), std::end(t1)); + C c2(t2, t2+l); + + c1.splice_after(next(c1.cbefore_begin(), p), std::move(c2)); + testd(c1, p, l); + } + } + } +#if __cplusplus >= 201103L + { + // splicing different containers + typedef std::forward_list> C; + for (int l = 0; l <= size_t2; ++l) + { + for (int p = 0; p <= size_t1; ++p) + { + C c1(std::begin(t1), std::end(t1)); + C c2(t2, t2+l); + + c1.splice_after(next(c1.cbefore_begin(), p), std::move(c2)); + testd(c1, p, l); + } + } + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp new file mode 100644 index 00000000000..296ffcd6955 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_one.pass.cpp @@ -0,0 +1,140 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void splice_after(const_iterator p, forward_list&& x, const_iterator i); + +#include +#include +#include + +#include "min_allocator.h" + +typedef int T; +const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7}; +const T t2[] = {10, 11, 12}; +const int size_t1 = std::end(t1) - std::begin(t1); +const int size_t2 = std::end(t2) - std::begin(t2); + +template +void +testd(const C& c, int p, int f) +{ + typename C::const_iterator i = c.begin(); + int n1 = 0; + for (; n1 < p; ++n1, ++i) + assert(*i == t1[n1]); + for (int n2 = f; n2 < f+1; ++n2, ++i) + assert(*i == t2[n2]); + for (; n1 < size_t1; ++n1, ++i) + assert(*i == t1[n1]); + assert(distance(c.begin(), c.end()) == size_t1 + 1); +} + +template +void +tests(const C& c, int p, int f) +{ + typename C::const_iterator i = c.begin(); + int n = 0; + int d = 1; + if (p == f || p == f+1) + { + for (n = 0; n < size_t1; ++n, ++i) + assert(*i == t1[n]); + } + else if (p < f) + { + for (n = 0; n < p; ++n, ++i) + assert(*i == t1[n]); + for (n = f; n < f+1; ++n, ++i) + assert(*i == t1[n]); + for (n = p; n < f; ++n, ++i) + assert(*i == t1[n]); + for (n = f+1; n < size_t1; ++n, ++i) + assert(*i == t1[n]); + } + else // p > f+1 + { + for (n = 0; n < f; ++n, ++i) + assert(*i == t1[n]); + for (n = f+1; n < p; ++n, ++i) + assert(*i == t1[n]); + for (n = f; n < f+1; ++n, ++i) + assert(*i == t1[n]); + for (n = p; n < size_t1; ++n, ++i) + assert(*i == t1[n]); + } + assert(distance(c.begin(), c.end()) == size_t1); +} + +int main() +{ + { + // splicing different containers + typedef std::forward_list C; + for (int f = 0; f <= size_t2-1; ++f) + { + for (int p = 0; p <= size_t1; ++p) + { + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + + c1.splice_after(next(c1.cbefore_begin(), p), std::move(c2), + next(c2.cbefore_begin(), f)); + testd(c1, p, f); + } + } + + // splicing within same container + for (int f = 0; f <= size_t1-1; ++f) + { + for (int p = 0; p <= size_t1; ++p) + { + C c1(std::begin(t1), std::end(t1)); + + c1.splice_after(next(c1.cbefore_begin(), p), std::move(c1), + next(c1.cbefore_begin(), f)); + tests(c1, p, f); + } + } + } +#if __cplusplus >= 201103L + { + // splicing different containers + typedef std::forward_list> C; + for (int f = 0; f <= size_t2-1; ++f) + { + for (int p = 0; p <= size_t1; ++p) + { + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + + c1.splice_after(next(c1.cbefore_begin(), p), std::move(c2), + next(c2.cbefore_begin(), f)); + testd(c1, p, f); + } + } + + // splicing within same container + for (int f = 0; f <= size_t1-1; ++f) + { + for (int p = 0; p <= size_t1; ++p) + { + C c1(std::begin(t1), std::end(t1)); + + c1.splice_after(next(c1.cbefore_begin(), p), std::move(c1), + next(c1.cbefore_begin(), f)); + tests(c1, p, f); + } + } + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_range.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_range.pass.cpp new file mode 100644 index 00000000000..90a15995963 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/splice_after_range.pass.cpp @@ -0,0 +1,169 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void splice_after(const_iterator p, forward_list&& x, +// const_iterator first, const_iterator last); + +#include +#include +#include + +#include "min_allocator.h" + +typedef int T; +const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7}; +const T t2[] = {10, 11, 12, 13, 14, 15}; +const int size_t1 = std::end(t1) - std::begin(t1); +const int size_t2 = std::end(t2) - std::begin(t2); + +template +void +testd(const C& c, int p, int f, int l) +{ + typename C::const_iterator i = c.begin(); + int n1 = 0; + for (; n1 < p; ++n1, ++i) + assert(*i == t1[n1]); + for (int n2 = f; n2 < l-1; ++n2, ++i) + assert(*i == t2[n2]); + for (; n1 < size_t1; ++n1, ++i) + assert(*i == t1[n1]); + assert(distance(c.begin(), c.end()) == size_t1 + (l > f+1 ? l-1-f : 0)); +} + +template +void +tests(const C& c, int p, int f, int l) +{ + typename C::const_iterator i = c.begin(); + int n = 0; + int d = l > f+1 ? l-1-f : 0; + if (d == 0 || p == f) + { + for (n = 0; n < size_t1; ++n, ++i) + assert(*i == t1[n]); + } + else if (p < f) + { + for (n = 0; n < p; ++n, ++i) + assert(*i == t1[n]); + for (n = f; n < l-1; ++n, ++i) + assert(*i == t1[n]); + for (n = p; n < f; ++n, ++i) + assert(*i == t1[n]); + for (n = l-1; n < size_t1; ++n, ++i) + assert(*i == t1[n]); + } + else // p > f + { + for (n = 0; n < f; ++n, ++i) + assert(*i == t1[n]); + for (n = l-1; n < p; ++n, ++i) + assert(*i == t1[n]); + for (n = f; n < l-1; ++n, ++i) + assert(*i == t1[n]); + for (n = p; n < size_t1; ++n, ++i) + assert(*i == t1[n]); + } + assert(distance(c.begin(), c.end()) == size_t1); +} + +int main() +{ + { + // splicing different containers + typedef std::forward_list C; + for (int f = 0; f <= size_t2+1; ++f) + { + for (int l = f; l <= size_t2+1; ++l) + { + for (int p = 0; p <= size_t1; ++p) + { + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + + c1.splice_after(next(c1.cbefore_begin(), p), std::move(c2), + next(c2.cbefore_begin(), f), next(c2.cbefore_begin(), l)); + testd(c1, p, f, l); + } + } + } + + // splicing within same container + for (int f = 0; f <= size_t1+1; ++f) + { + for (int l = f; l <= size_t1; ++l) + { + for (int p = 0; p <= f; ++p) + { + C c1(std::begin(t1), std::end(t1)); + + c1.splice_after(next(c1.cbefore_begin(), p), std::move(c1), + next(c1.cbefore_begin(), f), next(c1.cbefore_begin(), l)); + tests(c1, p, f, l); + } + for (int p = l; p <= size_t1; ++p) + { + C c1(std::begin(t1), std::end(t1)); + + c1.splice_after(next(c1.cbefore_begin(), p), std::move(c1), + next(c1.cbefore_begin(), f), next(c1.cbefore_begin(), l)); + tests(c1, p, f, l); + } + } + } + } +#if __cplusplus >= 201103L + { + // splicing different containers + typedef std::forward_list> C; + for (int f = 0; f <= size_t2+1; ++f) + { + for (int l = f; l <= size_t2+1; ++l) + { + for (int p = 0; p <= size_t1; ++p) + { + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + + c1.splice_after(next(c1.cbefore_begin(), p), std::move(c2), + next(c2.cbefore_begin(), f), next(c2.cbefore_begin(), l)); + testd(c1, p, f, l); + } + } + } + + // splicing within same container + for (int f = 0; f <= size_t1+1; ++f) + { + for (int l = f; l <= size_t1; ++l) + { + for (int p = 0; p <= f; ++p) + { + C c1(std::begin(t1), std::end(t1)); + + c1.splice_after(next(c1.cbefore_begin(), p), std::move(c1), + next(c1.cbefore_begin(), f), next(c1.cbefore_begin(), l)); + tests(c1, p, f, l); + } + for (int p = l; p <= size_t1; ++p) + { + C c1(std::begin(t1), std::end(t1)); + + c1.splice_after(next(c1.cbefore_begin(), p), std::move(c1), + next(c1.cbefore_begin(), f), next(c1.cbefore_begin(), l)); + tests(c1, p, f, l); + } + } + } + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/unique.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/unique.pass.cpp new file mode 100644 index 00000000000..25db6e64b8a --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/unique.pass.cpp @@ -0,0 +1,120 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void unique(); + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {0, 5, 5, 0, 0, 0, 5}; + const T t2[] = {0, 5, 0, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {0, 0, 0, 0}; + const T t2[] = {0}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {5, 5, 5}; + const T t2[] = {5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list C; + C c1; + C c2; + c1.unique(); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {5, 5, 5, 0}; + const T t2[] = {5, 0}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(); + assert(c1 == c2); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {0, 5, 5, 0, 0, 0, 5}; + const T t2[] = {0, 5, 0, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {0, 0, 0, 0}; + const T t2[] = {0}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {5, 5, 5}; + const T t2[] = {5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list> C; + C c1; + C c2; + c1.unique(); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {5, 5, 5, 0}; + const T t2[] = {5, 0}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(); + assert(c1 == c2); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/unique_pred.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/unique_pred.pass.cpp new file mode 100644 index 00000000000..b7dce20b709 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.ops/unique_pred.pass.cpp @@ -0,0 +1,125 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template void unique(BinaryPredicate binary_pred); + +#include +#include +#include + +#include "min_allocator.h" + +bool g(int x, int y) +{ + return x == y; +} + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {0, 5, 5, 0, 0, 0, 5}; + const T t2[] = {0, 5, 0, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(g); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {0, 0, 0, 0}; + const T t2[] = {0}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(g); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {5, 5, 5}; + const T t2[] = {5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(g); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list C; + C c1; + C c2; + c1.unique(g); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list C; + const T t1[] = {5, 5, 5, 0}; + const T t2[] = {5, 0}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(g); + assert(c1 == c2); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {0, 5, 5, 0, 0, 0, 5}; + const T t2[] = {0, 5, 0, 5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(g); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {0, 0, 0, 0}; + const T t2[] = {0}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(g); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {5, 5, 5}; + const T t2[] = {5}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(g); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list> C; + C c1; + C c2; + c1.unique(g); + assert(c1 == c2); + } + { + typedef int T; + typedef std::forward_list> C; + const T t1[] = {5, 5, 5, 0}; + const T t2[] = {5, 0}; + C c1(std::begin(t1), std::end(t1)); + C c2(std::begin(t2), std::end(t2)); + c1.unique(g); + assert(c1 == c2); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/equal.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/equal.pass.cpp new file mode 100644 index 00000000000..ca673b58368 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/equal.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// bool operator==(const forward_list& x, +// const forward_list& y); +// +// template +// bool operator!=(const forward_list& x, +// const forward_list& y); + +#include +#include +#include +#include + +#include "min_allocator.h" + +template +void test(int N, int M) +{ + typedef typename C::value_type T; + C c1; + for (int i = 0; i < N; ++i) + c1.push_front(i); + C c2; + for (int i = 0; i < M; ++i) + c2.push_front(i); + if (N == M) + assert(c1 == c2); + else + assert(c1 != c2); + c2 = c1; + assert(c1 == c2); + if (N > 0) + { + c2.front() = N+1; + assert(c1 != c2); + } +} + +int main() +{ + for (int i = 0; i < 10; ++i) + for (int j = 0; j < 10; ++j) + test >(i, j); +#if __cplusplus >= 201103L + for (int i = 0; i < 10; ++i) + for (int j = 0; j < 10; ++j) + test> >(i, j); +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/member_swap.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/member_swap.pass.cpp new file mode 100644 index 00000000000..2b2be7b6c22 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/member_swap.pass.cpp @@ -0,0 +1,259 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(forward_list& x); + +#include +#include + +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef test_allocator A; + typedef std::forward_list C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A(1)); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A(2)); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A(1)); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A(2)); + } + { + typedef int T; + typedef test_allocator A; + typedef std::forward_list C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A(1)); + C c2(A(2)); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A(1)); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A(2)); + } + { + typedef int T; + typedef test_allocator A; + typedef std::forward_list C; + C c1(A(1)); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A(2)); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A(1)); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A(2)); + } + { + typedef int T; + typedef test_allocator A; + typedef std::forward_list C; + C c1(A(1)); + C c2(A(2)); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A(1)); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A(2)); + } + + { + typedef int T; + typedef other_allocator A; + typedef std::forward_list C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A(1)); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A(2)); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A(2)); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A(1)); + } + { + typedef int T; + typedef other_allocator A; + typedef std::forward_list C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A(1)); + C c2(A(2)); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A(2)); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A(1)); + } + { + typedef int T; + typedef other_allocator A; + typedef std::forward_list C; + C c1(A(1)); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A(2)); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A(2)); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A(1)); + } + { + typedef int T; + typedef other_allocator A; + typedef std::forward_list C; + C c1(A(1)); + C c2(A(2)); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A(2)); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A(1)); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef min_allocator A; + typedef std::forward_list C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A()); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A()); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A()); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A()); + } + { + typedef int T; + typedef min_allocator A; + typedef std::forward_list C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A()); + C c2(A{}); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A()); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A()); + } + { + typedef int T; + typedef min_allocator A; + typedef std::forward_list C; + C c1(A{}); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A()); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A()); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A()); + } + { + typedef int T; + typedef min_allocator A; + typedef std::forward_list C; + C c1(A{}); + C c2(A{}); + c1.swap(c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A()); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/non_member_swap.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/non_member_swap.pass.cpp new file mode 100644 index 00000000000..d6ba5a47cbe --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/non_member_swap.pass.cpp @@ -0,0 +1,260 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// void swap(forward_list& x, forward_list& y); + +#include +#include + +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef test_allocator A; + typedef std::forward_list C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A(1)); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A(2)); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A(1)); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A(2)); + } + { + typedef int T; + typedef test_allocator A; + typedef std::forward_list C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A(1)); + C c2(A(2)); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A(1)); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A(2)); + } + { + typedef int T; + typedef test_allocator A; + typedef std::forward_list C; + C c1(A(1)); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A(2)); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A(1)); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A(2)); + } + { + typedef int T; + typedef test_allocator A; + typedef std::forward_list C; + C c1(A(1)); + C c2(A(2)); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A(1)); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A(2)); + } + + { + typedef int T; + typedef other_allocator A; + typedef std::forward_list C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A(1)); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A(2)); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A(2)); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A(1)); + } + { + typedef int T; + typedef other_allocator A; + typedef std::forward_list C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A(1)); + C c2(A(2)); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A(2)); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A(1)); + } + { + typedef int T; + typedef other_allocator A; + typedef std::forward_list C; + C c1(A(1)); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A(2)); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A(2)); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A(1)); + } + { + typedef int T; + typedef other_allocator A; + typedef std::forward_list C; + C c1(A(1)); + C c2(A(2)); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A(2)); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A(1)); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef min_allocator A; + typedef std::forward_list C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A()); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A()); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A()); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A()); + } + { + typedef int T; + typedef min_allocator A; + typedef std::forward_list C; + const T t1[] = {0, 1, 2, 3, 4, 5}; + C c1(std::begin(t1), std::end(t1), A()); + C c2(A{}); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A()); + + assert(distance(c2.begin(), c2.end()) == 6); + assert(*next(c2.begin(), 0) == 0); + assert(*next(c2.begin(), 1) == 1); + assert(*next(c2.begin(), 2) == 2); + assert(*next(c2.begin(), 3) == 3); + assert(*next(c2.begin(), 4) == 4); + assert(*next(c2.begin(), 5) == 5); + assert(c2.get_allocator() == A()); + } + { + typedef int T; + typedef min_allocator A; + typedef std::forward_list C; + C c1(A{}); + const T t2[] = {10, 11, 12}; + C c2(std::begin(t2), std::end(t2), A()); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 3); + assert(*next(c1.begin(), 0) == 10); + assert(*next(c1.begin(), 1) == 11); + assert(*next(c1.begin(), 2) == 12); + assert(c1.get_allocator() == A()); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A()); + } + { + typedef int T; + typedef min_allocator A; + typedef std::forward_list C; + C c1(A{}); + C c2(A{}); + swap(c1, c2); + + assert(distance(c1.begin(), c1.end()) == 0); + assert(c1.get_allocator() == A()); + + assert(distance(c2.begin(), c2.end()) == 0); + assert(c2.get_allocator() == A()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/relational.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/relational.pass.cpp new file mode 100644 index 00000000000..42e245d007b --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/relational.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// bool operator< (const forward_list& x, +// const forward_list& y); +// +// template +// bool operator> (const forward_list& x, +// const forward_list& y); +// +// template +// bool operator>=(const forward_list& x, +// const forward_list& y); +// +// template +// bool operator<=(const forward_list& x, +// const forward_list& y); + +#include +#include +#include +#include + +#include "min_allocator.h" + +template +void test(int N, int M) +{ + typedef typename C::value_type T; + C c1; + for (int i = 0; i < N; ++i) + c1.push_front(i); + C c2; + for (int i = 0; i < M; ++i) + c2.push_front(i); + if (N < M) + assert(c1 < c2); + if (N <= M) + assert(c1 <= c2); + if (N >= M) + assert(c1 >= c2); + if (N > M) + assert(c1 > c2); +} + +int main() +{ + for (int i = 0; i < 10; ++i) + for (int j = 0; j < 10; ++j) + test >(i, j); +#if __cplusplus >= 201103L + for (int i = 0; i < 10; ++i) + for (int j = 0; j < 10; ++j) + test> >(i, j); +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/swap_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..cde97d5f738 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/forwardlist.spec/swap_noexcept.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(forward_list& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + + some_alloc() {} + some_alloc(const some_alloc&); + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::forward_list C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::forward_list> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::forward_list> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::forward_list> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/max_size.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/max_size.pass.cpp new file mode 100644 index 00000000000..be7ebaf44b0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/max_size.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// size_type max_size() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::forward_list C; + C c; + assert(c.max_size() > 0); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::forward_list> C; + C c; + assert(c.max_size() > 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/types.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/types.pass.cpp new file mode 100644 index 00000000000..c95548710bc --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/types.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template > +// class forward_list +// { +// public: +// typedef T value_type; +// typedef Allocator allocator_type; +// +// typedef value_type& reference; +// typedef const value_type& const_reference; +// typedef typename allocator_traits::pointer pointer; +// typedef typename allocator_traits::const_pointer const_pointer; +// typedef typename allocator_traits::size_type size_type; +// typedef typename allocator_traits::difference_type difference_type; +// ... +// }; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::forward_list C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + } +#if __cplusplus >= 201103L + { + typedef std::forward_list> C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same>::value), ""); + static_assert((std::is_same>::value), ""); +// min_allocator doesn't have a size_type, so one gets synthesized + static_assert((std::is_same::type>::value), ""); + static_assert((std::is_same::value), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/forwardlist/version.pass.cpp b/libcxx/test/std/containers/sequences/forwardlist/version.pass.cpp new file mode 100644 index 00000000000..918c8dd5d73 --- /dev/null +++ b/libcxx/test/std/containers/sequences/forwardlist/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +#include + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/list/db_back.pass.cpp b/libcxx/test/std/containers/sequences/list/db_back.pass.cpp new file mode 100644 index 00000000000..b16c0e90701 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/db_back.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call back() on empty container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::list C; + C c(1); + assert(c.back() == 0); + c.clear(); + assert(c.back() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::list> C; + C c(1); + assert(c.back() == 0); + c.clear(); + assert(c.back() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/db_cback.pass.cpp b/libcxx/test/std/containers/sequences/list/db_cback.pass.cpp new file mode 100644 index 00000000000..ba3977e16f4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/db_cback.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call back() on empty const container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::list C; + const C c; + assert(c.back() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::list> C; + const C c; + assert(c.back() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/db_cfront.pass.cpp b/libcxx/test/std/containers/sequences/list/db_cfront.pass.cpp new file mode 100644 index 00000000000..d42290c43c0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/db_cfront.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call front() on empty const container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::list C; + const C c; + assert(c.front() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::list> C; + const C c; + assert(c.front() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/db_front.pass.cpp b/libcxx/test/std/containers/sequences/list/db_front.pass.cpp new file mode 100644 index 00000000000..037b16035c6 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/db_front.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call front() on empty container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::list C; + C c(1); + assert(c.front() == 0); + c.clear(); + assert(c.front() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::list> C; + C c(1); + assert(c.front() == 0); + c.clear(); + assert(c.front() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/db_iterators_6.pass.cpp b/libcxx/test/std/containers/sequences/list/db_iterators_6.pass.cpp new file mode 100644 index 00000000000..a5b8020b373 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/db_iterators_6.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Decrement iterator prior to begin. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::list C; + C c(1); + C::iterator i = c.end(); + --i; + assert(i == c.begin()); + --i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::list> C; + C c(1); + C::iterator i = c.end(); + --i; + assert(i == c.begin()); + --i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/db_iterators_7.pass.cpp b/libcxx/test/std/containers/sequences/list/db_iterators_7.pass.cpp new file mode 100644 index 00000000000..76a491b1184 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/db_iterators_7.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Increment iterator past end. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::list C; + C c(1); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::list> C; + C c(1); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/db_iterators_8.pass.cpp b/libcxx/test/std/containers/sequences/list/db_iterators_8.pass.cpp new file mode 100644 index 00000000000..1d1ee23a393 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/db_iterators_8.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Dereference non-dereferenceable iterator. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::list C; + C c(1); + C::iterator i = c.end(); + T j = *i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::list> C; + C c(1); + C::iterator i = c.end(); + T j = *i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/db_iterators_9.pass.cpp b/libcxx/test/std/containers/sequences/list/db_iterators_9.pass.cpp new file mode 100644 index 00000000000..d02fcd6e449 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/db_iterators_9.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Operations on "NULL" iterators + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) do { if (!x) throw 1; } while(0) + +#include +#include +#include +#include +#include + +struct S { int val; }; + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + unsigned lib_asserts; + + typedef S T; + typedef std::list C; + C::iterator i{}; + C::const_iterator ci{}; + + lib_asserts = 0; + try { ++i; } catch (int) { ++lib_asserts; } + try { i++; } catch (int) { ++lib_asserts; } + try { ++ci; } catch (int) { ++lib_asserts; } + try { ci++; } catch (int) { ++lib_asserts; } + assert(lib_asserts == 4); + + lib_asserts = 0; + try { --i; } catch (int) { ++lib_asserts; } + try { i--; } catch (int) { ++lib_asserts; } + try { --ci; } catch (int) { ++lib_asserts; } + try { ci--; } catch (int) { ++lib_asserts; } + assert(lib_asserts == 4); + + lib_asserts = 0; + try { *i; } catch (int) { ++lib_asserts; } + try { *ci; } catch (int) { ++lib_asserts; } + try { (void) i->val; } catch (int) { ++lib_asserts; } + try { (void) ci->val; } catch (int) { ++lib_asserts; } + assert(lib_asserts == 4); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/iterators.pass.cpp b/libcxx/test/std/containers/sequences/list/iterators.pass.cpp new file mode 100644 index 00000000000..a33ee3ecd2d --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/iterators.pass.cpp @@ -0,0 +1,159 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator begin(); +// iterator end(); +// const_iterator begin() const; +// const_iterator end() const; +// const_iterator cbegin() const; +// const_iterator cend() const; + +#include +#include +#include + +#include "min_allocator.h" + +struct A +{ + int first; + int second; +}; + +int main() +{ + { + typedef int T; + typedef std::list C; + C c; + C::iterator i = c.begin(); + C::iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef int T; + typedef std::list C; + const C c; + C::const_iterator i = c.begin(); + C::const_iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef int T; + typedef std::list C; + C c; + C::const_iterator i = c.cbegin(); + C::const_iterator j = c.cend(); + assert(std::distance(i, j) == 0); + assert(i == j); + assert(i == c.end()); + } + { + typedef int T; + typedef std::list C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + C::iterator i = c.begin(); + assert(*i == 0); + ++i; + assert(*i == 1); + *i = 10; + assert(*i == 10); + assert(std::distance(c.begin(), c.end()) == 10); + } + { + typedef int T; + typedef std::list C; + C::iterator i; + C::const_iterator j; + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::list> C; + C c; + C::iterator i = c.begin(); + C::iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef int T; + typedef std::list> C; + const C c; + C::const_iterator i = c.begin(); + C::const_iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef int T; + typedef std::list> C; + C c; + C::const_iterator i = c.cbegin(); + C::const_iterator j = c.cend(); + assert(std::distance(i, j) == 0); + assert(i == j); + assert(i == c.end()); + } + { + typedef int T; + typedef std::list> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + C::iterator i = c.begin(); + assert(*i == 0); + ++i; + assert(*i == 1); + *i = 10; + assert(*i == 10); + assert(std::distance(c.begin(), c.end()) == 10); + } + { + typedef int T; + typedef std::list> C; + C::iterator i; + C::const_iterator j; + } + { + typedef A T; + typedef std::list> C; + C c = {A{1, 2}}; + C::iterator i = c.begin(); + i->first = 3; + C::const_iterator j = i; + assert(j->first == 3); + } +#endif +#if _LIBCPP_STD_VER > 11 + { + std::list c; + std::list::iterator ii1{}, ii2{}; + std::list::iterator ii4 = ii1; + std::list::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + + assert ( ii1 != c.cbegin()); + assert ( cii != c.begin()); + } +#endif + +} diff --git a/libcxx/test/std/containers/sequences/list/list.capacity/resize_size.pass.cpp b/libcxx/test/std/containers/sequences/list/list.capacity/resize_size.pass.cpp new file mode 100644 index 00000000000..14629b173a6 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.capacity/resize_size.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void resize(size_type sz); + +#include +#include +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ + { + std::list l(5, 2); + l.resize(2); + assert(l.size() == 2); + assert(std::distance(l.begin(), l.end()) == 2); + assert(l == std::list(2, 2)); + } + { + std::list l(5, 2); + l.resize(10); + assert(l.size() == 10); + assert(std::distance(l.begin(), l.end()) == 10); + assert(l.front() == 2); + assert(l.back() == 0); + } +#ifdef __LIBCPP_MOVE + { + std::list l(10); + l.resize(5); + assert(l.size() == 5); + assert(std::distance(l.begin(), l.end()) == 5); + } + { + std::list l(10); + l.resize(20); + assert(l.size() == 20); + assert(std::distance(l.begin(), l.end()) == 20); + } +#endif // __LIBCPP_MOVE +#if __cplusplus >= 201103L + { + std::list> l(5, 2); + l.resize(2); + assert(l.size() == 2); + assert(std::distance(l.begin(), l.end()) == 2); + assert((l == std::list>(2, 2))); + } + { + std::list> l(5, 2); + l.resize(10); + assert(l.size() == 10); + assert(std::distance(l.begin(), l.end()) == 10); + assert(l.front() == 2); + assert(l.back() == 0); + } +#ifdef __LIBCPP_MOVE + { + std::list> l(10); + l.resize(5); + assert(l.size() == 5); + assert(std::distance(l.begin(), l.end()) == 5); + } + { + std::list> l(10); + l.resize(20); + assert(l.size() == 20); + assert(std::distance(l.begin(), l.end()) == 20); + } +#endif // __LIBCPP_MOVE +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.capacity/resize_size_value.pass.cpp b/libcxx/test/std/containers/sequences/list/list.capacity/resize_size_value.pass.cpp new file mode 100644 index 00000000000..2738ffbbefd --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.capacity/resize_size_value.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void resize(size_type sz, const value_type& x); + +#include +#include +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ + { + std::list l(5, 2); + l.resize(2, 3.5); + assert(l.size() == 2); + assert(std::distance(l.begin(), l.end()) == 2); + assert(l == std::list(2, 2)); + } + { + std::list l(5, 2); + l.resize(10, 3.5); + assert(l.size() == 10); + assert(std::distance(l.begin(), l.end()) == 10); + assert(l.front() == 2); + assert(l.back() == 3.5); + } +#if __cplusplus >= 201103L + { + std::list> l(5, 2); + l.resize(2, 3.5); + assert(l.size() == 2); + assert(std::distance(l.begin(), l.end()) == 2); + assert((l == std::list>(2, 2))); + } + { + std::list> l(5, 2); + l.resize(10, 3.5); + assert(l.size() == 10); + assert(std::distance(l.begin(), l.end()) == 10); + assert(l.front() == 2); + assert(l.back() == 3.5); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/assign_copy.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/assign_copy.pass.cpp new file mode 100644 index 00000000000..b851eb9dc5a --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/assign_copy.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// list& operator=(const list& c); + +#include +#include +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + std::list > l(3, 2, test_allocator(5)); + std::list > l2(l, test_allocator(3)); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == test_allocator(3)); + } + { + std::list > l(3, 2, other_allocator(5)); + std::list > l2(l, other_allocator(3)); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == other_allocator(5)); + } +#if __cplusplus >= 201103L + { + std::list > l(3, 2, min_allocator()); + std::list > l2(l, min_allocator()); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == min_allocator()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..24bd140c4e4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void assign(initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::list d; + d.assign({3, 4, 5, 6}); + assert(d.size() == 4); + std::list::iterator i = d.begin(); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); + } +#if __cplusplus >= 201103L + { + std::list> d; + d.assign({3, 4, 5, 6}); + assert(d.size() == 4); + std::list>::iterator i = d.begin(); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/assign_move.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/assign_move.pass.cpp new file mode 100644 index 00000000000..99f0a98204f --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/assign_move.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// list& operator=(list&& c); + +#include +#include +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::list > l(test_allocator(5)); + std::list > lo(test_allocator(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list > l2(test_allocator(5)); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } + { + std::list > l(test_allocator(5)); + std::list > lo(test_allocator(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list > l2(test_allocator(6)); + l2 = std::move(l); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == test_allocator(6)); + } + { + std::list > l(other_allocator(5)); + std::list > lo(other_allocator(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list > l2(other_allocator(6)); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } +#if __cplusplus >= 201103L + { + std::list > l(min_allocator{}); + std::list > lo(min_allocator{}); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list > l2(min_allocator{}); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/copy.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/copy.pass.cpp new file mode 100644 index 00000000000..530690a925d --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/copy.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// list(const list& c); + +#include +#include +#include "DefaultOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + std::list l(3, 2); + std::list l2 = l; + assert(l2 == l); + } + { + std::list > l(3, 2, test_allocator(5)); + std::list > l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == l.get_allocator()); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + std::list > l(3, 2, other_allocator(5)); + std::list > l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == other_allocator(-2)); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + std::list> l(3, 2); + std::list> l2 = l; + assert(l2 == l); + } + { + std::list > l(3, 2, min_allocator()); + std::list > l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == l.get_allocator()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/copy_alloc.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..99fe9f115f9 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/copy_alloc.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// list(const list& c, const allocator_type& a); + +#include +#include +#include "DefaultOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + std::list > l(3, 2, test_allocator(5)); + std::list > l2(l, test_allocator(3)); + assert(l2 == l); + assert(l2.get_allocator() == test_allocator(3)); + } + { + std::list > l(3, 2, other_allocator(5)); + std::list > l2(l, other_allocator(3)); + assert(l2 == l); + assert(l2.get_allocator() == other_allocator(3)); + } +#if __cplusplus >= 201103L + { + std::list > l(3, 2, min_allocator()); + std::list > l2(l, min_allocator()); + assert(l2 == l); + assert(l2.get_allocator() == min_allocator()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/default.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/default.pass.cpp new file mode 100644 index 00000000000..c05bd74ca79 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/default.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// explicit list(const Alloc& = Alloc()); + +#include +#include +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ + { + std::list l; + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } + { + std::list l; + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } + { + std::list l((std::allocator())); + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } +#if __cplusplus >= 201103L + { + std::list> l; + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } + { + std::list> l; + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } + { + std::list> l((min_allocator())); + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } + { + std::list l = {}; + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/default_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/default_noexcept.pass.cpp new file mode 100644 index 00000000000..f821fb4e7bb --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/default_noexcept.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// list() +// noexcept(is_nothrow_default_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::list C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::list> C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::list> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::list> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/default_stack_alloc.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/default_stack_alloc.pass.cpp new file mode 100644 index 00000000000..9d9946b6896 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/default_stack_alloc.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// explicit list(const Alloc& = Alloc()); + +#include +#include +#include "../../../stack_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + std::list l; + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } + { + std::list l((std::allocator())); + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } + { + std::list > l; + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } +#if __cplusplus >= 201103L + { + std::list> l; + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } + { + std::list> l((min_allocator())); + assert(l.size() == 0); + assert(std::distance(l.begin(), l.end()) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..13c7e5b5797 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// ~list() // implied noexcept; + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); + ~some_alloc() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::list C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::list> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::list> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::list> C; + static_assert(!std::is_nothrow_destructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..3307017989e --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/initializer_list.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// list(initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::list d = {3, 4, 5, 6}; + assert(d.size() == 4); + std::list::iterator i = d.begin(); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); + } +#if __cplusplus >= 201103L + { + std::list> d = {3, 4, 5, 6}; + assert(d.size() == 4); + std::list>::iterator i = d.begin(); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/initializer_list_alloc.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/initializer_list_alloc.pass.cpp new file mode 100644 index 00000000000..4a85e378c1c --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/initializer_list_alloc.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// list(initializer_list il, const Allocator& a = allocator_type()); + +#include +#include + +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::list> d({3, 4, 5, 6}, test_allocator(3)); + assert(d.get_allocator() == test_allocator(3)); + assert(d.size() == 4); + std::list::iterator i = d.begin(); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); + } +#if __cplusplus >= 201103L + { + std::list> d({3, 4, 5, 6}, min_allocator()); + assert(d.get_allocator() == min_allocator()); + assert(d.size() == 4); + std::list>::iterator i = d.begin(); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp new file mode 100644 index 00000000000..09eae8ab43c --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/input_iterator.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// list(InputIterator first, InputIterator last, const Allocator& = Allocator()); + +#include +#include +#include "test_iterators.h" +#include "../../../stack_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + int a[] = {0, 1, 2, 3}; + std::list l(input_iterator(a), + input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(l.size() == sizeof(a)/sizeof(a[0])); + assert(std::distance(l.begin(), l.end()) == sizeof(a)/sizeof(a[0])); + int j = 0; + for (std::list::const_iterator i = l.begin(), e = l.end(); i != e; ++i, ++j) + assert(*i == j); + } + { + int a[] = {0, 1, 2, 3}; + std::list l(input_iterator(a), + input_iterator(a + sizeof(a)/sizeof(a[0])), + std::allocator()); + assert(l.size() == sizeof(a)/sizeof(a[0])); + assert(std::distance(l.begin(), l.end()) == sizeof(a)/sizeof(a[0])); + int j = 0; + for (std::list::const_iterator i = l.begin(), e = l.end(); i != e; ++i, ++j) + assert(*i == j); + } + { + int a[] = {0, 1, 2, 3}; + std::list > l(input_iterator(a), + input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(l.size() == sizeof(a)/sizeof(a[0])); + assert(std::distance(l.begin(), l.end()) == sizeof(a)/sizeof(a[0])); + int j = 0; + for (std::list::const_iterator i = l.begin(), e = l.end(); i != e; ++i, ++j) + assert(*i == j); + } +#if __cplusplus >= 201103L + { + int a[] = {0, 1, 2, 3}; + std::list> l(input_iterator(a), + input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(l.size() == sizeof(a)/sizeof(a[0])); + assert(std::distance(l.begin(), l.end()) == sizeof(a)/sizeof(a[0])); + int j = 0; + for (std::list>::const_iterator i = l.begin(), e = l.end(); i != e; ++i, ++j) + assert(*i == j); + } + { + int a[] = {0, 1, 2, 3}; + std::list> l(input_iterator(a), + input_iterator(a + sizeof(a)/sizeof(a[0])), + min_allocator()); + assert(l.size() == sizeof(a)/sizeof(a[0])); + assert(std::distance(l.begin(), l.end()) == sizeof(a)/sizeof(a[0])); + int j = 0; + for (std::list>::const_iterator i = l.begin(), e = l.end(); i != e; ++i, ++j) + assert(*i == j); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/move.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/move.pass.cpp new file mode 100644 index 00000000000..44782b91075 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/move.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// list(list&& c); + +#include +#include +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::list > l(test_allocator(5)); + std::list > lo(test_allocator(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } + { + std::list > l(other_allocator(5)); + std::list > lo(other_allocator(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } +#if __cplusplus >= 201103L + { + std::list > l(min_allocator{}); + std::list > lo(min_allocator{}); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + std::list l1 = {1, 2, 3}; + std::list::iterator i = l1.begin(); + std::list l2 = std::move(l1); + assert(*l2.erase(i) == 2); + assert(l2.size() == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/move_alloc.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..4730755db81 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/move_alloc.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// list(list&& c, const allocator_type& a); + +#include +#include +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::list > l(test_allocator(5)); + std::list > lo(test_allocator(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list > l2(std::move(l), test_allocator(6)); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == test_allocator(6)); + } + { + std::list > l(test_allocator(5)); + std::list > lo(test_allocator(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list > l2(std::move(l), test_allocator(5)); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == test_allocator(5)); + } + { + std::list > l(other_allocator(5)); + std::list > lo(other_allocator(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list > l2(std::move(l), other_allocator(4)); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == other_allocator(4)); + } +#if __cplusplus >= 201103L + { + std::list > l(min_allocator{}); + std::list > lo(min_allocator{}); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::list > l2(std::move(l), min_allocator()); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == min_allocator()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..d502e1c09c8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// list& operator=(list&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::list C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::list> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::list> C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::list> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/move_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/move_noexcept.pass.cpp new file mode 100644 index 00000000000..2c10443f76b --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/move_noexcept.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// list(list&&) +// noexcept(is_nothrow_move_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::list C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::list> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::list> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::list> C; + static_assert(!std::is_nothrow_move_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/op_equal_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/op_equal_initializer_list.pass.cpp new file mode 100644 index 00000000000..7b7b8a327b8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/op_equal_initializer_list.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// list& operator=(initializer_list il); + +#include +#include +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::list d; + d = {3, 4, 5, 6}; + assert(d.size() == 4); + std::list::iterator i = d.begin(); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); + } +#if __cplusplus >= 201103L + { + std::list> d; + d = {3, 4, 5, 6}; + assert(d.size() == 4); + std::list>::iterator i = d.begin(); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/size_type.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/size_type.pass.cpp new file mode 100644 index 00000000000..75b93a3dfb6 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/size_type.pass.cpp @@ -0,0 +1,103 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// explicit list(size_type n); + +#include +#include +#include "DefaultOnly.h" +#include "../../../stack_allocator.h" +#include "min_allocator.h" + +template +void +test3(unsigned n, Allocator const &alloc = Allocator()) +{ +#if _LIBCPP_STD_VER > 11 + typedef std::list C; + typedef typename C::const_iterator const_iterator; + { + C d(n, alloc); + assert(d.size() == n); + assert(std::distance(d.begin(), d.end()) == n); + assert(d.get_allocator() == alloc); + } +#endif +} + + +int main() +{ + { + std::list l(3); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + std::list::const_iterator i = l.begin(); + assert(*i == 0); + ++i; + assert(*i == 0); + ++i; + assert(*i == 0); + } + { + std::list > l(3); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + std::list::const_iterator i = l.begin(); + assert(*i == 0); + ++i; + assert(*i == 0); + ++i; + assert(*i == 0); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::list > C; + C l(3, min_allocator ()); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + C::const_iterator i = l.begin(); + assert(*i == 0); + ++i; + assert(*i == 0); + ++i; + assert(*i == 0); + test3> (3); + } +#endif +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::list l(3); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + std::list> l(3); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + std::list>::const_iterator i = l.begin(); + assert(*i == 0); + ++i; + assert(*i == 0); + ++i; + assert(*i == 0); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::list> l(3); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.cons/size_value_alloc.pass.cpp b/libcxx/test/std/containers/sequences/list/list.cons/size_value_alloc.pass.cpp new file mode 100644 index 00000000000..12da86da0a4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.cons/size_value_alloc.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// list(size_type n, const T& value, const Allocator& = Allocator()); + +#include +#include +#include "DefaultOnly.h" +#include "../../../stack_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + std::list l(3, 2); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + std::list::const_iterator i = l.begin(); + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + } + { + std::list l(3, 2, std::allocator()); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + std::list::const_iterator i = l.begin(); + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + } + { + std::list > l(3, 2); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + std::list::const_iterator i = l.begin(); + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + } +#if __cplusplus >= 201103L + { + std::list> l(3, 2); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + std::list>::const_iterator i = l.begin(); + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + } + { + std::list> l(3, 2, min_allocator()); + assert(l.size() == 3); + assert(std::distance(l.begin(), l.end()) == 3); + std::list>::const_iterator i = l.begin(); + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/clear.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/clear.pass.cpp new file mode 100644 index 00000000000..38696b6eb50 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/clear.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void clear(); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a[] = {1, 2, 3}; + std::list c(a, a+3); + c.clear(); + assert(c.empty()); + } +#if __cplusplus >= 201103L + { + int a[] = {1, 2, 3}; + std::list> c(a, a+3); + c.clear(); + assert(c.empty()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/emplace.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/emplace.pass.cpp new file mode 100644 index 00000000000..6476d1d6c6a --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/emplace.pass.cpp @@ -0,0 +1,88 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template void emplace(const_iterator p, Args&&... args); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "min_allocator.h" + +class A +{ + int i_; + double d_; + + A(const A&); + A& operator=(const A&); +public: + A(int i, double d) + : i_(i), d_(d) {} + + int geti() const {return i_;} + double getd() const {return d_;} +}; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::list c; + c.emplace(c.cbegin(), 2, 3.5); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + c.emplace(c.cend(), 3, 4.5); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list c1; + std::list c2; + std::list::iterator i = c1.emplace(c2.cbegin(), 2, 3.5); + assert(false); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::list> c; + c.emplace(c.cbegin(), 2, 3.5); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + c.emplace(c.cend(), 3, 4.5); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list> c1; + std::list> c2; + std::list>::iterator i = c1.emplace(c2.cbegin(), 2, 3.5); + assert(false); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/emplace_back.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/emplace_back.pass.cpp new file mode 100644 index 00000000000..5983efc59ad --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/emplace_back.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template void emplace_back(Args&&... args); + +#include +#include + +#include "min_allocator.h" + +class A +{ + int i_; + double d_; + + A(const A&); + A& operator=(const A&); +public: + A(int i, double d) + : i_(i), d_(d) {} + + int geti() const {return i_;} + double getd() const {return d_;} +}; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::list c; + c.emplace_back(2, 3.5); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + c.emplace_back(3, 4.5); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + } +#if __cplusplus >= 201103L + { + std::list> c; + c.emplace_back(2, 3.5); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + c.emplace_back(3, 4.5); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/emplace_front.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/emplace_front.pass.cpp new file mode 100644 index 00000000000..e2e68e33138 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/emplace_front.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template void emplace_front(Args&&... args); + +#include +#include + +#include "min_allocator.h" + +class A +{ + int i_; + double d_; + + A(const A&); + A& operator=(const A&); +public: + A(int i, double d) + : i_(i), d_(d) {} + + int geti() const {return i_;} + double getd() const {return d_;} +}; + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::list c; + c.emplace_front(2, 3.5); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + c.emplace_front(3, 4.5); + assert(c.size() == 2); + assert(c.front().geti() == 3); + assert(c.front().getd() == 4.5); + assert(c.back().geti() == 2); + assert(c.back().getd() == 3.5); + } +#if __cplusplus >= 201103L + { + std::list> c; + c.emplace_front(2, 3.5); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + c.emplace_front(3, 4.5); + assert(c.size() == 2); + assert(c.front().geti() == 3); + assert(c.front().getd() == 4.5); + assert(c.back().geti() == 2); + assert(c.back().getd() == 3.5); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter.pass.cpp new file mode 100644 index 00000000000..c1cc9004367 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator erase(const_iterator position); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::list l1(a1, a1+3); + std::list::const_iterator i = l1.begin(); + ++i; + std::list::iterator j = l1.erase(i); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(*j == 3); + assert(*l1.begin() == 1); + assert(*next(l1.begin()) == 3); + j = l1.erase(j); + assert(j == l1.end()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(*l1.begin() == 1); + j = l1.erase(l1.begin()); + assert(j == l1.end()); + assert(l1.size() == 0); + assert(distance(l1.begin(), l1.end()) == 0); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::list> l1(a1, a1+3); + std::list>::const_iterator i = l1.begin(); + ++i; + std::list>::iterator j = l1.erase(i); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(*j == 3); + assert(*l1.begin() == 1); + assert(*next(l1.begin()) == 3); + j = l1.erase(j); + assert(j == l1.end()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(*l1.begin() == 1); + j = l1.erase(l1.begin()); + assert(j == l1.end()); + assert(l1.size() == 0); + assert(distance(l1.begin(), l1.end()) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_db1.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_db1.pass.cpp new file mode 100644 index 00000000000..18c15eb02c8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_db1.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator position) with end() + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::list l1(a1, a1+3); + std::list::const_iterator i = l1.end(); + l1.erase(i); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::list> l1(a1, a1+3); + std::list>::const_iterator i = l1.end(); + l1.erase(i); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_db2.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_db2.pass.cpp new file mode 100644 index 00000000000..61ff8409c96 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_db2.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator position) with iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::list l1(a1, a1+3); + std::list l2(a1, a1+3); + std::list::const_iterator i = l2.begin(); + l1.erase(i); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::list> l1(a1, a1+3); + std::list> l2(a1, a1+3); + std::list>::const_iterator i = l2.begin(); + l1.erase(i); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..bd3f66b4116 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator erase(const_iterator first, const_iterator last); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + int a1[] = {1, 2, 3}; + { + std::list l1(a1, a1+3); + std::list::iterator i = l1.erase(l1.cbegin(), l1.cbegin()); + assert(l1.size() == 3); + assert(distance(l1.cbegin(), l1.cend()) == 3); + assert(i == l1.begin()); + } + { + std::list l1(a1, a1+3); + std::list::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin())); + assert(l1.size() == 2); + assert(distance(l1.cbegin(), l1.cend()) == 2); + assert(i == l1.begin()); + assert(l1 == std::list(a1+1, a1+3)); + } + { + std::list l1(a1, a1+3); + std::list::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 2)); + assert(l1.size() == 1); + assert(distance(l1.cbegin(), l1.cend()) == 1); + assert(i == l1.begin()); + assert(l1 == std::list(a1+2, a1+3)); + } + { + std::list l1(a1, a1+3); + std::list::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 3)); + assert(l1.size() == 0); + assert(distance(l1.cbegin(), l1.cend()) == 0); + assert(i == l1.begin()); + } +#if __cplusplus >= 201103L + { + std::list> l1(a1, a1+3); + std::list>::iterator i = l1.erase(l1.cbegin(), l1.cbegin()); + assert(l1.size() == 3); + assert(distance(l1.cbegin(), l1.cend()) == 3); + assert(i == l1.begin()); + } + { + std::list> l1(a1, a1+3); + std::list>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin())); + assert(l1.size() == 2); + assert(distance(l1.cbegin(), l1.cend()) == 2); + assert(i == l1.begin()); + assert((l1 == std::list>(a1+1, a1+3))); + } + { + std::list> l1(a1, a1+3); + std::list>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 2)); + assert(l1.size() == 1); + assert(distance(l1.cbegin(), l1.cend()) == 1); + assert(i == l1.begin()); + assert((l1 == std::list>(a1+2, a1+3))); + } + { + std::list> l1(a1, a1+3); + std::list>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 3)); + assert(l1.size() == 0); + assert(distance(l1.cbegin(), l1.cend()) == 0); + assert(i == l1.begin()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db1.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db1.pass.cpp new file mode 100644 index 00000000000..71ad497e7d9 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db1.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with first iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::list l1(a1, a1+3); + std::list l2(a1, a1+3); + std::list::iterator i = l1.erase(l2.cbegin(), next(l1.cbegin())); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::list> l1(a1, a1+3); + std::list> l2(a1, a1+3); + std::list>::iterator i = l1.erase(l2.cbegin(), next(l1.cbegin())); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db2.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db2.pass.cpp new file mode 100644 index 00000000000..db76b4de486 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db2.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with second iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::list l1(a1, a1+3); + std::list l2(a1, a1+3); + std::list::iterator i = l1.erase(l1.cbegin(), next(l2.cbegin())); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::list> l1(a1, a1+3); + std::list> l2(a1, a1+3); + std::list>::iterator i = l1.erase(l1.cbegin(), next(l2.cbegin())); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db3.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db3.pass.cpp new file mode 100644 index 00000000000..25c5c6147a0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db3.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with both iterators from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::list l1(a1, a1+3); + std::list l2(a1, a1+3); + std::list::iterator i = l1.erase(l2.cbegin(), next(l2.cbegin())); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::list> l1(a1, a1+3); + std::list> l2(a1, a1+3); + std::list>::iterator i = l1.erase(l2.cbegin(), next(l2.cbegin())); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db4.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db4.pass.cpp new file mode 100644 index 00000000000..35a4ceb4848 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/erase_iter_iter_db4.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with a bad range + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::list l1(a1, a1+3); + std::list::iterator i = l1.erase(next(l1.cbegin()), l1.cbegin()); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::list> l1(a1, a1+3); + std::list>::iterator i = l1.erase(next(l1.cbegin()), l1.cbegin()); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_initializer_list.pass.cpp new file mode 100644 index 00000000000..a82a2696e82 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_initializer_list.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator insert(const_iterator p, initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::list d(10, 1); + std::list::iterator i = d.insert(next(d.cbegin(), 2), {3, 4, 5, 6}); + assert(d.size() == 14); + assert(i == next(d.begin(), 2)); + i = d.begin(); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 1); + } +#if __cplusplus >= 201103L + { + std::list> d(10, 1); + std::list>::iterator i = d.insert(next(d.cbegin(), 2), {3, 4, 5, 6}); + assert(d.size() == 14); + assert(i == next(d.begin(), 2)); + i = d.begin(); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 3); + assert(*i++ == 4); + assert(*i++ == 5); + assert(*i++ == 6); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 1); + assert(*i++ == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp new file mode 100644 index 00000000000..d69deac36a9 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_iter_iter.pass.cpp @@ -0,0 +1,185 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// iterator insert(const_iterator position, Iter first, Iter last); + +// UNSUPPORTED: asan, msan + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include +#include +#include "test_iterators.h" +#include "min_allocator.h" + +int throw_next = 0xFFFF; +int count = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + if (throw_next == 0) + throw std::bad_alloc(); + --throw_next; + ++count; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --count; + std::free(p); +} + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::list l1; + std::list::iterator i = l1.insert(l1.begin(), a1, a1+3); + assert(i == l1.begin()); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + int a2[] = {4, 5, 6}; + i = l1.insert(i, a2, a2+3); + assert(*i == 4); + assert(l1.size() == 6); + assert(distance(l1.begin(), l1.end()) == 6); + i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 3); + throw_next = 2; + int save_count = count; + try + { + i = l1.insert(i, a2, a2+3); + assert(false); + } + catch (...) + { + } + assert(save_count == count); + assert(l1.size() == 6); + assert(distance(l1.begin(), l1.end()) == 6); + i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 3); + } + throw_next = 0xFFFF; +#if _LIBCPP_DEBUG >= 1 + { + std::list v(100); + std::list v2(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::list::iterator i = v.insert(next(v2.cbegin(), 10), input_iterator(a), + input_iterator(a+N)); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::list> l1; + std::list>::iterator i = l1.insert(l1.begin(), a1, a1+3); + assert(i == l1.begin()); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + int a2[] = {4, 5, 6}; + i = l1.insert(i, a2, a2+3); + assert(*i == 4); + assert(l1.size() == 6); + assert(distance(l1.begin(), l1.end()) == 6); + i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 3); + throw_next = 2; + int save_count = count; + try + { + i = l1.insert(i, a2, a2+3); + assert(false); + } + catch (...) + { + } + assert(save_count == count); + assert(l1.size() == 6); + assert(distance(l1.begin(), l1.end()) == 6); + i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 3); + } +#if _LIBCPP_DEBUG >= 1 + { + throw_next = 0xFFFF; + std::list> v(100); + std::list> v2(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::list>::iterator i = v.insert(next(v2.cbegin(), 10), input_iterator(a), + input_iterator(a+N)); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_rvalue.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_rvalue.pass.cpp new file mode 100644 index 00000000000..27d0411fb04 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_rvalue.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator insert(const_iterator position, value_type&& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::list l1; + l1.insert(l1.cend(), MoveOnly(1)); + assert(l1.size() == 1); + assert(l1.front() == MoveOnly(1)); + l1.insert(l1.cbegin(), MoveOnly(2)); + assert(l1.size() == 2); + assert(l1.front() == MoveOnly(2)); + assert(l1.back() == MoveOnly(1)); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_DEBUG >= 1 + { + std::list v1(3); + std::list v2(3); + v1.insert(v2.begin(), 4); + assert(false); + } +#endif +#if __cplusplus >= 201103L +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::list> l1; + l1.insert(l1.cend(), MoveOnly(1)); + assert(l1.size() == 1); + assert(l1.front() == MoveOnly(1)); + l1.insert(l1.cbegin(), MoveOnly(2)); + assert(l1.size() == 2); + assert(l1.front() == MoveOnly(2)); + assert(l1.back() == MoveOnly(1)); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_DEBUG >= 1 + { + std::list> v1(3); + std::list> v2(3); + v1.insert(v2.begin(), 4); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp new file mode 100644 index 00000000000..a552e1f8360 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_size_value.pass.cpp @@ -0,0 +1,106 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator insert(const_iterator position, size_type n, const value_type& x); + +// UNSUPPORTED: asan, msan + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include +#include + +#include "min_allocator.h" + +int throw_next = 0xFFFF; +int count = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + if (throw_next == 0) + throw std::bad_alloc(); + --throw_next; + ++count; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --count; + std::free(p); +} + +int main() +{ + { + int a1[] = {1, 2, 3}; + int a2[] = {1, 4, 4, 4, 4, 4, 2, 3}; + std::list l1(a1, a1+3); + std::list::iterator i = l1.insert(next(l1.cbegin()), 5, 4); + assert(i == next(l1.begin())); + assert(l1 == std::list(a2, a2+8)); + throw_next = 4; + int save_count = count; + try + { + i = l1.insert(i, 5, 5); + assert(false); + } + catch (...) + { + } + throw_next = 0xFFFF; + assert(save_count == count); + assert(l1 == std::list(a2, a2+8)); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list c1(100); + std::list c2; + std::list::iterator i = c1.insert(next(c2.cbegin(), 10), 5, 1); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + int a2[] = {1, 4, 4, 4, 4, 4, 2, 3}; + std::list> l1(a1, a1+3); + std::list>::iterator i = l1.insert(next(l1.cbegin()), 5, 4); + assert(i == next(l1.begin())); + assert((l1 == std::list>(a2, a2+8))); + throw_next = 4; + int save_count = count; + try + { + i = l1.insert(i, 5, 5); + assert(false); + } + catch (...) + { + } + throw_next = 0xFFFF; + assert(save_count == count); + assert((l1 == std::list>(a2, a2+8))); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list> c1(100); + std::list> c2; + std::list>::iterator i = c1.insert(next(c2.cbegin(), 10), 5, 1); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp new file mode 100644 index 00000000000..093ad423cf8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/insert_iter_value.pass.cpp @@ -0,0 +1,112 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator insert(const_iterator position, const value_type& x); + +// UNSUPPORTED: asan, msan + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include +#include + +#include "min_allocator.h" + +int throw_next = 0xFFFF; +int count = 0; + +void* operator new(std::size_t s) throw(std::bad_alloc) +{ + if (throw_next == 0) + throw std::bad_alloc(); + --throw_next; + ++count; + return std::malloc(s); +} + +void operator delete(void* p) throw() +{ + --count; + std::free(p); +} + +int main() +{ + { + int a1[] = {1, 2, 3}; + int a2[] = {1, 4, 2, 3}; + std::list l1(a1, a1+3); + std::list::iterator i = l1.insert(next(l1.cbegin()), 4); + assert(i == next(l1.begin())); + assert(l1.size() == 4); + assert(distance(l1.begin(), l1.end()) == 4); + assert(l1 == std::list(a2, a2+4)); + throw_next = 0; + int save_count = count; + try + { + i = l1.insert(i, 5); + assert(false); + } + catch (...) + { + } + throw_next = 0xFFFF; + assert(save_count == count); + assert(l1 == std::list(a2, a2+4)); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list v1(3); + std::list v2(3); + int i = 4; + v1.insert(v2.begin(), i); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + int a2[] = {1, 4, 2, 3}; + std::list> l1(a1, a1+3); + std::list>::iterator i = l1.insert(next(l1.cbegin()), 4); + assert(i == next(l1.begin())); + assert(l1.size() == 4); + assert(distance(l1.begin(), l1.end()) == 4); + assert((l1 == std::list>(a2, a2+4))); + throw_next = 0; + int save_count = count; + try + { + i = l1.insert(i, 5); + assert(false); + } + catch (...) + { + } + throw_next = 0xFFFF; + assert(save_count == count); + assert((l1 == std::list>(a2, a2+4))); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list> v1(3); + std::list> v2(3); + int i = 4; + v1.insert(v2.begin(), i); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/pop_back.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/pop_back.pass.cpp new file mode 100644 index 00000000000..3add8518809 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/pop_back.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void pop_back(); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a[] = {1, 2, 3}; + std::list c(a, a+3); + c.pop_back(); + assert(c == std::list(a, a+2)); + c.pop_back(); + assert(c == std::list(a, a+1)); + c.pop_back(); + assert(c.empty()); +#if _LIBCPP_DEBUG >= 1 + c.pop_back(); + assert(false); +#endif + } +#if __cplusplus >= 201103L + { + int a[] = {1, 2, 3}; + std::list> c(a, a+3); + c.pop_back(); + assert((c == std::list>(a, a+2))); + c.pop_back(); + assert((c == std::list>(a, a+1))); + c.pop_back(); + assert(c.empty()); +#if _LIBCPP_DEBUG >= 1 + c.pop_back(); + assert(false); +#endif + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/pop_front.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/pop_front.pass.cpp new file mode 100644 index 00000000000..aec17cc08f4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/pop_front.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void pop_front(); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a[] = {1, 2, 3}; + std::list c(a, a+3); + c.pop_front(); + assert(c == std::list(a+1, a+3)); + c.pop_front(); + assert(c == std::list(a+2, a+3)); + c.pop_front(); + assert(c.empty()); + } +#if __cplusplus >= 201103L + { + int a[] = {1, 2, 3}; + std::list> c(a, a+3); + c.pop_front(); + assert((c == std::list>(a+1, a+3))); + c.pop_front(); + assert((c == std::list>(a+2, a+3))); + c.pop_front(); + assert(c.empty()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/push_back.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/push_back.pass.cpp new file mode 100644 index 00000000000..2638c541fa1 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/push_back.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push_back(const value_type& x); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + std::list c; + for (int i = 0; i < 5; ++i) + c.push_back(i); + int a[] = {0, 1, 2, 3, 4}; + assert(c == std::list(a, a+5)); + } +#if __cplusplus >= 201103L + { + std::list> c; + for (int i = 0; i < 5; ++i) + c.push_back(i); + int a[] = {0, 1, 2, 3, 4}; + assert((c == std::list>(a, a+5))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/push_back_exception_safety.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/push_back_exception_safety.pass.cpp new file mode 100644 index 00000000000..9d3c05e26b1 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/push_back_exception_safety.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push_back(const value_type& x); + +#include +#include + +// Flag that makes the copy constructor for CMyClass throw an exception +static bool gCopyConstructorShouldThow = false; + + +class CMyClass { + public: CMyClass(); + public: CMyClass(const CMyClass& iOther); + public: ~CMyClass(); + + private: int fMagicValue; + + private: static int kStartedConstructionMagicValue; + private: static int kFinishedConstructionMagicValue; +}; + +// Value for fMagicValue when the constructor has started running, but not yet finished +int CMyClass::kStartedConstructionMagicValue = 0; +// Value for fMagicValue when the constructor has finished running +int CMyClass::kFinishedConstructionMagicValue = 12345; + +CMyClass::CMyClass() : + fMagicValue(kStartedConstructionMagicValue) +{ + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::CMyClass(const CMyClass& /*iOther*/) : + fMagicValue(kStartedConstructionMagicValue) +{ + // If requested, throw an exception _before_ setting fMagicValue to kFinishedConstructionMagicValue + if (gCopyConstructorShouldThow) { + throw std::exception(); + } + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::~CMyClass() { + // Only instances for which the constructor has finished running should be destructed + assert(fMagicValue == kFinishedConstructionMagicValue); +} + +int main() +{ + CMyClass instance; + std::list vec; + + vec.push_back(instance); + + gCopyConstructorShouldThow = true; + try { + vec.push_back(instance); + } + catch (...) { + } +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/push_back_rvalue.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/push_back_rvalue.pass.cpp new file mode 100644 index 00000000000..070db9e8d6b --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/push_back_rvalue.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push_back(value_type&& x); + +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::list l1; + l1.push_back(MoveOnly(1)); + assert(l1.size() == 1); + assert(l1.front() == MoveOnly(1)); + l1.push_back(MoveOnly(2)); + assert(l1.size() == 2); + assert(l1.front() == MoveOnly(1)); + assert(l1.back() == MoveOnly(2)); + } +#if __cplusplus >= 201103L + { + std::list> l1; + l1.push_back(MoveOnly(1)); + assert(l1.size() == 1); + assert(l1.front() == MoveOnly(1)); + l1.push_back(MoveOnly(2)); + assert(l1.size() == 2); + assert(l1.front() == MoveOnly(1)); + assert(l1.back() == MoveOnly(2)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/push_front.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/push_front.pass.cpp new file mode 100644 index 00000000000..b7f4febcd38 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/push_front.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push_front(const value_type& x); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + std::list c; + for (int i = 0; i < 5; ++i) + c.push_front(i); + int a[] = {4, 3, 2, 1, 0}; + assert(c == std::list(a, a+5)); + } +#if __cplusplus >= 201103L + { + std::list> c; + for (int i = 0; i < 5; ++i) + c.push_front(i); + int a[] = {4, 3, 2, 1, 0}; + assert((c == std::list>(a, a+5))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/push_front_exception_safety.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/push_front_exception_safety.pass.cpp new file mode 100644 index 00000000000..6609005262e --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/push_front_exception_safety.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push_front(const value_type& x); + +#include +#include + +// Flag that makes the copy constructor for CMyClass throw an exception +static bool gCopyConstructorShouldThow = false; + + +class CMyClass { + public: CMyClass(); + public: CMyClass(const CMyClass& iOther); + public: ~CMyClass(); + + private: int fMagicValue; + + private: static int kStartedConstructionMagicValue; + private: static int kFinishedConstructionMagicValue; +}; + +// Value for fMagicValue when the constructor has started running, but not yet finished +int CMyClass::kStartedConstructionMagicValue = 0; +// Value for fMagicValue when the constructor has finished running +int CMyClass::kFinishedConstructionMagicValue = 12345; + +CMyClass::CMyClass() : + fMagicValue(kStartedConstructionMagicValue) +{ + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::CMyClass(const CMyClass& /*iOther*/) : + fMagicValue(kStartedConstructionMagicValue) +{ + // If requested, throw an exception _before_ setting fMagicValue to kFinishedConstructionMagicValue + if (gCopyConstructorShouldThow) { + throw std::exception(); + } + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::~CMyClass() { + // Only instances for which the constructor has finished running should be destructed + assert(fMagicValue == kFinishedConstructionMagicValue); +} + +int main() +{ + CMyClass instance; + std::list vec; + + vec.push_front(instance); + + gCopyConstructorShouldThow = true; + try { + vec.push_front(instance); + } + catch (...) { + } +} diff --git a/libcxx/test/std/containers/sequences/list/list.modifiers/push_front_rvalue.pass.cpp b/libcxx/test/std/containers/sequences/list/list.modifiers/push_front_rvalue.pass.cpp new file mode 100644 index 00000000000..8a3175504eb --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.modifiers/push_front_rvalue.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push_front(value_type&& x); + +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::list l1; + l1.push_front(MoveOnly(1)); + assert(l1.size() == 1); + assert(l1.front() == MoveOnly(1)); + l1.push_front(MoveOnly(2)); + assert(l1.size() == 2); + assert(l1.front() == MoveOnly(2)); + assert(l1.back() == MoveOnly(1)); + } +#if __cplusplus >= 201103L + { + std::list> l1; + l1.push_front(MoveOnly(1)); + assert(l1.size() == 1); + assert(l1.front() == MoveOnly(1)); + l1.push_front(MoveOnly(2)); + assert(l1.size() == 2); + assert(l1.front() == MoveOnly(2)); + assert(l1.back() == MoveOnly(1)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/merge.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/merge.pass.cpp new file mode 100644 index 00000000000..d226ed5dc64 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/merge.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void merge(list& x); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + int a3[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + std::list c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + c1.merge(c2); + assert(c1 == std::list(a3, a3+sizeof(a3)/sizeof(a3[0]))); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + int a3[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + std::list> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + c1.merge(c2); + assert((c1 == std::list>(a3, a3+sizeof(a3)/sizeof(a3[0])))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/merge_comp.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/merge_comp.pass.cpp new file mode 100644 index 00000000000..ce861a5dcb8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/merge_comp.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template void merge(list& x, Compare comp); + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {10, 9, 7, 3, 1}; + int a2[] = {11, 8, 6, 5, 4, 2, 0}; + int a3[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; + std::list c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + c1.merge(c2, std::greater()); + assert(c1 == std::list(a3, a3+sizeof(a3)/sizeof(a3[0]))); + } +#if __cplusplus >= 201103L + { + int a1[] = {10, 9, 7, 3, 1}; + int a2[] = {11, 8, 6, 5, 4, 2, 0}; + int a3[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; + std::list> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + c1.merge(c2, std::greater()); + assert((c1 == std::list>(a3, a3+sizeof(a3)/sizeof(a3[0])))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/remove.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/remove.pass.cpp new file mode 100644 index 00000000000..f580c94ef48 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/remove.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void remove(const value_type& value); + +#include +#include + +#include "min_allocator.h" + +struct S { + S(int i) : i_(new int(i)) {} + S(const S &rhs) : i_(new int(*rhs.i_)) {} + S& operator = (const S &rhs) { *i_ = *rhs.i_; return *this; } + ~S () { delete i_; i_ = NULL; } + bool operator == (const S &rhs) const { return *i_ == *rhs.i_; } + int get () const { return *i_; } + int *i_; + }; + + +int main() +{ + { + int a1[] = {1, 2, 3, 4}; + int a2[] = {1, 2, 4}; + std::list c(a1, a1+4); + c.remove(3); + assert(c == std::list(a2, a2+3)); + } + { // LWG issue #526 + int a1[] = {1, 2, 1, 3, 5, 8, 11}; + int a2[] = { 2, 3, 5, 8, 11}; + std::list c(a1, a1+7); + c.remove(c.front()); + assert(c == std::list(a2, a2+5)); + } + { + int a1[] = {1, 2, 1, 3, 5, 8, 11, 1}; + int a2[] = { 2, 3, 5, 8, 11 }; + std::list c; + for(int *ip = a1; ip < a1+8; ++ip) + c.push_back(S(*ip)); + c.remove(c.front()); + std::list::const_iterator it = c.begin(); + for(int *ip = a2; ip < a2+5; ++ip, ++it) { + assert ( it != c.end()); + assert ( *ip == it->get()); + } + assert ( it == c.end ()); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3, 4}; + int a2[] = {1, 2, 4}; + std::list> c(a1, a1+4); + c.remove(3); + assert((c == std::list>(a2, a2+3))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/remove_if.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/remove_if.pass.cpp new file mode 100644 index 00000000000..162919ed85d --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/remove_if.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template void remove_if(Pred pred); + +#include +#include +#include + +#include "min_allocator.h" +#include "counting_predicates.hpp" + +bool even(int i) +{ + return i % 2 == 0; +} + +bool g(int i) +{ + return i < 3; +} + +typedef unary_counting_predicate Predicate; + +int main() +{ + { + int a1[] = {1, 2, 3, 4}; + int a2[] = {3, 4}; + std::list c(a1, a1+4); + Predicate cp(g); + c.remove_if(std::ref(cp)); + assert(c == std::list(a2, a2+2)); + assert(cp.count() == 4); + } + { + int a1[] = {1, 2, 3, 4}; + int a2[] = {1, 3}; + std::list c(a1, a1+4); + Predicate cp(even); + c.remove_if(std::ref(cp)); + assert(c == std::list(a2, a2+2)); + assert(cp.count() == 4); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3, 4}; + int a2[] = {3, 4}; + std::list> c(a1, a1+4); + Predicate cp(g); + c.remove_if(std::ref(cp)); + assert((c == std::list>(a2, a2+2))); + assert(cp.count() == 4); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/reverse.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/reverse.pass.cpp new file mode 100644 index 00000000000..046453ae538 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/reverse.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void reverse(); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; + int a2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + std::list c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + c1.reverse(); + assert(c1 == std::list(a2, a2+sizeof(a2)/sizeof(a2[0]))); + } +#if __cplusplus >= 201103L + { + int a1[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; + int a2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + std::list> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + c1.reverse(); + assert((c1 == std::list>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/sort.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/sort.pass.cpp new file mode 100644 index 00000000000..1c11227237a --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/sort.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void sort(); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {4, 8, 1, 0, 5, 7, 2, 3, 6, 11, 10, 9}; + int a2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + std::list c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + c1.sort(); + assert(c1 == std::list(a2, a2+sizeof(a2)/sizeof(a2[0]))); + } +#if __cplusplus >= 201103L + { + int a1[] = {4, 8, 1, 0, 5, 7, 2, 3, 6, 11, 10, 9}; + int a2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; + std::list> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + c1.sort(); + assert((c1 == std::list>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/sort_comp.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/sort_comp.pass.cpp new file mode 100644 index 00000000000..28125ab83c0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/sort_comp.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template sort(Compare comp); + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {4, 8, 1, 0, 5, 7, 2, 3, 6, 11, 10, 9}; + int a2[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; + std::list c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + c1.sort(std::greater()); + assert(c1 == std::list(a2, a2+sizeof(a2)/sizeof(a2[0]))); + } +#if __cplusplus >= 201103L + { + int a1[] = {4, 8, 1, 0, 5, 7, 2, 3, 6, 11, 10, 9}; + int a2[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; + std::list> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + c1.sort(std::greater()); + assert((c1 == std::list>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list.pass.cpp new file mode 100644 index 00000000000..354871c20af --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list.pass.cpp @@ -0,0 +1,803 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void splice(const_iterator position, list& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "min_allocator.h" + +int main() +{ + int a1[] = {1, 2, 3}; + int a2[] = {4, 5, 6}; + { + std::list l1; + std::list l2; + l1.splice(l1.end(), l2); + assert(l1.size() == 0); + assert(distance(l1.begin(), l1.end()) == 0); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + } + { + std::list l1; + std::list l2(a2, a2+1); + l1.splice(l1.end(), l2); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 4); + } + { + std::list l1; + std::list l2(a2, a2+2); + l1.splice(l1.end(), l2); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + } + { + std::list l1; + std::list l2(a2, a2+3); + l1.splice(l1.end(), l2); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + } + { + std::list l1(a1, a1+1); + std::list l2; + l1.splice(l1.begin(), l2); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + } + { + std::list l1(a1, a1+1); + std::list l2; + l1.splice(l1.end(), l2); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + } + { + std::list l1(a1, a1+1); + std::list l2(a2, a2+1); + l1.splice(l1.begin(), l2); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 1); + } + { + std::list l1(a1, a1+1); + std::list l2(a2, a2+1); + l1.splice(l1.end(), l2); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + } + { + std::list l1(a1, a1+1); + std::list l2(a2, a2+2); + l1.splice(l1.begin(), l2); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 1); + } + { + std::list l1(a1, a1+1); + std::list l2(a2, a2+2); + l1.splice(l1.end(), l2); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + } + { + std::list l1(a1, a1+1); + std::list l2(a2, a2+3); + l1.splice(l1.begin(), l2); + assert(l1.size() == 4); + assert(distance(l1.begin(), l1.end()) == 4); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 1); + } + { + std::list l1(a1, a1+1); + std::list l2(a2, a2+3); + l1.splice(l1.end(), l2); + assert(l1.size() == 4); + assert(distance(l1.begin(), l1.end()) == 4); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + } + { + std::list l1(a1, a1+2); + std::list l2; + l1.splice(l1.begin(), l2); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list l1(a1, a1+2); + std::list l2; + l1.splice(next(l1.begin()), l2); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list l1(a1, a1+2); + std::list l2; + l1.splice(next(l1.begin(), 2), l2); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list l1(a1, a1+2); + std::list l2(a2, a2+1); + l1.splice(l1.begin(), l2); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list l1(a1, a1+2); + std::list l2(a2, a2+1); + l1.splice(next(l1.begin()), l2); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 2); + } + { + std::list l1(a1, a1+2); + std::list l2(a2, a2+1); + l1.splice(next(l1.begin(), 2), l2); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 4); + } + { + std::list l1(a1, a1+2); + std::list l2(a2, a2+2); + l1.splice(l1.begin(), l2); + assert(l1.size() == 4); + assert(distance(l1.begin(), l1.end()) == 4); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list l1(a1, a1+2); + std::list l2(a2, a2+2); + l1.splice(next(l1.begin()), l2); + assert(l1.size() == 4); + assert(distance(l1.begin(), l1.end()) == 4); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 2); + } + { + std::list l1(a1, a1+2); + std::list l2(a2, a2+2); + l1.splice(next(l1.begin(), 2), l2); + assert(l1.size() == 4); + assert(distance(l1.begin(), l1.end()) == 4); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + } + { + std::list l1(a1, a1+3); + std::list l2(a2, a2+3); + l1.splice(l1.begin(), l2); + assert(l1.size() == 6); + assert(distance(l1.begin(), l1.end()) == 6); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + } + { + std::list l1(a1, a1+3); + std::list l2(a2, a2+3); + l1.splice(next(l1.begin()), l2); + assert(l1.size() == 6); + assert(distance(l1.begin(), l1.end()) == 6); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + } + { + std::list l1(a1, a1+3); + std::list l2(a2, a2+3); + l1.splice(next(l1.begin(), 2), l2); + assert(l1.size() == 6); + assert(distance(l1.begin(), l1.end()) == 6); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 3); + } + { + std::list l1(a1, a1+3); + std::list l2(a2, a2+3); + l1.splice(next(l1.begin(), 3), l2); + assert(l1.size() == 6); + assert(distance(l1.begin(), l1.end()) == 6); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list v1(3); + std::list v2(3); + v1.splice(v2.begin(), v2); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::list> l1; + std::list> l2; + l1.splice(l1.end(), l2); + assert(l1.size() == 0); + assert(distance(l1.begin(), l1.end()) == 0); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + } + { + std::list> l1; + std::list> l2(a2, a2+1); + l1.splice(l1.end(), l2); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 4); + } + { + std::list> l1; + std::list> l2(a2, a2+2); + l1.splice(l1.end(), l2); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + } + { + std::list> l1; + std::list> l2(a2, a2+3); + l1.splice(l1.end(), l2); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + } + { + std::list> l1(a1, a1+1); + std::list> l2; + l1.splice(l1.begin(), l2); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + } + { + std::list> l1(a1, a1+1); + std::list> l2; + l1.splice(l1.end(), l2); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + } + { + std::list> l1(a1, a1+1); + std::list> l2(a2, a2+1); + l1.splice(l1.begin(), l2); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 1); + } + { + std::list> l1(a1, a1+1); + std::list> l2(a2, a2+1); + l1.splice(l1.end(), l2); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + } + { + std::list> l1(a1, a1+1); + std::list> l2(a2, a2+2); + l1.splice(l1.begin(), l2); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 1); + } + { + std::list> l1(a1, a1+1); + std::list> l2(a2, a2+2); + l1.splice(l1.end(), l2); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + } + { + std::list> l1(a1, a1+1); + std::list> l2(a2, a2+3); + l1.splice(l1.begin(), l2); + assert(l1.size() == 4); + assert(distance(l1.begin(), l1.end()) == 4); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 1); + } + { + std::list> l1(a1, a1+1); + std::list> l2(a2, a2+3); + l1.splice(l1.end(), l2); + assert(l1.size() == 4); + assert(distance(l1.begin(), l1.end()) == 4); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + } + { + std::list> l1(a1, a1+2); + std::list> l2; + l1.splice(l1.begin(), l2); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list> l1(a1, a1+2); + std::list> l2; + l1.splice(next(l1.begin()), l2); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list> l1(a1, a1+2); + std::list> l2; + l1.splice(next(l1.begin(), 2), l2); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list> l1(a1, a1+2); + std::list> l2(a2, a2+1); + l1.splice(l1.begin(), l2); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list> l1(a1, a1+2); + std::list> l2(a2, a2+1); + l1.splice(next(l1.begin()), l2); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 2); + } + { + std::list> l1(a1, a1+2); + std::list> l2(a2, a2+1); + l1.splice(next(l1.begin(), 2), l2); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 4); + } + { + std::list> l1(a1, a1+2); + std::list> l2(a2, a2+2); + l1.splice(l1.begin(), l2); + assert(l1.size() == 4); + assert(distance(l1.begin(), l1.end()) == 4); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list> l1(a1, a1+2); + std::list> l2(a2, a2+2); + l1.splice(next(l1.begin()), l2); + assert(l1.size() == 4); + assert(distance(l1.begin(), l1.end()) == 4); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 2); + } + { + std::list> l1(a1, a1+2); + std::list> l2(a2, a2+2); + l1.splice(next(l1.begin(), 2), l2); + assert(l1.size() == 4); + assert(distance(l1.begin(), l1.end()) == 4); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + } + { + std::list> l1(a1, a1+3); + std::list> l2(a2, a2+3); + l1.splice(l1.begin(), l2); + assert(l1.size() == 6); + assert(distance(l1.begin(), l1.end()) == 6); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + } + { + std::list> l1(a1, a1+3); + std::list> l2(a2, a2+3); + l1.splice(next(l1.begin()), l2); + assert(l1.size() == 6); + assert(distance(l1.begin(), l1.end()) == 6); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + } + { + std::list> l1(a1, a1+3); + std::list> l2(a2, a2+3); + l1.splice(next(l1.begin(), 2), l2); + assert(l1.size() == 6); + assert(distance(l1.begin(), l1.end()) == 6); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 3); + } + { + std::list> l1(a1, a1+3); + std::list> l2(a2, a2+3); + l1.splice(next(l1.begin(), 3), l2); + assert(l1.size() == 6); + assert(distance(l1.begin(), l1.end()) == 6); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list> v1(3); + std::list> v2(3); + v1.splice(v2.begin(), v2); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter.pass.cpp new file mode 100644 index 00000000000..5082c3f8517 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter.pass.cpp @@ -0,0 +1,357 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void splice(const_iterator position, list& x, iterator i); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "min_allocator.h" + +int main() +{ + int a1[] = {1, 2, 3}; + int a2[] = {4, 5, 6}; + { + std::list l1; + std::list l2(a2, a2+1); + l1.splice(l1.end(), l2, l2.begin()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 4); + } + { + std::list l1; + std::list l2(a2, a2+2); + l1.splice(l1.end(), l2, l2.begin()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 1); + assert(distance(l2.begin(), l2.end()) == 1); + std::list::const_iterator i = l1.begin(); + assert(*i == 4); + i = l2.begin(); + assert(*i == 5); + } + { + std::list l1; + std::list l2(a2, a2+2); + l1.splice(l1.end(), l2, next(l2.begin())); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 1); + assert(distance(l2.begin(), l2.end()) == 1); + std::list::const_iterator i = l1.begin(); + assert(*i == 5); + i = l2.begin(); + assert(*i == 4); + } + { + std::list l1; + std::list l2(a2, a2+3); + l1.splice(l1.end(), l2, l2.begin()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 2); + assert(distance(l2.begin(), l2.end()) == 2); + std::list::const_iterator i = l1.begin(); + assert(*i == 4); + i = l2.begin(); + assert(*i == 5); + ++i; + assert(*i == 6); + } + { + std::list l1; + std::list l2(a2, a2+3); + l1.splice(l1.end(), l2, next(l2.begin())); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 2); + assert(distance(l2.begin(), l2.end()) == 2); + std::list::const_iterator i = l1.begin(); + assert(*i == 5); + i = l2.begin(); + assert(*i == 4); + ++i; + assert(*i == 6); + } + { + std::list l1; + std::list l2(a2, a2+3); + l1.splice(l1.end(), l2, next(l2.begin(), 2)); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 2); + assert(distance(l2.begin(), l2.end()) == 2); + std::list::const_iterator i = l1.begin(); + assert(*i == 6); + i = l2.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + } + { + std::list l1(a1, a1+1); + l1.splice(l1.begin(), l1, l1.begin()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + } + { + std::list l1(a1, a1+1); + std::list l2(a2, a2+1); + l1.splice(l1.begin(), l2, l2.begin()); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 1); + } + { + std::list l1(a1, a1+1); + std::list l2(a2, a2+1); + l1.splice(next(l1.begin()), l2, l2.begin()); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + } + { + std::list l1(a1, a1+2); + l1.splice(l1.begin(), l1, l1.begin()); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list l1(a1, a1+2); + l1.splice(l1.begin(), l1, next(l1.begin())); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + std::list::const_iterator i = l1.begin(); + assert(*i == 2); + ++i; + assert(*i == 1); + } + { + std::list l1(a1, a1+2); + l1.splice(next(l1.begin()), l1, l1.begin()); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list l1(a1, a1+2); + l1.splice(next(l1.begin()), l1, next(l1.begin())); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list v1(3); + std::list v2(3); + v1.splice(v1.begin(), v2, v1.begin()); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::list> l1; + std::list> l2(a2, a2+1); + l1.splice(l1.end(), l2, l2.begin()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 4); + } + { + std::list> l1; + std::list> l2(a2, a2+2); + l1.splice(l1.end(), l2, l2.begin()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 1); + assert(distance(l2.begin(), l2.end()) == 1); + std::list>::const_iterator i = l1.begin(); + assert(*i == 4); + i = l2.begin(); + assert(*i == 5); + } + { + std::list> l1; + std::list> l2(a2, a2+2); + l1.splice(l1.end(), l2, next(l2.begin())); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 1); + assert(distance(l2.begin(), l2.end()) == 1); + std::list>::const_iterator i = l1.begin(); + assert(*i == 5); + i = l2.begin(); + assert(*i == 4); + } + { + std::list> l1; + std::list> l2(a2, a2+3); + l1.splice(l1.end(), l2, l2.begin()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 2); + assert(distance(l2.begin(), l2.end()) == 2); + std::list>::const_iterator i = l1.begin(); + assert(*i == 4); + i = l2.begin(); + assert(*i == 5); + ++i; + assert(*i == 6); + } + { + std::list> l1; + std::list> l2(a2, a2+3); + l1.splice(l1.end(), l2, next(l2.begin())); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 2); + assert(distance(l2.begin(), l2.end()) == 2); + std::list>::const_iterator i = l1.begin(); + assert(*i == 5); + i = l2.begin(); + assert(*i == 4); + ++i; + assert(*i == 6); + } + { + std::list> l1; + std::list> l2(a2, a2+3); + l1.splice(l1.end(), l2, next(l2.begin(), 2)); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(l2.size() == 2); + assert(distance(l2.begin(), l2.end()) == 2); + std::list>::const_iterator i = l1.begin(); + assert(*i == 6); + i = l2.begin(); + assert(*i == 4); + ++i; + assert(*i == 5); + } + { + std::list> l1(a1, a1+1); + l1.splice(l1.begin(), l1, l1.begin()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + } + { + std::list> l1(a1, a1+1); + std::list> l2(a2, a2+1); + l1.splice(l1.begin(), l2, l2.begin()); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 4); + ++i; + assert(*i == 1); + } + { + std::list> l1(a1, a1+1); + std::list> l2(a2, a2+1); + l1.splice(next(l1.begin()), l2, l2.begin()); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(l2.size() == 0); + assert(distance(l2.begin(), l2.end()) == 0); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 4); + } + { + std::list> l1(a1, a1+2); + l1.splice(l1.begin(), l1, l1.begin()); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list> l1(a1, a1+2); + l1.splice(l1.begin(), l1, next(l1.begin())); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + std::list>::const_iterator i = l1.begin(); + assert(*i == 2); + ++i; + assert(*i == 1); + } + { + std::list> l1(a1, a1+2); + l1.splice(next(l1.begin()), l1, l1.begin()); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } + { + std::list> l1(a1, a1+2); + l1.splice(next(l1.begin()), l1, next(l1.begin())); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list> v1(3); + std::list> v2(3); + v1.splice(v1.begin(), v2, v1.begin()); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter_iter.pass.cpp new file mode 100644 index 00000000000..fcc4acceec5 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list_iter_iter.pass.cpp @@ -0,0 +1,237 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void splice(const_iterator position, list& x, iterator first, iterator last); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "min_allocator.h" + +int main() +{ + int a1[] = {1, 2, 3}; + int a2[] = {4, 5, 6}; + { + std::list l1(a1, a1+3); + l1.splice(l1.begin(), l1, next(l1.begin()), next(l1.begin())); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + } + { + std::list l1(a1, a1+3); + l1.splice(l1.begin(), l1, next(l1.begin()), next(l1.begin(), 2)); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + std::list::const_iterator i = l1.begin(); + assert(*i == 2); + ++i; + assert(*i == 1); + ++i; + assert(*i == 3); + } + { + std::list l1(a1, a1+3); + l1.splice(l1.begin(), l1, next(l1.begin()), next(l1.begin(), 3)); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + std::list::const_iterator i = l1.begin(); + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 1); + } + { + std::list l1(a1, a1+3); + std::list l2(a2, a2+3); + l1.splice(l1.begin(), l2, next(l2.begin()), l2.end()); + assert(l1.size() == 5); + assert(distance(l1.begin(), l1.end()) == 5); + std::list::const_iterator i = l1.begin(); + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + assert(l2.size() == 1); + i = l2.begin(); + assert(*i == 4); + } + { + std::list l1(a1, a1+3); + std::list l2(a2, a2+3); + l1.splice(next(l1.begin()), l2, next(l2.begin()), l2.end()); + assert(l1.size() == 5); + assert(distance(l1.begin(), l1.end()) == 5); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + assert(l2.size() == 1); + i = l2.begin(); + assert(*i == 4); + } + { + std::list l1(a1, a1+3); + std::list l2(a2, a2+3); + l1.splice(l1.end(), l2, next(l2.begin()), l2.end()); + assert(l1.size() == 5); + assert(distance(l1.begin(), l1.end()) == 5); + std::list::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + assert(l2.size() == 1); + i = l2.begin(); + assert(*i == 4); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list v1(3); + std::list v2(3); + v1.splice(v1.begin(), v2, v2.begin(), v1.end()); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::list> l1(a1, a1+3); + l1.splice(l1.begin(), l1, next(l1.begin()), next(l1.begin())); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + } + { + std::list> l1(a1, a1+3); + l1.splice(l1.begin(), l1, next(l1.begin()), next(l1.begin(), 2)); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + std::list>::const_iterator i = l1.begin(); + assert(*i == 2); + ++i; + assert(*i == 1); + ++i; + assert(*i == 3); + } + { + std::list> l1(a1, a1+3); + l1.splice(l1.begin(), l1, next(l1.begin()), next(l1.begin(), 3)); + assert(l1.size() == 3); + assert(distance(l1.begin(), l1.end()) == 3); + std::list>::const_iterator i = l1.begin(); + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 1); + } + { + std::list> l1(a1, a1+3); + std::list> l2(a2, a2+3); + l1.splice(l1.begin(), l2, next(l2.begin()), l2.end()); + assert(l1.size() == 5); + assert(distance(l1.begin(), l1.end()) == 5); + std::list>::const_iterator i = l1.begin(); + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + assert(l2.size() == 1); + i = l2.begin(); + assert(*i == 4); + } + { + std::list> l1(a1, a1+3); + std::list> l2(a2, a2+3); + l1.splice(next(l1.begin()), l2, next(l2.begin()), l2.end()); + assert(l1.size() == 5); + assert(distance(l1.begin(), l1.end()) == 5); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + assert(l2.size() == 1); + i = l2.begin(); + assert(*i == 4); + } + { + std::list> l1(a1, a1+3); + std::list> l2(a2, a2+3); + l1.splice(l1.end(), l2, next(l2.begin()), l2.end()); + assert(l1.size() == 5); + assert(distance(l1.begin(), l1.end()) == 5); + std::list>::const_iterator i = l1.begin(); + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 5); + ++i; + assert(*i == 6); + assert(l2.size() == 1); + i = l2.begin(); + assert(*i == 4); + } +#if _LIBCPP_DEBUG >= 1 + { + std::list> v1(3); + std::list> v2(3); + v1.splice(v1.begin(), v2, v2.begin(), v1.end()); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/unique.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/unique.pass.cpp new file mode 100644 index 00000000000..48cad1ddd15 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/unique.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void unique(); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {2, 1, 1, 4, 4, 4, 4, 3, 3}; + int a2[] = {2, 1, 4, 3}; + std::list c(a1, a1+sizeof(a1)/sizeof(a1[0])); + c.unique(); + assert(c == std::list(a2, a2+4)); + } +#if __cplusplus >= 201103L + { + int a1[] = {2, 1, 1, 4, 4, 4, 4, 3, 3}; + int a2[] = {2, 1, 4, 3}; + std::list> c(a1, a1+sizeof(a1)/sizeof(a1[0])); + c.unique(); + assert((c == std::list>(a2, a2+4))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.ops/unique_pred.pass.cpp b/libcxx/test/std/containers/sequences/list/list.ops/unique_pred.pass.cpp new file mode 100644 index 00000000000..f8935b81f6a --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.ops/unique_pred.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template void unique(BinaryPred pred); + +#include +#include + +#include "min_allocator.h" + +bool g(int x, int y) +{ + return x == y; +} + +int main() +{ + { + int a1[] = {2, 1, 1, 4, 4, 4, 4, 3, 3}; + int a2[] = {2, 1, 4, 3}; + std::list c(a1, a1+sizeof(a1)/sizeof(a1[0])); + c.unique(g); + assert(c == std::list(a2, a2+4)); + } +#if __cplusplus >= 201103L + { + int a1[] = {2, 1, 1, 4, 4, 4, 4, 3, 3}; + int a2[] = {2, 1, 4, 3}; + std::list> c(a1, a1+sizeof(a1)/sizeof(a1[0])); + c.unique(g); + assert((c == std::list>(a2, a2+4))); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.special/db_swap_1.pass.cpp b/libcxx/test/std/containers/sequences/list/list.special/db_swap_1.pass.cpp new file mode 100644 index 00000000000..f7171795cd5 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.special/db_swap_1.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// void swap(list& x, list& y); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include <__debug> +#include "min_allocator.h" + +int main() +{ +#if _LIBCPP_DEBUG >= 1 + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::list c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + std::list::iterator i1 = c1.begin(); + std::list::iterator i2 = c2.begin(); + swap(c1, c2); + c1.erase(i2); + c2.erase(i1); + std::list::iterator j = i1; + c1.erase(i1); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::list> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + std::list>::iterator i1 = c1.begin(); + std::list>::iterator i2 = c2.begin(); + swap(c1, c2); + c1.erase(i2); + c2.erase(i1); + std::list>::iterator j = i1; + c1.erase(i1); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.special/swap.pass.cpp b/libcxx/test/std/containers/sequences/list/list.special/swap.pass.cpp new file mode 100644 index 00000000000..bc5f4857edc --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.special/swap.pass.cpp @@ -0,0 +1,146 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// void swap(list& x, list& y); + +#include +#include +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::list c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + swap(c1, c2); + assert(c1 == std::list(a2, a2+sizeof(a2)/sizeof(a2[0]))); + assert(c2 == std::list(a1, a1+sizeof(a1)/sizeof(a1[0]))); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::list c1(a1, a1); + std::list c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + swap(c1, c2); + assert(c1 == std::list(a2, a2+sizeof(a2)/sizeof(a2[0]))); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::list c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list c2(a2, a2); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert(c2 == std::list(a1, a1+sizeof(a1)/sizeof(a1[0]))); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::list c1(a1, a1); + std::list c2(a2, a2); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + } +#ifndef _LIBCPP_DEBUG_LEVEL +// This test known to result in undefined behavior detected by _LIBCPP_DEBUG_LEVEL >= 1 + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef test_allocator A; + std::list c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1)); + std::list c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2)); + swap(c1, c2); + assert((c1 == std::list(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A(1)); + assert((c2 == std::list(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A(2)); + } +#endif + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef other_allocator A; + std::list c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1)); + std::list c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2)); + swap(c1, c2); + assert((c1 == std::list(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A(2)); + assert((c2 == std::list(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A(1)); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::list> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + swap(c1, c2); + assert((c1 == std::list>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert((c2 == std::list>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::list> c1(a1, a1); + std::list> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + swap(c1, c2); + assert((c1 == std::list>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::list> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::list> c2(a2, a2); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert((c2 == std::list>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::list> c1(a1, a1); + std::list> c2(a2, a2); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + } +#ifndef _LIBCPP_DEBUG_LEVEL +// This test known to result in undefined behavior detected by _LIBCPP_DEBUG_LEVEL >= 1 + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef min_allocator A; + std::list c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A()); + std::list c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A()); + swap(c1, c2); + assert((c1 == std::list(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A()); + assert((c2 == std::list(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A()); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/list.special/swap_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/list/list.special/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..7a23398e80a --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/list.special/swap_noexcept.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(list& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + + some_alloc() {} + some_alloc(const some_alloc&); + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::list C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::list> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::list> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::list> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/types.pass.cpp b/libcxx/test/std/containers/sequences/list/types.pass.cpp new file mode 100644 index 00000000000..95d7f5010f0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/types.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template > +// class list +// { +// public: +// +// // types: +// typedef T value_type; +// typedef Alloc allocator_type; +// typedef typename allocator_type::reference reference; +// typedef typename allocator_type::const_reference const_reference; +// typedef typename allocator_type::pointer pointer; +// typedef typename allocator_type::const_pointer const_pointer; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + static_assert((std::is_same::value_type, int>::value), ""); + static_assert((std::is_same::allocator_type, std::allocator >::value), ""); + static_assert((std::is_same::reference, std::allocator::reference>::value), ""); + static_assert((std::is_same::const_reference, std::allocator::const_reference>::value), ""); + static_assert((std::is_same::pointer, std::allocator::pointer>::value), ""); + static_assert((std::is_same::const_pointer, std::allocator::const_pointer>::value), ""); +#if __cplusplus >= 201103L + static_assert((std::is_same>::value_type, int>::value), ""); + static_assert((std::is_same>::allocator_type, min_allocator >::value), ""); + static_assert((std::is_same>::reference, int&>::value), ""); + static_assert((std::is_same>::const_reference, const int&>::value), ""); + static_assert((std::is_same>::pointer, min_pointer>::value), ""); + static_assert((std::is_same>::const_pointer, min_pointer>::value), ""); +#endif +} diff --git a/libcxx/test/std/containers/sequences/list/version.pass.cpp b/libcxx/test/std/containers/sequences/list/version.pass.cpp new file mode 100644 index 00000000000..097c013f52c --- /dev/null +++ b/libcxx/test/std/containers/sequences/list/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +#include + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/nothing_to_do.pass.cpp b/libcxx/test/std/containers/sequences/nothing_to_do.pass.cpp new file mode 100644 index 00000000000..b58f5c55b64 --- /dev/null +++ b/libcxx/test/std/containers/sequences/nothing_to_do.pass.cpp @@ -0,0 +1,12 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/assign_copy.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/assign_copy.pass.cpp new file mode 100644 index 00000000000..9501799ae3d --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/assign_copy.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector& operator=(const vector& c); + +#include +#include +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + std::vector > l(3, 2, test_allocator(5)); + std::vector > l2(l, test_allocator(3)); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == test_allocator(3)); + } + { + std::vector > l(3, 2, other_allocator(5)); + std::vector > l2(l, other_allocator(3)); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == other_allocator(5)); + } +#if __cplusplus >= 201103L + { + std::vector > l(3, 2, min_allocator()); + std::vector > l2(l, min_allocator()); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == min_allocator()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..2925fbc6674 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/assign_initializer_list.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void assign(initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector d; + d.assign({true, false, false, true}); + assert(d.size() == 4); + assert(d[0] == true); + assert(d[1] == false); + assert(d[2] == false); + assert(d[3] == true); + } +#if __cplusplus >= 201103L + { + std::vector> d; + d.assign({true, false, false, true}); + assert(d.size() == 4); + assert(d[0] == true); + assert(d[1] == false); + assert(d[2] == false); + assert(d[3] == true); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/assign_move.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/assign_move.pass.cpp new file mode 100644 index 00000000000..df98c817fd5 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/assign_move.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector& operator=(vector&& c); + +#include +#include +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector > l(test_allocator(5)); + std::vector > lo(test_allocator(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector > l2(test_allocator(5)); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } + { + std::vector > l(test_allocator(5)); + std::vector > lo(test_allocator(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector > l2(test_allocator(6)); + l2 = std::move(l); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == test_allocator(6)); + } + { + std::vector > l(other_allocator(5)); + std::vector > lo(other_allocator(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector > l2(other_allocator(6)); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } +#if __cplusplus >= 201103L + { + std::vector > l(min_allocator{}); + std::vector > lo(min_allocator{}); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector > l2(min_allocator{}); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/capacity.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/capacity.pass.cpp new file mode 100644 index 00000000000..63bff25f9f9 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/capacity.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// size_type capacity() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + std::vector v; + assert(v.capacity() == 0); + } + { + std::vector v(100); + assert(v.capacity() >= 100); + v.push_back(0); + assert(v.capacity() >= 101); + } +#if __cplusplus >= 201103L + { + std::vector> v; + assert(v.capacity() == 0); + } + { + std::vector> v(100); + assert(v.capacity() >= 100); + v.push_back(0); + assert(v.capacity() >= 101); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/construct_default.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/construct_default.pass.cpp new file mode 100644 index 00000000000..d3d6670bbf2 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/construct_default.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// vector(const Alloc& = Alloc()); + +#include +#include + +#include "test_allocator.h" +#include "min_allocator.h" + +template +void +test0() +{ + C c; + assert(c.__invariants()); + assert(c.empty()); + assert(c.get_allocator() == typename C::allocator_type()); +#if __cplusplus >= 201103L + C c1 = {}; + assert(c1.__invariants()); + assert(c1.empty()); + assert(c1.get_allocator() == typename C::allocator_type()); +#endif +} + +template +void +test1(const typename C::allocator_type& a) +{ + C c(a); + assert(c.__invariants()); + assert(c.empty()); + assert(c.get_allocator() == a); +} + +int main() +{ + { + test0 >(); + test1 > >(test_allocator(3)); + } +#if __cplusplus >= 201103L + { + test0> >(); + test1 > >(min_allocator()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/construct_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/construct_iter_iter.pass.cpp new file mode 100644 index 00000000000..94e6801825d --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/construct_iter_iter.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// template vector(InputIter first, InputIter last); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +template +void +test(Iterator first, Iterator last) +{ + C c(first, last); + assert(c.__invariants()); + assert(c.size() == std::distance(first, last)); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first) + assert(*i == *first); +} + +int main() +{ + bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0}; + bool* an = a + sizeof(a)/sizeof(a[0]); + test >(input_iterator(a), input_iterator(an)); + test >(forward_iterator(a), forward_iterator(an)); + test >(bidirectional_iterator(a), bidirectional_iterator(an)); + test >(random_access_iterator(a), random_access_iterator(an)); + test >(a, an); +#if __cplusplus >= 201103L + test> >(input_iterator(a), input_iterator(an)); + test> >(forward_iterator(a), forward_iterator(an)); + test> >(bidirectional_iterator(a), bidirectional_iterator(an)); + test> >(random_access_iterator(a), random_access_iterator(an)); + test> >(a, an); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/construct_iter_iter_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/construct_iter_iter_alloc.pass.cpp new file mode 100644 index 00000000000..ea9d41d342f --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/construct_iter_iter_alloc.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// template vector(InputIter first, InputIter last, +// const allocator_type& a); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +template +void +test(Iterator first, Iterator last, const typename C::allocator_type& a) +{ + C c(first, last, a); + assert(c.__invariants()); + assert(c.size() == std::distance(first, last)); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first) + assert(*i == *first); +} + +int main() +{ + bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0}; + bool* an = a + sizeof(a)/sizeof(a[0]); + { + std::allocator alloc; + test >(input_iterator(a), input_iterator(an), alloc); + test >(forward_iterator(a), forward_iterator(an), alloc); + test >(bidirectional_iterator(a), bidirectional_iterator(an), alloc); + test >(random_access_iterator(a), random_access_iterator(an), alloc); + test >(a, an, alloc); + } +#if __cplusplus >= 201103L + { + min_allocator alloc; + test> >(input_iterator(a), input_iterator(an), alloc); + test> >(forward_iterator(a), forward_iterator(an), alloc); + test> >(bidirectional_iterator(a), bidirectional_iterator(an), alloc); + test> >(random_access_iterator(a), random_access_iterator(an), alloc); + test> >(a, an, alloc); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/construct_size.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/construct_size.pass.cpp new file mode 100644 index 00000000000..93ecbe87c38 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/construct_size.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// explicit vector(size_type n); + +#include +#include + +#include "min_allocator.h" +#include "test_allocator.h" + +template +void +test2(typename C::size_type n, typename C::allocator_type const& a = typename C::allocator_type ()) +{ +#if _LIBCPP_STD_VER > 11 + C c(n, a); + assert(c.__invariants()); + assert(c.size() == n); + assert(c.get_allocator() == a); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == typename C::value_type()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} + +template +void +test1(typename C::size_type n) +{ + C c(n); + assert(c.__invariants()); + assert(c.size() == n); + assert(c.get_allocator() == typename C::allocator_type()); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == typename C::value_type()); +} + +template +void +test(typename C::size_type n) +{ + test1 ( n ); + test2 ( n ); +} + +int main() +{ + test >(50); +#if __cplusplus >= 201103L + test> >(50); + test2> >( 100, test_allocator(23)); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/construct_size_value.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/construct_size_value.pass.cpp new file mode 100644 index 00000000000..fc772f10dfc --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/construct_size_value.pass.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// vector(size_type n, const value_type& x); + +#include +#include + +#include "min_allocator.h" + +template +void +test(typename C::size_type n, const typename C::value_type& x) +{ + C c(n, x); + assert(c.__invariants()); + assert(c.size() == n); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == x); +} + +int main() +{ + test >(50, 3); +#if __cplusplus >= 201103L + test> >(50, 3); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/construct_size_value_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/construct_size_value_alloc.pass.cpp new file mode 100644 index 00000000000..6cca948ed83 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/construct_size_value_alloc.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// vector(size_type n, const value_type& x, const allocator_type& a); + +#include +#include + +#include "min_allocator.h" + +template +void +test(typename C::size_type n, const typename C::value_type& x, + const typename C::allocator_type& a) +{ + C c(n, x, a); + assert(c.__invariants()); + assert(a == c.get_allocator()); + assert(c.size() == n); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == x); +} + +int main() +{ + test >(50, 3, std::allocator()); +#if __cplusplus >= 201103L + test> >(50, 3, min_allocator()); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/copy.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/copy.pass.cpp new file mode 100644 index 00000000000..58822782ff8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/copy.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// vector(const vector& v); + +#include +#include +#include "test_allocator.h" +#include "min_allocator.h" + +template +void +test(const C& x) +{ + unsigned s = x.size(); + C c(x); + assert(c.__invariants()); + assert(c.size() == s); + assert(c == x); +} + +int main() +{ + { + bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0}; + bool* an = a + sizeof(a)/sizeof(a[0]); + test(std::vector(a, an)); + } + { + std::vector > v(3, 2, test_allocator(5)); + std::vector > v2 = v; + assert(v2 == v); + assert(v2.get_allocator() == v.get_allocator()); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + std::vector > v(3, 2, other_allocator(5)); + std::vector > v2 = v; + assert(v2 == v); + assert(v2.get_allocator() == other_allocator(-2)); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0}; + bool* an = a + sizeof(a)/sizeof(a[0]); + test(std::vector>(a, an)); + } + { + std::vector > v(3, 2, min_allocator()); + std::vector > v2 = v; + assert(v2 == v); + assert(v2.get_allocator() == v.get_allocator()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/copy_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/copy_alloc.pass.cpp new file mode 100644 index 00000000000..2f0192b995a --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/copy_alloc.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector(const vector& v, const allocator_type& a); + +#include +#include +#include "test_allocator.h" +#include "min_allocator.h" + +template +void +test(const C& x, const typename C::allocator_type& a) +{ + unsigned s = x.size(); + C c(x, a); + assert(c.__invariants()); + assert(c.size() == s); + assert(c == x); +} + +int main() +{ + { + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + test(std::vector(a, an), std::allocator()); + } + { + std::vector > l(3, 2, test_allocator(5)); + std::vector > l2(l, test_allocator(3)); + assert(l2 == l); + assert(l2.get_allocator() == test_allocator(3)); + } + { + std::vector > l(3, 2, other_allocator(5)); + std::vector > l2(l, other_allocator(3)); + assert(l2 == l); + assert(l2.get_allocator() == other_allocator(3)); + } +#if __cplusplus >= 201103L + { + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + test(std::vector>(a, an), min_allocator()); + } + { + std::vector > l(3, 2, min_allocator()); + std::vector > l2(l, min_allocator()); + assert(l2 == l); + assert(l2.get_allocator() == min_allocator()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/default_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/default_noexcept.pass.cpp new file mode 100644 index 00000000000..b94588ead93 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/default_noexcept.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector() +// noexcept(is_nothrow_default_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::vector> C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::vector> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::vector> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..682e74ef03c --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/dtor_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// ~vector() // implied noexcept; + +#include +#include + +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); + ~some_alloc() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::vector> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::vector> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::vector> C; + static_assert(!std::is_nothrow_destructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/emplace.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/emplace.pass.cpp new file mode 100644 index 00000000000..f3fd1e9926f --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/emplace.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// template iterator emplace(const_iterator pos, Args&&... args); + +#include +#include +#include "min_allocator.h" + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + typedef std::vector C; + C c; + + C::iterator i = c.emplace(c.cbegin()); + assert(i == c.begin()); + assert(c.size() == 1); + assert(c.front() == false); + + i = c.emplace(c.cend(), true); + assert(i == c.end()-1); + assert(c.size() == 2); + assert(c.front() == false); + assert(c.back() == true); + + i = c.emplace(c.cbegin()+1, 1 == 1); + assert(i == c.begin()+1); + assert(c.size() == 3); + assert(c.front() == false); + assert(c[1] == true); + assert(c.back() == true); + } + { + typedef std::vector> C; + C c; + + C::iterator i = c.emplace(c.cbegin()); + assert(i == c.begin()); + assert(c.size() == 1); + assert(c.front() == false); + + i = c.emplace(c.cend(), true); + assert(i == c.end()-1); + assert(c.size() == 2); + assert(c.front() == false); + assert(c.back() == true); + + i = c.emplace(c.cbegin()+1, 1 == 1); + assert(i == c.begin()+1); + assert(c.size() == 3); + assert(c.size() == 3); + assert(c.front() == false); + assert(c[1] == true); + assert(c.back() == true); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/emplace_back.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/emplace_back.pass.cpp new file mode 100644 index 00000000000..57aa47822f8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/emplace_back.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector.bool + +// template void emplace_back(Args&&... args); + +#include +#include +#include "min_allocator.h" + + +int main() +{ +#if _LIBCPP_STD_VER > 11 + { + typedef std::vector C; + C c; + c.emplace_back(); + assert(c.size() == 1); + assert(c.front() == false); + c.emplace_back(true); + assert(c.size() == 2); + assert(c.front() == false); + assert(c.back() == true); + c.emplace_back(1 == 1); + assert(c.size() == 3); + assert(c.front() == false); + assert(c[1] == true); + assert(c.back() == true); + } + { + typedef std::vector> C; + C c; + + c.emplace_back(); + assert(c.size() == 1); + assert(c.front() == false); + c.emplace_back(true); + assert(c.size() == 2); + assert(c.front() == false); + assert(c.back() == true); + c.emplace_back(1 == 1); + assert(c.size() == 3); + assert(c.front() == false); + assert(c[1] == true); + assert(c.back() == true); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/erase_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/erase_iter.pass.cpp new file mode 100644 index 00000000000..cbf26dd570a --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/erase_iter.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// iterator erase(const_iterator position); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + bool a1[] = {1, 0, 1}; + { + std::vector l1(a1, a1+3); + std::vector::const_iterator i = l1.begin(); + ++i; + std::vector::iterator j = l1.erase(i); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(*j == true); + assert(*l1.begin() == 1); + assert(*next(l1.begin()) == true); + j = l1.erase(j); + assert(j == l1.end()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(*l1.begin() == true); + j = l1.erase(l1.begin()); + assert(j == l1.end()); + assert(l1.size() == 0); + assert(distance(l1.begin(), l1.end()) == 0); + } +#if __cplusplus >= 201103L + { + std::vector> l1(a1, a1+3); + std::vector>::const_iterator i = l1.begin(); + ++i; + std::vector>::iterator j = l1.erase(i); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(*j == true); + assert(*l1.begin() == 1); + assert(*next(l1.begin()) == true); + j = l1.erase(j); + assert(j == l1.end()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(*l1.begin() == true); + j = l1.erase(l1.begin()); + assert(j == l1.end()); + assert(l1.size() == 0); + assert(distance(l1.begin(), l1.end()) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/erase_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..2c2c4cc4861 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/erase_iter_iter.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// iterator erase(const_iterator first, const_iterator last); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + bool a1[] = {1, 0, 1}; + { + std::vector l1(a1, a1+3); + std::vector::iterator i = l1.erase(l1.cbegin(), l1.cbegin()); + assert(l1.size() == 3); + assert(distance(l1.cbegin(), l1.cend()) == 3); + assert(i == l1.begin()); + } + { + std::vector l1(a1, a1+3); + std::vector::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin())); + assert(l1.size() == 2); + assert(distance(l1.cbegin(), l1.cend()) == 2); + assert(i == l1.begin()); + assert(l1 == std::vector(a1+1, a1+3)); + } + { + std::vector l1(a1, a1+3); + std::vector::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 2)); + assert(l1.size() == 1); + assert(distance(l1.cbegin(), l1.cend()) == 1); + assert(i == l1.begin()); + assert(l1 == std::vector(a1+2, a1+3)); + } + { + std::vector l1(a1, a1+3); + std::vector::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 3)); + assert(l1.size() == 0); + assert(distance(l1.cbegin(), l1.cend()) == 0); + assert(i == l1.begin()); + } +#if __cplusplus >= 201103L + { + std::vector> l1(a1, a1+3); + std::vector>::iterator i = l1.erase(l1.cbegin(), l1.cbegin()); + assert(l1.size() == 3); + assert(distance(l1.cbegin(), l1.cend()) == 3); + assert(i == l1.begin()); + } + { + std::vector> l1(a1, a1+3); + std::vector>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin())); + assert(l1.size() == 2); + assert(distance(l1.cbegin(), l1.cend()) == 2); + assert(i == l1.begin()); + assert((l1 == std::vector>(a1+1, a1+3))); + } + { + std::vector> l1(a1, a1+3); + std::vector>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 2)); + assert(l1.size() == 1); + assert(distance(l1.cbegin(), l1.cend()) == 1); + assert(i == l1.begin()); + assert((l1 == std::vector>(a1+2, a1+3))); + } + { + std::vector> l1(a1, a1+3); + std::vector>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 3)); + assert(l1.size() == 0); + assert(distance(l1.cbegin(), l1.cend()) == 0); + assert(i == l1.begin()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/find.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/find.pass.cpp new file mode 100644 index 00000000000..75567a9b7bb --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/find.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// std::find with vector::iterator + +// http://llvm.org/bugs/show_bug.cgi?id=16816 + +#include +#include + +int main() +{ + { + for (unsigned i = 1; i < 256; ++i) + { + std::vector b(i,true); + std::vector::iterator j = std::find(b.begin()+1, b.end(), false); + assert(j-b.begin() == i); + assert(b.end() == j); + } + } + { + for (unsigned i = 1; i < 256; ++i) + { + std::vector b(i,false); + std::vector::iterator j = std::find(b.begin()+1, b.end(), true); + assert(j-b.begin() == i); + assert(b.end() == j); + } + } +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/initializer_list.pass.cpp new file mode 100644 index 00000000000..b9b46865449 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/initializer_list.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector(initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector d = {true, false, false, true}; + assert(d.size() == 4); + assert(d[0] == true); + assert(d[1] == false); + assert(d[2] == false); + assert(d[3] == true); + } +#if __cplusplus >= 201103L + { + std::vector> d = {true, false, false, true}; + assert(d.size() == 4); + assert(d[0] == true); + assert(d[1] == false); + assert(d[2] == false); + assert(d[3] == true); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/initializer_list_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/initializer_list_alloc.pass.cpp new file mode 100644 index 00000000000..aea3ad763cd --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/initializer_list_alloc.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector(initializer_list il, const Allocator& a = allocator_type()); + +#include +#include + +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector> d({true, false, false, true}, test_allocator(3)); + assert(d.get_allocator() == test_allocator(3)); + assert(d.size() == 4); + assert(d[0] == true); + assert(d[1] == false); + assert(d[2] == false); + assert(d[3] == true); + } +#if __cplusplus >= 201103L + { + std::vector> d({true, false, false, true}, min_allocator()); + assert(d.get_allocator() == min_allocator()); + assert(d.size() == 4); + assert(d[0] == true); + assert(d[1] == false); + assert(d[2] == false); + assert(d[3] == true); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/insert_iter_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/insert_iter_initializer_list.pass.cpp new file mode 100644 index 00000000000..c081cc81c59 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/insert_iter_initializer_list.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator insert(const_iterator p, initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector d(10, true); + std::vector::iterator i = d.insert(d.cbegin() + 2, {false, true, true, false}); + assert(d.size() == 14); + assert(i == d.begin() + 2); + assert(d[0] == true); + assert(d[1] == true); + assert(d[2] == false); + assert(d[3] == true); + assert(d[4] == true); + assert(d[5] == false); + assert(d[6] == true); + assert(d[7] == true); + assert(d[8] == true); + assert(d[9] == true); + assert(d[10] == true); + assert(d[11] == true); + assert(d[12] == true); + assert(d[13] == true); + } +#if __cplusplus >= 201103L + { + std::vector> d(10, true); + std::vector>::iterator i = d.insert(d.cbegin() + 2, {false, true, true, false}); + assert(d.size() == 14); + assert(i == d.begin() + 2); + assert(d[0] == true); + assert(d[1] == true); + assert(d[2] == false); + assert(d[3] == true); + assert(d[4] == true); + assert(d[5] == false); + assert(d[6] == true); + assert(d[7] == true); + assert(d[8] == true); + assert(d[9] == true); + assert(d[10] == true); + assert(d[11] == true); + assert(d[12] == true); + assert(d[13] == true); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp new file mode 100644 index 00000000000..e51f8b589c7 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/insert_iter_iter_iter.pass.cpp @@ -0,0 +1,126 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// template +// iterator insert(const_iterator position, Iter first, Iter last); + +#include +#include +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + std::vector v(100); + bool a[] = {1, 0, 0, 1, 1}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector::iterator i = v.insert(v.cbegin() + 10, input_iterator(a), + input_iterator(a+N)); + assert(v.size() == 100 + N); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector v(100); + bool a[] = {1, 0, 0, 1, 1}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector::iterator i = v.insert(v.cbegin() + 10, forward_iterator(a), + forward_iterator(a+N)); + assert(v.size() == 100 + N); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } + { + std::vector v(100); + while(v.size() < v.capacity()) v.push_back(false); + size_t sz = v.size(); + bool a[] = {1, 0, 0, 1, 1}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector::iterator i = v.insert(v.cbegin() + 10, forward_iterator(a), + forward_iterator(a+N)); + assert(v.size() == sz + N); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector v(100); + while(v.size() < v.capacity()) v.push_back(false); + v.pop_back(); v.pop_back(); v.pop_back(); + size_t sz = v.size(); + bool a[] = {1, 0, 0, 1, 1}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector::iterator i = v.insert(v.cbegin() + 10, forward_iterator(a), + forward_iterator(a+N)); + assert(v.size() == sz + N); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < v.size(); ++j) + assert(v[j] == 0); + } +#if __cplusplus >= 201103L + { + std::vector> v(100); + bool a[] = {1, 0, 0, 1, 1}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector>::iterator i = v.insert(v.cbegin() + 10, input_iterator(a), + input_iterator(a+N)); + assert(v.size() == 100 + N); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector> v(100); + bool a[] = {1, 0, 0, 1, 1}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector>::iterator i = v.insert(v.cbegin() + 10, forward_iterator(a), + forward_iterator(a+N)); + assert(v.size() == 100 + N); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < v.size(); ++j) + assert(v[j] == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp new file mode 100644 index 00000000000..710ad4885f0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/insert_iter_size_value.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// iterator insert(const_iterator position, size_type n, const value_type& x); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + std::vector v(100); + std::vector::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == 105); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector v(100); + while(v.size() < v.capacity()) v.push_back(false); + size_t sz = v.size(); + std::vector::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == sz + 5); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector v(100); + while(v.size() < v.capacity()) v.push_back(false); + v.pop_back(); v.pop_back(); + size_t sz = v.size(); + std::vector::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == sz + 5); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } +#if __cplusplus >= 201103L + { + std::vector> v(100); + std::vector>::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == 105); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/insert_iter_value.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/insert_iter_value.pass.cpp new file mode 100644 index 00000000000..51c4626de0d --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/insert_iter_value.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// iterator insert(const_iterator position, const value_type& x); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + std::vector v(100); + std::vector::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == 101); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector v(100); + while(v.size() < v.capacity()) v.push_back(false); + size_t sz = v.size(); + std::vector::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == sz + 1); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector v(100); + while(v.size() < v.capacity()) v.push_back(false); + v.pop_back(); v.pop_back(); + size_t sz = v.size(); + std::vector::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == sz + 1); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } +#if __cplusplus >= 201103L + { + std::vector> v(100); + std::vector>::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == 101); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/iterators.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/iterators.pass.cpp new file mode 100644 index 00000000000..c54fa4a80a9 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/iterators.pass.cpp @@ -0,0 +1,123 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator begin(); +// iterator end(); +// const_iterator begin() const; +// const_iterator end() const; +// const_iterator cbegin() const; +// const_iterator cend() const; + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef bool T; + typedef std::vector C; + C c; + C::iterator i = c.begin(); + C::iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef bool T; + typedef std::vector C; + const C c; + C::const_iterator i = c.begin(); + C::const_iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef bool T; + typedef std::vector C; + C c; + C::const_iterator i = c.cbegin(); + C::const_iterator j = c.cend(); + assert(std::distance(i, j) == 0); + assert(i == j); + assert(i == c.end()); + } + { + typedef bool T; + typedef std::vector C; + C::iterator i; + C::const_iterator j; + } +#if __cplusplus >= 201103L + { + typedef bool T; + typedef std::vector> C; + C c; + C::iterator i = c.begin(); + C::iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef bool T; + typedef std::vector> C; + const C c; + C::const_iterator i = c.begin(); + C::const_iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef bool T; + typedef std::vector> C; + C c; + C::const_iterator i = c.cbegin(); + C::const_iterator j = c.cend(); + assert(std::distance(i, j) == 0); + assert(i == j); + assert(i == c.end()); + } + { + typedef bool T; + typedef std::vector> C; + C::iterator i; + C::const_iterator j; + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + std::vector::iterator ii1{}, ii2{}; + std::vector::iterator ii4 = ii1; + std::vector::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + assert (!(ii1 < cii )); + assert (!(cii < ii1 )); + assert ( (ii1 <= cii )); + assert ( (cii <= ii1 )); + assert (!(ii1 > cii )); + assert (!(cii > ii1 )); + assert ( (ii1 >= cii )); + assert ( (cii >= ii1 )); + assert (cii - ii1 == 0); + assert (ii1 - cii == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/move.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/move.pass.cpp new file mode 100644 index 00000000000..e877292ced7 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/move.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector(vector&& c); + +#include +#include +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector > l(test_allocator(5)); + std::vector > lo(test_allocator(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } + { + std::vector > l(other_allocator(5)); + std::vector > lo(other_allocator(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } +#if __cplusplus >= 201103L + { + std::vector > l(min_allocator{}); + std::vector > lo(min_allocator{}); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/move_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/move_alloc.pass.cpp new file mode 100644 index 00000000000..deee9326197 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/move_alloc.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector(vector&& c, const allocator_type& a); + +#include +#include +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector > l(test_allocator(5)); + std::vector > lo(test_allocator(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector > l2(std::move(l), test_allocator(6)); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == test_allocator(6)); + } + { + std::vector > l(test_allocator(5)); + std::vector > lo(test_allocator(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector > l2(std::move(l), test_allocator(5)); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == test_allocator(5)); + } + { + std::vector > l(other_allocator(5)); + std::vector > lo(other_allocator(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector > l2(std::move(l), other_allocator(4)); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == other_allocator(4)); + } +#if __cplusplus >= 201103L + { + std::vector > l(min_allocator{}); + std::vector > lo(min_allocator{}); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + std::vector > l2(std::move(l), min_allocator()); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == min_allocator()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..b580eb4ae3b --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/move_assign_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector& operator=(vector&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable::value); + +// This tests a conforming extension + +#include +#include + +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::vector> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::vector> C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::vector> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/move_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/move_noexcept.pass.cpp new file mode 100644 index 00000000000..ab32bd0677b --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/move_noexcept.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector(vector&&) +// noexcept(is_nothrow_move_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::vector> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::vector> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::vector> C; + static_assert(!std::is_nothrow_move_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/op_equal_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/op_equal_initializer_list.pass.cpp new file mode 100644 index 00000000000..ef3dc5d1079 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/op_equal_initializer_list.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector& operator=(initializer_list il); + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector d; + d = {true, false, false, true}; + assert(d.size() == 4); + assert(d[0] == true); + assert(d[1] == false); + assert(d[2] == false); + assert(d[3] == true); + } +#if __cplusplus >= 201103L + { + std::vector> d; + d = {true, false, false, true}; + assert(d.size() == 4); + assert(d[0] == true); + assert(d[1] == false); + assert(d[2] == false); + assert(d[3] == true); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/push_back.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/push_back.pass.cpp new file mode 100644 index 00000000000..c6b0fbf4185 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/push_back.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// void push_back(const value_type& x); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + bool a[] = {0, 1, 1, 0, 1, 0, 0}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector c; + for (unsigned i = 0; i < N; ++i) + { + c.push_back(a[i]); + assert(c.size() == i+1); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == a[j]); + } + } +#if __cplusplus >= 201103L + { + bool a[] = {0, 1, 1, 0, 1, 0, 0}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector> c; + for (unsigned i = 0; i < N; ++i) + { + c.push_back(a[i]); + assert(c.size() == i+1); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == a[j]); + } + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/reserve.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/reserve.pass.cpp new file mode 100644 index 00000000000..be717a3be8a --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/reserve.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// void reserve(size_type n); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + std::vector v; + v.reserve(10); + assert(v.capacity() >= 10); + } + { + std::vector v(100); + assert(v.capacity() >= 100); + v.reserve(50); + assert(v.size() == 100); + assert(v.capacity() >= 100); + v.reserve(150); + assert(v.size() == 100); + assert(v.capacity() >= 150); + } +#if __cplusplus >= 201103L + { + std::vector> v; + v.reserve(10); + assert(v.capacity() >= 10); + } + { + std::vector> v(100); + assert(v.capacity() >= 100); + v.reserve(50); + assert(v.size() == 100); + assert(v.capacity() >= 100); + v.reserve(150); + assert(v.size() == 100); + assert(v.capacity() >= 150); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/resize_size.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/resize_size.pass.cpp new file mode 100644 index 00000000000..f75720c94ea --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/resize_size.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// void resize(size_type sz); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + std::vector v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() >= 100); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + v.reserve(400); + v.resize(300); // check the case when resizing and we already have room + assert(v.size() == 300); + assert(v.capacity() >= 400); + } +#if __cplusplus >= 201103L + { + std::vector> v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() >= 100); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + v.reserve(400); + v.resize(300); // check the case when resizing and we already have room + assert(v.size() == 300); + assert(v.capacity() >= 400); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/resize_size_value.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/resize_size_value.pass.cpp new file mode 100644 index 00000000000..8cecf44d2fb --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/resize_size_value.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// void resize(size_type sz, const value_type& x); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + std::vector v(100); + v.resize(50, 1); + assert(v.size() == 50); + assert(v.capacity() >= 100); + assert(v == std::vector(50)); + v.resize(200, 1); + assert(v.size() == 200); + assert(v.capacity() >= 200); + for (unsigned i = 0; i < 50; ++i) + assert(v[i] == 0); + for (unsigned i = 50; i < 200; ++i) + assert(v[i] == 1); + } +#if __cplusplus >= 201103L + { + std::vector> v(100); + v.resize(50, 1); + assert(v.size() == 50); + assert(v.capacity() >= 100); + assert((v == std::vector>(50))); + v.resize(200, 1); + assert(v.size() == 200); + assert(v.capacity() >= 200); + for (unsigned i = 0; i < 50; ++i) + assert(v[i] == 0); + for (unsigned i = 50; i < 200; ++i) + assert(v[i] == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/shrink_to_fit.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/shrink_to_fit.pass.cpp new file mode 100644 index 00000000000..1f9fcac3d9b --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/shrink_to_fit.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// void shrink_to_fit(); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + std::vector v(100); + v.push_back(1); + v.shrink_to_fit(); + assert(v.capacity() >= 101); + assert(v.size() >= 101); + } +#if __cplusplus >= 201103L + { + std::vector> v(100); + v.push_back(1); + v.shrink_to_fit(); + assert(v.capacity() >= 101); + assert(v.size() >= 101); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/swap.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/swap.pass.cpp new file mode 100644 index 00000000000..a92c6a6c165 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/swap.pass.cpp @@ -0,0 +1,98 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// vector + +// void swap(vector& x); + +#include +#include +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + std::vector v1(100); + std::vector v2(200); + v1.swap(v2); + assert(v1.size() == 200); + assert(v1.capacity() >= 200); + assert(v2.size() == 100); + assert(v2.capacity() >= 100); + } + { + typedef test_allocator A; + std::vector v1(100, true, A(1)); + std::vector v2(200, false, A(2)); + swap(v1, v2); + assert(v1.size() == 200); + assert(v1.capacity() >= 200); + assert(v2.size() == 100); + assert(v2.capacity() >= 100); + assert(v1.get_allocator() == A(1)); + assert(v2.get_allocator() == A(2)); + } + { + typedef other_allocator A; + std::vector v1(100, true, A(1)); + std::vector v2(200, false, A(2)); + swap(v1, v2); + assert(v1.size() == 200); + assert(v1.capacity() >= 200); + assert(v2.size() == 100); + assert(v2.capacity() >= 100); + assert(v1.get_allocator() == A(2)); + assert(v2.get_allocator() == A(1)); + } + { + std::vector v(2); + std::vector::reference r1 = v[0]; + std::vector::reference r2 = v[1]; + r1 = true; + using std::swap; + swap(r1, r2); + assert(v[0] == false); + assert(v[1] == true); + } +#if __cplusplus >= 201103L + { + std::vector> v1(100); + std::vector> v2(200); + v1.swap(v2); + assert(v1.size() == 200); + assert(v1.capacity() >= 200); + assert(v2.size() == 100); + assert(v2.capacity() >= 100); + } + { + typedef min_allocator A; + std::vector v1(100, true, A()); + std::vector v2(200, false, A()); + swap(v1, v2); + assert(v1.size() == 200); + assert(v1.capacity() >= 200); + assert(v2.size() == 100); + assert(v2.capacity() >= 100); + assert(v1.get_allocator() == A()); + assert(v2.get_allocator() == A()); + } + { + std::vector> v(2); + std::vector>::reference r1 = v[0]; + std::vector>::reference r2 = v[1]; + r1 = true; + using std::swap; + swap(r1, r2); + assert(v[0] == false); + assert(v[1] == true); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/swap_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..bcaf161119f --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/swap_noexcept.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(vector& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable::value); + +// This tests a conforming extension + +#include +#include + +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + + some_alloc() {} + some_alloc(const some_alloc&); + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::vector> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::vector> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::vector> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/types.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/types.pass.cpp new file mode 100644 index 00000000000..b266b3bbb92 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/types.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Test nested types and default template args: + +// template +// class vector reverse_iterator; +// typedef std::reverse_iterator const_reverse_iterator; +// }; + +#include +#include +#include + +#include "test_allocator.h" +#include "../../Copyable.h" +#include "min_allocator.h" + +template +void +test() +{ + typedef std::vector C; + + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::size_type>::value), ""); + static_assert((std::is_same::difference_type>::value), ""); + static_assert((std::is_same< + typename std::iterator_traits::iterator_category, + std::random_access_iterator_tag>::value), ""); + static_assert((std::is_same< + typename std::iterator_traits::iterator_category, + std::random_access_iterator_tag>::value), ""); + static_assert((std::is_same< + typename C::reverse_iterator, + std::reverse_iterator >::value), ""); + static_assert((std::is_same< + typename C::const_reverse_iterator, + std::reverse_iterator >::value), ""); +} + +int main() +{ + test >(); + test >(); + static_assert((std::is_same::allocator_type, + std::allocator >::value), ""); +#if __cplusplus >= 201103L + test >(); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector.bool/vector_bool.pass.cpp b/libcxx/test/std/containers/sequences/vector.bool/vector_bool.pass.cpp new file mode 100644 index 00000000000..ea2262cd9c1 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector.bool/vector_bool.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// struct hash +// : public unary_function +// { +// size_t operator()(T val) const; +// }; + +// Not very portable + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::vector T; + typedef std::hash H; + static_assert((std::is_base_of, + H>::value), ""); + bool ba[] = {true, false, true, true, false}; + T vb(std::begin(ba), std::end(ba)); + H h; + assert(h(vb) != 0); + } +#if __cplusplus >= 201103L + { + typedef std::vector> T; + typedef std::hash H; + static_assert((std::is_base_of, + H>::value), ""); + bool ba[] = {true, false, true, true, false}; + T vb(std::begin(ba), std::end(ba)); + H h; + assert(h(vb) != 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/asan.pass.cpp b/libcxx/test/std/containers/sequences/vector/asan.pass.cpp new file mode 100644 index 00000000000..86c02b29562 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/asan.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// reference operator[](size_type n); + +#include +#include +#include + +#include "min_allocator.h" +#include "asan_testing.h" + +#ifndef _LIBCPP_HAS_NO_ASAN +extern "C" void __asan_set_error_exit_code(int); + +int main() +{ +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + c.reserve(2*c.size()); + T foo = c[c.size()]; // bad, but not caught by ASAN + } +#endif + + __asan_set_error_exit_code(0); + { + typedef int T; + typedef std::vector C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + c.reserve(2*c.size()); + assert(is_contiguous_container_asan_correct(c)); + assert(!__sanitizer_verify_contiguous_container ( c.data(), c.data() + 1, c.data() + c.capacity())); + T foo = c[c.size()]; // should trigger ASAN + assert(false); // if we got here, ASAN didn't trigger + } +} +#else +int main () { return 0; } +#endif diff --git a/libcxx/test/std/containers/sequences/vector/asan_throw.pass.cc b/libcxx/test/std/containers/sequences/vector/asan_throw.pass.cc new file mode 100644 index 00000000000..a1dce4a3b44 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/asan_throw.pass.cc @@ -0,0 +1,198 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Test asan vector annotations with a class that throws in a CTOR. + +#include +#include + +#include "asan_testing.h" + +class X { +public: + X(const X &x) { Init(x.a); } + X(char arg) { Init(arg); } + X() { Init(42); } + X &operator=(const X &x) { + Init(x.a); + return *this; + } + void Init(char arg) { + if (arg == 42) + throw 0; + if (arg == 66) + arg = 42; + a = arg; + } + char get() const { return a; } + void set(char arg) { a = arg; } + +private: + char a; +}; + +void test_push_back() { + std::vector v; + v.reserve(2); + v.push_back(X(2)); + assert(v.size() == 1); + try { + v.push_back(X(66)); + assert(0); + } catch (int e) { + assert(v.size() == 1); + } + assert(v.size() == 1); + assert(is_contiguous_container_asan_correct(v)); +} + +void test_emplace_back() { +#ifndef _LIBCPP_HAS_NO_VARIADICS + std::vector v; + v.reserve(2); + v.push_back(X(2)); + assert(v.size() == 1); + try { + v.emplace_back(42); + assert(0); + } catch (int e) { + assert(v.size() == 1); + } + assert(v.size() == 1); + assert(is_contiguous_container_asan_correct(v)); +#endif // _LIBCPP_HAS_NO_VARIADICS +} + +void test_insert_range() { + std::vector v; + v.reserve(4); + v.push_back(X(1)); + v.push_back(X(2)); + assert(v.size() == 2); + assert(v.capacity() >= 4); + try { + char a[2] = {21, 42}; + v.insert(v.end(), a, a + 2); + assert(0); + } catch (int e) { + assert(v.size() == 3); + } + assert(v.size() == 3); + assert(is_contiguous_container_asan_correct(v)); +} + +void test_insert() { + std::vector v; + v.reserve(3); + v.insert(v.end(), X(1)); + v.insert(v.begin(), X(2)); + assert(v.size() == 2); + try { + v.insert(v.end(), X(66)); + assert(0); + } catch (int e) { + assert(v.size() == 2); + } + assert(v.size() == 2); + assert(is_contiguous_container_asan_correct(v)); +} + +void test_emplace() { +#ifndef _LIBCPP_HAS_NO_VARIADICS + std::vector v; + v.reserve(3); + v.insert(v.end(), X(1)); + v.insert(v.begin(), X(2)); + assert(v.size() == 2); + try { + v.emplace(v.end(), 42); + assert(0); + } catch (int e) { + assert(v.size() == 2); + } + assert(v.size() == 2); + assert(is_contiguous_container_asan_correct(v)); +#endif // _LIBCPP_HAS_NO_VARIADICS +} + +void test_insert_range2() { + std::vector v; + v.reserve(4); + v.insert(v.end(), X(1)); + v.insert(v.begin(), X(2)); + assert(v.size() == 2); + assert(v.capacity() >= 4); + try { + char a[2] = {10, 42}; + v.insert(v.begin(), a, a + 2); + assert(0); + } catch (int e) { + assert(v.size() <= 4); + assert(is_contiguous_container_asan_correct(v)); + return; + } + assert(0); +} + +void test_insert_n() { + std::vector v; + v.reserve(10); + v.insert(v.end(), X(1)); + v.insert(v.begin(), X(2)); + assert(v.size() == 2); + try { + v.insert(v.begin(), 1, X(66)); + assert(0); + } catch (int e) { + assert(v.size() <= 3); + assert(is_contiguous_container_asan_correct(v)); + return; + } + assert(0); +} + +void test_resize() { + std::vector v; + v.reserve(3); + v.push_back(X(0)); + try { + v.resize(3); + assert(0); + } catch (int e) { + assert(v.size() == 1); + } + assert(v.size() == 1); + assert(is_contiguous_container_asan_correct(v)); +} + +void test_resize_param() { + std::vector v; + v.reserve(3); + v.push_back(X(0)); + try { + v.resize(3, X(66)); + assert(0); + } catch (int e) { + assert(v.size() == 1); + } + assert(v.size() == 1); + assert(is_contiguous_container_asan_correct(v)); +} + +int main() { + test_push_back(); + test_emplace_back(); + test_insert_range(); + test_insert(); + test_emplace(); + test_insert_range2(); + test_insert_n(); + test_resize(); + test_resize_param(); +} diff --git a/libcxx/test/std/containers/sequences/vector/const_value_type.pass.cpp b/libcxx/test/std/containers/sequences/vector/const_value_type.pass.cpp new file mode 100644 index 00000000000..e16e439dec4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/const_value_type.pass.cpp @@ -0,0 +1,22 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector v; // an extension + +#include +#include + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + std::vector v = {1, 2, 3}; +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/db_back.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_back.pass.cpp new file mode 100644 index 00000000000..05f3d07712e --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_back.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call back() on empty container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector C; + C c(1); + assert(c.back() == 0); + c.clear(); + assert(c.back() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector> C; + C c(1); + assert(c.back() == 0); + c.clear(); + assert(c.back() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_cback.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_cback.pass.cpp new file mode 100644 index 00000000000..5eb1a353e8b --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_cback.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call back() on empty const container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector C; + const C c; + assert(c.back() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector> C; + const C c; + assert(c.back() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_cfront.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_cfront.pass.cpp new file mode 100644 index 00000000000..5e54da1d444 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_cfront.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call front() on empty const container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector C; + const C c; + assert(c.front() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector> C; + const C c; + assert(c.front() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_cindex.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_cindex.pass.cpp new file mode 100644 index 00000000000..133aa565282 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_cindex.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Index const vector out of bounds. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector C; + const C c(1); + assert(c[0] == 0); + assert(c[1] == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector> C; + const C c(1); + assert(c[0] == 0); + assert(c[1] == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_front.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_front.pass.cpp new file mode 100644 index 00000000000..388058fb315 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_front.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call front() on empty container. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector C; + C c(1); + assert(c.front() == 0); + c.clear(); + assert(c.front() == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector> C; + C c(1); + assert(c.front() == 0); + c.clear(); + assert(c.front() == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_index.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_index.pass.cpp new file mode 100644 index 00000000000..1daf076da67 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_index.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Index vector out of bounds. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector C; + C c(1); + assert(c[0] == 0); + c.clear(); + assert(c[0] == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector> C; + C c(1); + assert(c[0] == 0); + c.clear(); + assert(c[0] == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_iterators_2.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_iterators_2.pass.cpp new file mode 100644 index 00000000000..2d43843067b --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_iterators_2.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Compare iterators from different containers with <. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector C; + C c1; + C c2; + bool b = c1.begin() < c2.begin(); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector> C; + C c1; + C c2; + bool b = c1.begin() < c2.begin(); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_iterators_3.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_iterators_3.pass.cpp new file mode 100644 index 00000000000..051d66c3339 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_iterators_3.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Subtract iterators from different containers. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector C; + C c1; + C c2; + int i = c1.begin() - c2.begin(); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector> C; + C c1; + C c2; + int i = c1.begin() - c2.begin(); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_iterators_4.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_iterators_4.pass.cpp new file mode 100644 index 00000000000..4c2aa628de1 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_iterators_4.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Index iterator out of bounds. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector C; + C c(1); + C::iterator i = c.begin(); + assert(i[0] == 0); + assert(i[1] == 0); + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector> C; + C c(1); + C::iterator i = c.begin(); + assert(i[0] == 0); + assert(i[1] == 0); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_iterators_5.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_iterators_5.pass.cpp new file mode 100644 index 00000000000..1b1090499c2 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_iterators_5.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Add to iterator out of bounds. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector C; + C c(1); + C::iterator i = c.begin(); + i += 1; + assert(i == c.end()); + i = c.begin(); + i += 2; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector> C; + C c(1); + C::iterator i = c.begin(); + i += 1; + assert(i == c.end()); + i = c.begin(); + i += 2; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_iterators_6.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_iterators_6.pass.cpp new file mode 100644 index 00000000000..424bc939b13 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_iterators_6.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Decrement iterator prior to begin. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector C; + C c(1); + C::iterator i = c.end(); + --i; + assert(i == c.begin()); + --i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector> C; + C c(1); + C::iterator i = c.end(); + --i; + assert(i == c.begin()); + --i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_iterators_7.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_iterators_7.pass.cpp new file mode 100644 index 00000000000..72cdb10cbc8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_iterators_7.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Increment iterator past end. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector C; + C c(1); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector> C; + C c(1); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/db_iterators_8.pass.cpp b/libcxx/test/std/containers/sequences/vector/db_iterators_8.pass.cpp new file mode 100644 index 00000000000..7b898533197 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/db_iterators_8.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Dereference non-dereferenceable iterator. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::vector C; + C c(1); + C::iterator i = c.end(); + T j = *i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector> C; + C c(1); + C::iterator i = c.end(); + T j = *i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/iterators.pass.cpp b/libcxx/test/std/containers/sequences/vector/iterators.pass.cpp new file mode 100644 index 00000000000..75a08287a86 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/iterators.pass.cpp @@ -0,0 +1,165 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator begin(); +// iterator end(); +// const_iterator begin() const; +// const_iterator end() const; +// const_iterator cbegin() const; +// const_iterator cend() const; + +#include +#include +#include + +#include "min_allocator.h" + +struct A +{ + int first; + int second; +}; + +int main() +{ + { + typedef int T; + typedef std::vector C; + C c; + C::iterator i = c.begin(); + C::iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef int T; + typedef std::vector C; + const C c; + C::const_iterator i = c.begin(); + C::const_iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef int T; + typedef std::vector C; + C c; + C::const_iterator i = c.cbegin(); + C::const_iterator j = c.cend(); + assert(std::distance(i, j) == 0); + assert(i == j); + assert(i == c.end()); + } + { + typedef int T; + typedef std::vector C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + C::iterator i = c.begin(); + assert(*i == 0); + ++i; + assert(*i == 1); + *i = 10; + assert(*i == 10); + assert(std::distance(c.begin(), c.end()) == 10); + } + { + typedef int T; + typedef std::vector C; + C::iterator i; + C::const_iterator j; + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::vector> C; + C c; + C::iterator i = c.begin(); + C::iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef int T; + typedef std::vector> C; + const C c; + C::const_iterator i = c.begin(); + C::const_iterator j = c.end(); + assert(std::distance(i, j) == 0); + assert(i == j); + } + { + typedef int T; + typedef std::vector> C; + C c; + C::const_iterator i = c.cbegin(); + C::const_iterator j = c.cend(); + assert(std::distance(i, j) == 0); + assert(i == j); + assert(i == c.end()); + } + { + typedef int T; + typedef std::vector> C; + const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; + C c(std::begin(t), std::end(t)); + C::iterator i = c.begin(); + assert(*i == 0); + ++i; + assert(*i == 1); + *i = 10; + assert(*i == 10); + assert(std::distance(c.begin(), c.end()) == 10); + } + { + typedef int T; + typedef std::vector> C; + C::iterator i; + C::const_iterator j; + } + { + typedef A T; + typedef std::vector> C; + C c = {A{1, 2}}; + C::iterator i = c.begin(); + i->first = 3; + C::const_iterator j = i; + assert(j->first == 3); + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + typedef std::vector C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + assert (!(ii1 < cii )); + assert (!(cii < ii1 )); + assert ( (ii1 <= cii )); + assert ( (cii <= ii1 )); + assert (!(ii1 > cii )); + assert (!(cii > ii1 )); + assert ( (ii1 >= cii )); + assert ( (cii >= ii1 )); + assert (cii - ii1 == 0); + assert (ii1 - cii == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/types.pass.cpp b/libcxx/test/std/containers/sequences/vector/types.pass.cpp new file mode 100644 index 00000000000..3504de6f75d --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/types.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Test nested types and default template args: + +// template > +// class vector +// { +// public: +// typedef T value_type; +// typedef Allocator allocator_type; +// typedef typename allocator_type::reference reference; +// typedef typename allocator_type::const_reference const_reference; +// typedef implementation-defined iterator; +// typedef implementation-defined const_iterator; +// typedef typename allocator_type::size_type size_type; +// typedef typename allocator_type::difference_type difference_type; +// typedef typename allocator_type::pointer pointer; +// typedef typename allocator_type::const_pointer const_pointer; +// typedef std::reverse_iterator reverse_iterator; +// typedef std::reverse_iterator const_reverse_iterator; +// }; + +#include +#include +#include + +#include "test_allocator.h" +#include "../../Copyable.h" +#include "min_allocator.h" + +template +void +test() +{ + typedef std::vector C; + + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same< + typename std::iterator_traits::iterator_category, + std::random_access_iterator_tag>::value), ""); + static_assert((std::is_same< + typename std::iterator_traits::iterator_category, + std::random_access_iterator_tag>::value), ""); + static_assert((std::is_same< + typename C::reverse_iterator, + std::reverse_iterator >::value), ""); + static_assert((std::is_same< + typename C::const_reverse_iterator, + std::reverse_iterator >::value), ""); +} + +int main() +{ + test >(); + test >(); + test >(); + static_assert((std::is_same::allocator_type, + std::allocator >::value), ""); +#if __cplusplus >= 201103L + static_assert((std::is_same>::value_type, int>::value), ""); + static_assert((std::is_same>::allocator_type, min_allocator >::value), ""); + static_assert((std::is_same>::reference, int&>::value), ""); + static_assert((std::is_same>::const_reference, const int&>::value), ""); + static_assert((std::is_same>::pointer, min_pointer>::value), ""); + static_assert((std::is_same>::const_pointer, min_pointer>::value), ""); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.capacity/capacity.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.capacity/capacity.pass.cpp new file mode 100644 index 00000000000..21082c839f5 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.capacity/capacity.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// size_type capacity() const; + +#include +#include + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector v; + assert(v.capacity() == 0); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector v(100); + assert(v.capacity() == 100); + v.push_back(0); + assert(v.capacity() > 101); + assert(is_contiguous_container_asan_correct(v)); + } +#if __cplusplus >= 201103L + { + std::vector> v; + assert(v.capacity() == 0); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector> v(100); + assert(v.capacity() == 100); + v.push_back(0); + assert(v.capacity() > 101); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.capacity/reserve.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.capacity/reserve.pass.cpp new file mode 100644 index 00000000000..4df5702f2ad --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.capacity/reserve.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void reserve(size_type n); + +#include +#include +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector v; + v.reserve(10); + assert(v.capacity() >= 10); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector v(100); + assert(v.capacity() == 100); + v.reserve(50); + assert(v.size() == 100); + assert(v.capacity() == 100); + v.reserve(150); + assert(v.size() == 100); + assert(v.capacity() == 150); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector > v(100); + assert(v.capacity() == 100); + v.reserve(50); + assert(v.size() == 100); + assert(v.capacity() == 100); + v.reserve(150); + assert(v.size() == 100); + assert(v.capacity() == 150); + assert(is_contiguous_container_asan_correct(v)); + } +#if __cplusplus >= 201103L + { + std::vector> v; + v.reserve(10); + assert(v.capacity() >= 10); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector> v(100); + assert(v.capacity() == 100); + v.reserve(50); + assert(v.size() == 100); + assert(v.capacity() == 100); + v.reserve(150); + assert(v.size() == 100); + assert(v.capacity() == 150); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.capacity/resize_size.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.capacity/resize_size.pass.cpp new file mode 100644 index 00000000000..a47c5131d8a --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.capacity/resize_size.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void resize(size_type sz); + +#include +#include +#include "../../../stack_allocator.h" +#include "../../../MoveOnly.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector > v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } +#else // _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector > v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + std::vector> v(100); + v.resize(50); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + v.resize(200); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp new file mode 100644 index 00000000000..de5126b03d1 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.capacity/resize_size_value.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void resize(size_type sz, const value_type& x); + +#include +#include +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector v(100); + v.resize(50, 1); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(v == std::vector(50)); + v.resize(200, 1); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + for (unsigned i = 0; i < 50; ++i) + assert(v[i] == 0); + for (unsigned i = 50; i < 200; ++i) + assert(v[i] == 1); + } + { + std::vector > v(100); + v.resize(50, 1); + assert(v.size() == 50); + assert(v.capacity() == 100); + v.resize(200, 1); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } +#if __cplusplus >= 201103L + { + std::vector> v(100); + v.resize(50, 1); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + assert((v == std::vector>(50))); + v.resize(200, 1); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + for (unsigned i = 0; i < 50; ++i) + assert(v[i] == 0); + for (unsigned i = 50; i < 200; ++i) + assert(v[i] == 1); + } + { + std::vector> v(100); + v.resize(50, 1); + assert(v.size() == 50); + assert(v.capacity() == 100); + assert(is_contiguous_container_asan_correct(v)); + v.resize(200, 1); + assert(v.size() == 200); + assert(v.capacity() >= 200); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.capacity/shrink_to_fit.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.capacity/shrink_to_fit.pass.cpp new file mode 100644 index 00000000000..49ab9cc71de --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.capacity/shrink_to_fit.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void shrink_to_fit(); + +#include +#include +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector v(100); + v.push_back(1); + assert(is_contiguous_container_asan_correct(v)); + v.shrink_to_fit(); + assert(v.capacity() == 101); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector > v(100); + v.push_back(1); + assert(is_contiguous_container_asan_correct(v)); + v.shrink_to_fit(); + assert(v.capacity() == 101); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + } +#ifndef _LIBCPP_NO_EXCEPTIONS + { + std::vector > v(100); + v.push_back(1); + assert(is_contiguous_container_asan_correct(v)); + v.shrink_to_fit(); + assert(v.capacity() == 200); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +#if __cplusplus >= 201103L + { + std::vector> v(100); + v.push_back(1); + assert(is_contiguous_container_asan_correct(v)); + v.shrink_to_fit(); + assert(v.capacity() == 101); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.capacity/swap.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.capacity/swap.pass.cpp new file mode 100644 index 00000000000..f3d9289c36e --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.capacity/swap.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(vector& x); + +#include +#include + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector v1(100); + std::vector v2(200); + assert(is_contiguous_container_asan_correct(v1)); + assert(is_contiguous_container_asan_correct(v2)); + v1.swap(v2); + assert(v1.size() == 200); + assert(v1.capacity() == 200); + assert(is_contiguous_container_asan_correct(v1)); + assert(v2.size() == 100); + assert(v2.capacity() == 100); + assert(is_contiguous_container_asan_correct(v2)); + } +#if __cplusplus >= 201103L + { + std::vector> v1(100); + std::vector> v2(200); + assert(is_contiguous_container_asan_correct(v1)); + assert(is_contiguous_container_asan_correct(v2)); + v1.swap(v2); + assert(v1.size() == 200); + assert(v1.capacity() == 200); + assert(is_contiguous_container_asan_correct(v1)); + assert(v2.size() == 100); + assert(v2.capacity() == 100); + assert(is_contiguous_container_asan_correct(v2)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/assign_copy.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_copy.pass.cpp new file mode 100644 index 00000000000..6f02c3b7bc2 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_copy.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector& operator=(const vector& c); + +#include +#include +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + std::vector > l(3, 2, test_allocator(5)); + std::vector > l2(l, test_allocator(3)); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == test_allocator(3)); + } + { + std::vector > l(3, 2, other_allocator(5)); + std::vector > l2(l, other_allocator(3)); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == other_allocator(5)); + } +#if __cplusplus >= 201103L + { + std::vector > l(3, 2, min_allocator()); + std::vector > l2(l, min_allocator()); + l2 = l; + assert(l2 == l); + assert(l2.get_allocator() == min_allocator()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..f5c06b1a1bd --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void assign(initializer_list il); + +#include +#include + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector d; + d.assign({3, 4, 5, 6}); + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#if __cplusplus >= 201103L + { + std::vector> d; + d.assign({3, 4, 5, 6}); + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/assign_move.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_move.pass.cpp new file mode 100644 index 00000000000..d87ac8636b0 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/assign_move.pass.cpp @@ -0,0 +1,101 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector& operator=(vector&& c); + +#include +#include +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector > l(test_allocator(5)); + std::vector > lo(test_allocator(5)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector > l2(test_allocator(5)); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + assert(is_contiguous_container_asan_correct(l2)); + } + { + std::vector > l(test_allocator(5)); + std::vector > lo(test_allocator(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector > l2(test_allocator(6)); + l2 = std::move(l); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == test_allocator(6)); + assert(is_contiguous_container_asan_correct(l2)); + } + { + std::vector > l(other_allocator(5)); + std::vector > lo(other_allocator(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector > l2(other_allocator(6)); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + assert(is_contiguous_container_asan_correct(l2)); + } +#if __cplusplus >= 201103L + { + std::vector > l(min_allocator{}); + std::vector > lo(min_allocator{}); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector > l2(min_allocator{}); + l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + assert(is_contiguous_container_asan_correct(l2)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_default.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_default.pass.cpp new file mode 100644 index 00000000000..75772bef78a --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_default.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector(const Alloc& = Alloc()); + +#include +#include + +#include "test_allocator.h" +#include "../../../NotConstructible.h" +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +template +void +test0() +{ + C c; + assert(c.__invariants()); + assert(c.empty()); + assert(c.get_allocator() == typename C::allocator_type()); + assert(is_contiguous_container_asan_correct(c)); +#if __cplusplus >= 201103L + C c1 = {}; + assert(c1.__invariants()); + assert(c1.empty()); + assert(c1.get_allocator() == typename C::allocator_type()); + assert(is_contiguous_container_asan_correct(c1)); +#endif +} + +template +void +test1(const typename C::allocator_type& a) +{ + C c(a); + assert(c.__invariants()); + assert(c.empty()); + assert(c.get_allocator() == a); + assert(is_contiguous_container_asan_correct(c)); +} + +int main() +{ + { + test0 >(); + test0 >(); + test1 > >(test_allocator(3)); + test1 > > + (test_allocator(5)); + } + { + std::vector > v; + assert(v.empty()); + } +#if __cplusplus >= 201103L + { + test0> >(); + test0> >(); + test1 > >(min_allocator{}); + test1 > > + (min_allocator{}); + } + { + std::vector > v; + assert(v.empty()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp new file mode 100644 index 00000000000..36e231acce1 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template vector(InputIter first, InputIter last); + +#include +#include + +#include "test_iterators.h" +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +template +void +test(Iterator first, Iterator last) +{ + C c(first, last); + assert(c.__invariants()); + assert(c.size() == std::distance(first, last)); + assert(is_contiguous_container_asan_correct(c)); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first) + assert(*i == *first); +} + +int main() +{ + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + test >(input_iterator(a), input_iterator(an)); + test >(forward_iterator(a), forward_iterator(an)); + test >(bidirectional_iterator(a), bidirectional_iterator(an)); + test >(random_access_iterator(a), random_access_iterator(an)); + test >(a, an); + + test > >(input_iterator(a), input_iterator(an)); + test > >(forward_iterator(a), forward_iterator(an)); + test > >(bidirectional_iterator(a), bidirectional_iterator(an)); + test > >(random_access_iterator(a), random_access_iterator(an)); + test > >(a, an); +#if __cplusplus >= 201103L + test> >(input_iterator(a), input_iterator(an)); + test> >(forward_iterator(a), forward_iterator(an)); + test> >(bidirectional_iterator(a), bidirectional_iterator(an)); + test> >(random_access_iterator(a), random_access_iterator(an)); + test >(a, an); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp new file mode 100644 index 00000000000..7fa748a90d7 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_iter_iter_alloc.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template vector(InputIter first, InputIter last, +// const allocator_type& a); + +#include +#include + +#include "test_iterators.h" +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +template +void +test(Iterator first, Iterator last, const A& a) +{ + C c(first, last, a); + assert(c.__invariants()); + assert(c.size() == std::distance(first, last)); + assert(is_contiguous_container_asan_correct(c)); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i, ++first) + assert(*i == *first); +} + +#if __cplusplus >= 201103L + +template +struct implicit_conv_allocator : min_allocator +{ + implicit_conv_allocator(void* p) {} + implicit_conv_allocator(const implicit_conv_allocator&) = default; +}; + +#endif + +int main() +{ + { + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + std::allocator alloc; + test >(input_iterator(a), input_iterator(an), alloc); + test >(forward_iterator(a), forward_iterator(an), alloc); + test >(bidirectional_iterator(a), bidirectional_iterator(an), alloc); + test >(random_access_iterator(a), random_access_iterator(an), alloc); + test >(a, an, alloc); + } +#if __cplusplus >= 201103L + { + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + min_allocator alloc; + test> >(input_iterator(a), input_iterator(an), alloc); + test> >(forward_iterator(a), forward_iterator(an), alloc); + test> >(bidirectional_iterator(a), bidirectional_iterator(an), alloc); + test> >(random_access_iterator(a), random_access_iterator(an), alloc); + test> >(a, an, alloc); + test> >(a, an, nullptr); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size.pass.cpp new file mode 100644 index 00000000000..e03389593f1 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// explicit vector(size_type n); + +#include +#include + +#include "DefaultOnly.h" +#include "min_allocator.h" +#include "test_allocator.h" +#include "asan_testing.h" + +template +void +test2(typename C::size_type n, typename C::allocator_type const& a = typename C::allocator_type ()) +{ +#if _LIBCPP_STD_VER > 11 + C c(n, a); + assert(c.__invariants()); + assert(c.size() == n); + assert(c.get_allocator() == a); + assert(is_contiguous_container_asan_correct(c)); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == typename C::value_type()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} + +template +void +test1(typename C::size_type n) +{ + C c(n); + assert(c.__invariants()); + assert(c.size() == n); + assert(c.get_allocator() == typename C::allocator_type()); + assert(is_contiguous_container_asan_correct(c)); +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == typename C::value_type()); +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} + +template +void +test(typename C::size_type n) +{ + test1 ( n ); + test2 ( n ); +} + +int main() +{ + test >(50); + test >(500); + assert(DefaultOnly::count == 0); +#if __cplusplus >= 201103L + test> >(50); + test> >(500); + test2> >( 100, test_allocator(23)); + assert(DefaultOnly::count == 0); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp new file mode 100644 index 00000000000..5b6c4985704 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size_value.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector(size_type n, const value_type& x); + +#include +#include + +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +template +void +test(typename C::size_type n, const typename C::value_type& x) +{ + C c(n, x); + assert(c.__invariants()); + assert(c.size() == n); + assert(is_contiguous_container_asan_correct(c)); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == x); +} + +int main() +{ + test >(50, 3); + test > >(50, 5); +#if __cplusplus >= 201103L + test> >(50, 3); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size_value_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size_value_alloc.pass.cpp new file mode 100644 index 00000000000..c62b84104ab --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/construct_size_value_alloc.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector(size_type n, const value_type& x, const allocator_type& a); + +#include +#include +#include "min_allocator.h" +#include "asan_testing.h" + +template +void +test(typename C::size_type n, const typename C::value_type& x, + const typename C::allocator_type& a) +{ + C c(n, x, a); + assert(c.__invariants()); + assert(a == c.get_allocator()); + assert(c.size() == n); + assert(is_contiguous_container_asan_correct(c)); + for (typename C::const_iterator i = c.cbegin(), e = c.cend(); i != e; ++i) + assert(*i == x); +} + +int main() +{ + test >(50, 3, std::allocator()); +#if __cplusplus >= 201103L + test> >(50, 3, min_allocator()); +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/copy.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/copy.pass.cpp new file mode 100644 index 00000000000..677963deeb8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/copy.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector(const vector& v); + +#include +#include +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +template +void +test(const C& x) +{ + unsigned s = x.size(); + C c(x); + assert(c.__invariants()); + assert(c.size() == s); + assert(c == x); + assert(is_contiguous_container_asan_correct(c)); +} + +int main() +{ + { + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + test(std::vector(a, an)); + } + { + std::vector > v(3, 2, test_allocator(5)); + std::vector > v2 = v; + assert(is_contiguous_container_asan_correct(v)); + assert(is_contiguous_container_asan_correct(v2)); + assert(v2 == v); + assert(v2.get_allocator() == v.get_allocator()); + assert(is_contiguous_container_asan_correct(v)); + assert(is_contiguous_container_asan_correct(v2)); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + std::vector > v(3, 2, other_allocator(5)); + std::vector > v2 = v; + assert(is_contiguous_container_asan_correct(v)); + assert(is_contiguous_container_asan_correct(v2)); + assert(v2 == v); + assert(v2.get_allocator() == other_allocator(-2)); + assert(is_contiguous_container_asan_correct(v)); + assert(is_contiguous_container_asan_correct(v2)); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + test(std::vector>(a, an)); + } + { + std::vector > v(3, 2, min_allocator()); + std::vector > v2 = v; + assert(is_contiguous_container_asan_correct(v)); + assert(is_contiguous_container_asan_correct(v2)); + assert(v2 == v); + assert(v2.get_allocator() == v.get_allocator()); + assert(is_contiguous_container_asan_correct(v)); + assert(is_contiguous_container_asan_correct(v2)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/copy_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..128328c2a7d --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/copy_alloc.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector(const vector& v, const allocator_type& a); + +#include +#include +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +template +void +test(const C& x, const typename C::allocator_type& a) +{ + unsigned s = x.size(); + C c(x, a); + assert(c.__invariants()); + assert(c.size() == s); + assert(c == x); + assert(is_contiguous_container_asan_correct(c)); +} + +int main() +{ + { + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + test(std::vector(a, an), std::allocator()); + } + { + std::vector > l(3, 2, test_allocator(5)); + std::vector > l2(l, test_allocator(3)); + assert(l2 == l); + assert(l2.get_allocator() == test_allocator(3)); + } + { + std::vector > l(3, 2, other_allocator(5)); + std::vector > l2(l, other_allocator(3)); + assert(l2 == l); + assert(l2.get_allocator() == other_allocator(3)); + } +#if __cplusplus >= 201103L + { + int a[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0}; + int* an = a + sizeof(a)/sizeof(a[0]); + test(std::vector>(a, an), min_allocator()); + } + { + std::vector > l(3, 2, min_allocator()); + std::vector > l2(l, min_allocator()); + assert(l2 == l); + assert(l2.get_allocator() == min_allocator()); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/default.recursive.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/default.recursive.pass.cpp new file mode 100644 index 00000000000..1a4a1898cc6 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/default.recursive.pass.cpp @@ -0,0 +1,23 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// +// class vector +// vector(); + +#include + +struct X +{ + std::vector q; +}; + +int main() +{ +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/default_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/default_noexcept.pass.cpp new file mode 100644 index 00000000000..3fc33b68d39 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/default_noexcept.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector() +// noexcept(is_nothrow_default_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::vector> C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::vector> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::vector> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..0d73e9ef4d4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// ~vector() // implied noexcept; + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); + ~some_alloc() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::vector> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::vector> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::vector> C; + static_assert(!std::is_nothrow_destructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..7eb834ff387 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/initializer_list.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector(initializer_list il); + +#include +#include +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#if __cplusplus >= 201103L + { + std::vector> d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/initializer_list_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/initializer_list_alloc.pass.cpp new file mode 100644 index 00000000000..5d7ae884e38 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/initializer_list_alloc.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector(initializer_list il, const Allocator& a = allocator_type()); + +#include +#include + +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector> d({3, 4, 5, 6}, test_allocator(3)); + assert(d.get_allocator() == test_allocator(3)); + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#if __cplusplus >= 201103L + { + std::vector> d({3, 4, 5, 6}, min_allocator()); + assert(d.get_allocator() == min_allocator()); + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/move.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/move.pass.cpp new file mode 100644 index 00000000000..bb61d54948b --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/move.pass.cpp @@ -0,0 +1,103 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector(vector&& c); + +#include +#include +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector > l(test_allocator(5)); + std::vector > lo(test_allocator(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + assert(is_contiguous_container_asan_correct(l2)); + } + { + std::vector > l(other_allocator(5)); + std::vector > lo(other_allocator(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + assert(is_contiguous_container_asan_correct(l2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + std::vector c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + assert(is_contiguous_container_asan_correct(c1)); + std::vector::const_iterator i = c1.begin(); + std::vector c2 = std::move(c1); + assert(is_contiguous_container_asan_correct(c2)); + std::vector::iterator j = c2.erase(i); + assert(*j == 3); + assert(is_contiguous_container_asan_correct(c2)); + } +#if __cplusplus >= 201103L + { + std::vector > l(min_allocator{}); + std::vector > lo(min_allocator{}); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector > l2 = std::move(l); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == lo.get_allocator()); + assert(is_contiguous_container_asan_correct(l2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + std::vector> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + assert(is_contiguous_container_asan_correct(c1)); + std::vector>::const_iterator i = c1.begin(); + std::vector> c2 = std::move(c1); + assert(is_contiguous_container_asan_correct(c2)); + std::vector>::iterator j = c2.erase(i); + assert(*j == 3); + assert(is_contiguous_container_asan_correct(c2)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/move_alloc.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..1923e68f75e --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/move_alloc.pass.cpp @@ -0,0 +1,99 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector(vector&& c, const allocator_type& a); + +#include +#include +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector > l(test_allocator(5)); + std::vector > lo(test_allocator(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector > l2(std::move(l), test_allocator(6)); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == test_allocator(6)); + assert(is_contiguous_container_asan_correct(l2)); + } + { + std::vector > l(test_allocator(5)); + std::vector > lo(test_allocator(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector > l2(std::move(l), test_allocator(5)); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == test_allocator(5)); + assert(is_contiguous_container_asan_correct(l2)); + } + { + std::vector > l(other_allocator(5)); + std::vector > lo(other_allocator(5)); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector > l2(std::move(l), other_allocator(4)); + assert(l2 == lo); + assert(!l.empty()); + assert(l2.get_allocator() == other_allocator(4)); + assert(is_contiguous_container_asan_correct(l2)); + } +#if __cplusplus >= 201103L + { + std::vector > l(min_allocator{}); + std::vector > lo(min_allocator{}); + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + for (int i = 1; i <= 3; ++i) + { + l.push_back(i); + lo.push_back(i); + } + assert(is_contiguous_container_asan_correct(l)); + assert(is_contiguous_container_asan_correct(lo)); + std::vector > l2(std::move(l), min_allocator()); + assert(l2 == lo); + assert(l.empty()); + assert(l2.get_allocator() == min_allocator()); + assert(is_contiguous_container_asan_correct(l2)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..158370f4e1a --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector& operator=(vector&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::vector> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::vector> C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::vector> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/move_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/move_noexcept.pass.cpp new file mode 100644 index 00000000000..a2e36ccdf08 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/move_noexcept.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector(vector&&) +// noexcept(is_nothrow_move_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + some_alloc(const some_alloc&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::vector> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::vector> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::vector> C; + static_assert(!std::is_nothrow_move_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.cons/op_equal_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.cons/op_equal_initializer_list.pass.cpp new file mode 100644 index 00000000000..592b7146276 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.cons/op_equal_initializer_list.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// vector& operator=(initializer_list il); + +#include +#include + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector d; + d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#if __cplusplus >= 201103L + { + std::vector> d; + d = {3, 4, 5, 6}; + assert(d.size() == 4); + assert(is_contiguous_container_asan_correct(d)); + assert(d[0] == 3); + assert(d[1] == 4); + assert(d[2] == 5); + assert(d[3] == 6); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.data/data.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.data/data.pass.cpp new file mode 100644 index 00000000000..aed56bc0931 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.data/data.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// pointer data(); + +#include +#include + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector v; + assert(v.data() == 0); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector v(100); + assert(v.data() == &v.front()); + assert(is_contiguous_container_asan_correct(v)); + } +#if __cplusplus >= 201103L + { + std::vector> v; + assert(v.data() == 0); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector> v(100); + assert(v.data() == &v.front()); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.data/data_const.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.data/data_const.pass.cpp new file mode 100644 index 00000000000..cb6062694e4 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.data/data_const.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// const_pointer data() const; + +#include +#include + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + const std::vector v; + assert(v.data() == 0); + assert(is_contiguous_container_asan_correct(v)); + } + { + const std::vector v(100); + assert(v.data() == &v.front()); + assert(is_contiguous_container_asan_correct(v)); + } +#if __cplusplus >= 201103L + { + const std::vector> v; + assert(v.data() == 0); + assert(is_contiguous_container_asan_correct(v)); + } + { + const std::vector> v(100); + assert(v.data() == &v.front()); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace.pass.cpp new file mode 100644 index 00000000000..8af6bdacd0a --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace.pass.cpp @@ -0,0 +1,160 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template iterator emplace(const_iterator pos, Args&&... args); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +class A +{ + int i_; + double d_; + + A(const A&); + A& operator=(const A&); +public: + A(int i, double d) + : i_(i), d_(d) {} + + A(A&& a) + : i_(a.i_), + d_(a.d_) + { + a.i_ = 0; + a.d_ = 0; + } + + A& operator=(A&& a) + { + i_ = a.i_; + d_ = a.d_; + a.i_ = 0; + a.d_ = 0; + return *this; + } + + int geti() const {return i_;} + double getd() const {return d_;} +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector c; + std::vector::iterator i = c.emplace(c.cbegin(), 2, 3.5); + assert(i == c.begin()); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(is_contiguous_container_asan_correct(c)); + i = c.emplace(c.cend(), 3, 4.5); + assert(i == c.end()-1); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + assert(is_contiguous_container_asan_correct(c)); + i = c.emplace(c.cbegin()+1, 4, 6.5); + assert(i == c.begin()+1); + assert(c.size() == 3); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c[1].geti() == 4); + assert(c[1].getd() == 6.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + assert(is_contiguous_container_asan_correct(c)); + } + { + std::vector > c; + std::vector >::iterator i = c.emplace(c.cbegin(), 2, 3.5); + assert(i == c.begin()); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(is_contiguous_container_asan_correct(c)); + i = c.emplace(c.cend(), 3, 4.5); + assert(i == c.end()-1); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + assert(is_contiguous_container_asan_correct(c)); + i = c.emplace(c.cbegin()+1, 4, 6.5); + assert(i == c.begin()+1); + assert(c.size() == 3); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c[1].geti() == 4); + assert(c[1].getd() == 6.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + assert(is_contiguous_container_asan_correct(c)); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector c1; + std::vector c2; + std::vector::iterator i = c1.emplace(c2.cbegin(), 2, 3.5); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::vector> c; + std::vector>::iterator i = c.emplace(c.cbegin(), 2, 3.5); + assert(i == c.begin()); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + i = c.emplace(c.cend(), 3, 4.5); + assert(i == c.end()-1); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + i = c.emplace(c.cbegin()+1, 4, 6.5); + assert(i == c.begin()+1); + assert(c.size() == 3); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c[1].geti() == 4); + assert(c[1].getd() == 6.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector> c1; + std::vector> c2; + std::vector>::iterator i = c1.emplace(c2.cbegin(), 2, 3.5); + assert(false); + } +#endif +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace_back.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace_back.pass.cpp new file mode 100644 index 00000000000..bbf91a4255d --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace_back.pass.cpp @@ -0,0 +1,107 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template void emplace_back(Args&&... args); + +#include +#include +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + +class A +{ + int i_; + double d_; + + A(const A&); + A& operator=(const A&); +public: + A(int i, double d) + : i_(i), d_(d) {} + + A(A&& a) + : i_(a.i_), + d_(a.d_) + { + a.i_ = 0; + a.d_ = 0; + } + + A& operator=(A&& a) + { + i_ = a.i_; + d_ = a.d_; + a.i_ = 0; + a.d_ = 0; + return *this; + } + + int geti() const {return i_;} + double getd() const {return d_;} +}; + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector c; + c.emplace_back(2, 3.5); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(is_contiguous_container_asan_correct(c)); + c.emplace_back(3, 4.5); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + assert(is_contiguous_container_asan_correct(c)); + } + { + std::vector > c; + c.emplace_back(2, 3.5); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(is_contiguous_container_asan_correct(c)); + c.emplace_back(3, 4.5); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + assert(is_contiguous_container_asan_correct(c)); + } +#if __cplusplus >= 201103L + { + std::vector> c; + c.emplace_back(2, 3.5); + assert(c.size() == 1); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(is_contiguous_container_asan_correct(c)); + c.emplace_back(3, 4.5); + assert(c.size() == 2); + assert(c.front().geti() == 2); + assert(c.front().getd() == 3.5); + assert(c.back().geti() == 3); + assert(c.back().getd() == 4.5); + assert(is_contiguous_container_asan_correct(c)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace_extra.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace_extra.pass.cpp new file mode 100644 index 00000000000..85a47073bcb --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/emplace_extra.pass.cpp @@ -0,0 +1,62 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template iterator emplace(const_iterator pos, Args&&... args); + +#include +#include + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector v; + v.reserve(3); + assert(is_contiguous_container_asan_correct(v)); + v = { 1, 2, 3 }; + v.emplace(v.begin(), v.back()); + assert(v[0] == 3); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector v; + v.reserve(4); + assert(is_contiguous_container_asan_correct(v)); + v = { 1, 2, 3 }; + v.emplace(v.begin(), v.back()); + assert(v[0] == 3); + assert(is_contiguous_container_asan_correct(v)); + } +#if __cplusplus >= 201103L + { + std::vector> v; + v.reserve(3); + assert(is_contiguous_container_asan_correct(v)); + v = { 1, 2, 3 }; + v.emplace(v.begin(), v.back()); + assert(v[0] == 3); + assert(is_contiguous_container_asan_correct(v)); + } + { + std::vector> v; + v.reserve(4); + assert(is_contiguous_container_asan_correct(v)); + v = { 1, 2, 3 }; + v.emplace(v.begin(), v.back()); + assert(v[0] == 3); + assert(is_contiguous_container_asan_correct(v)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter.pass.cpp new file mode 100644 index 00000000000..7a850edda27 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator erase(const_iterator position); + +#include +#include + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::vector l1(a1, a1+3); + std::vector::const_iterator i = l1.begin(); + assert(is_contiguous_container_asan_correct(l1)); + ++i; + std::vector::iterator j = l1.erase(i); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(*j == 3); + assert(*l1.begin() == 1); + assert(*next(l1.begin()) == 3); + assert(is_contiguous_container_asan_correct(l1)); + j = l1.erase(j); + assert(j == l1.end()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(*l1.begin() == 1); + assert(is_contiguous_container_asan_correct(l1)); + j = l1.erase(l1.begin()); + assert(j == l1.end()); + assert(l1.size() == 0); + assert(distance(l1.begin(), l1.end()) == 0); + assert(is_contiguous_container_asan_correct(l1)); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector> l1(a1, a1+3); + std::vector>::const_iterator i = l1.begin(); + assert(is_contiguous_container_asan_correct(l1)); + ++i; + std::vector>::iterator j = l1.erase(i); + assert(l1.size() == 2); + assert(distance(l1.begin(), l1.end()) == 2); + assert(*j == 3); + assert(*l1.begin() == 1); + assert(*next(l1.begin()) == 3); + assert(is_contiguous_container_asan_correct(l1)); + j = l1.erase(j); + assert(j == l1.end()); + assert(l1.size() == 1); + assert(distance(l1.begin(), l1.end()) == 1); + assert(*l1.begin() == 1); + assert(is_contiguous_container_asan_correct(l1)); + j = l1.erase(l1.begin()); + assert(j == l1.end()); + assert(l1.size() == 0); + assert(distance(l1.begin(), l1.end()) == 0); + assert(is_contiguous_container_asan_correct(l1)); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db1.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db1.pass.cpp new file mode 100644 index 00000000000..0478d24c79f --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db1.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator position) with end() + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::vector l1(a1, a1+3); + std::vector::const_iterator i = l1.end(); + l1.erase(i); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector> l1(a1, a1+3); + std::vector>::const_iterator i = l1.end(); + l1.erase(i); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db2.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db2.pass.cpp new file mode 100644 index 00000000000..c394f197402 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_db2.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator position) with iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::vector l1(a1, a1+3); + std::vector l2(a1, a1+3); + std::vector::const_iterator i = l2.begin(); + l1.erase(i); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector> l1(a1, a1+3); + std::vector> l2(a1, a1+3); + std::vector>::const_iterator i = l2.begin(); + l1.erase(i); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..bfc18bc4864 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter.pass.cpp @@ -0,0 +1,127 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator erase(const_iterator first, const_iterator last); + +#include +#include + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + int a1[] = {1, 2, 3}; + { + std::vector l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector::iterator i = l1.erase(l1.cbegin(), l1.cbegin()); + assert(l1.size() == 3); + assert(distance(l1.cbegin(), l1.cend()) == 3); + assert(i == l1.begin()); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin())); + assert(l1.size() == 2); + assert(distance(l1.cbegin(), l1.cend()) == 2); + assert(i == l1.begin()); + assert(l1 == std::vector(a1+1, a1+3)); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 2)); + assert(l1.size() == 1); + assert(distance(l1.cbegin(), l1.cend()) == 1); + assert(i == l1.begin()); + assert(l1 == std::vector(a1+2, a1+3)); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 3)); + assert(l1.size() == 0); + assert(distance(l1.cbegin(), l1.cend()) == 0); + assert(i == l1.begin()); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector > outer(2, std::vector(1)); + assert(is_contiguous_container_asan_correct(outer)); + assert(is_contiguous_container_asan_correct(outer[0])); + assert(is_contiguous_container_asan_correct(outer[1])); + outer.erase(outer.begin(), outer.begin()); + assert(outer.size() == 2); + assert(outer[0].size() == 1); + assert(outer[1].size() == 1); + assert(is_contiguous_container_asan_correct(outer)); + assert(is_contiguous_container_asan_correct(outer[0])); + assert(is_contiguous_container_asan_correct(outer[1])); + } +#if __cplusplus >= 201103L + { + std::vector> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector>::iterator i = l1.erase(l1.cbegin(), l1.cbegin()); + assert(l1.size() == 3); + assert(distance(l1.cbegin(), l1.cend()) == 3); + assert(i == l1.begin()); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin())); + assert(l1.size() == 2); + assert(distance(l1.cbegin(), l1.cend()) == 2); + assert(i == l1.begin()); + assert((l1 == std::vector>(a1+1, a1+3))); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 2)); + assert(l1.size() == 1); + assert(distance(l1.cbegin(), l1.cend()) == 1); + assert(i == l1.begin()); + assert((l1 == std::vector>(a1+2, a1+3))); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector> l1(a1, a1+3); + assert(is_contiguous_container_asan_correct(l1)); + std::vector>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 3)); + assert(l1.size() == 0); + assert(distance(l1.cbegin(), l1.cend()) == 0); + assert(i == l1.begin()); + assert(is_contiguous_container_asan_correct(l1)); + } + { + std::vector>, min_allocator>>> outer(2, std::vector>(1)); + assert(is_contiguous_container_asan_correct(outer)); + assert(is_contiguous_container_asan_correct(outer[0])); + assert(is_contiguous_container_asan_correct(outer[1])); + outer.erase(outer.begin(), outer.begin()); + assert(outer.size() == 2); + assert(outer[0].size() == 1); + assert(outer[1].size() == 1); + assert(is_contiguous_container_asan_correct(outer)); + assert(is_contiguous_container_asan_correct(outer[0])); + assert(is_contiguous_container_asan_correct(outer[1])); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db1.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db1.pass.cpp new file mode 100644 index 00000000000..af6d0f75789 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db1.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with first iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::vector l1(a1, a1+3); + std::vector l2(a1, a1+3); + std::vector::iterator i = l1.erase(l2.cbegin(), l1.cbegin()+1); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector> l1(a1, a1+3); + std::vector> l2(a1, a1+3); + std::vector>::iterator i = l1.erase(l2.cbegin(), l1.cbegin()+1); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db2.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db2.pass.cpp new file mode 100644 index 00000000000..eee2c66c5c8 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db2.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with second iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::vector l1(a1, a1+3); + std::vector l2(a1, a1+3); + std::vector::iterator i = l1.erase(l1.cbegin(), l2.cbegin()+1); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector> l1(a1, a1+3); + std::vector> l2(a1, a1+3); + std::vector>::iterator i = l1.erase(l1.cbegin(), l2.cbegin()+1); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db3.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db3.pass.cpp new file mode 100644 index 00000000000..505067d05a1 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db3.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with both iterators from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::vector l1(a1, a1+3); + std::vector l2(a1, a1+3); + std::vector::iterator i = l1.erase(l2.cbegin(), l2.cbegin()+1); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector> l1(a1, a1+3); + std::vector> l2(a1, a1+3); + std::vector>::iterator i = l1.erase(l2.cbegin(), l2.cbegin()+1); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db4.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db4.pass.cpp new file mode 100644 index 00000000000..c7e4131cb49 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/erase_iter_iter_db4.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with a bad range + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::vector l1(a1, a1+3); + std::vector::iterator i = l1.erase(l1.cbegin()+1, l1.cbegin()); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 2, 3}; + std::vector> l1(a1, a1+3); + std::vector>::iterator i = l1.erase(l1.cbegin()+1, l1.cbegin()); + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_initializer_list.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_initializer_list.pass.cpp new file mode 100644 index 00000000000..30b80178801 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_initializer_list.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator insert(const_iterator p, initializer_list il); + +#include +#include + +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + std::vector d(10, 1); + std::vector::iterator i = d.insert(d.cbegin() + 2, {3, 4, 5, 6}); + assert(d.size() == 14); + assert(is_contiguous_container_asan_correct(d)); + assert(i == d.begin() + 2); + assert(d[0] == 1); + assert(d[1] == 1); + assert(d[2] == 3); + assert(d[3] == 4); + assert(d[4] == 5); + assert(d[5] == 6); + assert(d[6] == 1); + assert(d[7] == 1); + assert(d[8] == 1); + assert(d[9] == 1); + assert(d[10] == 1); + assert(d[11] == 1); + assert(d[12] == 1); + assert(d[13] == 1); + } +#if __cplusplus >= 201103L + { + std::vector> d(10, 1); + std::vector>::iterator i = d.insert(d.cbegin() + 2, {3, 4, 5, 6}); + assert(d.size() == 14); + assert(is_contiguous_container_asan_correct(d)); + assert(i == d.begin() + 2); + assert(d[0] == 1); + assert(d[1] == 1); + assert(d[2] == 3); + assert(d[3] == 4); + assert(d[4] == 5); + assert(d[5] == 6); + assert(d[6] == 1); + assert(d[7] == 1); + assert(d[8] == 1); + assert(d[9] == 1); + assert(d[10] == 1); + assert(d[11] == 1); + assert(d[12] == 1); + assert(d[13] == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp new file mode 100644 index 00000000000..782437be87f --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_iter_iter.pass.cpp @@ -0,0 +1,190 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// iterator insert(const_iterator position, Iter first, Iter last); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include +#include "../../../stack_allocator.h" +#include "test_iterators.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector v(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector::iterator i = v.insert(v.cbegin() + 10, input_iterator(a), + input_iterator(a+N)); + assert(v.size() == 100 + N); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } + { + std::vector v(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector::iterator i = v.insert(v.cbegin() + 10, forward_iterator(a), + forward_iterator(a+N)); + assert(v.size() == 100 + N); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } + { + std::vector v(100); + while(v.size() < v.capacity()) v.push_back(0); // force reallocation + size_t sz = v.size(); + int a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector::iterator i = v.insert(v.cbegin() + 10, forward_iterator(a), + forward_iterator(a+N)); + assert(v.size() == sz + N); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector v(100); + v.reserve(128); // force no reallocation + size_t sz = v.size(); + int a[] = {1, 2, 3, 4, 5}; + const unsigned N = sizeof(a)/sizeof(a[0]); + std::vector::iterator i = v.insert(v.cbegin() + 10, forward_iterator(a), + forward_iterator(a+N)); + assert(v.size() == sz + N); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector > v(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector::iterator i = v.insert(v.cbegin() + 10, input_iterator(a), + input_iterator(a+N)); + assert(v.size() == 100 + N); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } + { + std::vector > v(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector::iterator i = v.insert(v.cbegin() + 10, forward_iterator(a), + forward_iterator(a+N)); + assert(v.size() == 100 + N); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector v(100); + std::vector v2(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector::iterator i = v.insert(v2.cbegin() + 10, input_iterator(a), + input_iterator(a+N)); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::vector> v(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector>::iterator i = v.insert(v.cbegin() + 10, input_iterator(a), + input_iterator(a+N)); + assert(v.size() == 100 + N); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } + { + std::vector> v(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector>::iterator i = v.insert(v.cbegin() + 10, forward_iterator(a), + forward_iterator(a+N)); + assert(v.size() == 100 + N); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (int k = 0; k < N; ++j, ++k) + assert(v[j] == a[k]); + for (; j < 105; ++j) + assert(v[j] == 0); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector> v(100); + std::vector> v2(100); + int a[] = {1, 2, 3, 4, 5}; + const int N = sizeof(a)/sizeof(a[0]); + std::vector>::iterator i = v.insert(v2.cbegin() + 10, input_iterator(a), + input_iterator(a+N)); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.pass.cpp new file mode 100644 index 00000000000..cf3715ccb6f --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_rvalue.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator insert(const_iterator position, value_type&& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include +#include "../../../stack_allocator.h" +#include "../../../MoveOnly.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector v(100); + std::vector::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3)); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == MoveOnly()); + assert(v[j] == MoveOnly(3)); + for (++j; j < 101; ++j) + assert(v[j] == MoveOnly()); + } + { + std::vector > v(100); + std::vector >::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3)); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == MoveOnly()); + assert(v[j] == MoveOnly(3)); + for (++j; j < 101; ++j) + assert(v[j] == MoveOnly()); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector v1(3); + std::vector v2(3); + v1.insert(v2.begin(), 4); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::vector> v(100); + std::vector>::iterator i = v.insert(v.cbegin() + 10, MoveOnly(3)); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == MoveOnly()); + assert(v[j] == MoveOnly(3)); + for (++j; j < 101; ++j) + assert(v[j] == MoveOnly()); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector> v1(3); + std::vector> v2(3); + v1.insert(v2.begin(), 4); + assert(false); + } +#endif +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp new file mode 100644 index 00000000000..6997284f258 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_size_value.pass.cpp @@ -0,0 +1,132 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator insert(const_iterator position, size_type n, const value_type& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector v(100); + std::vector::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == 105); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < 105; ++j) + assert(v[j] == 0); + } + { + std::vector v(100); + while(v.size() < v.capacity()) v.push_back(0); // force reallocation + size_t sz = v.size(); + std::vector::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == sz + 5); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector v(100); + v.reserve(128); // force no reallocation + size_t sz = v.size(); + std::vector::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == sz + 5); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector > v(100); + std::vector >::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == 105); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < 105; ++j) + assert(v[j] == 0); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector c1(100); + std::vector c2; + std::vector::iterator i = c1.insert(c2.cbegin() + 10, 5, 1); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::vector> v(100); + std::vector>::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == 105); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < 105; ++j) + assert(v[j] == 0); + } + { + std::vector> v(100); + std::vector>::iterator i = v.insert(v.cbegin() + 10, 5, 1); + assert(v.size() == 105); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + for (; j < 15; ++j) + assert(v[j] == 1); + for (++j; j < 105; ++j) + assert(v[j] == 0); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector> c1(100); + std::vector> c2; + std::vector>::iterator i = c1.insert(c2.cbegin() + 10, 5, 1); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp new file mode 100644 index 00000000000..782e752157a --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/insert_iter_value.pass.cpp @@ -0,0 +1,116 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// iterator insert(const_iterator position, const value_type& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector v(100); + std::vector::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < 101; ++j) + assert(v[j] == 0); + } + { + std::vector v(100); + while(v.size() < v.capacity()) v.push_back(0); // force reallocation + size_t sz = v.size(); + std::vector::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == sz + 1); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector v(100); + while(v.size() < v.capacity()) v.push_back(0); + v.pop_back(); v.pop_back(); // force no reallocation + size_t sz = v.size(); + std::vector::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == sz + 1); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < v.size(); ++j) + assert(v[j] == 0); + } + { + std::vector > v(100); + std::vector >::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < 101; ++j) + assert(v[j] == 0); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector v1(3); + std::vector v2(3); + int i = 4; + v1.insert(v2.begin(), i); + assert(false); + } +#endif +#if __cplusplus >= 201103L + { + std::vector> v(100); + std::vector>::iterator i = v.insert(v.cbegin() + 10, 1); + assert(v.size() == 101); + assert(is_contiguous_container_asan_correct(v)); + assert(i == v.begin() + 10); + int j; + for (j = 0; j < 10; ++j) + assert(v[j] == 0); + assert(v[j] == 1); + for (++j; j < 101; ++j) + assert(v[j] == 0); + } +#if _LIBCPP_DEBUG >= 1 + { + std::vector> v1(3); + std::vector> v2(3); + int i = 4; + v1.insert(v2.begin(), i); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/pop_back.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/pop_back.pass.cpp new file mode 100644 index 00000000000..62fa60103ba --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/pop_back.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void pop_back(); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include +#include "../../../stack_allocator.h" +#include "min_allocator.h" + +#if _LIBCPP_DEBUG >= 1 +#include +#include + +#endif + +int main() +{ + { + std::vector c; + c.push_back(1); + assert(c.size() == 1); + c.pop_back(); + assert(c.size() == 0); +#if _LIBCPP_DEBUG >= 1 + c.pop_back(); + assert(false); +#endif + } +#if __cplusplus >= 201103L + { + std::vector> c; + c.push_back(1); + assert(c.size() == 1); + c.pop_back(); + assert(c.size() == 0); +#if _LIBCPP_DEBUG >= 1 + c.pop_back(); + assert(false); +#endif + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back.pass.cpp new file mode 100644 index 00000000000..eeeba6242d9 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back.pass.cpp @@ -0,0 +1,108 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push_back(const value_type& x); + +#include +#include +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + std::vector c; + c.push_back(0); + assert(c.size() == 1); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(1); + assert(c.size() == 2); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(2); + assert(c.size() == 3); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(3); + assert(c.size() == 4); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(4); + assert(c.size() == 5); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + } + { + std::vector > c; + c.push_back(0); + assert(c.size() == 1); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(1); + assert(c.size() == 2); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(2); + assert(c.size() == 3); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(3); + assert(c.size() == 4); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(4); + assert(c.size() == 5); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + } +#if __cplusplus >= 201103L + { + std::vector> c; + c.push_back(0); + assert(c.size() == 1); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(1); + assert(c.size() == 2); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(2); + assert(c.size() == 3); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(3); + assert(c.size() == 4); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + c.push_back(4); + assert(c.size() == 5); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == j); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp new file mode 100644 index 00000000000..6615a25a620 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back_exception_safety.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push_back(const value_type& x); + +#include +#include + +#include "asan_testing.h" + +// Flag that makes the copy constructor for CMyClass throw an exception +static bool gCopyConstructorShouldThow = false; + + +class CMyClass { + public: CMyClass(int tag); + public: CMyClass(const CMyClass& iOther); + public: ~CMyClass(); + + bool equal(const CMyClass &rhs) const + { return fTag == rhs.fTag && fMagicValue == rhs.fMagicValue; } + private: + int fMagicValue; + int fTag; + + private: static int kStartedConstructionMagicValue; + private: static int kFinishedConstructionMagicValue; +}; + +// Value for fMagicValue when the constructor has started running, but not yet finished +int CMyClass::kStartedConstructionMagicValue = 0; +// Value for fMagicValue when the constructor has finished running +int CMyClass::kFinishedConstructionMagicValue = 12345; + +CMyClass::CMyClass(int tag) : + fMagicValue(kStartedConstructionMagicValue), fTag(tag) +{ + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::CMyClass(const CMyClass& iOther) : + fMagicValue(kStartedConstructionMagicValue), fTag(iOther.fTag) +{ + // If requested, throw an exception _before_ setting fMagicValue to kFinishedConstructionMagicValue + if (gCopyConstructorShouldThow) { + throw std::exception(); + } + // Signal that the constructor has finished running + fMagicValue = kFinishedConstructionMagicValue; +} + +CMyClass::~CMyClass() { + // Only instances for which the constructor has finished running should be destructed + assert(fMagicValue == kFinishedConstructionMagicValue); +} + +bool operator==(const CMyClass &lhs, const CMyClass &rhs) { return lhs.equal(rhs); } + +int main() +{ + CMyClass instance(42); + std::vector vec; + + vec.push_back(instance); + std::vector vec2(vec); + assert(is_contiguous_container_asan_correct(vec)); + assert(is_contiguous_container_asan_correct(vec2)); + + gCopyConstructorShouldThow = true; + try { + vec.push_back(instance); + } + catch (...) { + assert(vec==vec2); + assert(is_contiguous_container_asan_correct(vec)); + } +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp new file mode 100644 index 00000000000..be488931263 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.modifiers/push_back_rvalue.pass.cpp @@ -0,0 +1,111 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void push_back(value_type&& x); + +#include +#include +#include "../../../MoveOnly.h" +#include "../../../stack_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + std::vector c; + c.push_back(MoveOnly(0)); + assert(c.size() == 1); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(1)); + assert(c.size() == 2); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(2)); + assert(c.size() == 3); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(3)); + assert(c.size() == 4); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(4)); + assert(c.size() == 5); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + } + { + std::vector > c; + c.push_back(MoveOnly(0)); + assert(c.size() == 1); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(1)); + assert(c.size() == 2); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(2)); + assert(c.size() == 3); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(3)); + assert(c.size() == 4); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(4)); + assert(c.size() == 5); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + } +#if __cplusplus >= 201103L + { + std::vector> c; + c.push_back(MoveOnly(0)); + assert(c.size() == 1); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(1)); + assert(c.size() == 2); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(2)); + assert(c.size() == 3); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(3)); + assert(c.size() == 4); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + c.push_back(MoveOnly(4)); + assert(c.size() == 5); + assert(is_contiguous_container_asan_correct(c)); + for (int j = 0; j < c.size(); ++j) + assert(c[j] == MoveOnly(j)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.special/db_swap_1.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.special/db_swap_1.pass.cpp new file mode 100644 index 00000000000..e7f6a0011e1 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.special/db_swap_1.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// void swap(vector& x, vector& y); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "min_allocator.h" + +int main() +{ +#if _LIBCPP_DEBUG >= 1 + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::vector c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + std::vector::iterator i1 = c1.begin(); + std::vector::iterator i2 = c2.begin(); + swap(c1, c2); + c1.erase(i2); + c2.erase(i1); + c1.erase(i1); + assert(false); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::vector> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + std::vector>::iterator i1 = c1.begin(); + std::vector>::iterator i2 = c2.begin(); + swap(c1, c2); + c1.erase(i2); + c2.erase(i1); + c1.erase(i1); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.special/swap.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.special/swap.pass.cpp new file mode 100644 index 00000000000..27001aef744 --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.special/swap.pass.cpp @@ -0,0 +1,187 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// void swap(vector& x, vector& y); + +#include +#include +#include "test_allocator.h" +#include "min_allocator.h" +#include "asan_testing.h" + +int main() +{ + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::vector c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert(c1 == std::vector(a2, a2+sizeof(a2)/sizeof(a2[0]))); + assert(c2 == std::vector(a1, a1+sizeof(a1)/sizeof(a1[0]))); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector c1(a1, a1); + std::vector c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert(c1 == std::vector(a2, a2+sizeof(a2)/sizeof(a2[0]))); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::vector c2(a2, a2); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert(c2 == std::vector(a1, a1+sizeof(a1)/sizeof(a1[0]))); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector c1(a1, a1); + std::vector c2(a2, a2); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } +#ifndef _LIBCPP_DEBUG_LEVEL +// This test known to result in undefined behavior detected by _LIBCPP_DEBUG_LEVEL >= 1 + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef test_allocator A; + std::vector c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1)); + std::vector c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2)); + swap(c1, c2); + assert((c1 == std::vector(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A(1)); + assert((c2 == std::vector(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A(2)); + } +#endif + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef other_allocator A; + std::vector c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A(1)); + std::vector c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A(2)); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert((c1 == std::vector(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A(2)); + assert((c2 == std::vector(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A(1)); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } +#if __cplusplus >= 201103L + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::vector> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert((c1 == std::vector>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert((c2 == std::vector>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector> c1(a1, a1); + std::vector> c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert((c1 == std::vector>(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector> c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::vector> c2(a2, a2); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert((c2 == std::vector>(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::vector> c1(a1, a1); + std::vector> c2(a2, a2); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert(c1.empty()); + assert(distance(c1.begin(), c1.end()) == 0); + assert(c2.empty()); + assert(distance(c2.begin(), c2.end()) == 0); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } +#ifndef _LIBCPP_DEBUG_LEVEL +// This test known to result in undefined behavior detected by _LIBCPP_DEBUG_LEVEL >= 1 + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + typedef min_allocator A; + std::vector c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A()); + std::vector c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A()); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + swap(c1, c2); + assert((c1 == std::vector(a2, a2+sizeof(a2)/sizeof(a2[0])))); + assert(c1.get_allocator() == A()); + assert((c2 == std::vector(a1, a1+sizeof(a1)/sizeof(a1[0])))); + assert(c2.get_allocator() == A()); + assert(is_contiguous_container_asan_correct(c1)); + assert(is_contiguous_container_asan_correct(c2)); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/vector.special/swap_noexcept.pass.cpp b/libcxx/test/std/containers/sequences/vector/vector.special/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..996712a33aa --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/vector.special/swap_noexcept.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(vector& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_alloc +{ + typedef T value_type; + + some_alloc() {} + some_alloc(const some_alloc&); + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::vector C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::vector> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::vector> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::vector> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/sequences/vector/version.pass.cpp b/libcxx/test/std/containers/sequences/vector/version.pass.cpp new file mode 100644 index 00000000000..2c4fa1263de --- /dev/null +++ b/libcxx/test/std/containers/sequences/vector/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +#include + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/std/containers/stack_allocator.h b/libcxx/test/std/containers/stack_allocator.h new file mode 100644 index 00000000000..d5fab025c9d --- /dev/null +++ b/libcxx/test/std/containers/stack_allocator.h @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef STACK_ALLOCATOR_H +#define STACK_ALLOCATOR_H + +#include +#include + +template +class stack_allocator +{ + char buf_[sizeof(T)*N]; + char* ptr_; +public: + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef std::size_t size_type; + typedef std::ptrdiff_t difference_type; + + template struct rebind {typedef stack_allocator other;}; + + stack_allocator() : ptr_(buf_) {} + +private: + stack_allocator(const stack_allocator&);// = delete; + stack_allocator& operator=(const stack_allocator&);// = delete; + +public: + pointer allocate(size_type n, const void* = 0) + { + if (n > N - (ptr_ - buf_) / sizeof(value_type)) { +#ifndef _LIBCPP_NO_EXCEPTIONS + throw std::bad_alloc(); +#else + std::terminate(); +#endif + } + pointer r = (T*)ptr_; + ptr_ += n * sizeof(T); + return r; + } + void deallocate(pointer p, size_type n) + { + if ((char*)(p + n) == ptr_) + ptr_ = (char*)p; + } + + size_type max_size() const {return N;} +}; + +template +inline +void +swap(stack_allocator& x, stack_allocator& y) {} + +#endif // STACK_ALLOCATOR_H diff --git a/libcxx/test/std/containers/test_compare.h b/libcxx/test/std/containers/test_compare.h new file mode 100644 index 00000000000..9c54799172e --- /dev/null +++ b/libcxx/test/std/containers/test_compare.h @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef TEST_COMPARE_H +#define TEST_COMPARE_H + +#include +#include +#include +#include +#include + +template +class test_compare + : private C +{ + int data_; +public: + explicit test_compare(int data = 0) : data_(data) {} + + typename C::result_type + operator()(typename std::add_lvalue_reference::type x, + typename std::add_lvalue_reference::type y) const + {return C::operator()(x, y);} + + bool operator==(const test_compare& c) const + {return data_ == c.data_;} +}; + +#endif // TEST_COMPARE_H diff --git a/libcxx/test/std/containers/test_hash.h b/libcxx/test/std/containers/test_hash.h new file mode 100644 index 00000000000..1a70e7cbdd9 --- /dev/null +++ b/libcxx/test/std/containers/test_hash.h @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef TEST_HASH_H +#define TEST_HASH_H + +#include +#include + +template +class test_hash + : private C +{ + int data_; +public: + explicit test_hash(int data = 0) : data_(data) {} + + std::size_t + operator()(typename std::add_lvalue_reference::type x) const + {return C::operator()(x);} + + bool operator==(const test_hash& c) const + {return data_ == c.data_;} +}; + +#endif // TEST_HASH_H diff --git a/libcxx/test/std/containers/unord/next_prime.pass.cpp b/libcxx/test/std/containers/unord/next_prime.pass.cpp new file mode 100644 index 00000000000..266d7f1f9d1 --- /dev/null +++ b/libcxx/test/std/containers/unord/next_prime.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// REQUIRES: long_tests + +// Not a portable test + +// <__hash_table> + +// size_t __next_prime(size_t n); + +// If n == 0, return 0, else return the lowest prime greater than or equal to n + +#include <__hash_table> +#include + +bool +is_prime(size_t n) +{ + switch (n) + { + case 0: + case 1: + return false; + } + for (size_t i = 2; i*i <= n; ++i) + { + if (n % i == 0) + return false; + } + return true; +} + +int main() +{ + assert(std::__next_prime(0) == 0); + for (std::size_t n = 1; n <= 100000; ++n) + { + std::size_t p = std::__next_prime(n); + assert(p >= n); + for (std::size_t i = n; i < p; ++i) + assert(!is_prime(i)); + assert(is_prime(p)); + } +} diff --git a/libcxx/test/std/containers/unord/unord.map/bucket.pass.cpp b/libcxx/test/std/containers/unord/unord.map/bucket.pass.cpp new file mode 100644 index 00000000000..6837294e35b --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/bucket.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// size_type bucket(const key_type& __k) const; + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(std::begin(a), std::end(a)); + size_t bc = c.bucket_count(); + assert(bc >= 5); + for (size_t i = 0; i < 13; ++i) + assert(c.bucket(i) == i % bc); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(std::begin(a), std::end(a)); + size_t bc = c.bucket_count(); + assert(bc >= 5); + for (size_t i = 0; i < 13; ++i) + assert(c.bucket(i) == i % bc); + } +#endif +#if _LIBCPP_DEBUG_LEVEL >= 1 + { + typedef std::unordered_map C; + C c; + C::size_type i = c.bucket(3); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/bucket_count.pass.cpp b/libcxx/test/std/containers/unord/unord.map/bucket_count.pass.cpp new file mode 100644 index 00000000000..d3e80d86379 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/bucket_count.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// size_type bucket_count() const; + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef C::const_iterator I; + typedef std::pair P; + const C c; + assert(c.bucket_count() == 0); + } + { + typedef std::unordered_map C; + typedef C::const_iterator I; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 11); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef C::const_iterator I; + typedef std::pair P; + const C c; + assert(c.bucket_count() == 0); + } + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef C::const_iterator I; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 11); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/bucket_size.pass.cpp b/libcxx/test/std/containers/unord/unord.map/bucket_size.pass.cpp new file mode 100644 index 00000000000..f3ab8fff4e4 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/bucket_size.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// size_type bucket_size(size_type n) const + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 5); + assert(c.bucket_size(0) == 0); + assert(c.bucket_size(1) == 1); + assert(c.bucket_size(2) == 1); + assert(c.bucket_size(3) == 1); + assert(c.bucket_size(4) == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 5); + assert(c.bucket_size(0) == 0); + assert(c.bucket_size(1) == 1); + assert(c.bucket_size(2) == 1); + assert(c.bucket_size(3) == 1); + assert(c.bucket_size(4) == 1); + } +#endif +#if _LIBCPP_DEBUG_LEVEL >= 1 + { + typedef std::unordered_map C; + C c; + C::size_type i = c.bucket_size(3); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/compare.pass.cpp b/libcxx/test/std/containers/unord/unord.map/compare.pass.cpp new file mode 100644 index 00000000000..8979a3a34ad --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/compare.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// http://llvm.org/bugs/show_bug.cgi?id=16538 +// http://llvm.org/bugs/show_bug.cgi?id=16549 + +#include + +struct Key { + template Key(const T&) {} + bool operator== (const Key&) const { return true; } +}; + +namespace std +{ + template <> + struct hash + { + size_t operator()(Key const &) const {return 0;} + }; +} + +int +main() +{ + std::unordered_map::iterator it = + std::unordered_map().find(Key(0)); + std::pair::iterator, bool> result = + std::unordered_map().insert(std::make_pair(Key(0), 0)); +} diff --git a/libcxx/test/std/containers/unord/unord.map/count.pass.cpp b/libcxx/test/std/containers/unord/unord.map/count.pass.cpp new file mode 100644 index 00000000000..50abb53464e --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/count.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// size_type count(const key_type& k) const; + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + assert(c.count(30) == 1); + assert(c.count(5) == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + assert(c.count(30) == 1); + assert(c.count(5) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/db_iterators_7.pass.cpp b/libcxx/test/std/containers/unord/unord.map/db_iterators_7.pass.cpp new file mode 100644 index 00000000000..b8db0a35ffc --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/db_iterators_7.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Increment iterator past end. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + C c; + c.insert(std::make_pair(1, "one")); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + C c; + c.insert(std::make_pair(1, "one")); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.map/db_iterators_8.pass.cpp b/libcxx/test/std/containers/unord/unord.map/db_iterators_8.pass.cpp new file mode 100644 index 00000000000..c923dd77862 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/db_iterators_8.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Dereference non-dereferenceable iterator. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + C c; + c.insert(std::make_pair(1, "one")); + C::iterator i = c.end(); + C::value_type j = *i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + C c; + c.insert(std::make_pair(1, "one")); + C::iterator i = c.end(); + C::value_type j = *i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.map/db_local_iterators_7.pass.cpp b/libcxx/test/std/containers/unord/unord.map/db_local_iterators_7.pass.cpp new file mode 100644 index 00000000000..fa1886bfff1 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/db_local_iterators_7.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Increment local_iterator past end. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + C c(1); + C::local_iterator i = c.begin(0); + ++i; + ++i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + C c(1); + C::local_iterator i = c.begin(0); + ++i; + ++i; + assert(false); + } +#endif + +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.map/db_local_iterators_8.pass.cpp b/libcxx/test/std/containers/unord/unord.map/db_local_iterators_8.pass.cpp new file mode 100644 index 00000000000..4b071cad7b4 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/db_local_iterators_8.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Dereference non-dereferenceable iterator. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + C c(1); + C::local_iterator i = c.end(0); + C::value_type j = *i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + C c(1); + C::local_iterator i = c.end(0); + C::value_type j = *i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.map/eq.pass.cpp b/libcxx/test/std/containers/unord/unord.map/eq.pass.cpp new file mode 100644 index 00000000000..9258378eb09 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/eq.pass.cpp @@ -0,0 +1,163 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// bool +// operator==(const unordered_map& x, +// const unordered_map& y); +// +// template +// bool +// operator!=(const unordered_map& x, +// const unordered_map& y); + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c1(std::begin(a), std::end(a)); + const C c2; + assert(!(c1 == c2)); + assert( (c1 != c2)); + } + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c1(std::begin(a), std::end(a)); + const C c2 = c1; + assert( (c1 == c2)); + assert(!(c1 != c2)); + } + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(std::begin(a), std::end(a)); + C c2 = c1; + c2.rehash(30); + assert( (c1 == c2)); + assert(!(c1 != c2)); + c2.insert(P(90, "ninety")); + assert(!(c1 == c2)); + assert( (c1 != c2)); + c1.insert(P(90, "ninety")); + assert( (c1 == c2)); + assert(!(c1 != c2)); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c1(std::begin(a), std::end(a)); + const C c2; + assert(!(c1 == c2)); + assert( (c1 != c2)); + } + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c1(std::begin(a), std::end(a)); + const C c2 = c1; + assert( (c1 == c2)); + assert(!(c1 != c2)); + } + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(std::begin(a), std::end(a)); + C c2 = c1; + c2.rehash(30); + assert( (c1 == c2)); + assert(!(c1 != c2)); + c2.insert(P(90, "ninety")); + assert(!(c1 == c2)); + assert( (c1 != c2)); + c1.insert(P(90, "ninety")); + assert( (c1 == c2)); + assert(!(c1 != c2)); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/equal_range_const.pass.cpp b/libcxx/test/std/containers/unord/unord.map/equal_range_const.pass.cpp new file mode 100644 index 00000000000..fe166c965b1 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/equal_range_const.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// pair equal_range(const key_type& k) const; + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef C::const_iterator I; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + std::pair r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(r.first->first == 30); + assert(r.first->second == "thirty"); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef C::const_iterator I; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + std::pair r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(r.first->first == 30); + assert(r.first->second == "thirty"); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/equal_range_non_const.pass.cpp b/libcxx/test/std/containers/unord/unord.map/equal_range_non_const.pass.cpp new file mode 100644 index 00000000000..9e8d1a9644c --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/equal_range_non_const.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// pair equal_range(const key_type& k); + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef C::iterator I; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c(std::begin(a), std::end(a)); + std::pair r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(r.first->first == 30); + assert(r.first->second == "thirty"); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef C::iterator I; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c(std::begin(a), std::end(a)); + std::pair r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(r.first->first == 30); + assert(r.first->second == "thirty"); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/find_const.pass.cpp b/libcxx/test/std/containers/unord/unord.map/find_const.pass.cpp new file mode 100644 index 00000000000..120efa3061b --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/find_const.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// const_iterator find(const key_type& k) const; + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + C::const_iterator i = c.find(30); + assert(i->first == 30); + assert(i->second == "thirty"); + i = c.find(5); + assert(i == c.cend()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + C::const_iterator i = c.find(30); + assert(i->first == 30); + assert(i->second == "thirty"); + i = c.find(5); + assert(i == c.cend()); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/find_non_const.pass.cpp b/libcxx/test/std/containers/unord/unord.map/find_non_const.pass.cpp new file mode 100644 index 00000000000..7582a796dd7 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/find_non_const.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// iterator find(const key_type& k); + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c(std::begin(a), std::end(a)); + C::iterator i = c.find(30); + assert(i->first == 30); + assert(i->second == "thirty"); + i = c.find(5); + assert(i == c.end()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c(std::begin(a), std::end(a)); + C::iterator i = c.find(30); + assert(i->first == 30); + assert(i->second == "thirty"); + i = c.find(5); + assert(i == c.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/iterators.pass.cpp b/libcxx/test/std/containers/unord/unord.map/iterators.pass.cpp new file mode 100644 index 00000000000..47b1d738668 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/iterators.pass.cpp @@ -0,0 +1,128 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// iterator begin() {return __table_.begin();} +// iterator end() {return __table_.end();} +// const_iterator begin() const {return __table_.begin();} +// const_iterator end() const {return __table_.end();} +// const_iterator cbegin() const {return __table_.begin();} +// const_iterator cend() const {return __table_.end();} + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::iterator i; + } + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::const_iterator i; + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::iterator i; + } + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::const_iterator i; + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + typedef std::unordered_map C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/load_factor.pass.cpp b/libcxx/test/std/containers/unord/unord.map/load_factor.pass.cpp new file mode 100644 index 00000000000..472e41abf6e --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/load_factor.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// float load_factor() const + +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + } + { + typedef std::unordered_map C; + typedef std::pair P; + const C c; + assert(c.load_factor() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + } + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + const C c; + assert(c.load_factor() == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/local_iterators.pass.cpp b/libcxx/test/std/containers/unord/unord.map/local_iterators.pass.cpp new file mode 100644 index 00000000000..770b1ace7a3 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/local_iterators.pass.cpp @@ -0,0 +1,421 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// local_iterator begin (size_type n); +// local_iterator end (size_type n); +// const_local_iterator begin (size_type n) const; +// const_local_iterator end (size_type n) const; +// const_local_iterator cbegin(size_type n) const; +// const_local_iterator cend (size_type n) const; + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + typedef C::local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 1); + assert(i->second == "one"); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 2); + assert(i->second == "two"); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + } + { + typedef std::unordered_map C; + typedef std::pair P; + typedef C::const_local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 1); + assert(i->second == "one"); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 2); + assert(i->second == "two"); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + } + { + typedef std::unordered_map C; + typedef std::pair P; + typedef C::const_local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 1); + assert(i->second == "one"); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 2); + assert(i->second == "two"); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + } + { + typedef std::unordered_map C; + typedef std::pair P; + typedef C::const_local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 1); + assert(i->second == "one"); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 2); + assert(i->second == "two"); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + typedef C::local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 1); + assert(i->second == "one"); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 2); + assert(i->second == "two"); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + } + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + typedef C::const_local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 1); + assert(i->second == "one"); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 2); + assert(i->second == "two"); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + } + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + typedef C::const_local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 1); + assert(i->second == "one"); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 2); + assert(i->second == "two"); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + } + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + typedef C::const_local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 1); + assert(i->second == "one"); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 2); + assert(i->second == "two"); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/max_bucket_count.pass.cpp b/libcxx/test/std/containers/unord/unord.map/max_bucket_count.pass.cpp new file mode 100644 index 00000000000..b4ca8eb0447 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/max_bucket_count.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// size_type max_bucket_count() const; + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef C::const_iterator I; + typedef std::pair P; + const C c; + assert(c.max_bucket_count() > 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef C::const_iterator I; + typedef std::pair P; + const C c; + assert(c.max_bucket_count() > 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/max_load_factor.pass.cpp b/libcxx/test/std/containers/unord/unord.map/max_load_factor.pass.cpp new file mode 100644 index 00000000000..69fd70d2a17 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/max_load_factor.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// float max_load_factor() const; +// void max_load_factor(float mlf); + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + const C c; + assert(c.max_load_factor() == 1); + } + { + typedef std::unordered_map C; + typedef std::pair P; + C c; + assert(c.max_load_factor() == 1); + c.max_load_factor(2.5); + assert(c.max_load_factor() == 2.5); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + const C c; + assert(c.max_load_factor() == 1); + } + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + C c; + assert(c.max_load_factor() == 1); + c.max_load_factor(2.5); + assert(c.max_load_factor() == 2.5); + } +#endif +#if _LIBCPP_DEBUG_LEVEL >= 1 + { + typedef std::unordered_map C; + C c; + c.max_load_factor(0); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/max_size.pass.cpp b/libcxx/test/std/containers/unord/unord.map/max_size.pass.cpp new file mode 100644 index 00000000000..7d5ae3a8e46 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/max_size.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// size_type max_size() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + std::unordered_map u; + assert(u.max_size() > 0); + } +#if __cplusplus >= 201103L + { + std::unordered_map, std::equal_to, + min_allocator>> u; + assert(u.max_size() > 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/rehash.pass.cpp b/libcxx/test/std/containers/unord/unord.map/rehash.pass.cpp new file mode 100644 index 00000000000..84ece235551 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/rehash.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// void rehash(size_type n); + +#include +#include +#include + +#include "min_allocator.h" + +template +void test(const C& c) +{ + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); +} + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 5); + c.rehash(3); + assert(c.bucket_count() == 5); + test(c); + c.max_load_factor(2); + c.rehash(3); + assert(c.bucket_count() == 3); + test(c); + c.rehash(31); + assert(c.bucket_count() == 31); + test(c); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 5); + c.rehash(3); + assert(c.bucket_count() == 5); + test(c); + c.max_load_factor(2); + c.rehash(3); + assert(c.bucket_count() == 3); + test(c); + c.rehash(31); + assert(c.bucket_count() == 31); + test(c); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/reserve.pass.cpp b/libcxx/test/std/containers/unord/unord.map/reserve.pass.cpp new file mode 100644 index 00000000000..48667cdc7f9 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/reserve.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// void reserve(size_type n); + +#include +#include +#include + +#include "min_allocator.h" + +template +void test(const C& c) +{ + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); +} + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 5); + c.reserve(3); + assert(c.bucket_count() == 5); + test(c); + c.max_load_factor(2); + c.reserve(3); + assert(c.bucket_count() >= 2); + test(c); + c.reserve(31); + assert(c.bucket_count() >= 16); + test(c); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 5); + c.reserve(3); + assert(c.bucket_count() == 5); + test(c); + c.max_load_factor(2); + c.reserve(3); + assert(c.bucket_count() >= 2); + test(c); + c.reserve(31); + assert(c.bucket_count() >= 16); + test(c); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/swap_member.pass.cpp b/libcxx/test/std/containers/unord/unord.map/swap_member.pass.cpp new file mode 100644 index 00000000000..8ab1eb6211b --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/swap_member.pass.cpp @@ -0,0 +1,572 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// void swap(unordered_map& __u); + +#include +#include +#include + +#include "../../test_compare.h" +#include "../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.at(10) == "ten"); + assert(c1.at(20) == "twenty"); + assert(c1.at(30) == "thirty"); + assert(c1.at(40) == "forty"); + assert(c1.at(50) == "fifty"); + assert(c1.at(60) == "sixty"); + assert(c1.at(70) == "seventy"); + assert(c1.at(80) == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.at(1) == "one"); + assert(c2.at(2) == "two"); + assert(c2.at(3) == "three"); + assert(c2.at(4) == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.at(10) == "ten"); + assert(c1.at(20) == "twenty"); + assert(c1.at(30) == "thirty"); + assert(c1.at(40) == "forty"); + assert(c1.at(50) == "fifty"); + assert(c1.at(60) == "sixty"); + assert(c1.at(70) == "seventy"); + assert(c1.at(80) == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.at(1) == "one"); + assert(c2.at(2) == "two"); + assert(c2.at(3) == "three"); + assert(c2.at(4) == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.at(10) == "ten"); + assert(c1.at(20) == "twenty"); + assert(c1.at(30) == "thirty"); + assert(c1.at(40) == "forty"); + assert(c1.at(50) == "fifty"); + assert(c1.at(60) == "sixty"); + assert(c1.at(70) == "seventy"); + assert(c1.at(80) == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.at(1) == "one"); + assert(c2.at(2) == "two"); + assert(c2.at(3) == "three"); + assert(c2.at(4) == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.at(10) == "ten"); + assert(c1.at(20) == "twenty"); + assert(c1.at(30) == "thirty"); + assert(c1.at(40) == "forty"); + assert(c1.at(50) == "fifty"); + assert(c1.at(60) == "sixty"); + assert(c1.at(70) == "seventy"); + assert(c1.at(80) == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.at(1) == "one"); + assert(c2.at(2) == "two"); + assert(c2.at(3) == "three"); + assert(c2.at(4) == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.at(10) == "ten"); + assert(c1.at(20) == "twenty"); + assert(c1.at(30) == "thirty"); + assert(c1.at(40) == "forty"); + assert(c1.at(50) == "fifty"); + assert(c1.at(60) == "sixty"); + assert(c1.at(70) == "seventy"); + assert(c1.at(80) == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.at(1) == "one"); + assert(c2.at(2) == "two"); + assert(c2.at(3) == "three"); + assert(c2.at(4) == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.at(10) == "ten"); + assert(c1.at(20) == "twenty"); + assert(c1.at(30) == "thirty"); + assert(c1.at(40) == "forty"); + assert(c1.at(50) == "fifty"); + assert(c1.at(60) == "sixty"); + assert(c1.at(70) == "seventy"); + assert(c1.at(80) == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.at(1) == "one"); + assert(c2.at(2) == "two"); + assert(c2.at(3) == "three"); + assert(c2.at(4) == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/types.pass.cpp b/libcxx/test/std/containers/unord/unord.map/types.pass.cpp new file mode 100644 index 00000000000..b53ff8e1540 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/types.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map +// { +// public: +// // types +// typedef Key key_type; +// typedef T mapped_type; +// typedef Hash hasher; +// typedef Pred key_equal; +// typedef Alloc allocator_type; +// typedef pair value_type; +// typedef value_type& reference; +// typedef const value_type& const_reference; +// typedef typename allocator_traits::pointer pointer; +// typedef typename allocator_traits::const_pointer const_pointer; +// typedef typename allocator_traits::size_type size_type; +// typedef typename allocator_traits::difference_type difference_type; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same>::value), ""); + static_assert((std::is_same>::value), ""); + // min_allocator doesn't have a size_type, so one gets synthesized + static_assert((std::is_same::type>::value), ""); + static_assert((std::is_same::value), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/allocator.pass.cpp new file mode 100644 index 00000000000..0fc76db0fb2 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/allocator.pass.cpp @@ -0,0 +1,111 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// explicit unordered_map(const allocator_type& __a); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + C c(test_allocator >(10)); + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (test_allocator >(10))); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + C c(min_allocator >{}); + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (min_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if _LIBCPP_STD_VER > 11 + { + typedef NotConstructible T; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_map C; + + A a(10); + C c(2, a); + assert(c.bucket_count() == 2); + assert(c.hash_function() == HF()); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } + { + typedef NotConstructible T; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_map C; + + A a(10); + HF hf(12); + C c(2, hf, a); + assert(c.bucket_count() == 2); + assert(c.hash_function() == hf); + assert(!(c.hash_function() == HF())); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_copy.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_copy.pass.cpp new file mode 100644 index 00000000000..fa0105604f1 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_copy.pass.cpp @@ -0,0 +1,185 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// unordered_map& operator=(const unordered_map& u); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_allocator > A; + typedef std::unordered_map >, + test_compare >, + A + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(4) + ); + c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(4)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + { + typedef std::unordered_map C; + typedef std::pair P; + const P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C *p = &c; + c = *p; + assert(c.size() == 4); + assert(std::is_permutation(c.begin(), c.end(), a)); + } + { + typedef other_allocator > A; + typedef std::unordered_map >, + test_compare >, + A + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(4) + ); + c = c0; + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef min_allocator > A; + typedef std::unordered_map >, + test_compare >, + A + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A() + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A() + ); + c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_init.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_init.pass.cpp new file mode 100644 index 00000000000..3a854e10654 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_init.pass.cpp @@ -0,0 +1,97 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// unordered_map& operator=(initializer_list il); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::allocator > A; + typedef std::unordered_map >, + test_compare >, + A + > C; + typedef std::pair P; + C c = { + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + c = { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef min_allocator > A; + typedef std::unordered_map >, + test_compare >, + A + > C; + typedef std::pair P; + C c = { + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + c = { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_move.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_move.pass.cpp new file mode 100644 index 00000000000..dd57c58214f --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/assign_move.pass.cpp @@ -0,0 +1,229 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// unordered_map& operator=(unordered_map&& u); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef test_allocator > A; + typedef std::unordered_map >, + test_compare >, + A + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(4) + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(4)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + { + typedef test_allocator > A; + typedef std::unordered_map >, + test_compare >, + A + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(10) + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c0.size() == 0); + } + { + typedef other_allocator > A; + typedef std::unordered_map >, + test_compare >, + A + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(4) + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c0.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef min_allocator > A; + typedef std::unordered_map >, + test_compare >, + A + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A() + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A() + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c0.size() == 0); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + std::unordered_map s1 = {{1, 1}, {2, 2}, {3, 3}}; + std::unordered_map::iterator i = s1.begin(); + std::pair k = *i; + std::unordered_map s2; + s2 = std::move(s1); + assert(*i == k); + s2.erase(i); + assert(s2.size() == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/copy.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/copy.pass.cpp new file mode 100644 index 00000000000..227343e6d5b --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/copy.pass.cpp @@ -0,0 +1,151 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// unordered_map(const unordered_map& u); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + test_allocator >(10) + ); + C c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (test_allocator >(10))); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + typedef std::unordered_map >, + test_compare >, + other_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + other_allocator >(10) + ); + C c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (other_allocator >(-2))); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + min_allocator >() + ); + C c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (min_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/copy_alloc.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/copy_alloc.pass.cpp new file mode 100644 index 00000000000..d1757d8a3c1 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/copy_alloc.pass.cpp @@ -0,0 +1,110 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// unordered_map(const unordered_map& u, const allocator_type& a); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + test_allocator >(10) + ); + C c(c0, test_allocator >(5)); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (test_allocator >(5))); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + min_allocator >() + ); + C c(c0, min_allocator >()); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (min_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/default.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/default.pass.cpp new file mode 100644 index 00000000000..a0825db1ecd --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/default.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// unordered_map(); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + C c; + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (test_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + C c; + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (min_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } + { + std::unordered_map c = {}; + assert(c.bucket_count() == 0); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/default_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/default_noexcept.pass.cpp new file mode 100644 index 00000000000..df8c7b57c93 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/default_noexcept.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// unordered_map() +// noexcept( +// is_nothrow_default_constructible::value && +// is_nothrow_default_constructible::value && +// is_nothrow_copy_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "../../../test_hash.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp(); + some_comp(const some_comp&); +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_map C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::unordered_map, + std::equal_to, test_allocator>> C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::unordered_map, + std::equal_to, other_allocator>> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::unordered_map> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::unordered_map, + some_comp> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..1fc37f7594d --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/dtor_noexcept.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// ~unordered_map() // implied noexcept; + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template +struct some_comp +{ + typedef T value_type; + ~some_comp() noexcept(false); +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); + ~some_hash() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_map C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::unordered_map, + std::equal_to, test_allocator>> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::unordered_map, + std::equal_to, other_allocator>> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::unordered_map> C; + static_assert(!std::is_nothrow_destructible::value, ""); + } + { + typedef std::unordered_map, + some_comp> C; + static_assert(!std::is_nothrow_destructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init.pass.cpp new file mode 100644 index 00000000000..dbc48f816c8 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init.pass.cpp @@ -0,0 +1,162 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// unordered_map(initializer_list il); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + C c = { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (test_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + C c = { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (min_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair P; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_map C; + + A a(42); + C c ( { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, 12, a); + assert(c.bucket_count() >= 12); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == a); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + { + typedef std::pair P; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_map C; + + HF hf(42); + A a(43); + C c ( { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, 12, hf, a); + assert(c.bucket_count() >= 12); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == hf); + assert(!(c.hash_function() == test_hash >())); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == a); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init_size.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init_size.pass.cpp new file mode 100644 index 00000000000..ac09053b1eb --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init_size.pass.cpp @@ -0,0 +1,100 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// unordered_map(initializer_list il, size_type n); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + C c({ + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, + 7 + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (test_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + C c({ + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, + 7 + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (min_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init_size_hash.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init_size_hash.pass.cpp new file mode 100644 index 00000000000..7a4130bde8f --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init_size_hash.pass.cpp @@ -0,0 +1,102 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// unordered_map(initializer_list il, size_type n, const hasher& hf); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + C c({ + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, + 7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (test_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + C c({ + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, + 7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (min_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init_size_hash_equal.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init_size_hash_equal.pass.cpp new file mode 100644 index 00000000000..036008c0b86 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init_size_hash_equal.pass.cpp @@ -0,0 +1,105 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// unordered_map(initializer_list il, size_type n, +// const hasher& hf, const key_equal& eql); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + C c({ + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, + 7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (test_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + C c({ + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, + 7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (min_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init_size_hash_equal_allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init_size_hash_equal_allocator.pass.cpp new file mode 100644 index 00000000000..7c83192b664 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/init_size_hash_equal_allocator.pass.cpp @@ -0,0 +1,107 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// unordered_map(initializer_list il, size_type n, +// const hasher& hf, const key_equal& eql, const allocator_type& a); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + C c({ + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, + 7, + test_hash >(8), + test_compare >(9), + test_allocator >(10) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (test_allocator >(10))); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + C c({ + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, + 7, + test_hash >(8), + test_compare >(9), + min_allocator >() + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (min_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move.pass.cpp new file mode 100644 index 00000000000..18e6683011c --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move.pass.cpp @@ -0,0 +1,199 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// unordered_map(unordered_map&& u); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(7, + test_hash >(8), + test_compare >(9), + test_allocator >(10) + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 0); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (test_allocator >(10))); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + test_allocator >(10) + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (test_allocator >(10))); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(7, + test_hash >(8), + test_compare >(9), + min_allocator >() + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 0); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (min_allocator >())); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + min_allocator >() + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (min_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + std::unordered_map s1 = {{1, 1}, {2, 2}, {3, 3}}; + std::unordered_map::iterator i = s1.begin(); + std::pair k = *i; + std::unordered_map s2 = std::move(s1); + assert(*i == k); + s2.erase(i); + assert(s2.size() == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move_alloc.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move_alloc.pass.cpp new file mode 100644 index 00000000000..091a72f0d16 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move_alloc.pass.cpp @@ -0,0 +1,157 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// unordered_map(unordered_map&& u, const allocator_type& a); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::pair P; + typedef test_allocator> A; + typedef std::unordered_map >, + test_compare >, + A + > C; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(std::move(c0), A(12)); + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(12)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } + { + typedef std::pair P; + typedef test_allocator> A; + typedef std::unordered_map >, + test_compare >, + A + > C; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(std::move(c0), A(10)); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } +#if __cplusplus >= 201103L + { + typedef std::pair P; + typedef min_allocator> A; + typedef std::unordered_map >, + test_compare >, + A + > C; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A() + ); + C c(std::move(c0), A()); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..f7fde37869a --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move_assign_noexcept.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// unordered_map& operator=(unordered_map&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable::value && +// is_nothrow_move_assignable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp& operator=(const some_comp&); +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); + some_hash& operator=(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_map C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::unordered_map, + std::equal_to, test_allocator>> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::unordered_map, + std::equal_to, other_allocator>> C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::unordered_map> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::unordered_map, + some_comp> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move_noexcept.pass.cpp new file mode 100644 index 00000000000..1c86dd3902a --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/move_noexcept.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// unordered_map(unordered_map&&) +// noexcept(is_nothrow_move_constructible::value && +// is_nothrow_move_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp(const some_comp&); +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_map C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::unordered_map, + std::equal_to, test_allocator>> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::unordered_map, + std::equal_to, other_allocator>> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::unordered_map> C; + static_assert(!std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::unordered_map, + some_comp> C; + static_assert(!std::is_nothrow_move_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range.pass.cpp new file mode 100644 index 00000000000..c1784d63b29 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range.pass.cpp @@ -0,0 +1,170 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// template +// unordered_map(InputIterator first, InputIterator last); + +#include +#include +#include +#include + +#include "test_iterators.h" +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (test_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (min_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair P; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_map C; + + P arr[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(arr), input_iterator(arr + sizeof(arr)/sizeof(arr[0])), 14); + assert(c.bucket_count() >= 14); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == HF()); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == A()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + { + typedef std::pair P; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_map C; + + P arr[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + HF hf(42); + A a(43); + C c(input_iterator(arr), input_iterator(arr + sizeof(arr)/sizeof(arr[0])), 14, hf, a); + assert(c.bucket_count() >= 14); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == hf); + assert(!(c.hash_function() == HF())); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range_size.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range_size.pass.cpp new file mode 100644 index 00000000000..f914b306071 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range_size.pass.cpp @@ -0,0 +1,105 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// template +// unordered_map(InputIterator first, InputIterator last, size_type n); + +#include +#include +#include +#include + +#include "test_iterators.h" +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 10 + ); + assert(c.bucket_count() == 11); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (test_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 10 + ); + assert(c.bucket_count() == 11); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (min_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range_size_hash.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range_size_hash.pass.cpp new file mode 100644 index 00000000000..7a0dbceb17c --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range_size_hash.pass.cpp @@ -0,0 +1,108 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// template +// unordered_map(InputIterator first, InputIterator last, size_type n, +// const hasher& hf); + +#include +#include +#include +#include + +#include "test_iterators.h" +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (test_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (min_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range_size_hash_equal.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range_size_hash_equal.pass.cpp new file mode 100644 index 00000000000..61eef5bc40a --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range_size_hash_equal.pass.cpp @@ -0,0 +1,110 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// template +// unordered_map(InputIterator first, InputIterator last, size_type n, +// const hasher& hf, const key_equal& eql); + +#include +#include +#include +#include + +#include "test_iterators.h" +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (test_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (min_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range_size_hash_equal_allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range_size_hash_equal_allocator.pass.cpp new file mode 100644 index 00000000000..99493fad32c --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/range_size_hash_equal_allocator.pass.cpp @@ -0,0 +1,113 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// template +// unordered_map(InputIterator first, InputIterator last, size_type n, +// const hasher& hf, const key_equal& eql, +// const allocator_type& a); + +#include +#include +#include +#include + +#include "test_iterators.h" +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8), + test_compare >(9), + test_allocator >(10) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (test_allocator >(10))); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8), + test_compare >(9), + min_allocator >() + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (min_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size.fail.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size.fail.cpp new file mode 100644 index 00000000000..0a3ae3a117f --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size.fail.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// unordered_map(size_type n); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + C c = 7; + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (test_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + C c = 7; + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (min_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size.pass.cpp new file mode 100644 index 00000000000..708dc236273 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// unordered_map(size_type n); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + C c(7); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (test_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + C c(7); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (min_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size_hash.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size_hash.pass.cpp new file mode 100644 index 00000000000..6c975ec7203 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size_hash.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// unordered_map(size_type n, const hasher& hf); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + C c(7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (test_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + C c(7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (min_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size_hash_equal.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size_hash_equal.pass.cpp new file mode 100644 index 00000000000..8b2bb317987 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size_hash_equal.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// unordered_map(size_type n, const hasher& hf, const key_equal& eql); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + C c(7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (test_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + C c(7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (min_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size_hash_equal_allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size_hash_equal_allocator.pass.cpp new file mode 100644 index 00000000000..bcf7b91503a --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.cnstr/size_hash_equal_allocator.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// unordered_map(size_type n, const hasher& hf, const key_equal& eql, const allocator_type& a); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map >, + test_compare >, + test_allocator > + > C; + C c(7, + test_hash >(8), + test_compare >(9), + test_allocator >(10) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (test_allocator >(10))); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map >, + test_compare >, + min_allocator > + > C; + C c(7, + test_hash >(8), + test_compare >(9), + min_allocator >() + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (min_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp new file mode 100644 index 00000000000..c4d7128698e --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.elem/at.pass.cpp @@ -0,0 +1,134 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// mapped_type& at(const key_type& k); +// const mapped_type& at(const key_type& k) const; + +#include +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.size() == 4); + c.at(1) = "ONE"; + assert(c.at(1) == "ONE"); + try + { + c.at(11) = "eleven"; + assert(false); + } + catch (std::out_of_range&) + { + } + assert(c.size() == 4); + } + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.size() == 4); + assert(c.at(1) == "one"); + try + { + c.at(11); + assert(false); + } + catch (std::out_of_range&) + { + } + assert(c.size() == 4); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.size() == 4); + c.at(1) = "ONE"; + assert(c.at(1) == "ONE"); + try + { + c.at(11) = "eleven"; + assert(false); + } + catch (std::out_of_range&) + { + } + assert(c.size() == 4); + } + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.size() == 4); + assert(c.at(1) == "one"); + try + { + c.at(11); + assert(false); + } + catch (std::out_of_range&) + { + } + assert(c.size() == 4); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.elem/index.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.elem/index.pass.cpp new file mode 100644 index 00000000000..7f4e067c515 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.elem/index.pass.cpp @@ -0,0 +1,115 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// mapped_type& operator[](const key_type& k); + +#include +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.size() == 4); + c[1] = "ONE"; + assert(c.at(1) == "ONE"); + c[11] = "eleven"; + assert(c.size() == 5); + assert(c.at(11) == "eleven"); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.size() == 4); + c[1] = "ONE"; + assert(c.at(1) == "ONE"); + c[11] = "eleven"; + assert(c.size() == 5); + assert(c.at(11) == "eleven"); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.size() == 4); + c[1] = "ONE"; + assert(c.at(1) == "ONE"); + c[11] = "eleven"; + assert(c.size() == 5); + assert(c.at(11) == "eleven"); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.size() == 4); + c[1] = "ONE"; + assert(c.at(1) == "ONE"); + c[11] = "eleven"; + assert(c.size() == 5); + assert(c.at(11) == "eleven"); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.elem/index_tuple.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.elem/index_tuple.pass.cpp new file mode 100644 index 00000000000..c319b5c30b2 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.elem/index_tuple.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// mapped_type& operator[](const key_type& k); + +// http://llvm.org/bugs/show_bug.cgi?id=16542 + +#include + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +#include + +using namespace std; + +struct my_hash +{ + size_t operator()(const tuple&) const {return 0;} +}; + +#endif + +int main() +{ +#ifndef _LIBCPP_HAS_NO_VARIADICS + unordered_map, size_t, my_hash> m; + m[make_tuple(2,3)]=7; +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.swap/db_swap_1.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.swap/db_swap_1.pass.cpp new file mode 100644 index 00000000000..6ab9c923da3 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.swap/db_swap_1.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// void swap(unordered_map& x, unordered_map& y); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +int main() +{ +#if _LIBCPP_DEBUG >= 1 + { + typedef std::pair P; + P a1[] = {P(1, 1), P(3, 3), P(7, 7), P(9, 9), P(10, 10)}; + P a2[] = {P(0, 0), P(2, 2), P(4, 4), P(5, 5), P(6, 6), P(8, 8), P(11, 11)}; + std::unordered_map c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::unordered_map c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + std::unordered_map::iterator i1 = c1.begin(); + std::unordered_map::iterator i2 = c2.begin(); + swap(c1, c2); + c1.erase(i2); + c2.erase(i1); + std::unordered_map::iterator j = i1; + c1.erase(i1); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.swap/swap_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.swap/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..49ac757eefb --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.swap/swap_noexcept.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(unordered_map& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + + some_comp() {} + some_comp(const some_comp&) {} +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash() {} + some_hash(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_map C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_map, + std::equal_to, test_allocator>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_map, + std::equal_to, other_allocator>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_map> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_map, + some_comp> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unord.map.swap/swap_non_member.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unord.map.swap/swap_non_member.pass.cpp new file mode 100644 index 00000000000..7e04b8db117 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unord.map.swap/swap_non_member.pass.cpp @@ -0,0 +1,572 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// void swap(unordered_map& __u); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.at(10) == "ten"); + assert(c1.at(20) == "twenty"); + assert(c1.at(30) == "thirty"); + assert(c1.at(40) == "forty"); + assert(c1.at(50) == "fifty"); + assert(c1.at(60) == "sixty"); + assert(c1.at(70) == "seventy"); + assert(c1.at(80) == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.at(1) == "one"); + assert(c2.at(2) == "two"); + assert(c2.at(3) == "three"); + assert(c2.at(4) == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.at(10) == "ten"); + assert(c1.at(20) == "twenty"); + assert(c1.at(30) == "thirty"); + assert(c1.at(40) == "forty"); + assert(c1.at(50) == "fifty"); + assert(c1.at(60) == "sixty"); + assert(c1.at(70) == "seventy"); + assert(c1.at(80) == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.at(1) == "one"); + assert(c2.at(2) == "two"); + assert(c2.at(3) == "three"); + assert(c2.at(4) == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.at(10) == "ten"); + assert(c1.at(20) == "twenty"); + assert(c1.at(30) == "thirty"); + assert(c1.at(40) == "forty"); + assert(c1.at(50) == "fifty"); + assert(c1.at(60) == "sixty"); + assert(c1.at(70) == "seventy"); + assert(c1.at(80) == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.at(1) == "one"); + assert(c2.at(2) == "two"); + assert(c2.at(3) == "three"); + assert(c2.at(4) == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.at(10) == "ten"); + assert(c1.at(20) == "twenty"); + assert(c1.at(30) == "thirty"); + assert(c1.at(40) == "forty"); + assert(c1.at(50) == "fifty"); + assert(c1.at(60) == "sixty"); + assert(c1.at(70) == "seventy"); + assert(c1.at(80) == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.at(1) == "one"); + assert(c2.at(2) == "two"); + assert(c2.at(3) == "three"); + assert(c2.at(4) == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.at(10) == "ten"); + assert(c1.at(20) == "twenty"); + assert(c1.at(30) == "thirty"); + assert(c1.at(40) == "forty"); + assert(c1.at(50) == "fifty"); + assert(c1.at(60) == "sixty"); + assert(c1.at(70) == "seventy"); + assert(c1.at(80) == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.at(1) == "one"); + assert(c2.at(2) == "two"); + assert(c2.at(3) == "three"); + assert(c2.at(4) == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator > Alloc; + typedef std::unordered_map C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.at(10) == "ten"); + assert(c1.at(20) == "twenty"); + assert(c1.at(30) == "thirty"); + assert(c1.at(40) == "forty"); + assert(c1.at(50) == "fifty"); + assert(c1.at(60) == "sixty"); + assert(c1.at(70) == "seventy"); + assert(c1.at(80) == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.at(1) == "one"); + assert(c2.at(2) == "two"); + assert(c2.at(3) == "three"); + assert(c2.at(4) == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/clear.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/clear.pass.cpp new file mode 100644 index 00000000000..9f320e94947 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/clear.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// void clear() + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + c.clear(); + assert(c.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + c.clear(); + assert(c.size() == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/emplace.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/emplace.pass.cpp new file mode 100644 index 00000000000..5de74d2e6c9 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/emplace.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// template +// pair emplace(Args&&... args); + +#include +#include + +#include "../../../Emplaceable.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_map C; + typedef std::pair R; + C c; + R r = c.emplace(std::piecewise_construct, std::forward_as_tuple(3), + std::forward_as_tuple()); + assert(r.second); + assert(c.size() == 1); + assert(r.first->first == 3); + assert(r.first->second == Emplaceable()); + + r = c.emplace(std::pair(4, Emplaceable(5, 6))); + assert(r.second); + assert(c.size() == 2); + assert(r.first->first == 4); + assert(r.first->second == Emplaceable(5, 6)); + + r = c.emplace(std::piecewise_construct, std::forward_as_tuple(5), + std::forward_as_tuple(6, 7)); + assert(r.second); + assert(c.size() == 3); + assert(r.first->first == 5); + assert(r.first->second == Emplaceable(6, 7)); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair R; + C c; + R r = c.emplace(std::piecewise_construct, std::forward_as_tuple(3), + std::forward_as_tuple()); + assert(r.second); + assert(c.size() == 1); + assert(r.first->first == 3); + assert(r.first->second == Emplaceable()); + + r = c.emplace(std::pair(4, Emplaceable(5, 6))); + assert(r.second); + assert(c.size() == 2); + assert(r.first->first == 4); + assert(r.first->second == Emplaceable(5, 6)); + + r = c.emplace(std::piecewise_construct, std::forward_as_tuple(5), + std::forward_as_tuple(6, 7)); + assert(r.second); + assert(c.size() == 3); + assert(r.first->first == 5); + assert(r.first->second == Emplaceable(6, 7)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/emplace_hint.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/emplace_hint.pass.cpp new file mode 100644 index 00000000000..21a4689658a --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/emplace_hint.pass.cpp @@ -0,0 +1,93 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// template +// iterator emplace_hint(const_iterator p, Args&&... args); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "../../../Emplaceable.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_map C; + typedef C::iterator R; + C c; + C::const_iterator e = c.end(); + R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(3), + std::forward_as_tuple()); + assert(c.size() == 1); + assert(r->first == 3); + assert(r->second == Emplaceable()); + + r = c.emplace_hint(c.end(), std::pair(4, Emplaceable(5, 6))); + assert(c.size() == 2); + assert(r->first == 4); + assert(r->second == Emplaceable(5, 6)); + + r = c.emplace_hint(c.end(), std::piecewise_construct, std::forward_as_tuple(5), + std::forward_as_tuple(6, 7)); + assert(c.size() == 3); + assert(r->first == 5); + assert(r->second == Emplaceable(6, 7)); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef C::iterator R; + C c; + C::const_iterator e = c.end(); + R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(3), + std::forward_as_tuple()); + assert(c.size() == 1); + assert(r->first == 3); + assert(r->second == Emplaceable()); + + r = c.emplace_hint(c.end(), std::pair(4, Emplaceable(5, 6))); + assert(c.size() == 2); + assert(r->first == 4); + assert(r->second == Emplaceable(5, 6)); + + r = c.emplace_hint(c.end(), std::piecewise_construct, std::forward_as_tuple(5), + std::forward_as_tuple(6, 7)); + assert(c.size() == 3); + assert(r->first == 5); + assert(r->second == Emplaceable(6, 7)); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + typedef std::unordered_map C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C c2; + R r = c.emplace_hint(c2.end(), std::piecewise_construct, + std::forward_as_tuple(3), + std::forward_as_tuple()); + assert(false); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_const_iter.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_const_iter.pass.cpp new file mode 100644 index 00000000000..422dbe45b43 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_const_iter.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// iterator erase(const_iterator p) + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::iterator j = c.erase(i); + assert(c.size() == 3); + assert(c.at(1) == "one"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::iterator j = c.erase(i); + assert(c.size() == 3); + assert(c.at(1) == "one"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_db1.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_db1.pass.cpp new file mode 100644 index 00000000000..60b093553f1 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_db1.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator position) with end() + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include + +int main() +{ + { + typedef std::pair P; + P a1[] = {P(1, 1), P(2, 2), P(3, 3)}; + std::unordered_map l1(a1, a1+3); + std::unordered_map::const_iterator i = l1.end(); + l1.erase(i); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_db2.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_db2.pass.cpp new file mode 100644 index 00000000000..05046f5dedc --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_db2.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator position) with iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + typedef std::pair P; + P a1[] = {P(1, 1), P(2, 2), P(3, 3)}; + std::unordered_map l1(a1, a1+3); + std::unordered_map l2(a1, a1+3); + std::unordered_map::const_iterator i = l2.begin(); + l1.erase(i); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db1.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db1.pass.cpp new file mode 100644 index 00000000000..81a8d3de157 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db1.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with first iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + typedef std::pair P; + P a1[] = {P(1, 1), P(2, 2), P(3, 3)}; + std::unordered_map l1(a1, a1+3); + std::unordered_map l2(a1, a1+3); + std::unordered_map::iterator i = l1.erase(l2.cbegin(), next(l1.cbegin())); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db2.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db2.pass.cpp new file mode 100644 index 00000000000..4b103a0ad75 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db2.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with second iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + typedef std::pair P; + P a1[] = {P(1, 1), P(2, 2), P(3, 3)}; + std::unordered_map l1(a1, a1+3); + std::unordered_map l2(a1, a1+3); + std::unordered_map::iterator i = l1.erase(l1.cbegin(), next(l2.cbegin())); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db3.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db3.pass.cpp new file mode 100644 index 00000000000..6ef1e07add1 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db3.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with both iterators from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + typedef std::pair P; + P a1[] = {P(1, 1), P(2, 2), P(3, 3)}; + std::unordered_map l1(a1, a1+3); + std::unordered_map l2(a1, a1+3); + std::unordered_map::iterator i = l1.erase(l2.cbegin(), next(l2.cbegin())); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db4.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db4.pass.cpp new file mode 100644 index 00000000000..1185ddf8fd4 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_iter_iter_db4.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with a bad range + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + typedef std::pair P; + P a1[] = {P(1, 1), P(2, 2), P(3, 3)}; + std::unordered_map l1(a1, a1+3); + std::unordered_map::iterator i = l1.erase(next(l1.cbegin()), l1.cbegin()); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_key.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_key.pass.cpp new file mode 100644 index 00000000000..0e8ef8b895a --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_key.pass.cpp @@ -0,0 +1,177 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// size_type erase(const key_type& k); + +#include +#include +#include + +#include "min_allocator.h" + +#if __cplusplus >= 201103L +template +bool only_deletions ( const Unordered &whole, const Unordered &part ) { + typename Unordered::const_iterator w = whole.begin(); + typename Unordered::const_iterator p = part.begin(); + + while ( w != whole.end () && p != part.end()) { + if ( *w == *p ) + p++; + w++; + } + + return p == part.end(); +} +#endif + + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.erase(5) == 0); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + + assert(c.erase(2) == 1); + assert(c.size() == 3); + assert(c.at(1) == "one"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + + assert(c.erase(2) == 0); + assert(c.size() == 3); + assert(c.at(1) == "one"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + + assert(c.erase(4) == 1); + assert(c.size() == 2); + assert(c.at(1) == "one"); + assert(c.at(3) == "three"); + + assert(c.erase(4) == 0); + assert(c.size() == 2); + assert(c.at(1) == "one"); + assert(c.at(3) == "three"); + + assert(c.erase(1) == 1); + assert(c.size() == 1); + assert(c.at(3) == "three"); + + assert(c.erase(1) == 0); + assert(c.size() == 1); + assert(c.at(3) == "three"); + + assert(c.erase(3) == 1); + assert(c.size() == 0); + + assert(c.erase(3) == 0); + assert(c.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.erase(5) == 0); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + + assert(c.erase(2) == 1); + assert(c.size() == 3); + assert(c.at(1) == "one"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + + assert(c.erase(2) == 0); + assert(c.size() == 3); + assert(c.at(1) == "one"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + + assert(c.erase(4) == 1); + assert(c.size() == 2); + assert(c.at(1) == "one"); + assert(c.at(3) == "three"); + + assert(c.erase(4) == 0); + assert(c.size() == 2); + assert(c.at(1) == "one"); + assert(c.at(3) == "three"); + + assert(c.erase(1) == 1); + assert(c.size() == 1); + assert(c.at(3) == "three"); + + assert(c.erase(1) == 0); + assert(c.size() == 1); + assert(c.at(3) == "three"); + + assert(c.erase(3) == 1); + assert(c.size() == 0); + + assert(c.erase(3) == 0); + assert(c.size() == 0); + } + { + typedef std::unordered_map C; + C m, m2; + for ( int i = 0; i < 10; ++i ) { + m[i] = i; + m2[i] = i; + } + + C::iterator i = m2.begin(); + int ctr = 0; + while (i != m2.end()) { + if (ctr++ % 2 == 0) + m2.erase(i++); + else + ++i; + } + + assert (only_deletions (m, m2)); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_range.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_range.pass.cpp new file mode 100644 index 00000000000..f0664c3c3ff --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/erase_range.pass.cpp @@ -0,0 +1,99 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// iterator erase(const_iterator first, const_iterator last) + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::const_iterator j = next(i, 1); + C::iterator k = c.erase(i, i); + assert(k == i); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + + k = c.erase(i, j); + assert(c.size() == 3); + assert(k == j); + assert(c.at(1) == "one"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + + k = c.erase(c.cbegin(), c.cend()); + assert(k == c.cend()); + assert(c.size() == 0); + assert(k == c.end()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::const_iterator j = next(i, 1); + C::iterator k = c.erase(i, i); + assert(k == i); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + + k = c.erase(i, j); + assert(c.size() == 3); + assert(k == j); + assert(c.at(1) == "one"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + + k = c.erase(c.cbegin(), c.cend()); + assert(k == c.cend()); + assert(c.size() == 0); + assert(k == c.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_const_lvalue.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_const_lvalue.pass.cpp new file mode 100644 index 00000000000..a16f097b4c0 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_const_lvalue.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// pair insert(const value_type& x); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair R; + typedef C::value_type P; + C c; + R r = c.insert(P(3.5, 3)); + assert(r.second); + assert(c.size() == 1); + assert(r.first->first == 3.5); + assert(r.first->second == 3); + + r = c.insert(P(3.5, 4)); + assert(!r.second); + assert(c.size() == 1); + assert(r.first->first == 3.5); + assert(r.first->second == 3); + + r = c.insert(P(4.5, 4)); + assert(r.second); + assert(c.size() == 2); + assert(r.first->first == 4.5); + assert(r.first->second == 4); + + r = c.insert(P(5.5, 4)); + assert(r.second); + assert(c.size() == 3); + assert(r.first->first == 5.5); + assert(r.first->second == 4); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair R; + typedef C::value_type P; + C c; + R r = c.insert(P(3.5, 3)); + assert(r.second); + assert(c.size() == 1); + assert(r.first->first == 3.5); + assert(r.first->second == 3); + + r = c.insert(P(3.5, 4)); + assert(!r.second); + assert(c.size() == 1); + assert(r.first->first == 3.5); + assert(r.first->second == 3); + + r = c.insert(P(4.5, 4)); + assert(r.second); + assert(c.size() == 2); + assert(r.first->first == 4.5); + assert(r.first->second == 4); + + r = c.insert(P(5.5, 4)); + assert(r.second); + assert(c.size() == 3); + assert(r.first->first == 5.5); + assert(r.first->second == 4); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_hint_const_lvalue.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_hint_const_lvalue.pass.cpp new file mode 100644 index 00000000000..981b8fb18a0 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_hint_const_lvalue.pass.cpp @@ -0,0 +1,97 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// iterator insert(const_iterator p, const value_type& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5, 3)); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + r = c.insert(c.end(), P(3.5, 4)); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + r = c.insert(c.end(), P(4.5, 4)); + assert(c.size() == 2); + assert(r->first == 4.5); + assert(r->second == 4); + + r = c.insert(c.end(), P(5.5, 4)); + assert(c.size() == 3); + assert(r->first == 5.5); + assert(r->second == 4); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5, 3)); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + r = c.insert(c.end(), P(3.5, 4)); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + r = c.insert(c.end(), P(4.5, 4)); + assert(c.size() == 2); + assert(r->first == 4.5); + assert(r->second == 4); + + r = c.insert(c.end(), P(5.5, 4)); + assert(c.size() == 3); + assert(r->first == 5.5); + assert(r->second == 4); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + typedef std::unordered_map C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C c2; + C::const_iterator e = c2.end(); + P v(3.5, 3); + R r = c.insert(e, v); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_hint_rvalue.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_hint_rvalue.pass.cpp new file mode 100644 index 00000000000..92f6c40e4de --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_hint_rvalue.pass.cpp @@ -0,0 +1,156 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// template ::value>::type> +// iterator insert(const_iterator p, P&& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef C::iterator R; + typedef std::pair P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5, 3)); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + r = c.insert(c.end(), P(3.5, 4)); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + r = c.insert(c.end(), P(4.5, 4)); + assert(c.size() == 2); + assert(r->first == 4.5); + assert(r->second == 4); + + r = c.insert(c.end(), P(5.5, 4)); + assert(c.size() == 3); + assert(r->first == 5.5); + assert(r->second == 4); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_map C; + typedef C::iterator R; + typedef std::pair P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3, 3)); + assert(c.size() == 1); + assert(r->first == 3); + assert(r->second == 3); + + r = c.insert(c.end(), P(3, 4)); + assert(c.size() == 1); + assert(r->first == 3); + assert(r->second == 3); + + r = c.insert(c.end(), P(4, 4)); + assert(c.size() == 2); + assert(r->first == 4); + assert(r->second == 4); + + r = c.insert(c.end(), P(5, 4)); + assert(c.size() == 3); + assert(r->first == 5); + assert(r->second == 4); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef C::iterator R; + typedef std::pair P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5, 3)); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + r = c.insert(c.end(), P(3.5, 4)); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + r = c.insert(c.end(), P(4.5, 4)); + assert(c.size() == 2); + assert(r->first == 4.5); + assert(r->second == 4); + + r = c.insert(c.end(), P(5.5, 4)); + assert(c.size() == 3); + assert(r->first == 5.5); + assert(r->second == 4); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef C::iterator R; + typedef std::pair P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3, 3)); + assert(c.size() == 1); + assert(r->first == 3); + assert(r->second == 3); + + r = c.insert(c.end(), P(3, 4)); + assert(c.size() == 1); + assert(r->first == 3); + assert(r->second == 3); + + r = c.insert(c.end(), P(4, 4)); + assert(c.size() == 2); + assert(r->first == 4); + assert(r->second == 4); + + r = c.insert(c.end(), P(5, 4)); + assert(c.size() == 3); + assert(r->first == 5); + assert(r->second == 4); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_DEBUG >= 1 + { + typedef std::unordered_map C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C c2; + C::const_iterator e = c2.end(); + R r = c.insert(e, P(3.5, 3)); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_init.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_init.pass.cpp new file mode 100644 index 00000000000..81e8a468d83 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_init.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// void insert(initializer_list il); + +#include +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_map C; + typedef std::pair P; + C c; + c.insert( + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + } + ); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + C c; + c.insert( + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + } + ); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_range.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_range.pass.cpp new file mode 100644 index 00000000000..fc44e7828ff --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_range.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// template +// void insert(InputIterator first, InputIterator last); + +#include +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c; + c.insert(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c; + c.insert(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(c.size() == 4); + assert(c.at(1) == "one"); + assert(c.at(2) == "two"); + assert(c.at(3) == "three"); + assert(c.at(4) == "four"); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_rvalue.pass.cpp b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_rvalue.pass.cpp new file mode 100644 index 00000000000..6c5e8c8ee84 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/unorder.map.modifiers/insert_rvalue.pass.cpp @@ -0,0 +1,152 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_map + +// template ::value>::type> +// pair insert(P&& x); + +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_map C; + typedef std::pair R; + typedef std::pair P; + C c; + R r = c.insert(P(3.5, 3)); + assert(r.second); + assert(c.size() == 1); + assert(r.first->first == 3.5); + assert(r.first->second == 3); + + r = c.insert(P(3.5, 4)); + assert(!r.second); + assert(c.size() == 1); + assert(r.first->first == 3.5); + assert(r.first->second == 3); + + r = c.insert(P(4.5, 4)); + assert(r.second); + assert(c.size() == 2); + assert(r.first->first == 4.5); + assert(r.first->second == 4); + + r = c.insert(P(5.5, 4)); + assert(r.second); + assert(c.size() == 3); + assert(r.first->first == 5.5); + assert(r.first->second == 4); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_map C; + typedef std::pair R; + typedef std::pair P; + C c; + R r = c.insert(P(3, 3)); + assert(r.second); + assert(c.size() == 1); + assert(r.first->first == 3); + assert(r.first->second == 3); + + r = c.insert(P(3, 4)); + assert(!r.second); + assert(c.size() == 1); + assert(r.first->first == 3); + assert(r.first->second == 3); + + r = c.insert(P(4, 4)); + assert(r.second); + assert(c.size() == 2); + assert(r.first->first == 4); + assert(r.first->second == 4); + + r = c.insert(P(5, 4)); + assert(r.second); + assert(c.size() == 3); + assert(r.first->first == 5); + assert(r.first->second == 4); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair R; + typedef std::pair P; + C c; + R r = c.insert(P(3.5, 3)); + assert(r.second); + assert(c.size() == 1); + assert(r.first->first == 3.5); + assert(r.first->second == 3); + + r = c.insert(P(3.5, 4)); + assert(!r.second); + assert(c.size() == 1); + assert(r.first->first == 3.5); + assert(r.first->second == 3); + + r = c.insert(P(4.5, 4)); + assert(r.second); + assert(c.size() == 2); + assert(r.first->first == 4.5); + assert(r.first->second == 4); + + r = c.insert(P(5.5, 4)); + assert(r.second); + assert(c.size() == 3); + assert(r.first->first == 5.5); + assert(r.first->second == 4); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_map, std::equal_to, + min_allocator>> C; + typedef std::pair R; + typedef std::pair P; + C c; + R r = c.insert(P(3, 3)); + assert(r.second); + assert(c.size() == 1); + assert(r.first->first == 3); + assert(r.first->second == 3); + + r = c.insert(P(3, 4)); + assert(!r.second); + assert(c.size() == 1); + assert(r.first->first == 3); + assert(r.first->second == 3); + + r = c.insert(P(4, 4)); + assert(r.second); + assert(c.size() == 2); + assert(r.first->first == 4); + assert(r.first->second == 4); + + r = c.insert(P(5, 4)); + assert(r.second); + assert(c.size() == 3); + assert(r.first->first == 5); + assert(r.first->second == 4); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.map/version.pass.cpp b/libcxx/test/std/containers/unord/unord.map/version.pass.cpp new file mode 100644 index 00000000000..fc47a326c57 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.map/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +#include + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/bucket.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/bucket.pass.cpp new file mode 100644 index 00000000000..be5acc19630 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/bucket.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// size_type bucket(const key_type& __k) const; + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(std::begin(a), std::end(a)); + size_t bc = c.bucket_count(); + assert(bc >= 7); + for (size_t i = 0; i < 13; ++i) + assert(c.bucket(i) == i % bc); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(std::begin(a), std::end(a)); + size_t bc = c.bucket_count(); + assert(bc >= 7); + for (size_t i = 0; i < 13; ++i) + assert(c.bucket(i) == i % bc); + } +#endif +#if _LIBCPP_DEBUG_LEVEL >= 1 + { + typedef std::unordered_multimap C; + C c; + C::size_type i = c.bucket(3); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/bucket_count.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/bucket_count.pass.cpp new file mode 100644 index 00000000000..d44412fedf6 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/bucket_count.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// size_type bucket_count() const; + +#include +#include +#include + +int main() +{ + { + typedef std::unordered_multimap C; + typedef C::const_iterator I; + typedef std::pair P; + const C c; + assert(c.bucket_count() == 0); + } + { + typedef std::unordered_multimap C; + typedef C::const_iterator I; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 11); + } +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/bucket_size.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/bucket_size.pass.cpp new file mode 100644 index 00000000000..a02f72efc6c --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/bucket_size.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// size_type bucket_size(size_type n) const + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 7); + assert(c.bucket_size(0) == 0); + assert(c.bucket_size(1) == 2); + assert(c.bucket_size(2) == 2); + assert(c.bucket_size(3) == 1); + assert(c.bucket_size(4) == 1); + assert(c.bucket_size(5) == 0); + assert(c.bucket_size(6) == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 7); + assert(c.bucket_size(0) == 0); + assert(c.bucket_size(1) == 2); + assert(c.bucket_size(2) == 2); + assert(c.bucket_size(3) == 1); + assert(c.bucket_size(4) == 1); + assert(c.bucket_size(5) == 0); + assert(c.bucket_size(6) == 0); + } +#endif +#if _LIBCPP_DEBUG_LEVEL >= 1 + { + typedef std::unordered_multimap C; + C c; + C::size_type i = c.bucket_size(3); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/count.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/count.pass.cpp new file mode 100644 index 00000000000..efaf02e3a57 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/count.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// size_type count(const key_type& k) const; + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(50, "fiftyA"), + P(50, "fiftyB"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + assert(c.count(30) == 1); + assert(c.count(50) == 3); + assert(c.count(5) == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(50, "fiftyA"), + P(50, "fiftyB"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + assert(c.count(30) == 1); + assert(c.count(50) == 3); + assert(c.count(5) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/db_iterators_7.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/db_iterators_7.pass.cpp new file mode 100644 index 00000000000..b6ba8d6194a --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/db_iterators_7.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Increment iterator past end. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + C c; + c.insert(std::make_pair(1, "one")); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + C c; + c.insert(std::make_pair(1, "one")); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multimap/db_iterators_8.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/db_iterators_8.pass.cpp new file mode 100644 index 00000000000..f5ea5089349 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/db_iterators_8.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Dereference non-dereferenceable iterator. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + C c; + c.insert(std::make_pair(1, "one")); + C::iterator i = c.end(); + C::value_type j = *i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + C c; + c.insert(std::make_pair(1, "one")); + C::iterator i = c.end(); + C::value_type j = *i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multimap/db_local_iterators_7.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/db_local_iterators_7.pass.cpp new file mode 100644 index 00000000000..93cbd5433f4 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/db_local_iterators_7.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Increment local_iterator past end. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + C c(1); + C::local_iterator i = c.begin(0); + ++i; + ++i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + C c(1); + C::local_iterator i = c.begin(0); + ++i; + ++i; + assert(false); + } +#endif + +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multimap/db_local_iterators_8.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/db_local_iterators_8.pass.cpp new file mode 100644 index 00000000000..159ae496353 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/db_local_iterators_8.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Dereference non-dereferenceable iterator. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + C c(1); + C::local_iterator i = c.end(0); + C::value_type j = *i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + C c(1); + C::local_iterator i = c.end(0); + C::value_type j = *i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multimap/eq.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/eq.pass.cpp new file mode 100644 index 00000000000..3604e7792c1 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/eq.pass.cpp @@ -0,0 +1,181 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// bool +// operator==(const unordered_multimap& x, +// const unordered_multimap& y); +// +// template +// bool +// operator!=(const unordered_multimap& x, +// const unordered_multimap& y); + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(20, "twenty 2"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(50, "fifty 2"), + P(50, "fifty 3"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c1(std::begin(a), std::end(a)); + const C c2; + assert(!(c1 == c2)); + assert( (c1 != c2)); + } + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(20, "twenty 2"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(50, "fifty 2"), + P(50, "fifty 3"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c1(std::begin(a), std::end(a)); + const C c2 = c1; + assert( (c1 == c2)); + assert(!(c1 != c2)); + } + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(20, "twenty 2"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(50, "fifty 2"), + P(50, "fifty 3"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(std::begin(a), std::end(a)); + C c2 = c1; + c2.rehash(30); + assert( (c1 == c2)); + assert(!(c1 != c2)); + c2.insert(P(90, "ninety")); + assert(!(c1 == c2)); + assert( (c1 != c2)); + c1.insert(P(90, "ninety")); + assert( (c1 == c2)); + assert(!(c1 != c2)); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(20, "twenty 2"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(50, "fifty 2"), + P(50, "fifty 3"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c1(std::begin(a), std::end(a)); + const C c2; + assert(!(c1 == c2)); + assert( (c1 != c2)); + } + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(20, "twenty 2"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(50, "fifty 2"), + P(50, "fifty 3"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c1(std::begin(a), std::end(a)); + const C c2 = c1; + assert( (c1 == c2)); + assert(!(c1 != c2)); + } + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(20, "twenty 2"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(50, "fifty 2"), + P(50, "fifty 3"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(std::begin(a), std::end(a)); + C c2 = c1; + c2.rehash(30); + assert( (c1 == c2)); + assert(!(c1 != c2)); + c2.insert(P(90, "ninety")); + assert(!(c1 == c2)); + assert( (c1 != c2)); + c1.insert(P(90, "ninety")); + assert( (c1 == c2)); + assert(!(c1 != c2)); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/equal_range_const.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/equal_range_const.pass.cpp new file mode 100644 index 00000000000..67613b094bf --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/equal_range_const.pass.cpp @@ -0,0 +1,97 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// pair equal_range(const key_type& k) const; + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef C::const_iterator I; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(50, "fiftyA"), + P(50, "fiftyB"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + std::pair r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(r.first->first == 30); + assert(r.first->second == "thirty"); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + r = c.equal_range(50); + assert(r.first->first == 50); + assert(r.first->second == "fifty"); + ++r.first; + assert(r.first->first == 50); + assert(r.first->second == "fiftyA"); + ++r.first; + assert(r.first->first == 50); + assert(r.first->second == "fiftyB"); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef C::const_iterator I; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(50, "fiftyA"), + P(50, "fiftyB"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + std::pair r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(r.first->first == 30); + assert(r.first->second == "thirty"); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + r = c.equal_range(50); + assert(r.first->first == 50); + assert(r.first->second == "fifty"); + ++r.first; + assert(r.first->first == 50); + assert(r.first->second == "fiftyA"); + ++r.first; + assert(r.first->first == 50); + assert(r.first->second == "fiftyB"); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/equal_range_non_const.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/equal_range_non_const.pass.cpp new file mode 100644 index 00000000000..eb4c019af95 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/equal_range_non_const.pass.cpp @@ -0,0 +1,97 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// pair equal_range(const key_type& k); + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef C::iterator I; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(50, "fiftyA"), + P(50, "fiftyB"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c(std::begin(a), std::end(a)); + std::pair r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(r.first->first == 30); + assert(r.first->second == "thirty"); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + r = c.equal_range(50); + assert(r.first->first == 50); + assert(r.first->second == "fifty"); + ++r.first; + assert(r.first->first == 50); + assert(r.first->second == "fiftyA"); + ++r.first; + assert(r.first->first == 50); + assert(r.first->second == "fiftyB"); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef C::iterator I; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(50, "fiftyA"), + P(50, "fiftyB"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c(std::begin(a), std::end(a)); + std::pair r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(r.first->first == 30); + assert(r.first->second == "thirty"); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + r = c.equal_range(50); + assert(r.first->first == 50); + assert(r.first->second == "fifty"); + ++r.first; + assert(r.first->first == 50); + assert(r.first->second == "fiftyA"); + ++r.first; + assert(r.first->first == 50); + assert(r.first->second == "fiftyB"); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/find_const.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/find_const.pass.cpp new file mode 100644 index 00000000000..bc2650d111f --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/find_const.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// const_iterator find(const key_type& k) const; + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + C::const_iterator i = c.find(30); + assert(i->first == 30); + assert(i->second == "thirty"); + i = c.find(5); + assert(i == c.cend()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + C::const_iterator i = c.find(30); + assert(i->first == 30); + assert(i->second == "thirty"); + i = c.find(5); + assert(i == c.cend()); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/find_non_const.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/find_non_const.pass.cpp new file mode 100644 index 00000000000..5a128c0f37e --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/find_non_const.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// iterator find(const key_type& k); + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c(std::begin(a), std::end(a)); + C::iterator i = c.find(30); + assert(i->first == 30); + assert(i->second == "thirty"); + i = c.find(5); + assert(i == c.end()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c(std::begin(a), std::end(a)); + C::iterator i = c.find(30); + assert(i->first == 30); + assert(i->second == "thirty"); + i = c.find(5); + assert(i == c.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/iterators.fail.cpp b/libcxx/test/std/containers/unord/unord.multimap/iterators.fail.cpp new file mode 100644 index 00000000000..d0adb2c25d5 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/iterators.fail.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// iterator begin() {return __table_.begin();} +// iterator end() {return __table_.end();} +// const_iterator begin() const {return __table_.begin();} +// const_iterator end() const {return __table_.end();} +// const_iterator cbegin() const {return __table_.begin();} +// const_iterator cend() const {return __table_.end();} + +#include +#include +#include + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::iterator i = c.begin(); + i->second = "ONE"; + assert(i->second == "ONE"); + i->first = 2; + } + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + } +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/iterators.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/iterators.pass.cpp new file mode 100644 index 00000000000..1831cf1149b --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/iterators.pass.cpp @@ -0,0 +1,134 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// iterator begin() {return __table_.begin();} +// iterator end() {return __table_.end();} +// const_iterator begin() const {return __table_.begin();} +// const_iterator end() const {return __table_.end();} +// const_iterator cbegin() const {return __table_.begin();} +// const_iterator cend() const {return __table_.end();} + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::iterator i; + i = c.begin(); + i->second = "ONE"; + assert(i->second == "ONE"); + } + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::const_iterator i; + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::iterator i; + i = c.begin(); + i->second = "ONE"; + assert(i->second == "ONE"); + } + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::const_iterator i; + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + typedef std::unordered_multimap C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/load_factor.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/load_factor.pass.cpp new file mode 100644 index 00000000000..f407097dc0c --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/load_factor.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// float load_factor() const + +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + } + { + typedef std::unordered_multimap C; + typedef std::pair P; + const C c; + assert(c.load_factor() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + const C c(std::begin(a), std::end(a)); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + } + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + const C c; + assert(c.load_factor() == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/local_iterators.fail.cpp b/libcxx/test/std/containers/unord/unord.multimap/local_iterators.fail.cpp new file mode 100644 index 00000000000..5f66cfe287e --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/local_iterators.fail.cpp @@ -0,0 +1,286 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// local_iterator begin (size_type n); +// local_iterator end (size_type n); +// const_local_iterator begin (size_type n) const; +// const_local_iterator end (size_type n) const; +// const_local_iterator cbegin(size_type n) const; +// const_local_iterator cend (size_type n) const; + +#include +#include +#include + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + typedef C::local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() == 7); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + i->first = 2; + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multimap C; + typedef std::pair P; + typedef C::const_local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() == 7); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multimap C; + typedef std::pair P; + typedef C::const_local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() == 7); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multimap C; + typedef std::pair P; + typedef C::const_local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() == 7); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/local_iterators.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/local_iterators.pass.cpp new file mode 100644 index 00000000000..35e4c772fd3 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/local_iterators.pass.cpp @@ -0,0 +1,549 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// local_iterator begin (size_type n); +// local_iterator end (size_type n); +// const_local_iterator begin (size_type n) const; +// const_local_iterator end (size_type n) const; +// const_local_iterator cbegin(size_type n) const; +// const_local_iterator cend (size_type n) const; + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + typedef C::local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multimap C; + typedef std::pair P; + typedef C::const_local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multimap C; + typedef std::pair P; + typedef C::const_local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multimap C; + typedef std::pair P; + typedef C::const_local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + typedef C::local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + typedef C::const_local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + typedef C::const_local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + typedef C::const_local_iterator I; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 3); + assert(i->second == "three"); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(i->first == 4); + assert(i->second == "four"); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/max_bucket_count.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/max_bucket_count.pass.cpp new file mode 100644 index 00000000000..23b90579ec4 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/max_bucket_count.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// size_type max_bucket_count() const; + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef C::const_iterator I; + typedef std::pair P; + const C c; + assert(c.max_bucket_count() > 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef C::const_iterator I; + typedef std::pair P; + const C c; + assert(c.max_bucket_count() > 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/max_load_factor.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/max_load_factor.pass.cpp new file mode 100644 index 00000000000..39b7feeba4e --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/max_load_factor.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// float max_load_factor() const; +// void max_load_factor(float mlf); + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + const C c; + assert(c.max_load_factor() == 1); + } + { + typedef std::unordered_multimap C; + typedef std::pair P; + C c; + assert(c.max_load_factor() == 1); + c.max_load_factor(2.5); + assert(c.max_load_factor() == 2.5); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + const C c; + assert(c.max_load_factor() == 1); + } + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + C c; + assert(c.max_load_factor() == 1); + c.max_load_factor(2.5); + assert(c.max_load_factor() == 2.5); + } +#endif +#if _LIBCPP_DEBUG_LEVEL >= 1 + { + typedef std::unordered_multimap C; + C c; + c.max_load_factor(0); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/max_size.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/max_size.pass.cpp new file mode 100644 index 00000000000..caba5932b23 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/max_size.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// size_type max_size() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + std::unordered_multimap u; + assert(u.max_size() > 0); + } +#if __cplusplus >= 201103L + { + std::unordered_multimap, std::equal_to, + min_allocator>> u; + assert(u.max_size() > 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/rehash.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/rehash.pass.cpp new file mode 100644 index 00000000000..1d99208596c --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/rehash.pass.cpp @@ -0,0 +1,119 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// void rehash(size_type n); + +#include +#include +#include +#include + +#include "min_allocator.h" + +template +void test(const C& c) +{ + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + typename C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); +} + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 7); + c.rehash(3); + assert(c.bucket_count() == 7); + test(c); + c.max_load_factor(2); + c.rehash(3); + assert(c.bucket_count() == 3); + test(c); + c.rehash(31); + assert(c.bucket_count() == 31); + test(c); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 7); + c.rehash(3); + assert(c.bucket_count() == 7); + test(c); + c.max_load_factor(2); + c.rehash(3); + assert(c.bucket_count() == 3); + test(c); + c.rehash(31); + assert(c.bucket_count() == 31); + test(c); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/reserve.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/reserve.pass.cpp new file mode 100644 index 00000000000..801c74457d7 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/reserve.pass.cpp @@ -0,0 +1,93 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// void rehash(size_type n); + +#include +#include +#include + +#include "min_allocator.h" + +template +void test(const C& c) +{ + assert(c.size() == 6); + assert(c.find(1)->second == "one"); + assert(next(c.find(1))->second == "four"); + assert(c.find(2)->second == "two"); + assert(next(c.find(2))->second == "four"); + assert(c.find(3)->second == "three"); + assert(c.find(4)->second == "four"); +} + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 7); + c.reserve(3); + assert(c.bucket_count() == 7); + test(c); + c.max_load_factor(2); + c.reserve(3); + assert(c.bucket_count() == 3); + test(c); + c.reserve(31); + assert(c.bucket_count() >= 16); + test(c); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 7); + c.reserve(3); + assert(c.bucket_count() == 7); + test(c); + c.max_load_factor(2); + c.reserve(3); + assert(c.bucket_count() == 3); + test(c); + c.reserve(31); + assert(c.bucket_count() >= 16); + test(c); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/scary.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/scary.pass.cpp new file mode 100644 index 00000000000..e619a7a5429 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/scary.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class unordered_map class unordered_multimap + +// Extension: SCARY/N2913 iterator compatibility between unordered_map and unordered_multimap + +#include + +int main() +{ + typedef std::unordered_map M1; + typedef std::unordered_multimap M2; + M2::iterator i; + M1::iterator j = i; +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/swap_member.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/swap_member.pass.cpp new file mode 100644 index 00000000000..225eccd4793 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/swap_member.pass.cpp @@ -0,0 +1,585 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// void swap(unordered_multimap& __u); + +#include +#include +#include + +#include "../../test_compare.h" +#include "../../test_hash.h" +#include "test_allocator.h" + +#include "min_allocator.h" + +int main() +{ + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.find(10)->second == "ten"); + assert(c1.find(20)->second == "twenty"); + assert(c1.find(30)->second == "thirty"); + assert(c1.find(40)->second == "forty"); + assert(c1.find(50)->second == "fifty"); + assert(c1.find(60)->second == "sixty"); + assert(c1.find(70)->second == "seventy"); + assert(c1.find(80)->second == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.find(1)->second == "one"); + assert(next(c2.find(1))->second == "four"); + assert(c2.find(2)->second == "two"); + assert(next(c2.find(2))->second == "four"); + assert(c2.find(3)->second == "three"); + assert(c2.find(4)->second == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.find(10)->second == "ten"); + assert(c1.find(20)->second == "twenty"); + assert(c1.find(30)->second == "thirty"); + assert(c1.find(40)->second == "forty"); + assert(c1.find(50)->second == "fifty"); + assert(c1.find(60)->second == "sixty"); + assert(c1.find(70)->second == "seventy"); + assert(c1.find(80)->second == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.find(1)->second == "one"); + assert(next(c2.find(1))->second == "four"); + assert(c2.find(2)->second == "two"); + assert(next(c2.find(2))->second == "four"); + assert(c2.find(3)->second == "three"); + assert(c2.find(4)->second == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.find(10)->second == "ten"); + assert(c1.find(20)->second == "twenty"); + assert(c1.find(30)->second == "thirty"); + assert(c1.find(40)->second == "forty"); + assert(c1.find(50)->second == "fifty"); + assert(c1.find(60)->second == "sixty"); + assert(c1.find(70)->second == "seventy"); + assert(c1.find(80)->second == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.find(1)->second == "one"); + assert(next(c2.find(1))->second == "four"); + assert(c2.find(2)->second == "two"); + assert(next(c2.find(2))->second == "four"); + assert(c2.find(3)->second == "three"); + assert(c2.find(4)->second == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.find(10)->second == "ten"); + assert(c1.find(20)->second == "twenty"); + assert(c1.find(30)->second == "thirty"); + assert(c1.find(40)->second == "forty"); + assert(c1.find(50)->second == "fifty"); + assert(c1.find(60)->second == "sixty"); + assert(c1.find(70)->second == "seventy"); + assert(c1.find(80)->second == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.find(1)->second == "one"); + assert(next(c2.find(1))->second == "four"); + assert(c2.find(2)->second == "two"); + assert(next(c2.find(2))->second == "four"); + assert(c2.find(3)->second == "three"); + assert(c2.find(4)->second == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.find(10)->second == "ten"); + assert(c1.find(20)->second == "twenty"); + assert(c1.find(30)->second == "thirty"); + assert(c1.find(40)->second == "forty"); + assert(c1.find(50)->second == "fifty"); + assert(c1.find(60)->second == "sixty"); + assert(c1.find(70)->second == "seventy"); + assert(c1.find(80)->second == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.find(1)->second == "one"); + assert(next(c2.find(1))->second == "four"); + assert(c2.find(2)->second == "two"); + assert(next(c2.find(2))->second == "four"); + assert(c2.find(3)->second == "three"); + assert(c2.find(4)->second == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.find(10)->second == "ten"); + assert(c1.find(20)->second == "twenty"); + assert(c1.find(30)->second == "thirty"); + assert(c1.find(40)->second == "forty"); + assert(c1.find(50)->second == "fifty"); + assert(c1.find(60)->second == "sixty"); + assert(c1.find(70)->second == "seventy"); + assert(c1.find(80)->second == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.find(1)->second == "one"); + assert(next(c2.find(1))->second == "four"); + assert(c2.find(2)->second == "two"); + assert(next(c2.find(2))->second == "four"); + assert(c2.find(3)->second == "three"); + assert(c2.find(4)->second == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/types.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/types.pass.cpp new file mode 100644 index 00000000000..55ae749746c --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/types.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap +// { +// public: +// // types +// typedef Key key_type; +// typedef T mapped_type; +// typedef Hash hasher; +// typedef Pred key_equal; +// typedef Alloc allocator_type; +// typedef pair value_type; +// typedef value_type& reference; +// typedef const value_type& const_reference; +// typedef typename allocator_traits::pointer pointer; +// typedef typename allocator_traits::const_pointer const_pointer; +// typedef typename allocator_traits::size_type size_type; +// typedef typename allocator_traits::difference_type difference_type; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same>::value), ""); + static_assert((std::is_same>::value), ""); + // min_allocator doesn't have a size_type, so one gets synthesized + static_assert((std::is_same::type>::value), ""); + static_assert((std::is_same::value), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/allocator.pass.cpp new file mode 100644 index 00000000000..dc41fad29af --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/allocator.pass.cpp @@ -0,0 +1,111 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// explicit unordered_multimap(const allocator_type& __a); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + C c(test_allocator >(10)); + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (test_allocator >(10))); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + C c(min_allocator >{}); + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (min_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if _LIBCPP_STD_VER > 11 + { + typedef NotConstructible T; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_multimap C; + + A a(10); + C c(2, a); + assert(c.bucket_count() == 2); + assert(c.hash_function() == HF()); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } + { + typedef NotConstructible T; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_multimap C; + + A a(10); + HF hf(12); + C c(2, hf, a); + assert(c.bucket_count() == 2); + assert(c.hash_function() == hf); + assert(!(c.hash_function() == HF())); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_copy.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_copy.pass.cpp new file mode 100644 index 00000000000..df566b396f9 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_copy.pass.cpp @@ -0,0 +1,227 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// unordered_multimap& operator=(const unordered_multimap& u); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_allocator > A; + typedef std::unordered_multimap >, + test_compare >, + A + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(4) + ); + c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + ++i; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + ++i; + assert(i->first == 3); + assert(i->second == "three"); + ++i; + assert(i->first == 4); + assert(i->second == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(4)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + { + typedef std::unordered_multimap C; + typedef std::pair P; + const P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a+sizeof(a)/sizeof(a[0])); + C *p = &c; + c = *p; + assert(c.size() == 6); + assert(std::is_permutation(c.begin(), c.end(), a)); + } + { + typedef other_allocator > A; + typedef std::unordered_multimap >, + test_compare >, + A + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(4) + ); + c = c0; + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + ++i; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + ++i; + assert(i->first == 3); + assert(i->second == "three"); + ++i; + assert(i->first == 4); + assert(i->second == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef min_allocator > A; + typedef std::unordered_multimap >, + test_compare >, + A + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A() + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A() + ); + c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + ++i; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + ++i; + assert(i->first == 3); + assert(i->second == "three"); + ++i; + assert(i->first == 4); + assert(i->second == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_init.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_init.pass.cpp new file mode 100644 index 00000000000..2d3c1434d69 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_init.pass.cpp @@ -0,0 +1,146 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// unordered_multimap& operator=(initializer_list il); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef test_allocator > A; + typedef std::unordered_multimap >, + test_compare >, + A + > C; + typedef std::pair P; + C c = { + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + c = { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef min_allocator > A; + typedef std::unordered_multimap >, + test_compare >, + A + > C; + typedef std::pair P; + C c = { + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + c = { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_move.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_move.pass.cpp new file mode 100644 index 00000000000..0c43fa8f06e --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/assign_move.pass.cpp @@ -0,0 +1,306 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// unordered_multimap& operator=(unordered_multimap&& u); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef test_allocator > A; + typedef std::unordered_multimap >, + test_compare >, + A + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(4) + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + { + typedef test_allocator > A; + typedef std::unordered_multimap >, + test_compare >, + A + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(10) + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + { + typedef other_allocator > A; + typedef std::unordered_multimap >, + test_compare >, + A + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(4) + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef min_allocator > A; + typedef std::unordered_multimap >, + test_compare >, + A + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A() + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A() + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + std::unordered_multimap s1 = {{1, 1}, {2, 2}, {3, 3}}; + std::unordered_multimap::iterator i = s1.begin(); + std::pair k = *i; + std::unordered_multimap s2; + s2 = std::move(s1); + assert(*i == k); + s2.erase(i); + assert(s2.size() == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/copy.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/copy.pass.cpp new file mode 100644 index 00000000000..d71838f1dfb --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/copy.pass.cpp @@ -0,0 +1,193 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// unordered_multimap(const unordered_multimap& u); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + test_allocator >(10) + ); + C c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + ++i; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + ++i; + assert(i->first == 3); + assert(i->second == "three"); + ++i; + assert(i->first == 4); + assert(i->second == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (test_allocator >(10))); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + typedef std::unordered_multimap >, + test_compare >, + other_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + other_allocator >(10) + ); + C c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + ++i; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + ++i; + assert(i->first == 3); + assert(i->second == "three"); + ++i; + assert(i->first == 4); + assert(i->second == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (other_allocator >(-2))); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + min_allocator >() + ); + C c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + ++i; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + ++i; + assert(i->first == 3); + assert(i->second == "three"); + ++i; + assert(i->first == 4); + assert(i->second == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (min_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/copy_alloc.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/copy_alloc.pass.cpp new file mode 100644 index 00000000000..2a064c5b5f6 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/copy_alloc.pass.cpp @@ -0,0 +1,138 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// unordered_multimap(const unordered_multimap& u, const allocator_type& a); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + test_allocator >(10) + ); + C c(c0, test_allocator >(5)); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + ++i; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + ++i; + assert(i->first == 3); + assert(i->second == "three"); + ++i; + assert(i->first == 4); + assert(i->second == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (test_allocator >(5))); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + min_allocator >() + ); + C c(c0, min_allocator >()); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + ++i; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + ++i; + assert(i->first == 3); + assert(i->second == "three"); + ++i; + assert(i->first == 4); + assert(i->second == "four"); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (min_allocator >())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/default.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/default.pass.cpp new file mode 100644 index 00000000000..1884065ce0c --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/default.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// unordered_multimap(); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + C c; + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (test_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + C c; + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (min_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } + { + std::unordered_multimap c = {}; + assert(c.bucket_count() == 0); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/default_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/default_noexcept.pass.cpp new file mode 100644 index 00000000000..9812a45203b --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/default_noexcept.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// unordered_multimap() +// noexcept( +// is_nothrow_default_constructible::value && +// is_nothrow_default_constructible::value && +// is_nothrow_copy_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "../../../test_hash.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp(); + some_comp(const some_comp&); +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_multimap C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::unordered_multimap, + std::equal_to, test_allocator>> C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::unordered_multimap, + std::equal_to, other_allocator>> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::unordered_multimap> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::unordered_multimap, + some_comp> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..ae2a96e2ac4 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/dtor_noexcept.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// ~unordered_multimap() // implied noexcept; + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template +struct some_comp +{ + typedef T value_type; + ~some_comp() noexcept(false); +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); + ~some_hash() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_multimap C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::unordered_multimap, + std::equal_to, test_allocator>> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::unordered_multimap, + std::equal_to, other_allocator>> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::unordered_multimap> C; + static_assert(!std::is_nothrow_destructible::value, ""); + } + { + typedef std::unordered_multimap, + some_comp> C; + static_assert(!std::is_nothrow_destructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init.pass.cpp new file mode 100644 index 00000000000..cc5532adbe0 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init.pass.cpp @@ -0,0 +1,254 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// unordered_multimap(initializer_list il); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + C c = { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert((c.get_allocator() == test_allocator >())); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + C c = { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert((c.get_allocator() == min_allocator >())); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair P; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_multimap C; + + A a(42); + C c ({ + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, 12, a ); + assert(c.bucket_count() >= 12); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == HF()); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + assert(!(c.get_allocator() == A())); + } + { + typedef std::pair P; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_multimap C; + + HF hf(42); + A a(43); + C c ({ + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, 12, hf, a ); + assert(c.bucket_count() >= 12); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == hf); + assert(!(c.hash_function() == HF())); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + assert(!(c.get_allocator() == A())); + } +#endif +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init_size.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init_size.pass.cpp new file mode 100644 index 00000000000..48239db1fa2 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init_size.pass.cpp @@ -0,0 +1,144 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// unordered_multimap(initializer_list il, size_type n); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + C c({ + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, + 7 + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert((c.get_allocator() == test_allocator >())); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + C c({ + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, + 7 + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert((c.get_allocator() == min_allocator >())); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init_size_hash.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init_size_hash.pass.cpp new file mode 100644 index 00000000000..ff005467705 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init_size_hash.pass.cpp @@ -0,0 +1,146 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// unordered_multimap(initializer_list il, size_type n, const hasher& hf); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + C c({ + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, + 7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert((c.get_allocator() == test_allocator >())); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + C c({ + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, + 7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert((c.get_allocator() == min_allocator >())); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init_size_hash_equal.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init_size_hash_equal.pass.cpp new file mode 100644 index 00000000000..095e9c327f0 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init_size_hash_equal.pass.cpp @@ -0,0 +1,149 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// unordered_multimap(initializer_list il, size_type n, +// const hasher& hf, const key_equal& eql); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + C c({ + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, + 7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert((c.get_allocator() == test_allocator >())); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + C c({ + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, + 7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert((c.get_allocator() == min_allocator >())); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init_size_hash_equal_allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init_size_hash_equal_allocator.pass.cpp new file mode 100644 index 00000000000..d2f698ac2bc --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/init_size_hash_equal_allocator.pass.cpp @@ -0,0 +1,151 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// unordered_multimap(initializer_list il, size_type n, +// const hasher& hf, const key_equal& eql, const allocator_type& a); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + C c({ + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, + 7, + test_hash >(8), + test_compare >(9), + test_allocator >(10) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert((c.get_allocator() == test_allocator >(10))); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + C c({ + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }, + 7, + test_hash >(8), + test_compare >(9), + min_allocator >() + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert((c.get_allocator() == min_allocator >())); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move.pass.cpp new file mode 100644 index 00000000000..fd70ff10a70 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move.pass.cpp @@ -0,0 +1,243 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// unordered_multimap(unordered_multimap&& u); + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(7, + test_hash >(8), + test_compare >(9), + test_allocator >(10) + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 0); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (test_allocator >(10))); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + test_allocator >(10) + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert((c.get_allocator() == test_allocator >(10))); + + assert(c0.empty()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(7, + test_hash >(8), + test_compare >(9), + min_allocator >() + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 0); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (min_allocator >())); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + min_allocator >() + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert((c.get_allocator() == min_allocator >())); + + assert(c0.empty()); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + std::unordered_multimap s1 = {{1, 1}, {2, 2}, {3, 3}}; + std::unordered_multimap::iterator i = s1.begin(); + std::pair k = *i; + std::unordered_multimap s2 = std::move(s1); + assert(*i == k); + s2.erase(i); + assert(s2.size() == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_alloc.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_alloc.pass.cpp new file mode 100644 index 00000000000..d958e23ddd0 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_alloc.pass.cpp @@ -0,0 +1,228 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// unordered_multimap(unordered_multimap&& u, const allocator_type& a); + +#include + +#include +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::pair P; + typedef test_allocator> A; + typedef std::unordered_multimap >, + test_compare >, + A + > C; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(std::move(c0), A(12)); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert((c.get_allocator() == test_allocator >(12))); + + assert(c0.empty()); + } + { + typedef std::pair P; + typedef test_allocator> A; + typedef std::unordered_multimap >, + test_compare >, + A + > C; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(std::move(c0), A(10)); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert((c.get_allocator() == test_allocator >(10))); + + assert(c0.empty()); + } +#if __cplusplus >= 201103L + { + typedef std::pair P; + typedef min_allocator> A; + typedef std::unordered_multimap >, + test_compare >, + A + > C; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A() + ); + C c(std::move(c0), A()); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert((c.get_allocator() == min_allocator >())); + + assert(c0.empty()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..078693d52b2 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_assign_noexcept.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// unordered_multimap& operator=(unordered_multimap&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable::value && +// is_nothrow_move_assignable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp& operator=(const some_comp&); +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); + some_hash& operator=(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_multimap C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::unordered_multimap, + std::equal_to, test_allocator>> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::unordered_multimap, + std::equal_to, other_allocator>> C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::unordered_multimap> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::unordered_multimap, + some_comp> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_noexcept.pass.cpp new file mode 100644 index 00000000000..44565d11503 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/move_noexcept.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// unordered_multimap(unordered_multimap&&) +// noexcept(is_nothrow_move_constructible::value && +// is_nothrow_move_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp(const some_comp&); +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_multimap C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::unordered_multimap, + std::equal_to, test_allocator>> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::unordered_multimap, + std::equal_to, other_allocator>> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::unordered_multimap> C; + static_assert(!std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::unordered_multimap, + some_comp> C; + static_assert(!std::is_nothrow_move_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range.pass.cpp new file mode 100644 index 00000000000..bb700ec565d --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range.pass.cpp @@ -0,0 +1,263 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// template +// unordered_multimap(InputIterator first, InputIterator last); + +#include +#include +#include +#include + +#include "test_iterators.h" +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert((c.get_allocator() == test_allocator >())); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert((c.get_allocator() == min_allocator >())); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair P; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_multimap C; + + P arr[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + A a(42); + C c(input_iterator(arr), input_iterator(arr + sizeof(arr)/sizeof(arr[0])), 14, a); + assert(c.bucket_count() >= 14); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == HF()); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + assert(!(c.get_allocator() == A())); + } + { + typedef std::pair P; + typedef test_allocator> A; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef std::unordered_multimap C; + + P arr[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + A a(42); + HF hf (43); + C c(input_iterator(arr), input_iterator(arr + sizeof(arr)/sizeof(arr[0])), 12, hf, a ); + assert(c.bucket_count() >= 12); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == hf); + assert(!(c.hash_function() == HF())); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + assert(!(c.get_allocator() == A())); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range_size.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range_size.pass.cpp new file mode 100644 index 00000000000..a3fd4d14573 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range_size.pass.cpp @@ -0,0 +1,149 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// template +// unordered_multimap(InputIterator first, InputIterator last, size_type n); + +#include +#include +#include +#include + +#include "test_iterators.h" +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 10 + ); + assert(c.bucket_count() == 11); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert((c.get_allocator() == test_allocator >())); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 10 + ); + assert(c.bucket_count() == 11); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert((c.get_allocator() == min_allocator >())); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range_size_hash.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range_size_hash.pass.cpp new file mode 100644 index 00000000000..4e7b1ac17a2 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range_size_hash.pass.cpp @@ -0,0 +1,152 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// template +// unordered_multimap(InputIterator first, InputIterator last, size_type n, +// const hasher& hf); + +#include +#include +#include +#include + +#include "test_iterators.h" +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert((c.get_allocator() == test_allocator >())); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert((c.get_allocator() == min_allocator >())); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range_size_hash_equal.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range_size_hash_equal.pass.cpp new file mode 100644 index 00000000000..879e6811f2d --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range_size_hash_equal.pass.cpp @@ -0,0 +1,154 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// template +// unordered_multimap(InputIterator first, InputIterator last, size_type n, +// const hasher& hf, const key_equal& eql); + +#include +#include +#include +#include + +#include "test_iterators.h" +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert((c.get_allocator() == test_allocator >())); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert((c.get_allocator() == min_allocator >())); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range_size_hash_equal_allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range_size_hash_equal_allocator.pass.cpp new file mode 100644 index 00000000000..8e42ca7245e --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/range_size_hash_equal_allocator.pass.cpp @@ -0,0 +1,157 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// template +// unordered_multimap(InputIterator first, InputIterator last, size_type n, +// const hasher& hf, const key_equal& eql, +// const allocator_type& a); + +#include +#include +#include +#include + +#include "test_iterators.h" +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8), + test_compare >(9), + test_allocator >(10) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert((c.get_allocator() == test_allocator >(10))); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8), + test_compare >(9), + min_allocator >() + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator i = eq.first; + assert(i->first == 1); + assert(i->second == "one"); + ++i; + assert(i->first == 1); + assert(i->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + i = eq.first; + assert(i->first == 2); + assert(i->second == "two"); + ++i; + assert(i->first == 2); + assert(i->second == "four"); + + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 3); + assert(i->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + i = eq.first; + assert(i->first == 4); + assert(i->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert((c.get_allocator() == min_allocator >())); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size.fail.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size.fail.cpp new file mode 100644 index 00000000000..44cf84ff323 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size.fail.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// unordered_multimap(size_type n); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + C c = 7; + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (test_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + C c = 7; + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (min_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size.pass.cpp new file mode 100644 index 00000000000..bd56a41fd71 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// unordered_multimap(size_type n); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + C c(7); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (test_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + C c(7); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (min_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size_hash.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size_hash.pass.cpp new file mode 100644 index 00000000000..33460612ce3 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size_hash.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// unordered_multimap(size_type n, const hasher& hf); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + C c(7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (test_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + C c(7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == + (min_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size_hash_equal.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size_hash_equal.pass.cpp new file mode 100644 index 00000000000..c2420ce9e6f --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size_hash_equal.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// unordered_multimap(size_type n, const hasher& hf, const key_equal& eql); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + C c(7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (test_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + C c(7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (min_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size_hash_equal_allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size_hash_equal_allocator.pass.cpp new file mode 100644 index 00000000000..33886670b3b --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.cnstr/size_hash_equal_allocator.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// unordered_multimap(size_type n, const hasher& hf, const key_equal& eql, const allocator_type& a); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap >, + test_compare >, + test_allocator > + > C; + C c(7, + test_hash >(8), + test_compare >(9), + test_allocator >(10) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (test_allocator >(10))); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap >, + test_compare >, + min_allocator > + > C; + C c(7, + test_hash >(8), + test_compare >(9), + min_allocator >() + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == + (min_allocator >())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/clear.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/clear.pass.cpp new file mode 100644 index 00000000000..4efcfaa6ce5 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/clear.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// void clear() + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + c.clear(); + assert(c.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + c.clear(); + assert(c.size() == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/emplace.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/emplace.pass.cpp new file mode 100644 index 00000000000..4f2e8ef061f --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/emplace.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// template +// iterator emplace(Args&&... args); + +#include +#include + +#include "../../../Emplaceable.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multimap C; + typedef C::iterator R; + C c; + R r = c.emplace(std::piecewise_construct, std::forward_as_tuple(3), + std::forward_as_tuple()); + assert(c.size() == 1); + assert(r->first == 3); + assert(r->second == Emplaceable()); + + r = c.emplace(std::pair(4, Emplaceable(5, 6))); + assert(c.size() == 2); + assert(r->first == 4); + assert(r->second == Emplaceable(5, 6)); + + r = c.emplace(std::piecewise_construct, std::forward_as_tuple(5), + std::forward_as_tuple(6, 7)); + assert(c.size() == 3); + assert(r->first == 5); + assert(r->second == Emplaceable(6, 7)); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef C::iterator R; + C c; + R r = c.emplace(std::piecewise_construct, std::forward_as_tuple(3), + std::forward_as_tuple()); + assert(c.size() == 1); + assert(r->first == 3); + assert(r->second == Emplaceable()); + + r = c.emplace(std::pair(4, Emplaceable(5, 6))); + assert(c.size() == 2); + assert(r->first == 4); + assert(r->second == Emplaceable(5, 6)); + + r = c.emplace(std::piecewise_construct, std::forward_as_tuple(5), + std::forward_as_tuple(6, 7)); + assert(c.size() == 3); + assert(r->first == 5); + assert(r->second == Emplaceable(6, 7)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/emplace_hint.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/emplace_hint.pass.cpp new file mode 100644 index 00000000000..4d141ad137c --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/emplace_hint.pass.cpp @@ -0,0 +1,109 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// template +// iterator emplace_hint(const_iterator p, Args&&... args); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "../../../Emplaceable.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multimap C; + typedef C::iterator R; + C c; + C::const_iterator e = c.end(); + R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(3), + std::forward_as_tuple()); + assert(c.size() == 1); + assert(r->first == 3); + assert(r->second == Emplaceable()); + + r = c.emplace_hint(c.end(), std::pair(3, Emplaceable(5, 6))); + assert(c.size() == 2); + assert(r->first == 3); + assert(r->second == Emplaceable(5, 6)); + assert(r == next(c.begin())); + + r = c.emplace_hint(r, std::piecewise_construct, std::forward_as_tuple(3), + std::forward_as_tuple(6, 7)); + assert(c.size() == 3); + assert(r->first == 3); + assert(r->second == Emplaceable(6, 7)); + assert(r == next(c.begin())); + r = c.begin(); + assert(r->first == 3); + assert(r->second == Emplaceable()); + r = next(r, 2); + assert(r->first == 3); + assert(r->second == Emplaceable(5, 6)); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef C::iterator R; + C c; + C::const_iterator e = c.end(); + R r = c.emplace_hint(e, std::piecewise_construct, std::forward_as_tuple(3), + std::forward_as_tuple()); + assert(c.size() == 1); + assert(r->first == 3); + assert(r->second == Emplaceable()); + + r = c.emplace_hint(c.end(), std::pair(3, Emplaceable(5, 6))); + assert(c.size() == 2); + assert(r->first == 3); + assert(r->second == Emplaceable(5, 6)); + assert(r == next(c.begin())); + + r = c.emplace_hint(r, std::piecewise_construct, std::forward_as_tuple(3), + std::forward_as_tuple(6, 7)); + assert(c.size() == 3); + assert(r->first == 3); + assert(r->second == Emplaceable(6, 7)); + assert(r == next(c.begin())); + r = c.begin(); + assert(r->first == 3); + assert(r->second == Emplaceable()); + r = next(r, 2); + assert(r->first == 3); + assert(r->second == Emplaceable(5, 6)); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + typedef std::unordered_multimap C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C c2; + R r = c.emplace_hint(c2.end(), std::piecewise_construct, + std::forward_as_tuple(3), + std::forward_as_tuple()); + assert(false); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_const_iter.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_const_iter.pass.cpp new file mode 100644 index 00000000000..25d6a7a010d --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_const_iter.pass.cpp @@ -0,0 +1,117 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// iterator erase(const_iterator p) + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::iterator j = c.erase(i); + + assert(c.size() == 5); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 2); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 4); + assert(k->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::iterator j = c.erase(i); + + assert(c.size() == 5); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 2); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 4); + assert(k->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_db1.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_db1.pass.cpp new file mode 100644 index 00000000000..83ccf3b7396 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_db1.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator position) with end() + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include + +int main() +{ + { + typedef std::pair P; + P a1[] = {P(1, 1), P(2, 2), P(3, 3)}; + std::unordered_multimap l1(a1, a1+3); + std::unordered_multimap::const_iterator i = l1.end(); + l1.erase(i); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_db2.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_db2.pass.cpp new file mode 100644 index 00000000000..fffcfa69142 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_db2.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator position) with iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + typedef std::pair P; + P a1[] = {P(1, 1), P(2, 2), P(3, 3)}; + std::unordered_multimap l1(a1, a1+3); + std::unordered_multimap l2(a1, a1+3); + std::unordered_multimap::const_iterator i = l2.begin(); + l1.erase(i); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db1.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db1.pass.cpp new file mode 100644 index 00000000000..be6caba5902 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db1.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with first iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + typedef std::pair P; + P a1[] = {P(1, 1), P(2, 2), P(3, 3)}; + std::unordered_multimap l1(a1, a1+3); + std::unordered_multimap l2(a1, a1+3); + std::unordered_multimap::iterator i = l1.erase(l2.cbegin(), next(l1.cbegin())); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db2.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db2.pass.cpp new file mode 100644 index 00000000000..a6d54084e72 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db2.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with second iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + typedef std::pair P; + P a1[] = {P(1, 1), P(2, 2), P(3, 3)}; + std::unordered_multimap l1(a1, a1+3); + std::unordered_multimap l2(a1, a1+3); + std::unordered_multimap::iterator i = l1.erase(l1.cbegin(), next(l2.cbegin())); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db3.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db3.pass.cpp new file mode 100644 index 00000000000..301cfb4402d --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db3.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with both iterators from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + typedef std::pair P; + P a1[] = {P(1, 1), P(2, 2), P(3, 3)}; + std::unordered_multimap l1(a1, a1+3); + std::unordered_multimap l2(a1, a1+3); + std::unordered_multimap::iterator i = l1.erase(l2.cbegin(), next(l2.cbegin())); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db4.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db4.pass.cpp new file mode 100644 index 00000000000..b53b486a56a --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_iter_iter_db4.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with a bad range + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + typedef std::pair P; + P a1[] = {P(1, 1), P(2, 2), P(3, 3)}; + std::unordered_multimap l1(a1, a1+3); + std::unordered_multimap::iterator i = l1.erase(next(l1.cbegin()), l1.cbegin()); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_key.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_key.pass.cpp new file mode 100644 index 00000000000..892f8a24750 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_key.pass.cpp @@ -0,0 +1,388 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// size_type erase(const key_type& k); + +#include +#include +#include + +#include "min_allocator.h" + +#if __cplusplus >= 201103L +template +bool only_deletions ( const Unordered &whole, const Unordered &part ) { + typename Unordered::const_iterator w = whole.begin(); + typename Unordered::const_iterator p = part.begin(); + + while ( w != whole.end () && p != part.end()) { + if ( *w == *p ) + p++; + w++; + } + + return p == part.end(); +} +#endif + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.erase(5) == 0); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 2); + assert(k->second == "two"); + ++k; + assert(k->first == 2); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 4); + assert(k->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + assert(c.erase(2) == 2); + assert(c.size() == 4); + eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 4); + assert(k->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + assert(c.erase(2) == 0); + assert(c.size() == 4); + eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 4); + assert(k->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + assert(c.erase(4) == 1); + assert(c.size() == 3); + eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + assert(c.erase(4) == 0); + assert(c.size() == 3); + eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + assert(c.erase(1) == 2); + assert(c.size() == 1); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + assert(c.erase(1) == 0); + assert(c.size() == 1); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + assert(c.erase(3) == 1); + assert(c.size() == 0); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 0); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + assert(c.erase(3) == 0); + assert(c.size() == 0); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 0); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.erase(5) == 0); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::const_iterator k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 2); + assert(k->second == "two"); + ++k; + assert(k->first == 2); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 4); + assert(k->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + assert(c.erase(2) == 2); + assert(c.size() == 4); + eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 4); + assert(k->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + assert(c.erase(2) == 0); + assert(c.size() == 4); + eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 4); + assert(k->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + assert(c.erase(4) == 1); + assert(c.size() == 3); + eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + assert(c.erase(4) == 0); + assert(c.size() == 3); + eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + assert(c.erase(1) == 2); + assert(c.size() == 1); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + assert(c.erase(1) == 0); + assert(c.size() == 1); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + assert(c.erase(3) == 1); + assert(c.size() == 0); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 0); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + assert(c.erase(3) == 0); + assert(c.size() == 0); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 0); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + } + { + typedef std::unordered_multimap C; + C m, m2; + for ( int i = 0; i < 10; ++i ) { + for (int j = 0; j < 2; ++j ) { + m.insert (std::make_pair(i,j)); + m2.insert(std::make_pair(i,j)); + } + } + + C::iterator i = m2.begin(); + int ctr = 0; + while (i != m2.end()) { + if (ctr++ % 2 == 0) + m2.erase(i++); + else + ++i; + } + + assert (only_deletions (m, m2)); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_range.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_range.pass.cpp new file mode 100644 index 00000000000..f60ec071ff7 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/erase_range.pass.cpp @@ -0,0 +1,179 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// iterator erase(const_iterator first, const_iterator last) + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::const_iterator j = next(i, 2); + C::iterator k = c.erase(i, i); + assert(k == i); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 2); + assert(k->second == "two"); + ++k; + assert(k->first == 2); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 4); + assert(k->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + k = c.erase(i, j); + assert(c.size() == 4); + eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 4); + assert(k->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + k = c.erase(c.cbegin(), c.cend()); + assert(c.size() == 0); + assert(k == c.end()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::const_iterator j = next(i, 2); + C::iterator k = c.erase(i, i); + assert(k == i); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 2); + assert(k->second == "two"); + ++k; + assert(k->first == 2); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 4); + assert(k->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + k = c.erase(i, j); + assert(c.size() == 4); + eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 4); + assert(k->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + + k = c.erase(c.cbegin(), c.cend()); + assert(c.size() == 0); + assert(k == c.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_const_lvalue.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_const_lvalue.pass.cpp new file mode 100644 index 00000000000..e7e7cb03b6d --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_const_lvalue.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// iterator insert(const value_type& x); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef C::iterator R; + typedef C::value_type P; + C c; + R r = c.insert(P(3.5, 3)); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + r = c.insert(P(3.5, 4)); + assert(c.size() == 2); + assert(r->first == 3.5); + assert(r->second == 4); + + r = c.insert(P(4.5, 4)); + assert(c.size() == 3); + assert(r->first == 4.5); + assert(r->second == 4); + + r = c.insert(P(5.5, 4)); + assert(c.size() == 4); + assert(r->first == 5.5); + assert(r->second == 4); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef C::iterator R; + typedef C::value_type P; + C c; + R r = c.insert(P(3.5, 3)); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + r = c.insert(P(3.5, 4)); + assert(c.size() == 2); + assert(r->first == 3.5); + assert(r->second == 4); + + r = c.insert(P(4.5, 4)); + assert(c.size() == 3); + assert(r->first == 4.5); + assert(r->second == 4); + + r = c.insert(P(5.5, 4)); + assert(c.size() == 4); + assert(r->first == 5.5); + assert(r->second == 4); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_const_lvalue.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_const_lvalue.pass.cpp new file mode 100644 index 00000000000..c7cb1f4c014 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_const_lvalue.pass.cpp @@ -0,0 +1,97 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// iterator insert(const_iterator p, const value_type& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5, 3)); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + r = c.insert(c.end(), P(3.5, 4)); + assert(c.size() == 2); + assert(r->first == 3.5); + assert(r->second == 4); + + r = c.insert(c.end(), P(4.5, 4)); + assert(c.size() == 3); + assert(r->first == 4.5); + assert(r->second == 4); + + r = c.insert(c.end(), P(5.5, 4)); + assert(c.size() == 4); + assert(r->first == 5.5); + assert(r->second == 4); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5, 3)); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + r = c.insert(c.end(), P(3.5, 4)); + assert(c.size() == 2); + assert(r->first == 3.5); + assert(r->second == 4); + + r = c.insert(c.end(), P(4.5, 4)); + assert(c.size() == 3); + assert(r->first == 4.5); + assert(r->second == 4); + + r = c.insert(c.end(), P(5.5, 4)); + assert(c.size() == 4); + assert(r->first == 5.5); + assert(r->second == 4); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + typedef std::unordered_multimap C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C c2; + C::const_iterator e = c2.end(); + P v(3.5, 3); + R r = c.insert(e, v); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_rvalue.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_rvalue.pass.cpp new file mode 100644 index 00000000000..bb89c3f1bca --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_hint_rvalue.pass.cpp @@ -0,0 +1,156 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// template ::value>::type> +// iterator insert(const_iterator p, P&& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef C::iterator R; + typedef std::pair P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5, 3)); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + r = c.insert(r, P(3.5, 4)); + assert(c.size() == 2); + assert(r->first == 3.5); + assert(r->second == 4); + + r = c.insert(c.end(), P(4.5, 4)); + assert(c.size() == 3); + assert(r->first == 4.5); + assert(r->second == 4); + + r = c.insert(c.end(), P(5.5, 4)); + assert(c.size() == 4); + assert(r->first == 5.5); + assert(r->second == 4); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multimap C; + typedef C::iterator R; + typedef std::pair P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3, 3)); + assert(c.size() == 1); + assert(r->first == 3); + assert(r->second == 3); + + r = c.insert(r, P(3, 4)); + assert(c.size() == 2); + assert(r->first == 3); + assert(r->second == 4); + + r = c.insert(c.end(), P(4, 4)); + assert(c.size() == 3); + assert(r->first == 4); + assert(r->second == 4); + + r = c.insert(c.end(), P(5, 4)); + assert(c.size() == 4); + assert(r->first == 5); + assert(r->second == 4); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef C::iterator R; + typedef std::pair P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5, 3)); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + r = c.insert(r, P(3.5, 4)); + assert(c.size() == 2); + assert(r->first == 3.5); + assert(r->second == 4); + + r = c.insert(c.end(), P(4.5, 4)); + assert(c.size() == 3); + assert(r->first == 4.5); + assert(r->second == 4); + + r = c.insert(c.end(), P(5.5, 4)); + assert(c.size() == 4); + assert(r->first == 5.5); + assert(r->second == 4); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef C::iterator R; + typedef std::pair P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3, 3)); + assert(c.size() == 1); + assert(r->first == 3); + assert(r->second == 3); + + r = c.insert(r, P(3, 4)); + assert(c.size() == 2); + assert(r->first == 3); + assert(r->second == 4); + + r = c.insert(c.end(), P(4, 4)); + assert(c.size() == 3); + assert(r->first == 4); + assert(r->second == 4); + + r = c.insert(c.end(), P(5, 4)); + assert(c.size() == 4); + assert(r->first == 5); + assert(r->second == 4); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_DEBUG >= 1 + { + typedef std::unordered_multimap C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C c2; + C::const_iterator e = c2.end(); + R r = c.insert(e, P(3.5, 3)); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_init.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_init.pass.cpp new file mode 100644 index 00000000000..23dbe84a3c5 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_init.pass.cpp @@ -0,0 +1,122 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// void insert(initializer_list il); + +#include +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_multimap C; + typedef std::pair P; + C c; + c.insert( + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + } + ); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::iterator k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 2); + assert(k->second == "two"); + ++k; + assert(k->first == 2); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 4); + assert(k->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + C c; + c.insert( + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + } + ); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::iterator k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 2); + assert(k->second == "two"); + ++k; + assert(k->first == 2); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 4); + assert(k->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_range.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_range.pass.cpp new file mode 100644 index 00000000000..2820639b4ea --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_range.pass.cpp @@ -0,0 +1,121 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// template +// void insert(InputIterator first, InputIterator last); + +#include +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c; + c.insert(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::iterator k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 2); + assert(k->second == "two"); + ++k; + assert(k->first == 2); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 4); + assert(k->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef std::pair P; + P a[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c; + c.insert(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(c.size() == 6); + typedef std::pair Eq; + Eq eq = c.equal_range(1); + assert(std::distance(eq.first, eq.second) == 2); + C::iterator k = eq.first; + assert(k->first == 1); + assert(k->second == "one"); + ++k; + assert(k->first == 1); + assert(k->second == "four"); + eq = c.equal_range(2); + assert(std::distance(eq.first, eq.second) == 2); + k = eq.first; + assert(k->first == 2); + assert(k->second == "two"); + ++k; + assert(k->first == 2); + assert(k->second == "four"); + eq = c.equal_range(3); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 3); + assert(k->second == "three"); + eq = c.equal_range(4); + assert(std::distance(eq.first, eq.second) == 1); + k = eq.first; + assert(k->first == 4); + assert(k->second == "four"); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_rvalue.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_rvalue.pass.cpp new file mode 100644 index 00000000000..f3637587efe --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.modifiers/insert_rvalue.pass.cpp @@ -0,0 +1,136 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// template ::value>::type> +// iterator insert(P&& x); + +#include +#include + +#include "../../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multimap C; + typedef C::iterator R; + typedef std::pair P; + C c; + R r = c.insert(P(3.5, 3)); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + r = c.insert(P(3.5, 4)); + assert(c.size() == 2); + assert(r->first == 3.5); + assert(r->second == 4); + + r = c.insert(P(4.5, 4)); + assert(c.size() == 3); + assert(r->first == 4.5); + assert(r->second == 4); + + r = c.insert(P(5.5, 4)); + assert(c.size() == 4); + assert(r->first == 5.5); + assert(r->second == 4); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multimap C; + typedef C::iterator R; + typedef std::pair P; + C c; + R r = c.insert(P(3, 3)); + assert(c.size() == 1); + assert(r->first == 3); + assert(r->second == 3); + + r = c.insert(P(3, 4)); + assert(c.size() == 2); + assert(r->first == 3); + assert(r->second == 4); + + r = c.insert(P(4, 4)); + assert(c.size() == 3); + assert(r->first == 4); + assert(r->second == 4); + + r = c.insert(P(5, 4)); + assert(c.size() == 4); + assert(r->first == 5); + assert(r->second == 4); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef C::iterator R; + typedef std::pair P; + C c; + R r = c.insert(P(3.5, 3)); + assert(c.size() == 1); + assert(r->first == 3.5); + assert(r->second == 3); + + r = c.insert(P(3.5, 4)); + assert(c.size() == 2); + assert(r->first == 3.5); + assert(r->second == 4); + + r = c.insert(P(4.5, 4)); + assert(c.size() == 3); + assert(r->first == 4.5); + assert(r->second == 4); + + r = c.insert(P(5.5, 4)); + assert(c.size() == 4); + assert(r->first == 5.5); + assert(r->second == 4); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multimap, std::equal_to, + min_allocator>> C; + typedef C::iterator R; + typedef std::pair P; + C c; + R r = c.insert(P(3, 3)); + assert(c.size() == 1); + assert(r->first == 3); + assert(r->second == 3); + + r = c.insert(P(3, 4)); + assert(c.size() == 2); + assert(r->first == 3); + assert(r->second == 4); + + r = c.insert(P(4, 4)); + assert(c.size() == 3); + assert(r->first == 4); + assert(r->second == 4); + + r = c.insert(P(5, 4)); + assert(c.size() == 4); + assert(r->first == 5); + assert(r->second == 4); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.swap/db_swap_1.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.swap/db_swap_1.pass.cpp new file mode 100644 index 00000000000..a332b6fa418 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.swap/db_swap_1.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// void swap(unordered_multimap& x, unordered_multimap& y); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +int main() +{ +#if _LIBCPP_DEBUG >= 1 + { + typedef std::pair P; + P a1[] = {P(1, 1), P(3, 3), P(7, 7), P(9, 9), P(10, 10)}; + P a2[] = {P(0, 0), P(2, 2), P(4, 4), P(5, 5), P(6, 6), P(8, 8), P(11, 11)}; + std::unordered_multimap c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::unordered_multimap c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + std::unordered_multimap::iterator i1 = c1.begin(); + std::unordered_multimap::iterator i2 = c2.begin(); + swap(c1, c2); + c1.erase(i2); + c2.erase(i1); + std::unordered_multimap::iterator j = i1; + c1.erase(i1); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..a7700b4de69 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_noexcept.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(unordered_multimap& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + + some_comp() {} + some_comp(const some_comp&) {} +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash() {} + some_hash(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_multimap C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_multimap, + std::equal_to, test_allocator>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_multimap, + std::equal_to, other_allocator>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_multimap> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_multimap, + some_comp> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_non_member.pass.cpp b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_non_member.pass.cpp new file mode 100644 index 00000000000..0f579e09168 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multimap/unord.multimap.swap/swap_non_member.pass.cpp @@ -0,0 +1,584 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator>> +// class unordered_multimap + +// void swap(unordered_multimap& __u); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.find(10)->second == "ten"); + assert(c1.find(20)->second == "twenty"); + assert(c1.find(30)->second == "thirty"); + assert(c1.find(40)->second == "forty"); + assert(c1.find(50)->second == "fifty"); + assert(c1.find(60)->second == "sixty"); + assert(c1.find(70)->second == "seventy"); + assert(c1.find(80)->second == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.find(1)->second == "one"); + assert(next(c2.find(1))->second == "four"); + assert(c2.find(2)->second == "two"); + assert(next(c2.find(2))->second == "four"); + assert(c2.find(3)->second == "three"); + assert(c2.find(4)->second == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.find(10)->second == "ten"); + assert(c1.find(20)->second == "twenty"); + assert(c1.find(30)->second == "thirty"); + assert(c1.find(40)->second == "forty"); + assert(c1.find(50)->second == "fifty"); + assert(c1.find(60)->second == "sixty"); + assert(c1.find(70)->second == "seventy"); + assert(c1.find(80)->second == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.find(1)->second == "one"); + assert(next(c2.find(1))->second == "four"); + assert(c2.find(2)->second == "two"); + assert(next(c2.find(2))->second == "four"); + assert(c2.find(3)->second == "three"); + assert(c2.find(4)->second == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.find(10)->second == "ten"); + assert(c1.find(20)->second == "twenty"); + assert(c1.find(30)->second == "thirty"); + assert(c1.find(40)->second == "forty"); + assert(c1.find(50)->second == "fifty"); + assert(c1.find(60)->second == "sixty"); + assert(c1.find(70)->second == "seventy"); + assert(c1.find(80)->second == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.find(1)->second == "one"); + assert(next(c2.find(1))->second == "four"); + assert(c2.find(2)->second == "two"); + assert(next(c2.find(2))->second == "four"); + assert(c2.find(3)->second == "three"); + assert(c2.find(4)->second == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.find(10)->second == "ten"); + assert(c1.find(20)->second == "twenty"); + assert(c1.find(30)->second == "thirty"); + assert(c1.find(40)->second == "forty"); + assert(c1.find(50)->second == "fifty"); + assert(c1.find(60)->second == "sixty"); + assert(c1.find(70)->second == "seventy"); + assert(c1.find(80)->second == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.find(1)->second == "one"); + assert(next(c2.find(1))->second == "four"); + assert(c2.find(2)->second == "two"); + assert(next(c2.find(2))->second == "four"); + assert(c2.find(3)->second == "three"); + assert(c2.find(4)->second == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.find(10)->second == "ten"); + assert(c1.find(20)->second == "twenty"); + assert(c1.find(30)->second == "thirty"); + assert(c1.find(40)->second == "forty"); + assert(c1.find(50)->second == "fifty"); + assert(c1.find(60)->second == "sixty"); + assert(c1.find(70)->second == "seventy"); + assert(c1.find(80)->second == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.find(1)->second == "one"); + assert(next(c2.find(1))->second == "four"); + assert(c2.find(2)->second == "two"); + assert(next(c2.find(2))->second == "four"); + assert(c2.find(3)->second == "three"); + assert(c2.find(4)->second == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator > Alloc; + typedef std::unordered_multimap C; + typedef std::pair P; + P a1[] = + { + P(1, "one"), + P(2, "two"), + P(3, "three"), + P(4, "four"), + P(1, "four"), + P(2, "four"), + }; + P a2[] = + { + P(10, "ten"), + P(20, "twenty"), + P(30, "thirty"), + P(40, "forty"), + P(50, "fifty"), + P(60, "sixty"), + P(70, "seventy"), + P(80, "eighty"), + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(c1.find(10)->second == "ten"); + assert(c1.find(20)->second == "twenty"); + assert(c1.find(30)->second == "thirty"); + assert(c1.find(40)->second == "forty"); + assert(c1.find(50)->second == "fifty"); + assert(c1.find(60)->second == "sixty"); + assert(c1.find(70)->second == "seventy"); + assert(c1.find(80)->second == "eighty"); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.find(1)->second == "one"); + assert(next(c2.find(1))->second == "four"); + assert(c2.find(2)->second == "two"); + assert(next(c2.find(2))->second == "four"); + assert(c2.find(3)->second == "three"); + assert(c2.find(4)->second == "four"); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/bucket.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/bucket.pass.cpp new file mode 100644 index 00000000000..0293133d494 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/bucket.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// size_type bucket(const key_type& __k) const; + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(std::begin(a), std::end(a)); + size_t bc = c.bucket_count(); + assert(bc >= 7); + for (size_t i = 0; i < 13; ++i) + assert(c.bucket(i) == i % bc); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(std::begin(a), std::end(a)); + size_t bc = c.bucket_count(); + assert(bc >= 7); + for (size_t i = 0; i < 13; ++i) + assert(c.bucket(i) == i % bc); + } +#endif +#if _LIBCPP_DEBUG_LEVEL >= 1 + { + typedef std::unordered_multiset C; + C c; + C::size_type i = c.bucket(3); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/bucket_count.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/bucket_count.pass.cpp new file mode 100644 index 00000000000..c7842e5c197 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/bucket_count.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// size_type bucket_count() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef C::const_iterator I; + typedef int P; + const C c; + assert(c.bucket_count() == 0); + } + { + typedef std::unordered_multiset C; + typedef C::const_iterator I; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 11); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef C::const_iterator I; + typedef int P; + const C c; + assert(c.bucket_count() == 0); + } + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef C::const_iterator I; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 11); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/bucket_size.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/bucket_size.pass.cpp new file mode 100644 index 00000000000..639d7ac3796 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/bucket_size.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// size_type bucket_size(size_type n) const + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 7); + assert(c.bucket_size(0) == 0); + assert(c.bucket_size(1) == 2); + assert(c.bucket_size(2) == 2); + assert(c.bucket_size(3) == 1); + assert(c.bucket_size(4) == 1); + assert(c.bucket_size(5) == 0); + assert(c.bucket_size(6) == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 7); + assert(c.bucket_size(0) == 0); + assert(c.bucket_size(1) == 2); + assert(c.bucket_size(2) == 2); + assert(c.bucket_size(3) == 1); + assert(c.bucket_size(4) == 1); + assert(c.bucket_size(5) == 0); + assert(c.bucket_size(6) == 0); + } +#endif +#if _LIBCPP_DEBUG_LEVEL >= 1 + { + typedef std::unordered_multiset C; + C c; + C::size_type i = c.bucket_size(3); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/clear.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/clear.pass.cpp new file mode 100644 index 00000000000..61ca847e7c4 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/clear.pass.cpp @@ -0,0 +1,60 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// void clear() + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + c.clear(); + assert(c.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + c.clear(); + assert(c.size() == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/count.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/count.pass.cpp new file mode 100644 index 00000000000..e548324d954 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/count.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// size_type count(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + assert(c.count(30) == 1); + assert(c.count(50) == 3); + assert(c.count(5) == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + assert(c.count(30) == 1); + assert(c.count(50) == 3); + assert(c.count(5) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/db_iterators_7.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/db_iterators_7.pass.cpp new file mode 100644 index 00000000000..c8ef2fbca16 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/db_iterators_7.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Increment iterator past end. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::unordered_multiset C; + C c(1); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::unordered_multiset> C; + C c(1); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multiset/db_iterators_8.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/db_iterators_8.pass.cpp new file mode 100644 index 00000000000..eef79978794 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/db_iterators_8.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Dereference non-dereferenceable iterator. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::unordered_multiset C; + C c(1); + C::iterator i = c.end(); + T j = *i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::unordered_multiset> C; + C c(1); + C::iterator i = c.end(); + T j = *i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multiset/db_local_iterators_7.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/db_local_iterators_7.pass.cpp new file mode 100644 index 00000000000..c1de95cace7 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/db_local_iterators_7.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Increment local_iterator past end. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::unordered_multiset C; + C c(1); + C::local_iterator i = c.begin(0); + ++i; + ++i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::unordered_multiset> C; + C c(1); + C::local_iterator i = c.begin(0); + ++i; + ++i; + assert(false); + } +#endif + +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multiset/db_local_iterators_8.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/db_local_iterators_8.pass.cpp new file mode 100644 index 00000000000..962b85298ae --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/db_local_iterators_8.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Dereference non-dereferenceable iterator. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::unordered_multiset C; + C c(1); + C::local_iterator i = c.end(0); + T j = *i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::unordered_multiset> C; + C c(1); + C::local_iterator i = c.end(0); + T j = *i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multiset/emplace.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/emplace.pass.cpp new file mode 100644 index 00000000000..13787d9b403 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/emplace.pass.cpp @@ -0,0 +1,64 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// template +// iterator emplace(Args&&... args); + +#include +#include + +#include "../../Emplaceable.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multiset C; + typedef C::iterator R; + C c; + R r = c.emplace(); + assert(c.size() == 1); + assert(*r == Emplaceable()); + + r = c.emplace(Emplaceable(5, 6)); + assert(c.size() == 2); + assert(*r == Emplaceable(5, 6)); + + r = c.emplace(5, 6); + assert(c.size() == 3); + assert(*r == Emplaceable(5, 6)); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef C::iterator R; + C c; + R r = c.emplace(); + assert(c.size() == 1); + assert(*r == Emplaceable()); + + r = c.emplace(Emplaceable(5, 6)); + assert(c.size() == 2); + assert(*r == Emplaceable(5, 6)); + + r = c.emplace(5, 6); + assert(c.size() == 3); + assert(*r == Emplaceable(5, 6)); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/emplace_hint.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/emplace_hint.pass.cpp new file mode 100644 index 00000000000..8885cc03cf0 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/emplace_hint.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// template +// iterator emplace_hint(const_iterator p, Args&&... args); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "../../Emplaceable.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multiset C; + typedef C::iterator R; + C c; + C::const_iterator e = c.end(); + R r = c.emplace_hint(e); + assert(c.size() == 1); + assert(*r == Emplaceable()); + + r = c.emplace_hint(c.end(), Emplaceable(5, 6)); + assert(c.size() == 2); + assert(*r == Emplaceable(5, 6)); + + r = c.emplace_hint(r, 5, 6); + assert(c.size() == 3); + assert(*r == Emplaceable(5, 6)); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef C::iterator R; + C c; + C::const_iterator e = c.end(); + R r = c.emplace_hint(e); + assert(c.size() == 1); + assert(*r == Emplaceable()); + + r = c.emplace_hint(c.end(), Emplaceable(5, 6)); + assert(c.size() == 2); + assert(*r == Emplaceable(5, 6)); + + r = c.emplace_hint(r, 5, 6); + assert(c.size() == 3); + assert(*r == Emplaceable(5, 6)); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + typedef std::unordered_multiset C; + typedef C::iterator R; + C c1; + C c2; + R r = c1.emplace_hint(c2.begin(), 5, 6); + assert(false); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/eq.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/eq.pass.cpp new file mode 100644 index 00000000000..bbedbc905a4 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/eq.pass.cpp @@ -0,0 +1,180 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// bool +// operator==(const unordered_multiset& x, +// const unordered_multiset& y); +// +// template +// bool +// operator!=(const unordered_multiset& x, +// const unordered_multiset& y); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c1(std::begin(a), std::end(a)); + const C c2; + assert(!(c1 == c2)); + assert( (c1 != c2)); + } + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c1(std::begin(a), std::end(a)); + const C c2 = c1; + assert( (c1 == c2)); + assert(!(c1 != c2)); + } + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a), std::end(a)); + C c2 = c1; + c2.rehash(30); + assert( (c1 == c2)); + assert(!(c1 != c2)); + c2.insert(P(90)); + assert(!(c1 == c2)); + assert( (c1 != c2)); + c1.insert(P(90)); + assert( (c1 == c2)); + assert(!(c1 != c2)); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c1(std::begin(a), std::end(a)); + const C c2; + assert(!(c1 == c2)); + assert( (c1 != c2)); + } + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c1(std::begin(a), std::end(a)); + const C c2 = c1; + assert( (c1 == c2)); + assert(!(c1 != c2)); + } + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a), std::end(a)); + C c2 = c1; + c2.rehash(30); + assert( (c1 == c2)); + assert(!(c1 != c2)); + c2.insert(P(90)); + assert(!(c1 == c2)); + assert( (c1 != c2)); + c1.insert(P(90)); + assert( (c1 == c2)); + assert(!(c1 != c2)); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/equal_range_const.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/equal_range_const.pass.cpp new file mode 100644 index 00000000000..a0aaac2bd86 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/equal_range_const.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// pair equal_range(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef C::const_iterator I; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + std::pair r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(*r.first == 30); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + r = c.equal_range(50); + assert(std::distance(r.first, r.second) == 3); + assert(*r.first == 50); + ++r.first; + assert(*r.first == 50); + ++r.first; + assert(*r.first == 50); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef C::const_iterator I; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + std::pair r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(*r.first == 30); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + r = c.equal_range(50); + assert(std::distance(r.first, r.second) == 3); + assert(*r.first == 50); + ++r.first; + assert(*r.first == 50); + ++r.first; + assert(*r.first == 50); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/equal_range_non_const.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/equal_range_non_const.pass.cpp new file mode 100644 index 00000000000..73d44f7a56b --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/equal_range_non_const.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// pair equal_range(const key_type& k); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef C::iterator I; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + C c(std::begin(a), std::end(a)); + std::pair r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(*r.first == 30); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + r = c.equal_range(50); + assert(std::distance(r.first, r.second) == 3); + assert(*r.first == 50); + ++r.first; + assert(*r.first == 50); + ++r.first; + assert(*r.first == 50); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef C::iterator I; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + C c(std::begin(a), std::end(a)); + std::pair r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(*r.first == 30); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + r = c.equal_range(50); + assert(std::distance(r.first, r.second) == 3); + assert(*r.first == 50); + ++r.first; + assert(*r.first == 50); + ++r.first; + assert(*r.first == 50); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/erase_const_iter.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/erase_const_iter.pass.cpp new file mode 100644 index 00000000000..6a005d3e3ba --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/erase_const_iter.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// iterator erase(const_iterator p) + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::iterator j = c.erase(i); + assert(c.size() == 5); + assert(c.count(1) == 2); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::iterator j = c.erase(i); + assert(c.size() == 5); + assert(c.count(1) == 2); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/erase_iter_db1.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/erase_iter_db1.pass.cpp new file mode 100644 index 00000000000..baad3858bd4 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/erase_iter_db1.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator position) with end() + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::unordered_multiset l1(a1, a1+3); + std::unordered_multiset::const_iterator i = l1.end(); + l1.erase(i); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multiset/erase_iter_db2.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/erase_iter_db2.pass.cpp new file mode 100644 index 00000000000..a21f29ef7b4 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/erase_iter_db2.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator position) with iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::unordered_multiset l1(a1, a1+3); + std::unordered_multiset l2(a1, a1+3); + std::unordered_multiset::const_iterator i = l2.begin(); + l1.erase(i); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multiset/erase_iter_iter_db1.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/erase_iter_iter_db1.pass.cpp new file mode 100644 index 00000000000..03c9ec5d048 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/erase_iter_iter_db1.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with first iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::unordered_multiset l1(a1, a1+3); + std::unordered_multiset l2(a1, a1+3); + std::unordered_multiset::iterator i = l1.erase(l2.cbegin(), next(l1.cbegin())); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multiset/erase_iter_iter_db2.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/erase_iter_iter_db2.pass.cpp new file mode 100644 index 00000000000..4c6f209f1a4 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/erase_iter_iter_db2.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with second iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::unordered_multiset l1(a1, a1+3); + std::unordered_multiset l2(a1, a1+3); + std::unordered_multiset::iterator i = l1.erase(l1.cbegin(), next(l2.cbegin())); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multiset/erase_iter_iter_db3.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/erase_iter_iter_db3.pass.cpp new file mode 100644 index 00000000000..5ce378974c9 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/erase_iter_iter_db3.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with both iterators from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::unordered_multiset l1(a1, a1+3); + std::unordered_multiset l2(a1, a1+3); + std::unordered_multiset::iterator i = l1.erase(l2.cbegin(), next(l2.cbegin())); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multiset/erase_iter_iter_db4.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/erase_iter_iter_db4.pass.cpp new file mode 100644 index 00000000000..7c362a2a2b1 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/erase_iter_iter_db4.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with a bad range + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::unordered_multiset l1(a1, a1+3); + std::unordered_multiset::iterator i = l1.erase(next(l1.cbegin()), l1.cbegin()); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.multiset/erase_key.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/erase_key.pass.cpp new file mode 100644 index 00000000000..7c243973f16 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/erase_key.pass.cpp @@ -0,0 +1,176 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// size_type erase(const key_type& k); + +#include +#include +#include + +#include "min_allocator.h" + +#if __cplusplus >= 201103L +template +bool only_deletions ( const Unordered &whole, const Unordered &part ) { + typename Unordered::const_iterator w = whole.begin(); + typename Unordered::const_iterator p = part.begin(); + + while ( w != whole.end () && p != part.end()) { + if ( *w == *p ) + p++; + w++; + } + + return p == part.end(); +} +#endif + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.erase(5) == 0); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + assert(c.erase(2) == 2); + assert(c.size() == 4); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + assert(c.erase(2) == 0); + assert(c.size() == 4); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + assert(c.erase(4) == 1); + assert(c.size() == 3); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + + assert(c.erase(4) == 0); + assert(c.size() == 3); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + + assert(c.erase(1) == 2); + assert(c.size() == 1); + assert(c.count(3) == 1); + + assert(c.erase(1) == 0); + assert(c.size() == 1); + assert(c.count(3) == 1); + + assert(c.erase(3) == 1); + assert(c.size() == 0); + + assert(c.erase(3) == 0); + assert(c.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.erase(5) == 0); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + assert(c.erase(2) == 2); + assert(c.size() == 4); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + assert(c.erase(2) == 0); + assert(c.size() == 4); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + assert(c.erase(4) == 1); + assert(c.size() == 3); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + + assert(c.erase(4) == 0); + assert(c.size() == 3); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + + assert(c.erase(1) == 2); + assert(c.size() == 1); + assert(c.count(3) == 1); + + assert(c.erase(1) == 0); + assert(c.size() == 1); + assert(c.count(3) == 1); + + assert(c.erase(3) == 1); + assert(c.size() == 0); + + assert(c.erase(3) == 0); + assert(c.size() == 0); + } + { + typedef std::unordered_multiset C; + C m, m2; + for ( int i = 0; i < 10; ++i ) { + m.insert(i); m.insert(i); + m2.insert(i); m2.insert(i); + } + + C::iterator i = m2.begin(); + int ctr = 0; + while (i != m2.end()) { + if (ctr++ % 2 == 0) + m2.erase(i++); + else + ++i; + } + + assert (only_deletions (m, m2)); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/erase_range.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/erase_range.pass.cpp new file mode 100644 index 00000000000..baac08eddc1 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/erase_range.pass.cpp @@ -0,0 +1,94 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// iterator erase(const_iterator first, const_iterator last) + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::const_iterator j = next(i, 2); + C::iterator k = c.erase(i, i); + assert(k == i); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + k = c.erase(i, j); + assert(c.size() == 4); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + k = c.erase(c.cbegin(), c.cend()); + assert(c.size() == 0); + assert(k == c.end()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::const_iterator j = next(i, 2); + C::iterator k = c.erase(i, i); + assert(k == i); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + k = c.erase(i, j); + assert(c.size() == 4); + assert(c.count(1) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + k = c.erase(c.cbegin(), c.cend()); + assert(c.size() == 0); + assert(k == c.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/find_const.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/find_const.pass.cpp new file mode 100644 index 00000000000..5caaf207aaf --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/find_const.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// const_iterator find(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + C::const_iterator i = c.find(30); + assert(*i == 30); + i = c.find(5); + assert(i == c.cend()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + C::const_iterator i = c.find(30); + assert(*i == 30); + i = c.find(5); + assert(i == c.cend()); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/find_non_const.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/find_non_const.pass.cpp new file mode 100644 index 00000000000..030487863f9 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/find_non_const.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// iterator find(const key_type& k); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c(std::begin(a), std::end(a)); + C::iterator i = c.find(30); + assert(*i == 30); + i = c.find(5); + assert(i == c.cend()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c(std::begin(a), std::end(a)); + C::iterator i = c.find(30); + assert(*i == 30); + i = c.find(5); + assert(i == c.cend()); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/insert_const_lvalue.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/insert_const_lvalue.pass.cpp new file mode 100644 index 00000000000..0051e497fd7 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/insert_const_lvalue.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// iterator insert(const value_type& x); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef C::iterator R; + typedef C::value_type P; + C c; + R r = c.insert(P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(P(3.5)); + assert(c.size() == 2); + assert(*r == 3.5); + + r = c.insert(P(4.5)); + assert(c.size() == 3); + assert(*r == 4.5); + + r = c.insert(P(5.5)); + assert(c.size() == 4); + assert(*r == 5.5); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef C::iterator R; + typedef C::value_type P; + C c; + R r = c.insert(P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(P(3.5)); + assert(c.size() == 2); + assert(*r == 3.5); + + r = c.insert(P(4.5)); + assert(c.size() == 3); + assert(*r == 4.5); + + r = c.insert(P(5.5)); + assert(c.size() == 4); + assert(*r == 5.5); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/insert_hint_const_lvalue.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/insert_hint_const_lvalue.pass.cpp new file mode 100644 index 00000000000..25b4bc1aa04 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/insert_hint_const_lvalue.pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// iterator insert(const_iterator p, const value_type& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(c.end(), P(3.5)); + assert(c.size() == 2); + assert(*r == 3.5); + + r = c.insert(c.end(), P(4.5)); + assert(c.size() == 3); + assert(*r == 4.5); + + r = c.insert(c.end(), P(5.5)); + assert(c.size() == 4); + assert(*r == 5.5); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(c.end(), P(3.5)); + assert(c.size() == 2); + assert(*r == 3.5); + + r = c.insert(c.end(), P(4.5)); + assert(c.size() == 3); + assert(*r == 4.5); + + r = c.insert(c.end(), P(5.5)); + assert(c.size() == 4); + assert(*r == 5.5); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + typedef std::unordered_multiset C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C c2; + C::const_iterator e = c2.end(); + P v(3.5); + R r = c.insert(e, v); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/insert_hint_rvalue.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/insert_hint_rvalue.pass.cpp new file mode 100644 index 00000000000..634e4f4a176 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/insert_hint_rvalue.pass.cpp @@ -0,0 +1,138 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// iterator insert(const_iterator p, value_type&& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef C::iterator R; + typedef double P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(r, P(3.5)); + assert(c.size() == 2); + assert(*r == 3.5); + + r = c.insert(c.end(), P(4.5)); + assert(c.size() == 3); + assert(*r == 4.5); + + r = c.insert(c.end(), P(5.5)); + assert(c.size() == 4); + assert(*r == 5.5); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multiset C; + typedef C::iterator R; + typedef MoveOnly P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3)); + assert(c.size() == 1); + assert(*r == 3); + + r = c.insert(r, P(3)); + assert(c.size() == 2); + assert(*r == 3); + + r = c.insert(c.end(), P(4)); + assert(c.size() == 3); + assert(*r == 4); + + r = c.insert(c.end(), P(5)); + assert(c.size() == 4); + assert(*r == 5); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef C::iterator R; + typedef double P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(r, P(3.5)); + assert(c.size() == 2); + assert(*r == 3.5); + + r = c.insert(c.end(), P(4.5)); + assert(c.size() == 3); + assert(*r == 4.5); + + r = c.insert(c.end(), P(5.5)); + assert(c.size() == 4); + assert(*r == 5.5); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef C::iterator R; + typedef MoveOnly P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3)); + assert(c.size() == 1); + assert(*r == 3); + + r = c.insert(r, P(3)); + assert(c.size() == 2); + assert(*r == 3); + + r = c.insert(c.end(), P(4)); + assert(c.size() == 3); + assert(*r == 4); + + r = c.insert(c.end(), P(5)); + assert(c.size() == 4); + assert(*r == 5); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_DEBUG >= 1 + { + typedef std::unordered_multiset C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C c2; + C::const_iterator e = c2.end(); + R r = c.insert(e, P(3.5)); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/insert_init.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/insert_init.pass.cpp new file mode 100644 index 00000000000..6941d86f619 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/insert_init.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// void insert(initializer_list il); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_multiset C; + typedef int P; + C c; + c.insert( + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + } + ); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + C c; + c.insert( + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + } + ); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/insert_range.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/insert_range.pass.cpp new file mode 100644 index 00000000000..41c9d8136fe --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/insert_range.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// template +// void insert(InputIterator first, InputIterator last); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c; + c.insert(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c; + c.insert(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/insert_rvalue.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/insert_rvalue.pass.cpp new file mode 100644 index 00000000000..65a5bc2eb2a --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/insert_rvalue.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// iterator insert(value_type&& x); + +#include +#include + +#include "../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef C::iterator R; + typedef double P; + C c; + R r = c.insert(P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(P(3.5)); + assert(c.size() == 2); + assert(*r == 3.5); + + r = c.insert(P(4.5)); + assert(c.size() == 3); + assert(*r == 4.5); + + r = c.insert(P(5.5)); + assert(c.size() == 4); + assert(*r == 5.5); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multiset C; + typedef C::iterator R; + typedef MoveOnly P; + C c; + R r = c.insert(P(3)); + assert(c.size() == 1); + assert(*r == 3); + + r = c.insert(P(3)); + assert(c.size() == 2); + assert(*r == 3); + + r = c.insert(P(4)); + assert(c.size() == 3); + assert(*r == 4); + + r = c.insert(P(5)); + assert(c.size() == 4); + assert(*r == 5); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef C::iterator R; + typedef double P; + C c; + R r = c.insert(P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(P(3.5)); + assert(c.size() == 2); + assert(*r == 3.5); + + r = c.insert(P(4.5)); + assert(c.size() == 3); + assert(*r == 4.5); + + r = c.insert(P(5.5)); + assert(c.size() == 4); + assert(*r == 5.5); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef C::iterator R; + typedef MoveOnly P; + C c; + R r = c.insert(P(3)); + assert(c.size() == 1); + assert(*r == 3); + + r = c.insert(P(3)); + assert(c.size() == 2); + assert(*r == 3); + + r = c.insert(P(4)); + assert(c.size() == 3); + assert(*r == 4); + + r = c.insert(P(5)); + assert(c.size() == 4); + assert(*r == 5); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/iterators.fail.cpp b/libcxx/test/std/containers/unord/unord.multiset/iterators.fail.cpp new file mode 100644 index 00000000000..f78bccbd423 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/iterators.fail.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// iterator begin() {return __table_.begin();} +// iterator end() {return __table_.end();} +// const_iterator begin() const {return __table_.begin();} +// const_iterator end() const {return __table_.end();} +// const_iterator cbegin() const {return __table_.begin();} +// const_iterator cend() const {return __table_.end();} + +#include +#include + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::iterator i = c.begin(); + assert(*i == 1); + *i = 2; + } + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + } +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/iterators.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/iterators.pass.cpp new file mode 100644 index 00000000000..be95b44517f --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/iterators.pass.cpp @@ -0,0 +1,127 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// iterator begin(); +// iterator end(); +// const_iterator begin() const; +// const_iterator end() const; +// const_iterator cbegin() const; +// const_iterator cend() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::iterator i; + } + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::const_iterator i; + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::iterator i; + } + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::const_iterator i; + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + typedef std::unordered_multiset C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/load_factor.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/load_factor.pass.cpp new file mode 100644 index 00000000000..07980c2afc8 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/load_factor.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// float load_factor() const + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + } + { + typedef std::unordered_multiset C; + typedef int P; + const C c; + assert(c.load_factor() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + } + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + const C c; + assert(c.load_factor() == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/local_iterators.fail.cpp b/libcxx/test/std/containers/unord/unord.multiset/local_iterators.fail.cpp new file mode 100644 index 00000000000..4118987c2ae --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/local_iterators.fail.cpp @@ -0,0 +1,261 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// local_iterator begin (size_type n); +// local_iterator end (size_type n); +// const_local_iterator begin (size_type n) const; +// const_local_iterator end (size_type n) const; +// const_local_iterator cbegin(size_type n) const; +// const_local_iterator cend (size_type n) const; + +#include +#include + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + typedef C::local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() == 7); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + *i = 2; + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multiset C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() == 7); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multiset C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() == 7); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multiset C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() == 7); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/local_iterators.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/local_iterators.pass.cpp new file mode 100644 index 00000000000..3471707e42a --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/local_iterators.pass.cpp @@ -0,0 +1,500 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// local_iterator begin (size_type n); +// local_iterator end (size_type n); +// const_local_iterator begin (size_type n) const; +// const_local_iterator end (size_type n) const; +// const_local_iterator cbegin(size_type n) const; +// const_local_iterator cend (size_type n) const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + typedef C::local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multiset C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multiset C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multiset C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + typedef C::local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 7); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/max_bucket_count.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/max_bucket_count.pass.cpp new file mode 100644 index 00000000000..619a8cf1266 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/max_bucket_count.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// size_type max_bucket_count() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + const C c; + assert(c.max_bucket_count() > 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + const C c; + assert(c.max_bucket_count() > 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/max_load_factor.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/max_load_factor.pass.cpp new file mode 100644 index 00000000000..08f52bb7084 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/max_load_factor.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// float max_load_factor() const; +// void max_load_factor(float mlf); + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + const C c; + assert(c.max_load_factor() == 1); + } + { + typedef std::unordered_multiset C; + typedef int P; + C c; + assert(c.max_load_factor() == 1); + c.max_load_factor(2.5); + assert(c.max_load_factor() == 2.5); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + const C c; + assert(c.max_load_factor() == 1); + } + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + C c; + assert(c.max_load_factor() == 1); + c.max_load_factor(2.5); + assert(c.max_load_factor() == 2.5); + } +#endif +#if _LIBCPP_DEBUG_LEVEL >= 1 + { + typedef std::unordered_multiset C; + C c; + c.max_load_factor(0); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/max_size.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/max_size.pass.cpp new file mode 100644 index 00000000000..a5d0b5538bc --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/max_size.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// size_type max_size() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + std::unordered_multiset u; + assert(u.max_size() > 0); + } +#if __cplusplus >= 201103L + { + std::unordered_multiset, + std::equal_to, min_allocator> u; + assert(u.max_size() > 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/rehash.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/rehash.pass.cpp new file mode 100644 index 00000000000..bc8d461c60b --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/rehash.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// void rehash(size_type n); + +#include +#include + +#include "min_allocator.h" + +template +void test(const C& c) +{ + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); +} + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 7); + c.rehash(3); + assert(c.bucket_count() == 7); + test(c); + c.max_load_factor(2); + c.rehash(3); + assert(c.bucket_count() == 3); + test(c); + c.rehash(31); + assert(c.bucket_count() == 31); + test(c); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 7); + c.rehash(3); + assert(c.bucket_count() == 7); + test(c); + c.max_load_factor(2); + c.rehash(3); + assert(c.bucket_count() == 3); + test(c); + c.rehash(31); + assert(c.bucket_count() == 31); + test(c); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/reserve.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/reserve.pass.cpp new file mode 100644 index 00000000000..0c17583d371 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/reserve.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// void reserve(size_type n); + +#include +#include + +#include "min_allocator.h" + +template +void test(const C& c) +{ + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); +} + +int main() +{ + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 7); + c.reserve(3); + assert(c.bucket_count() == 7); + test(c); + c.max_load_factor(2); + c.reserve(3); + assert(c.bucket_count() == 3); + test(c); + c.reserve(31); + assert(c.bucket_count() >= 16); + test(c); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 7); + c.reserve(3); + assert(c.bucket_count() == 7); + test(c); + c.max_load_factor(2); + c.reserve(3); + assert(c.bucket_count() == 3); + test(c); + c.reserve(31); + assert(c.bucket_count() >= 16); + test(c); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/scary.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/scary.pass.cpp new file mode 100644 index 00000000000..dfd144bb317 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/scary.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// class unordered_set class unordered_multiset + +// Extension: SCARY/N2913 iterator compatibility between unordered_set and unordered_multiset + +#include + +int main() +{ + typedef std::unordered_set M1; + typedef std::unordered_multiset M2; + M2::iterator i; + M1::iterator j = i; +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/swap_member.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/swap_member.pass.cpp new file mode 100644 index 00000000000..275ff4094e8 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/swap_member.pass.cpp @@ -0,0 +1,571 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// void swap(unordered_multiset& __u); + +#include +#include + +#include "../../test_compare.h" +#include "../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/types.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/types.pass.cpp new file mode 100644 index 00000000000..5222222d819 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/types.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset +// { +// public: +// // types +// typedef Value value_type; +// typedef value_type key_type; +// typedef Hash hasher; +// typedef Pred key_equal; +// typedef Alloc allocator_type; +// typedef value_type& reference; +// typedef const value_type& const_reference; +// typedef typename allocator_traits::pointer pointer; +// typedef typename allocator_traits::const_pointer const_pointer; +// typedef typename allocator_traits::size_type size_type; +// typedef typename allocator_traits::difference_type difference_type; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset, + std::equal_to, min_allocator> C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same>::value), ""); + static_assert((std::is_same>::value), ""); + // min_allocator doesn't have a size_type, so one gets synthesized + static_assert((std::is_same::type>::value), ""); + static_assert((std::is_same::value), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/allocator.pass.cpp new file mode 100644 index 00000000000..ccd21a58b22 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/allocator.pass.cpp @@ -0,0 +1,109 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// explicit unordered_multiset(const allocator_type& __a); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + C c(test_allocator(10)); + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == test_allocator(10)); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + C c(min_allocator{}); + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == min_allocator()); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if _LIBCPP_STD_VER > 11 + { + typedef NotConstructible T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_multiset C; + + A a(43); + C c(3, a); + assert(c.bucket_count() == 3); + assert(c.hash_function() == HF()); + assert(c.key_eq() == Comp ()); + assert(c.get_allocator() == a); + assert(!(c.get_allocator() == A())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } + { + typedef NotConstructible T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_multiset C; + + HF hf(42); + A a(43); + C c(4, hf, a); + assert(c.bucket_count() == 4); + assert(c.hash_function() == hf); + assert(!(c.hash_function() == HF())); + assert(c.key_eq() == Comp ()); + assert(c.get_allocator() == a); + assert(!(c.get_allocator() == A())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_copy.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_copy.pass.cpp new file mode 100644 index 00000000000..2042f69fd77 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_copy.pass.cpp @@ -0,0 +1,209 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// unordered_multiset& operator=(const unordered_multiset& u); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_allocator A; + typedef std::unordered_multiset >, + test_compare >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(4) + ); + c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(4)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + { + typedef std::unordered_multiset C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C *p = &c; + c = *p; + + assert(c.size() == 6); + assert(std::is_permutation(c.begin(), c.end(), a)); + } + { + typedef other_allocator A; + typedef std::unordered_multiset >, + test_compare >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(4) + ); + c = c0; + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef min_allocator A; + typedef std::unordered_multiset >, + test_compare >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A() + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A() + ); + c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_init.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_init.pass.cpp new file mode 100644 index 00000000000..4eaf2c5779f --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_init.pass.cpp @@ -0,0 +1,97 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// unordered_multiset& operator=(initializer_list il); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef test_allocator A; + typedef std::unordered_multiset >, + test_compare >, + A + > C; + typedef int P; + C c = { + P(4), + P(1), + P(2) + }; + c = { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef min_allocator A; + typedef std::unordered_multiset >, + test_compare >, + A + > C; + typedef int P; + C c = { + P(4), + P(1), + P(2) + }; + c = { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_move.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_move.pass.cpp new file mode 100644 index 00000000000..4b0e52c5930 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_move.pass.cpp @@ -0,0 +1,286 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// unordered_multiset& operator=(unordered_multiset&& u); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef test_allocator A; + typedef std::unordered_multiset >, + test_compare >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(4) + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(4)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + { + typedef test_allocator A; + typedef std::unordered_multiset >, + test_compare >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(10) + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + { + typedef other_allocator A; + typedef std::unordered_multiset >, + test_compare >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(4) + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef test_allocator A; + typedef std::unordered_multiset >, + test_compare >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A() + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A() + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 4); + ++i; + assert(*i == 3); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 1); + ++i; + assert(*i == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + { + typedef min_allocator A; + typedef std::unordered_multiset >, + test_compare >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A() + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A() + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + std::unordered_multiset s1 = {1, 2, 3}; + std::unordered_multiset::iterator i = s1.begin(); + int k = *i; + std::unordered_multiset s2; + s2 = std::move(s1); + assert(*i == k); + s2.erase(i); + assert(s2.size() == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy.pass.cpp new file mode 100644 index 00000000000..94241830a06 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy.pass.cpp @@ -0,0 +1,171 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// unordered_multiset(const unordered_multiset& u); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + test_allocator(10) + ); + C c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == test_allocator(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + typedef std::unordered_multiset >, + test_compare >, + other_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + other_allocator(10) + ); + C c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == other_allocator(-2)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + min_allocator() + ); + C c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy_alloc.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy_alloc.pass.cpp new file mode 100644 index 00000000000..22e372bb3ad --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/copy_alloc.pass.cpp @@ -0,0 +1,123 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// unordered_multiset(const unordered_multiset& u, const allocator_type& a); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + test_allocator(10) + ); + C c(c0, test_allocator(5)); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == test_allocator(5)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + min_allocator() + ); + C c(c0, min_allocator()); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/default.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/default.pass.cpp new file mode 100644 index 00000000000..737ae2dae79 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/default.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// unordered_multiset(); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + C c; + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == (test_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + C c; + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == (min_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } + { + std::unordered_multiset c = {}; + assert(c.bucket_count() == 0); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/default_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/default_noexcept.pass.cpp new file mode 100644 index 00000000000..0effeed911b --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/default_noexcept.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// unordered_multiset() +// noexcept( +// is_nothrow_default_constructible::value && +// is_nothrow_default_constructible::value && +// is_nothrow_copy_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "../../../test_hash.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp(); + some_comp(const some_comp&); +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_multiset C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::unordered_multiset, + std::equal_to, test_allocator> C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::unordered_multiset, + std::equal_to, other_allocator> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::unordered_multiset> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::unordered_multiset, + some_comp> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..c4c54a5a0dd --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/dtor_noexcept.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// ~unordered_multiset() // implied noexcept; + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template +struct some_comp +{ + typedef T value_type; + ~some_comp() noexcept(false); +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); + ~some_hash() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_multiset C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::unordered_multiset, + std::equal_to, test_allocator> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::unordered_multiset, + std::equal_to, other_allocator> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::unordered_multiset> C; + static_assert(!std::is_nothrow_destructible::value, ""); + } + { + typedef std::unordered_multiset, + some_comp> C; + static_assert(!std::is_nothrow_destructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init.pass.cpp new file mode 100644 index 00000000000..416c28cf83d --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init.pass.cpp @@ -0,0 +1,163 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// unordered_multiset(initializer_list il); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + typedef int P; + C c = { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == test_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + typedef int P; + C c = { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if _LIBCPP_STD_VER > 11 + { + typedef int T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_multiset C; + + A a(42); + C c({ + T(1), + T(2), + T(3), + T(4), + T(1), + T(2) + }, 12, a); + + assert(c.bucket_count() >= 12); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == HF()); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + assert(!(c.get_allocator() == A())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + { + typedef int T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_multiset C; + + A a(42); + HF hf(43); + C c({ + T(1), + T(2), + T(3), + T(4), + T(1), + T(2) + }, 12, hf, a); + + assert(c.bucket_count() >= 12); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == hf); + assert(!(c.hash_function() == HF())); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + assert(!(c.get_allocator() == A())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size.pass.cpp new file mode 100644 index 00000000000..a6543a0e6f4 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size.pass.cpp @@ -0,0 +1,97 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// unordered_multiset(initializer_list il, size_type n); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7 + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == test_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7 + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash.pass.cpp new file mode 100644 index 00000000000..7d0f37163a1 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash.pass.cpp @@ -0,0 +1,100 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// unordered_multiset(initializer_list il, size_type n, +// const hasher& hf); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == test_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash_equal.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash_equal.pass.cpp new file mode 100644 index 00000000000..cd013f9554a --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash_equal.pass.cpp @@ -0,0 +1,102 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// unordered_multiset(initializer_list il, size_type n, +// const hasher& hf, const key_equal& eql); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == test_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash_equal_allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash_equal_allocator.pass.cpp new file mode 100644 index 00000000000..4621c7fbb3f --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/init_size_hash_equal_allocator.pass.cpp @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// unordered_multiset(initializer_list il, size_type n, +// const hasher& hf, const key_equal& eql, const allocator_type& a); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7, + test_hash >(8), + test_compare >(9), + test_allocator(10) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == test_allocator(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7, + test_hash >(8), + test_compare >(9), + min_allocator() + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move.pass.cpp new file mode 100644 index 00000000000..a68cfe8cd3b --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move.pass.cpp @@ -0,0 +1,194 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// unordered_multiset(unordered_multiset&& u); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(7, + test_hash >(8), + test_compare >(9), + test_allocator(10) + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 0); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == test_allocator(10)); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + test_allocator(10) + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == test_allocator(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(7, + test_hash >(8), + test_compare >(9), + min_allocator() + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 0); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == min_allocator()); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + min_allocator() + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + std::unordered_multiset s1 = {1, 2, 3}; + std::unordered_multiset::iterator i = s1.begin(); + int k = *i; + std::unordered_multiset s2 = std::move(s1); + assert(*i == k); + s2.erase(i); + assert(s2.size() == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_alloc.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_alloc.pass.cpp new file mode 100644 index 00000000000..9eee69a58e5 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_alloc.pass.cpp @@ -0,0 +1,213 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// unordered_multiset(unordered_multiset&& u, const allocator_type& a); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef int P; + typedef test_allocator A; + typedef std::unordered_multiset >, + test_compare >, + A + > C; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(std::move(c0), A(12)); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 1); + ++i; + assert(*i == 1); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 3); + ++i; + assert(*i == 4); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(12)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } + { + typedef int P; + typedef test_allocator A; + typedef std::unordered_multiset >, + test_compare >, + A + > C; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(std::move(c0), A(10)); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } +#if __cplusplus >= 201103L + { + typedef int P; + typedef min_allocator A; + typedef std::unordered_multiset >, + test_compare >, + A + > C; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A() + ); + C c(std::move(c0), A()); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + C::const_iterator i = c.cbegin(); + assert(*i == 4); + ++i; + assert(*i == 3); + ++i; + assert(*i == 2); + ++i; + assert(*i == 2); + ++i; + assert(*i == 1); + ++i; + assert(*i == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } + { + typedef int P; + typedef min_allocator A; + typedef std::unordered_multiset >, + test_compare >, + A + > C; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A() + ); + C c(std::move(c0), A()); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..8a56d1a4859 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_assign_noexcept.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// unordered_multiset& operator=(unordered_multiset&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable::value && +// is_nothrow_move_assignable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp& operator=(const some_comp&); +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); + some_hash& operator=(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_multiset C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::unordered_multiset, + std::equal_to, test_allocator> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::unordered_multiset, + std::equal_to, other_allocator> C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::unordered_multiset> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::unordered_multiset, + some_comp> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_noexcept.pass.cpp new file mode 100644 index 00000000000..aa7ad05afad --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/move_noexcept.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// unordered_multiset(unordered_multiset&&) +// noexcept(is_nothrow_move_constructible::value && +// is_nothrow_move_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp(const some_comp&); +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_multiset C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::unordered_multiset, + std::equal_to, test_allocator> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::unordered_multiset, + std::equal_to, other_allocator> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::unordered_multiset> C; + static_assert(!std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::unordered_multiset, + some_comp> C; + static_assert(!std::is_nothrow_move_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range.pass.cpp new file mode 100644 index 00000000000..cd2bb1e7bbc --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range.pass.cpp @@ -0,0 +1,167 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// template +// unordered_multiset(InputIterator first, InputIterator last); + +#include +#include +#include + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == test_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(c.bucket_count() >= 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if _LIBCPP_STD_VER > 11 + { + typedef int T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_multiset C; + T arr[] = + { + T(1), + T(2), + T(3), + T(4), + T(1), + T(2) + }; + A a(42); + C c(input_iterator(arr), input_iterator(arr + sizeof(arr)/sizeof(arr[0])), 12, a); + assert(c.bucket_count() >= 12); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == HF()); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + assert(!(c.get_allocator() == A())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + { + typedef int T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_multiset C; + T arr[] = + { + T(1), + T(2), + T(3), + T(4), + T(1), + T(2) + }; + HF hf(43); + A a(42); + C c(input_iterator(arr), input_iterator(arr + sizeof(arr)/sizeof(arr[0])), 16, hf, a); + assert(c.bucket_count() >= 16); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == hf); + assert(!(c.hash_function() == HF())); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + assert(!(c.get_allocator() == A())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size.pass.cpp new file mode 100644 index 00000000000..4f5e03e28f4 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size.pass.cpp @@ -0,0 +1,101 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// template +// unordered_multiset(InputIterator first, InputIterator last, size_type n); + +#include +#include +#include + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7 + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == test_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7 + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash.pass.cpp new file mode 100644 index 00000000000..6b83bde9bc5 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash.pass.cpp @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// template +// unordered_multiset(InputIterator first, InputIterator last, size_type n, +// const hasher& hf); + +#include +#include +#include + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == test_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash_equal.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash_equal.pass.cpp new file mode 100644 index 00000000000..89e7c7fa2e3 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash_equal.pass.cpp @@ -0,0 +1,106 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// template +// unordered_multiset(InputIterator first, InputIterator last, size_type n, +// const hasher& hf, const key_equal& eql); + +#include +#include +#include + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == test_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash_equal_allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash_equal_allocator.pass.cpp new file mode 100644 index 00000000000..b712a96f05b --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/range_size_hash_equal_allocator.pass.cpp @@ -0,0 +1,109 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// template +// unordered_multiset(InputIterator first, InputIterator last, size_type n, +// const hasher& hf, const key_equal& eql, +// const allocator_type& a); + +#include +#include +#include + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8), + test_compare >(9), + test_allocator(10) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == test_allocator(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8), + test_compare >(9), + min_allocator() + ); + assert(c.bucket_count() == 7); + assert(c.size() == 6); + assert(c.count(1) == 2); + assert(c.count(2) == 2); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size.fail.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size.fail.cpp new file mode 100644 index 00000000000..e55db7ca2aa --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size.fail.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// explicit unordered_multiset(size_type n); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + C c = 7; + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == (test_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + C c = 7; + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == (min_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size.pass.cpp new file mode 100644 index 00000000000..35bfbe331b4 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// explicit unordered_multiset(size_type n); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + C c(7); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == (test_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + C c(7); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == (min_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash.pass.cpp new file mode 100644 index 00000000000..0171ea64ebb --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// unordered_multiset(size_type n, const hasher& hf); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + C c(7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == (test_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + C c(7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == (min_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash_equal.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash_equal.pass.cpp new file mode 100644 index 00000000000..785cdf24636 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash_equal.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// unordered_multiset(size_type n, const hasher& hf, const key_equal& eql); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + C c(7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == (test_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + C c(7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == (min_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash_equal_allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash_equal_allocator.pass.cpp new file mode 100644 index 00000000000..50dd3c95ee5 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/size_hash_equal_allocator.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// unordered_multiset(size_type n, const hasher& hf, const key_equal& eql, const allocator_type& a); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_multiset >, + test_compare >, + test_allocator + > C; + C c(7, + test_hash >(8), + test_compare >(9), + test_allocator >(10) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == (test_allocator(10))); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_multiset >, + test_compare >, + min_allocator + > C; + C c(7, + test_hash >(8), + test_compare >(9), + min_allocator >() + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == (min_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.swap/db_swap_1.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.swap/db_swap_1.pass.cpp new file mode 100644 index 00000000000..9470b1a6fa8 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.swap/db_swap_1.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// void swap(unordered_multiset& x, unordered_multiset& y); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +int main() +{ +#if _LIBCPP_DEBUG >= 1 + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::unordered_multiset c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::unordered_multiset c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + std::unordered_multiset::iterator i1 = c1.begin(); + std::unordered_multiset::iterator i2 = c2.begin(); + swap(c1, c2); + c1.erase(i2); + c2.erase(i1); + std::unordered_multiset::iterator j = i1; + c1.erase(i1); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..40dac3cc070 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_noexcept.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(unordered_multiset& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + + some_comp() {} + some_comp(const some_comp&) {} +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash() {} + some_hash(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_multiset C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_multiset, + std::equal_to, test_allocator> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_multiset, + std::equal_to, other_allocator> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_multiset> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_multiset, + some_comp> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_non_member.pass.cpp b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_non_member.pass.cpp new file mode 100644 index 00000000000..624b81c5eb3 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.multiset/unord.multiset.swap/swap_non_member.pass.cpp @@ -0,0 +1,571 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_multiset + +// void swap(unordered_multiset& x, unordered_multiset& y); + +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator Alloc; + typedef std::unordered_multiset C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 7); + assert(c2.size() == 6); + assert(c2.count(1) == 2); + assert(c2.count(2) == 2); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/bucket.pass.cpp b/libcxx/test/std/containers/unord/unord.set/bucket.pass.cpp new file mode 100644 index 00000000000..0dae664e0b2 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/bucket.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// size_type bucket(const key_type& __k) const; + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(std::begin(a), std::end(a)); + size_t bc = c.bucket_count(); + assert(bc >= 5); + for (size_t i = 0; i < 13; ++i) + assert(c.bucket(i) == i % bc); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(std::begin(a), std::end(a)); + size_t bc = c.bucket_count(); + assert(bc >= 5); + for (size_t i = 0; i < 13; ++i) + assert(c.bucket(i) == i % bc); + } +#endif +#if _LIBCPP_DEBUG_LEVEL >= 1 + { + typedef std::unordered_set C; + C c; + C::size_type i = c.bucket(3); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/bucket_count.pass.cpp b/libcxx/test/std/containers/unord/unord.set/bucket_count.pass.cpp new file mode 100644 index 00000000000..caaa5a6011a --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/bucket_count.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// size_type bucket_count() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef C::const_iterator I; + typedef int P; + const C c; + assert(c.bucket_count() == 0); + } + { + typedef std::unordered_set C; + typedef C::const_iterator I; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 11); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, std::equal_to, min_allocator> C; + typedef C::const_iterator I; + typedef int P; + const C c; + assert(c.bucket_count() == 0); + } + { + typedef std::unordered_set, std::equal_to, min_allocator> C; + typedef C::const_iterator I; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 11); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/bucket_size.pass.cpp b/libcxx/test/std/containers/unord/unord.set/bucket_size.pass.cpp new file mode 100644 index 00000000000..628d55737a8 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/bucket_size.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// size_type bucket_size(size_type n) const + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 5); + assert(c.bucket_size(0) == 0); + assert(c.bucket_size(1) == 1); + assert(c.bucket_size(2) == 1); + assert(c.bucket_size(3) == 1); + assert(c.bucket_size(4) == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(std::begin(a), std::end(a)); + assert(c.bucket_count() >= 5); + assert(c.bucket_size(0) == 0); + assert(c.bucket_size(1) == 1); + assert(c.bucket_size(2) == 1); + assert(c.bucket_size(3) == 1); + assert(c.bucket_size(4) == 1); + } +#endif +#if _LIBCPP_DEBUG_LEVEL >= 1 + { + typedef std::unordered_set C; + C c; + C::size_type i = c.bucket_size(3); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/clear.pass.cpp b/libcxx/test/std/containers/unord/unord.set/clear.pass.cpp new file mode 100644 index 00000000000..6da15308508 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/clear.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// void clear() + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + c.clear(); + assert(c.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + c.clear(); + assert(c.size() == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/count.pass.cpp b/libcxx/test/std/containers/unord/unord.set/count.pass.cpp new file mode 100644 index 00000000000..83bb8aaa2be --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/count.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// size_type count(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + assert(c.count(30) == 1); + assert(c.count(50) == 1); + assert(c.count(5) == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + assert(c.count(30) == 1); + assert(c.count(50) == 1); + assert(c.count(5) == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/db_iterators_7.pass.cpp b/libcxx/test/std/containers/unord/unord.set/db_iterators_7.pass.cpp new file mode 100644 index 00000000000..80b1a49c575 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/db_iterators_7.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Increment iterator past end. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::unordered_set C; + C c(1); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::unordered_set> C; + C c(1); + C::iterator i = c.begin(); + ++i; + assert(i == c.end()); + ++i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.set/db_iterators_8.pass.cpp b/libcxx/test/std/containers/unord/unord.set/db_iterators_8.pass.cpp new file mode 100644 index 00000000000..8b266bbf664 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/db_iterators_8.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Dereference non-dereferenceable iterator. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::unordered_set C; + C c(1); + C::iterator i = c.end(); + T j = *i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::unordered_set> C; + C c(1); + C::iterator i = c.end(); + T j = *i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.set/db_local_iterators_7.pass.cpp b/libcxx/test/std/containers/unord/unord.set/db_local_iterators_7.pass.cpp new file mode 100644 index 00000000000..b9fcb8c4ae0 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/db_local_iterators_7.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Increment local_iterator past end. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::unordered_set C; + C c(1); + C::local_iterator i = c.begin(0); + ++i; + ++i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::unordered_set> C; + C c(1); + C::local_iterator i = c.begin(0); + ++i; + ++i; + assert(false); + } +#endif + +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.set/db_local_iterators_8.pass.cpp b/libcxx/test/std/containers/unord/unord.set/db_local_iterators_8.pass.cpp new file mode 100644 index 00000000000..74d131b19ab --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/db_local_iterators_8.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Dereference non-dereferenceable iterator. + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef int T; + typedef std::unordered_set C; + C c(1); + C::local_iterator i = c.end(0); + T j = *i; + assert(false); + } +#if __cplusplus >= 201103L + { + typedef int T; + typedef std::unordered_set> C; + C c(1); + C::local_iterator i = c.end(0); + T j = *i; + assert(false); + } +#endif +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.set/emplace.pass.cpp b/libcxx/test/std/containers/unord/unord.set/emplace.pass.cpp new file mode 100644 index 00000000000..d105e7ac0f4 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/emplace.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// template +// pair emplace(Args&&... args); + +#include +#include + +#include "../../Emplaceable.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_set C; + typedef std::pair R; + C c; + R r = c.emplace(); + assert(c.size() == 1); + assert(*r.first == Emplaceable()); + assert(r.second); + + r = c.emplace(Emplaceable(5, 6)); + assert(c.size() == 2); + assert(*r.first == Emplaceable(5, 6)); + assert(r.second); + + r = c.emplace(5, 6); + assert(c.size() == 2); + assert(*r.first == Emplaceable(5, 6)); + assert(!r.second); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef std::pair R; + C c; + R r = c.emplace(); + assert(c.size() == 1); + assert(*r.first == Emplaceable()); + assert(r.second); + + r = c.emplace(Emplaceable(5, 6)); + assert(c.size() == 2); + assert(*r.first == Emplaceable(5, 6)); + assert(r.second); + + r = c.emplace(5, 6); + assert(c.size() == 2); + assert(*r.first == Emplaceable(5, 6)); + assert(!r.second); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.set/emplace_hint.pass.cpp b/libcxx/test/std/containers/unord/unord.set/emplace_hint.pass.cpp new file mode 100644 index 00000000000..50b0035165d --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/emplace_hint.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// template +// iterator emplace_hint(const_iterator p, Args&&... args); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "../../Emplaceable.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_set C; + typedef C::iterator R; + C c; + C::const_iterator e = c.end(); + R r = c.emplace_hint(e); + assert(c.size() == 1); + assert(*r == Emplaceable()); + + r = c.emplace_hint(e, Emplaceable(5, 6)); + assert(c.size() == 2); + assert(*r == Emplaceable(5, 6)); + + r = c.emplace_hint(r, 5, 6); + assert(c.size() == 2); + assert(*r == Emplaceable(5, 6)); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef C::iterator R; + C c; + C::const_iterator e = c.end(); + R r = c.emplace_hint(e); + assert(c.size() == 1); + assert(*r == Emplaceable()); + + r = c.emplace_hint(e, Emplaceable(5, 6)); + assert(c.size() == 2); + assert(*r == Emplaceable(5, 6)); + + r = c.emplace_hint(r, 5, 6); + assert(c.size() == 2); + assert(*r == Emplaceable(5, 6)); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + typedef std::unordered_set C; + typedef C::iterator R; + C c1; + C c2; + R r = c1.emplace_hint(c2.begin(), 5, 6); + assert(false); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.set/eq.pass.cpp b/libcxx/test/std/containers/unord/unord.set/eq.pass.cpp new file mode 100644 index 00000000000..54a9c2eced3 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/eq.pass.cpp @@ -0,0 +1,159 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template +// bool +// operator==(const unordered_set& x, +// const unordered_set& y); +// +// template +// bool +// operator!=(const unordered_set& x, +// const unordered_set& y); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c1(std::begin(a), std::end(a)); + const C c2; + assert(!(c1 == c2)); + assert( (c1 != c2)); + } + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c1(std::begin(a), std::end(a)); + const C c2 = c1; + assert( (c1 == c2)); + assert(!(c1 != c2)); + } + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a), std::end(a)); + C c2 = c1; + c2.rehash(30); + assert( (c1 == c2)); + assert(!(c1 != c2)); + c2.insert(P(90)); + assert(!(c1 == c2)); + assert( (c1 != c2)); + c1.insert(P(90)); + assert( (c1 == c2)); + assert(!(c1 != c2)); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c1(std::begin(a), std::end(a)); + const C c2; + assert(!(c1 == c2)); + assert( (c1 != c2)); + } + { + typedef std::unordered_set, std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c1(std::begin(a), std::end(a)); + const C c2 = c1; + assert( (c1 == c2)); + assert(!(c1 != c2)); + } + { + typedef std::unordered_set, std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a), std::end(a)); + C c2 = c1; + c2.rehash(30); + assert( (c1 == c2)); + assert(!(c1 != c2)); + c2.insert(P(90)); + assert(!(c1 == c2)); + assert( (c1 != c2)); + c1.insert(P(90)); + assert( (c1 == c2)); + assert(!(c1 != c2)); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/equal_range_const.pass.cpp b/libcxx/test/std/containers/unord/unord.set/equal_range_const.pass.cpp new file mode 100644 index 00000000000..4168903e020 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/equal_range_const.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// pair equal_range(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef C::const_iterator I; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + std::pair r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(*r.first == 30); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + r = c.equal_range(50); + assert(std::distance(r.first, r.second) == 1); + assert(*r.first == 50); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, std::equal_to, min_allocator> C; + typedef C::const_iterator I; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + std::pair r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(*r.first == 30); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + r = c.equal_range(50); + assert(std::distance(r.first, r.second) == 1); + assert(*r.first == 50); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/equal_range_non_const.pass.cpp b/libcxx/test/std/containers/unord/unord.set/equal_range_non_const.pass.cpp new file mode 100644 index 00000000000..5a55083ba8a --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/equal_range_non_const.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// pair equal_range(const key_type& k); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef C::iterator I; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + C c(std::begin(a), std::end(a)); + std::pair r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(*r.first == 30); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + r = c.equal_range(50); + assert(std::distance(r.first, r.second) == 1); + assert(*r.first == 50); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, std::equal_to, min_allocator> C; + typedef C::iterator I; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(50), + P(50), + P(60), + P(70), + P(80) + }; + C c(std::begin(a), std::end(a)); + std::pair r = c.equal_range(30); + assert(std::distance(r.first, r.second) == 1); + assert(*r.first == 30); + r = c.equal_range(5); + assert(std::distance(r.first, r.second) == 0); + r = c.equal_range(50); + assert(std::distance(r.first, r.second) == 1); + assert(*r.first == 50); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/erase_const_iter.pass.cpp b/libcxx/test/std/containers/unord/unord.set/erase_const_iter.pass.cpp new file mode 100644 index 00000000000..3a9cb5817df --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/erase_const_iter.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// iterator erase(const_iterator p) + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::iterator j = c.erase(i); + assert(c.size() == 3); + assert(c.count(1) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::iterator j = c.erase(i); + assert(c.size() == 3); + assert(c.count(1) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/erase_iter_db1.pass.cpp b/libcxx/test/std/containers/unord/unord.set/erase_iter_db1.pass.cpp new file mode 100644 index 00000000000..231152d14f4 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/erase_iter_db1.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator position) with end() + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::unordered_set l1(a1, a1+3); + std::unordered_set::const_iterator i = l1.end(); + l1.erase(i); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.set/erase_iter_db2.pass.cpp b/libcxx/test/std/containers/unord/unord.set/erase_iter_db2.pass.cpp new file mode 100644 index 00000000000..06d61db017d --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/erase_iter_db2.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator position) with iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::unordered_set l1(a1, a1+3); + std::unordered_set l2(a1, a1+3); + std::unordered_set::const_iterator i = l2.begin(); + l1.erase(i); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.set/erase_iter_iter_db1.pass.cpp b/libcxx/test/std/containers/unord/unord.set/erase_iter_iter_db1.pass.cpp new file mode 100644 index 00000000000..92c77f5567d --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/erase_iter_iter_db1.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with first iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::unordered_set l1(a1, a1+3); + std::unordered_set l2(a1, a1+3); + std::unordered_set::iterator i = l1.erase(l2.cbegin(), next(l1.cbegin())); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.set/erase_iter_iter_db2.pass.cpp b/libcxx/test/std/containers/unord/unord.set/erase_iter_iter_db2.pass.cpp new file mode 100644 index 00000000000..d6066589624 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/erase_iter_iter_db2.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with second iterator from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::unordered_set l1(a1, a1+3); + std::unordered_set l2(a1, a1+3); + std::unordered_set::iterator i = l1.erase(l1.cbegin(), next(l2.cbegin())); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.set/erase_iter_iter_db3.pass.cpp b/libcxx/test/std/containers/unord/unord.set/erase_iter_iter_db3.pass.cpp new file mode 100644 index 00000000000..f7ff42621fe --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/erase_iter_iter_db3.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with both iterators from another container + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::unordered_set l1(a1, a1+3); + std::unordered_set l2(a1, a1+3); + std::unordered_set::iterator i = l1.erase(l2.cbegin(), next(l2.cbegin())); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.set/erase_iter_iter_db4.pass.cpp b/libcxx/test/std/containers/unord/unord.set/erase_iter_iter_db4.pass.cpp new file mode 100644 index 00000000000..6cde216f4a9 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/erase_iter_iter_db4.pass.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// Call erase(const_iterator first, const_iterator last); with a bad range + +#if _LIBCPP_DEBUG >= 1 + +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) + +#include +#include +#include +#include + +int main() +{ + { + int a1[] = {1, 2, 3}; + std::unordered_set l1(a1, a1+3); + std::unordered_set::iterator i = l1.erase(next(l1.cbegin()), l1.cbegin()); + assert(false); + } +} + +#else + +int main() +{ +} + +#endif diff --git a/libcxx/test/std/containers/unord/unord.set/erase_key.pass.cpp b/libcxx/test/std/containers/unord/unord.set/erase_key.pass.cpp new file mode 100644 index 00000000000..ca165083b02 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/erase_key.pass.cpp @@ -0,0 +1,175 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// size_type erase(const key_type& k); + +#include +#include +#include + +#include "min_allocator.h" + +#if __cplusplus >= 201103L +template +bool only_deletions ( const Unordered &whole, const Unordered &part ) { + typename Unordered::const_iterator w = whole.begin(); + typename Unordered::const_iterator p = part.begin(); + + while ( w != whole.end () && p != part.end()) { + if ( *w == *p ) + p++; + w++; + } + + return p == part.end(); +} +#endif + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.erase(5) == 0); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + assert(c.erase(2) == 1); + assert(c.size() == 3); + assert(c.count(1) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + assert(c.erase(2) == 0); + assert(c.size() == 3); + assert(c.count(1) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + assert(c.erase(4) == 1); + assert(c.size() == 2); + assert(c.count(1) == 1); + assert(c.count(3) == 1); + + assert(c.erase(4) == 0); + assert(c.size() == 2); + assert(c.count(1) == 1); + assert(c.count(3) == 1); + + assert(c.erase(1) == 1); + assert(c.size() == 1); + assert(c.count(3) == 1); + + assert(c.erase(1) == 0); + assert(c.size() == 1); + assert(c.count(3) == 1); + + assert(c.erase(3) == 1); + assert(c.size() == 0); + + assert(c.erase(3) == 0); + assert(c.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.erase(5) == 0); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + assert(c.erase(2) == 1); + assert(c.size() == 3); + assert(c.count(1) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + assert(c.erase(2) == 0); + assert(c.size() == 3); + assert(c.count(1) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + assert(c.erase(4) == 1); + assert(c.size() == 2); + assert(c.count(1) == 1); + assert(c.count(3) == 1); + + assert(c.erase(4) == 0); + assert(c.size() == 2); + assert(c.count(1) == 1); + assert(c.count(3) == 1); + + assert(c.erase(1) == 1); + assert(c.size() == 1); + assert(c.count(3) == 1); + + assert(c.erase(1) == 0); + assert(c.size() == 1); + assert(c.count(3) == 1); + + assert(c.erase(3) == 1); + assert(c.size() == 0); + + assert(c.erase(3) == 0); + assert(c.size() == 0); + } + { + typedef std::unordered_set C; + C m, m2; + for ( int i = 0; i < 10; ++i ) { + m.insert(i); + m2.insert(i); + } + + C::iterator i = m2.begin(); + int ctr = 0; + while (i != m2.end()) { + if (ctr++ % 2 == 0) + m2.erase(i++); + else + ++i; + } + + assert (only_deletions (m, m2)); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/erase_range.pass.cpp b/libcxx/test/std/containers/unord/unord.set/erase_range.pass.cpp new file mode 100644 index 00000000000..a8a900551c7 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/erase_range.pass.cpp @@ -0,0 +1,93 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// iterator erase(const_iterator first, const_iterator last) + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::const_iterator j = next(i); + C::iterator k = c.erase(i, i); + assert(k == i); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + k = c.erase(i, j); + assert(c.size() == 3); + assert(c.count(1) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + k = c.erase(c.cbegin(), c.cend()); + assert(c.size() == 0); + assert(k == c.end()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C::const_iterator i = c.find(2); + C::const_iterator j = next(i); + C::iterator k = c.erase(i, i); + assert(k == i); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + k = c.erase(i, j); + assert(c.size() == 3); + assert(c.count(1) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + + k = c.erase(c.cbegin(), c.cend()); + assert(c.size() == 0); + assert(k == c.end()); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/find_const.pass.cpp b/libcxx/test/std/containers/unord/unord.set/find_const.pass.cpp new file mode 100644 index 00000000000..e2238e5665f --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/find_const.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// const_iterator find(const key_type& k) const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + C::const_iterator i = c.find(30); + assert(*i == 30); + i = c.find(5); + assert(i == c.cend()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + C::const_iterator i = c.find(30); + assert(*i == 30); + i = c.find(5); + assert(i == c.cend()); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/find_non_const.pass.cpp b/libcxx/test/std/containers/unord/unord.set/find_non_const.pass.cpp new file mode 100644 index 00000000000..8afe32abd72 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/find_non_const.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// iterator find(const key_type& k); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c(std::begin(a), std::end(a)); + C::iterator i = c.find(30); + assert(*i == 30); + i = c.find(5); + assert(i == c.cend()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c(std::begin(a), std::end(a)); + C::iterator i = c.find(30); + assert(*i == 30); + i = c.find(5); + assert(i == c.cend()); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/insert_const_lvalue.pass.cpp b/libcxx/test/std/containers/unord/unord.set/insert_const_lvalue.pass.cpp new file mode 100644 index 00000000000..321e9054af6 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/insert_const_lvalue.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// pair insert(const value_type& x); + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef std::pair R; + typedef C::value_type P; + C c; + R r = c.insert(P(3.5)); + assert(c.size() == 1); + assert(*r.first == 3.5); + assert(r.second); + + r = c.insert(P(3.5)); + assert(c.size() == 1); + assert(*r.first == 3.5); + assert(!r.second); + + r = c.insert(P(4.5)); + assert(c.size() == 2); + assert(*r.first == 4.5); + assert(r.second); + + r = c.insert(P(5.5)); + assert(c.size() == 3); + assert(*r.first == 5.5); + assert(r.second); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef std::pair R; + typedef C::value_type P; + C c; + R r = c.insert(P(3.5)); + assert(c.size() == 1); + assert(*r.first == 3.5); + assert(r.second); + + r = c.insert(P(3.5)); + assert(c.size() == 1); + assert(*r.first == 3.5); + assert(!r.second); + + r = c.insert(P(4.5)); + assert(c.size() == 2); + assert(*r.first == 4.5); + assert(r.second); + + r = c.insert(P(5.5)); + assert(c.size() == 3); + assert(*r.first == 5.5); + assert(r.second); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/insert_hint_const_lvalue.pass.cpp b/libcxx/test/std/containers/unord/unord.set/insert_hint_const_lvalue.pass.cpp new file mode 100644 index 00000000000..1393f542011 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/insert_hint_const_lvalue.pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// iterator insert(const_iterator p, const value_type& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(e, P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(e, P(4.5)); + assert(c.size() == 2); + assert(*r == 4.5); + + r = c.insert(e, P(5.5)); + assert(c.size() == 3); + assert(*r == 5.5); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(e, P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(e, P(4.5)); + assert(c.size() == 2); + assert(*r == 4.5); + + r = c.insert(e, P(5.5)); + assert(c.size() == 3); + assert(*r == 5.5); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + typedef std::unordered_set C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C c2; + C::const_iterator e = c2.end(); + P v(3.5); + R r = c.insert(e, v); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/insert_hint_rvalue.pass.cpp b/libcxx/test/std/containers/unord/unord.set/insert_hint_rvalue.pass.cpp new file mode 100644 index 00000000000..f612ec57249 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/insert_hint_rvalue.pass.cpp @@ -0,0 +1,138 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// iterator insert(const_iterator p, value_type&& x); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef C::iterator R; + typedef double P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(r, P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(e, P(4.5)); + assert(c.size() == 2); + assert(*r == 4.5); + + r = c.insert(e, P(5.5)); + assert(c.size() == 3); + assert(*r == 5.5); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_set C; + typedef C::iterator R; + typedef MoveOnly P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3)); + assert(c.size() == 1); + assert(*r == 3); + + r = c.insert(r, P(3)); + assert(c.size() == 1); + assert(*r == 3); + + r = c.insert(e, P(4)); + assert(c.size() == 2); + assert(*r == 4); + + r = c.insert(e, P(5)); + assert(c.size() == 3); + assert(*r == 5); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef C::iterator R; + typedef double P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(r, P(3.5)); + assert(c.size() == 1); + assert(*r == 3.5); + + r = c.insert(e, P(4.5)); + assert(c.size() == 2); + assert(*r == 4.5); + + r = c.insert(e, P(5.5)); + assert(c.size() == 3); + assert(*r == 5.5); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef C::iterator R; + typedef MoveOnly P; + C c; + C::const_iterator e = c.end(); + R r = c.insert(e, P(3)); + assert(c.size() == 1); + assert(*r == 3); + + r = c.insert(r, P(3)); + assert(c.size() == 1); + assert(*r == 3); + + r = c.insert(e, P(4)); + assert(c.size() == 2); + assert(*r == 4); + + r = c.insert(e, P(5)); + assert(c.size() == 3); + assert(*r == 5); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if _LIBCPP_DEBUG >= 1 + { + typedef std::unordered_set C; + typedef C::iterator R; + typedef C::value_type P; + C c; + C c2; + C::const_iterator e = c2.end(); + R r = c.insert(e, P(3.5)); + assert(false); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/insert_init.pass.cpp b/libcxx/test/std/containers/unord/unord.set/insert_init.pass.cpp new file mode 100644 index 00000000000..2d8eafba489 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/insert_init.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// void insert(initializer_list il); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_set C; + typedef int P; + C c; + c.insert( + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + } + ); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef int P; + C c; + c.insert( + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + } + ); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.set/insert_range.pass.cpp b/libcxx/test/std/containers/unord/unord.set/insert_range.pass.cpp new file mode 100644 index 00000000000..72a83abf74e --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/insert_range.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// template +// void insert(InputIterator first, InputIterator last); + +#include +#include + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c; + c.insert(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c; + c.insert(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/insert_rvalue.pass.cpp b/libcxx/test/std/containers/unord/unord.set/insert_rvalue.pass.cpp new file mode 100644 index 00000000000..d62308e7357 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/insert_rvalue.pass.cpp @@ -0,0 +1,134 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// pair insert(value_type&& x); + +#include +#include + +#include "../../MoveOnly.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef std::pair R; + typedef double P; + C c; + R r = c.insert(P(3.5)); + assert(c.size() == 1); + assert(*r.first == 3.5); + assert(r.second); + + r = c.insert(P(3.5)); + assert(c.size() == 1); + assert(*r.first == 3.5); + assert(!r.second); + + r = c.insert(P(4.5)); + assert(c.size() == 2); + assert(*r.first == 4.5); + assert(r.second); + + r = c.insert(P(5.5)); + assert(c.size() == 3); + assert(*r.first == 5.5); + assert(r.second); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_set C; + typedef std::pair R; + typedef MoveOnly P; + C c; + R r = c.insert(P(3)); + assert(c.size() == 1); + assert(*r.first == 3); + assert(r.second); + + r = c.insert(P(3)); + assert(c.size() == 1); + assert(*r.first == 3); + assert(!r.second); + + r = c.insert(P(4)); + assert(c.size() == 2); + assert(*r.first == 4); + assert(r.second); + + r = c.insert(P(5)); + assert(c.size() == 3); + assert(*r.first == 5); + assert(r.second); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef std::pair R; + typedef double P; + C c; + R r = c.insert(P(3.5)); + assert(c.size() == 1); + assert(*r.first == 3.5); + assert(r.second); + + r = c.insert(P(3.5)); + assert(c.size() == 1); + assert(*r.first == 3.5); + assert(!r.second); + + r = c.insert(P(4.5)); + assert(c.size() == 2); + assert(*r.first == 4.5); + assert(r.second); + + r = c.insert(P(5.5)); + assert(c.size() == 3); + assert(*r.first == 5.5); + assert(r.second); + } +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef std::pair R; + typedef MoveOnly P; + C c; + R r = c.insert(P(3)); + assert(c.size() == 1); + assert(*r.first == 3); + assert(r.second); + + r = c.insert(P(3)); + assert(c.size() == 1); + assert(*r.first == 3); + assert(!r.second); + + r = c.insert(P(4)); + assert(c.size() == 2); + assert(*r.first == 4); + assert(r.second); + + r = c.insert(P(5)); + assert(c.size() == 3); + assert(*r.first == 5); + assert(r.second); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/iterators.fail.cpp b/libcxx/test/std/containers/unord/unord.set/iterators.fail.cpp new file mode 100644 index 00000000000..2bb180b6e21 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/iterators.fail.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// iterator begin() {return __table_.begin();} +// iterator end() {return __table_.end();} +// const_iterator begin() const {return __table_.begin();} +// const_iterator end() const {return __table_.end();} +// const_iterator cbegin() const {return __table_.begin();} +// const_iterator cend() const {return __table_.end();} + +#include +#include + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::iterator i = c.begin(); + assert(*i == 1); + *i = 2; + } + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + assert(c.size() == 6); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + } +} diff --git a/libcxx/test/std/containers/unord/unord.set/iterators.pass.cpp b/libcxx/test/std/containers/unord/unord.set/iterators.pass.cpp new file mode 100644 index 00000000000..d3a45801f16 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/iterators.pass.cpp @@ -0,0 +1,127 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// iterator begin() {return __table_.begin();} +// iterator end() {return __table_.end();} +// const_iterator begin() const {return __table_.begin();} +// const_iterator end() const {return __table_.end();} +// const_iterator cbegin() const {return __table_.begin();} +// const_iterator cend() const {return __table_.end();} + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::iterator i; + } + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::const_iterator i; + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::iterator i; + } + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + C::const_iterator i; + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + typedef std::unordered_set C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/load_factor.pass.cpp b/libcxx/test/std/containers/unord/unord.set/load_factor.pass.cpp new file mode 100644 index 00000000000..e0ed1694b05 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/load_factor.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// float load_factor() const + +#include +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + } + { + typedef std::unordered_set C; + typedef int P; + const C c; + assert(c.load_factor() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + const C c(std::begin(a), std::end(a)); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + } + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef int P; + const C c; + assert(c.load_factor() == 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/local_iterators.fail.cpp b/libcxx/test/std/containers/unord/unord.set/local_iterators.fail.cpp new file mode 100644 index 00000000000..eb671a442f1 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/local_iterators.fail.cpp @@ -0,0 +1,261 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// local_iterator begin (size_type n); +// local_iterator end (size_type n); +// const_local_iterator begin (size_type n) const; +// const_local_iterator end (size_type n) const; +// const_local_iterator cbegin(size_type n) const; +// const_local_iterator cend (size_type n) const; + +#include +#include + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + typedef C::local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + *i = 2; + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_set C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_set C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } + { + typedef std::unordered_set C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 1); + ++i; + assert(*i == 1); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 2); + assert(*i == 2); + ++i; + assert(*i == 2); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + + b = c.bucket(5); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(6); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 0); + } +} diff --git a/libcxx/test/std/containers/unord/unord.set/local_iterators.pass.cpp b/libcxx/test/std/containers/unord/unord.set/local_iterators.pass.cpp new file mode 100644 index 00000000000..2ffd93f30d1 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/local_iterators.pass.cpp @@ -0,0 +1,388 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// local_iterator begin (size_type n); +// local_iterator end (size_type n); +// const_local_iterator begin (size_type n) const; +// const_local_iterator end (size_type n) const; +// const_local_iterator cbegin(size_type n) const; +// const_local_iterator cend (size_type n) const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + typedef C::local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 1); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 2); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + } + { + typedef std::unordered_set C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 1); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 2); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + } + { + typedef std::unordered_set C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 1); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 2); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + } + { + typedef std::unordered_set C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 1); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 2); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef int P; + typedef C::local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 1); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 2); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + } + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.begin(b); + I j = c.end(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 1); + + b = c.bucket(2); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 2); + + b = c.bucket(3); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.begin(b); + j = c.end(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + } + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 1); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 2); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + } + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef int P; + typedef C::const_local_iterator I; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + const C c(a, a + sizeof(a)/sizeof(a[0])); + assert(c.bucket_count() >= 5); + C::size_type b = c.bucket(0); + I i = c.cbegin(b); + I j = c.cend(b); + assert(std::distance(i, j) == 0); + + b = c.bucket(1); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 1); + + b = c.bucket(2); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 2); + + b = c.bucket(3); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 3); + + b = c.bucket(4); + i = c.cbegin(b); + j = c.cend(b); + assert(std::distance(i, j) == 1); + assert(*i == 4); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/max_bucket_count.pass.cpp b/libcxx/test/std/containers/unord/unord.set/max_bucket_count.pass.cpp new file mode 100644 index 00000000000..8b5e265de3f --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/max_bucket_count.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// size_type max_bucket_count() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + const C c; + assert(c.max_bucket_count() > 0); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + const C c; + assert(c.max_bucket_count() > 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/max_load_factor.pass.cpp b/libcxx/test/std/containers/unord/unord.set/max_load_factor.pass.cpp new file mode 100644 index 00000000000..d326f4a2d7e --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/max_load_factor.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// float max_load_factor() const; +// void max_load_factor(float mlf); + +#ifdef _LIBCPP_DEBUG +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + const C c; + assert(c.max_load_factor() == 1); + } + { + typedef std::unordered_set C; + typedef int P; + C c; + assert(c.max_load_factor() == 1); + c.max_load_factor(2.5); + assert(c.max_load_factor() == 2.5); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef int P; + const C c; + assert(c.max_load_factor() == 1); + } + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef int P; + C c; + assert(c.max_load_factor() == 1); + c.max_load_factor(2.5); + assert(c.max_load_factor() == 2.5); + } +#endif +#if _LIBCPP_DEBUG_LEVEL >= 1 + { + typedef std::unordered_set C; + C c; + c.max_load_factor(-0.5f); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/max_size.pass.cpp b/libcxx/test/std/containers/unord/unord.set/max_size.pass.cpp new file mode 100644 index 00000000000..1c6e74125c7 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/max_size.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// size_type max_size() const; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + std::unordered_set u; + assert(u.max_size() > 0); + } +#if __cplusplus >= 201103L + { + std::unordered_set, + std::equal_to, min_allocator> u; + assert(u.max_size() > 0); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/rehash.pass.cpp b/libcxx/test/std/containers/unord/unord.set/rehash.pass.cpp new file mode 100644 index 00000000000..30fffa561f7 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/rehash.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// void rehash(size_type n); + +#include +#include + +#include "min_allocator.h" + +template +void test(const C& c) +{ + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); +} + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 5); + c.rehash(3); + assert(c.bucket_count() == 5); + test(c); + c.max_load_factor(2); + c.rehash(3); + assert(c.bucket_count() == 3); + test(c); + c.rehash(31); + assert(c.bucket_count() == 31); + test(c); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 5); + c.rehash(3); + assert(c.bucket_count() == 5); + test(c); + c.max_load_factor(2); + c.rehash(3); + assert(c.bucket_count() == 3); + test(c); + c.rehash(31); + assert(c.bucket_count() == 31); + test(c); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/reserve.pass.cpp b/libcxx/test/std/containers/unord/unord.set/reserve.pass.cpp new file mode 100644 index 00000000000..7d6656a1867 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/reserve.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// void reserve(size_type n); + +#include +#include + +#include "min_allocator.h" + +template +void test(const C& c) +{ + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); +} + +int main() +{ + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 5); + c.reserve(3); + assert(c.bucket_count() == 5); + test(c); + c.max_load_factor(2); + c.reserve(3); + assert(c.bucket_count() >= 2); + test(c); + c.reserve(31); + assert(c.bucket_count() >= 16); + test(c); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + test(c); + assert(c.bucket_count() >= 5); + c.reserve(3); + assert(c.bucket_count() == 5); + test(c); + c.max_load_factor(2); + c.reserve(3); + assert(c.bucket_count() >= 2); + test(c); + c.reserve(31); + assert(c.bucket_count() >= 16); + test(c); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/swap_member.pass.cpp b/libcxx/test/std/containers/unord/unord.set/swap_member.pass.cpp new file mode 100644 index 00000000000..89ec986d08f --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/swap_member.pass.cpp @@ -0,0 +1,571 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// void swap(unordered_set& u); + +#include +#include + +#include "../../test_compare.h" +#include "../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.count(1) == 1); + assert(c2.count(2) == 1); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.count(1) == 1); + assert(c2.count(2) == 1); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.count(1) == 1); + assert(c2.count(2) == 1); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.count(1) == 1); + assert(c2.count(2) == 1); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.count(1) == 1); + assert(c2.count(2) == 1); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + c1.swap(c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.count(1) == 1); + assert(c2.count(2) == 1); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/types.pass.cpp b/libcxx/test/std/containers/unord/unord.set/types.pass.cpp new file mode 100644 index 00000000000..7e752a434ec --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/types.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set +// { +// public: +// // types +// typedef Value value_type; +// typedef value_type key_type; +// typedef Hash hasher; +// typedef Pred key_equal; +// typedef Alloc allocator_type; +// typedef value_type& reference; +// typedef const value_type& const_reference; +// typedef typename allocator_traits::pointer pointer; +// typedef typename allocator_traits::const_pointer const_pointer; +// typedef typename allocator_traits::size_type size_type; +// typedef typename allocator_traits::difference_type difference_type; + +#include +#include + +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set, + std::equal_to, min_allocator> C; + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same >::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same::value), ""); + static_assert((std::is_same>::value), ""); + static_assert((std::is_same>::value), ""); + // min_allocator doesn't have a size_type, so one gets synthesized + static_assert((std::is_same::type>::value), ""); + static_assert((std::is_same::value), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/allocator.pass.cpp new file mode 100644 index 00000000000..30905aeb9fe --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/allocator.pass.cpp @@ -0,0 +1,109 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// explicit unordered_set(const allocator_type& __a); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + C c(test_allocator(10)); + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == test_allocator(10)); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + C c(min_allocator{}); + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == min_allocator()); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if _LIBCPP_STD_VER > 11 + { + typedef NotConstructible T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_set C; + + A a(43); + C c(3, a); + assert(c.bucket_count() == 3); + assert(c.hash_function() == HF()); + assert(c.key_eq() == Comp ()); + assert(c.get_allocator() == a); + assert(!(c.get_allocator() == A())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } + { + typedef NotConstructible T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_set C; + + HF hf(42); + A a(43); + C c(4, hf, a); + assert(c.bucket_count() == 4); + assert(c.hash_function() == hf); + assert(!(c.hash_function() == HF())); + assert(c.key_eq() == Comp ()); + assert(c.get_allocator() == a); + assert(!(c.get_allocator() == A())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_copy.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_copy.pass.cpp new file mode 100644 index 00000000000..6925e304541 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_copy.pass.cpp @@ -0,0 +1,184 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// unordered_set& operator=(const unordered_set& u); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_allocator A; + typedef std::unordered_set >, + test_compare >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(4) + ); + c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(4)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + { + typedef std::unordered_set C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(a, a + sizeof(a)/sizeof(a[0])); + C *p = &c; + c = *p; + assert(c.size() == 4); + assert(std::is_permutation(c.begin(), c.end(), a)); + } + { + typedef other_allocator A; + typedef std::unordered_set >, + test_compare >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(4) + ); + c = c0; + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef min_allocator A; + typedef std::unordered_set >, + test_compare >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A() + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A() + ); + c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_init.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_init.pass.cpp new file mode 100644 index 00000000000..69d19a4dac2 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_init.pass.cpp @@ -0,0 +1,97 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// unordered_set& operator=(initializer_list il); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef test_allocator A; + typedef std::unordered_set >, + test_compare >, + A + > C; + typedef int P; + C c = { + P(4), + P(1), + P(2) + }; + c = { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef min_allocator A; + typedef std::unordered_set >, + test_compare >, + A + > C; + typedef int P; + C c = { + P(4), + P(1), + P(2) + }; + c = { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_move.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_move.pass.cpp new file mode 100644 index 00000000000..e8712b7431c --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/assign_move.pass.cpp @@ -0,0 +1,225 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// unordered_set& operator=(unordered_set&& u); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef test_allocator A; + typedef std::unordered_set >, + test_compare >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(4) + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(4)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + { + typedef test_allocator A; + typedef std::unordered_set >, + test_compare >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(10) + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + { + typedef other_allocator A; + typedef std::unordered_set >, + test_compare >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A(4) + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef min_allocator A; + typedef std::unordered_set >, + test_compare >, + A + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A() + ); + C c(a, a + 2, + 7, + test_hash >(2), + test_compare >(3), + A() + ); + c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + std::unordered_set s1 = {1, 2, 3}; + std::unordered_set::iterator i = s1.begin(); + int k = *i; + std::unordered_set s2; + s2 = std::move(s1); + assert(*i == k); + s2.erase(i); + assert(s2.size() == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/copy.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/copy.pass.cpp new file mode 100644 index 00000000000..ee05acd6be9 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/copy.pass.cpp @@ -0,0 +1,147 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// unordered_set(const unordered_set& u); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + test_allocator(10) + ); + C c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == test_allocator(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE + { + typedef std::unordered_set >, + test_compare >, + other_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + other_allocator(10) + ); + C c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == other_allocator(-2)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + min_allocator() + ); + C c = c0; + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/copy_alloc.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/copy_alloc.pass.cpp new file mode 100644 index 00000000000..8e1ecd8167f --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/copy_alloc.pass.cpp @@ -0,0 +1,107 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// unordered_set(const unordered_set& u, const allocator_type& a); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + test_allocator(10) + ); + C c(c0, test_allocator(5)); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == test_allocator(5)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + min_allocator() + ); + C c(c0, min_allocator()); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/default.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/default.pass.cpp new file mode 100644 index 00000000000..6efa9ed8d1d --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/default.pass.cpp @@ -0,0 +1,74 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// unordered_set(); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + C c; + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == (test_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + C c; + assert(c.bucket_count() == 0); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == (min_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } + { + std::unordered_set c = {}; + assert(c.bucket_count() == 0); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/default_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/default_noexcept.pass.cpp new file mode 100644 index 00000000000..b3cd9c3f1ff --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/default_noexcept.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// unordered_set() +// noexcept( +// is_nothrow_default_constructible::value && +// is_nothrow_default_constructible::value && +// is_nothrow_copy_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" +#include "../../../test_hash.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp(); + some_comp(const some_comp&); +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_set C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::unordered_set, + std::equal_to, test_allocator> C; + static_assert(std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::unordered_set, + std::equal_to, other_allocator> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::unordered_set> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } + { + typedef std::unordered_set, + some_comp> C; + static_assert(!std::is_nothrow_default_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/dtor_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/dtor_noexcept.pass.cpp new file mode 100644 index 00000000000..68ef7f4f9ae --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/dtor_noexcept.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// ~unordered_set() // implied noexcept; + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template +struct some_comp +{ + typedef T value_type; + ~some_comp() noexcept(false); +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); + ~some_hash() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_set C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::unordered_set, + std::equal_to, test_allocator> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::unordered_set, + std::equal_to, other_allocator> C; + static_assert(std::is_nothrow_destructible::value, ""); + } + { + typedef std::unordered_set> C; + static_assert(!std::is_nothrow_destructible::value, ""); + } + { + typedef std::unordered_set, + some_comp> C; + static_assert(!std::is_nothrow_destructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init.pass.cpp new file mode 100644 index 00000000000..2c31d575b63 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init.pass.cpp @@ -0,0 +1,163 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// unordered_set(initializer_list il); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + typedef int P; + C c = { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == test_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + typedef int P; + C c = { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if _LIBCPP_STD_VER > 11 + { + typedef int T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_set C; + + A a(42); + C c({ + T(1), + T(2), + T(3), + T(4), + T(1), + T(2) + }, 12, a); + + assert(c.bucket_count() >= 12); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == HF()); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + assert(!(c.get_allocator() == A())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + { + typedef int T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_set C; + + A a(42); + HF hf(43); + C c({ + T(1), + T(2), + T(3), + T(4), + T(1), + T(2) + }, 12, hf, a); + + assert(c.bucket_count() >= 12); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == hf); + assert(!(c.hash_function() == HF())); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + assert(!(c.get_allocator() == A())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init_size.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init_size.pass.cpp new file mode 100644 index 00000000000..36dab799c78 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init_size.pass.cpp @@ -0,0 +1,97 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// unordered_set(initializer_list il, size_type n); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7 + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == test_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7 + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init_size_hash.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init_size_hash.pass.cpp new file mode 100644 index 00000000000..81af2b41bae --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init_size_hash.pass.cpp @@ -0,0 +1,100 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// unordered_set(initializer_list il, size_type n, +// const hasher& hf); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == test_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init_size_hash_equal.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init_size_hash_equal.pass.cpp new file mode 100644 index 00000000000..f35dd1afa87 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init_size_hash_equal.pass.cpp @@ -0,0 +1,102 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// unordered_set(initializer_list il, size_type n, +// const hasher& hf, const key_equal& eql); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == test_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init_size_hash_equal_allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init_size_hash_equal_allocator.pass.cpp new file mode 100644 index 00000000000..34ff62ea77b --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/init_size_hash_equal_allocator.pass.cpp @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// unordered_set(initializer_list il, size_type n, +// const hasher& hf, const key_equal& eql, const allocator_type& a); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7, + test_hash >(8), + test_compare >(9), + test_allocator(10) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == test_allocator(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + typedef int P; + C c({ + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }, + 7, + test_hash >(8), + test_compare >(9), + min_allocator() + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move.pass.cpp new file mode 100644 index 00000000000..6bda4afc99c --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move.pass.cpp @@ -0,0 +1,194 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// unordered_set(unordered_set&& u); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(7, + test_hash >(8), + test_compare >(9), + test_allocator(10) + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 0); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == test_allocator(10)); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + test_allocator(10) + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == test_allocator(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(7, + test_hash >(8), + test_compare >(9), + min_allocator() + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 0); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == min_allocator()); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + min_allocator() + ); + C c = std::move(c0); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } +#endif +#if _LIBCPP_DEBUG >= 1 + { + std::unordered_set s1 = {1, 2, 3}; + std::unordered_set::iterator i = s1.begin(); + int k = *i; + std::unordered_set s2 = std::move(s1); + assert(*i == k); + s2.erase(i); + assert(s2.size() == 2); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move_alloc.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move_alloc.pass.cpp new file mode 100644 index 00000000000..229e79925f2 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move_alloc.pass.cpp @@ -0,0 +1,156 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// unordered_set(unordered_set&& u, const allocator_type& a); + +#include +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef int P; + typedef test_allocator A; + typedef std::unordered_set >, + test_compare >, + A + > C; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(std::move(c0), A(12)); + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(12)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } + { + typedef int P; + typedef test_allocator A; + typedef std::unordered_set >, + test_compare >, + A + > C; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A(10) + ); + C c(std::move(c0), A(10)); + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } +#if __cplusplus >= 201103L + { + typedef int P; + typedef min_allocator A; + typedef std::unordered_set >, + test_compare >, + A + > C; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c0(a, a + sizeof(a)/sizeof(a[0]), + 7, + test_hash >(8), + test_compare >(9), + A() + ); + C c(std::move(c0), A()); + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == A()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + + assert(c0.empty()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move_assign_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move_assign_noexcept.pass.cpp new file mode 100644 index 00000000000..c3c94fd1a04 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move_assign_noexcept.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// unordered_set& operator=(unordered_set&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable::value && +// is_nothrow_move_assignable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp& operator=(const some_comp&); +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); + some_hash& operator=(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_set C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::unordered_set, + std::equal_to, test_allocator> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::unordered_set, + std::equal_to, other_allocator> C; + static_assert(std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::unordered_set> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } + { + typedef std::unordered_set, + some_comp> C; + static_assert(!std::is_nothrow_move_assignable::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move_noexcept.pass.cpp new file mode 100644 index 00000000000..791a67d2119 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/move_noexcept.pass.cpp @@ -0,0 +1,66 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// unordered_set(unordered_set&&) +// noexcept(is_nothrow_move_constructible::value && +// is_nothrow_move_constructible::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + some_comp(const some_comp&); +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash(); + some_hash(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_set C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::unordered_set, + std::equal_to, test_allocator> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::unordered_set, + std::equal_to, other_allocator> C; + static_assert(std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::unordered_set> C; + static_assert(!std::is_nothrow_move_constructible::value, ""); + } + { + typedef std::unordered_set, + some_comp> C; + static_assert(!std::is_nothrow_move_constructible::value, ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range.pass.cpp new file mode 100644 index 00000000000..40f3f4f4d7f --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range.pass.cpp @@ -0,0 +1,168 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// template +// unordered_set(InputIterator first, InputIterator last); + +#include +#include +#include + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == test_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0]))); + assert(c.bucket_count() >= 5); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if _LIBCPP_STD_VER > 11 + { + typedef int T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_set C; + T arr[] = + { + T(1), + T(2), + T(3), + T(4), + T(1), + T(2) + }; + A a(42); + C c(input_iterator(arr), input_iterator(arr + sizeof(arr)/sizeof(arr[0])), 12, a); + assert(c.bucket_count() >= 12); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == HF()); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + assert(!(c.get_allocator() == A())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + { + typedef int T; + typedef test_hash> HF; + typedef test_compare> Comp; + typedef test_allocator A; + typedef std::unordered_set C; + T arr[] = + { + T(1), + T(2), + T(3), + T(4), + T(1), + T(2) + }; + HF hf(43); + A a(42); + C c(input_iterator(arr), input_iterator(arr + sizeof(arr)/sizeof(arr[0])), 16, hf, a); + assert(c.bucket_count() >= 16); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == hf); + assert(!(c.hash_function() == HF())); + assert(c.key_eq() == Comp()); + assert(c.get_allocator() == a); + assert(!(c.get_allocator() == A())); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } + +#endif +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range_size.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range_size.pass.cpp new file mode 100644 index 00000000000..179f73d7e18 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range_size.pass.cpp @@ -0,0 +1,101 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// template +// unordered_set(InputIterator first, InputIterator last, size_type n); + +#include +#include +#include + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7 + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == test_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7 + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range_size_hash.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range_size_hash.pass.cpp new file mode 100644 index 00000000000..60350de962c --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range_size_hash.pass.cpp @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// template +// unordered_set(InputIterator first, InputIterator last, size_type n, +// const hasher& hf); + +#include +#include +#include + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == test_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range_size_hash_equal.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range_size_hash_equal.pass.cpp new file mode 100644 index 00000000000..70e82d03464 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range_size_hash_equal.pass.cpp @@ -0,0 +1,106 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// template +// unordered_set(InputIterator first, InputIterator last, size_type n, +// const hasher& hf, const key_equal& eql); + +#include +#include +#include + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == test_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range_size_hash_equal_allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range_size_hash_equal_allocator.pass.cpp new file mode 100644 index 00000000000..a6fb2e667ae --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/range_size_hash_equal_allocator.pass.cpp @@ -0,0 +1,109 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// template +// unordered_set(InputIterator first, InputIterator last, size_type n, +// const hasher& hf, const key_equal& eql, +// const allocator_type& a); + +#include +#include +#include + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8), + test_compare >(9), + test_allocator(10) + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == test_allocator(10)); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + typedef int P; + P a[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c(input_iterator(a), input_iterator(a + sizeof(a)/sizeof(a[0])), + 7, + test_hash >(8), + test_compare >(9), + min_allocator() + ); + assert(c.bucket_count() == 7); + assert(c.size() == 4); + assert(c.count(1) == 1); + assert(c.count(2) == 1); + assert(c.count(3) == 1); + assert(c.count(4) == 1); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == min_allocator()); + assert(!c.empty()); + assert(std::distance(c.begin(), c.end()) == c.size()); + assert(std::distance(c.cbegin(), c.cend()) == c.size()); + assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size.fail.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size.fail.cpp new file mode 100644 index 00000000000..389c54c58cd --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size.fail.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// explicit unordered_set(size_type n); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" + +int main() +{ + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + C c = 7; + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == (test_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size.pass.cpp new file mode 100644 index 00000000000..8f6228ad8ec --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size.pass.cpp @@ -0,0 +1,65 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// explicit unordered_set(size_type n); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + C c(7); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == (test_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + C c(7); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >()); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == (min_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size_hash.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size_hash.pass.cpp new file mode 100644 index 00000000000..4c2c18edd1c --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size_hash.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// unordered_set(size_type n, const hasher& hf); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + C c(7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == (test_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + C c(7, + test_hash >(8) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >()); + assert(c.get_allocator() == (min_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size_hash_equal.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size_hash_equal.pass.cpp new file mode 100644 index 00000000000..e9368782ad9 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size_hash_equal.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// unordered_set(size_type n, const hasher& hf, const key_equal& eql); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + C c(7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == (test_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + C c(7, + test_hash >(8), + test_compare >(9) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == (min_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size_hash_equal_allocator.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size_hash_equal_allocator.pass.cpp new file mode 100644 index 00000000000..96233e187af --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.cnstr/size_hash_equal_allocator.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// unordered_set(size_type n, const hasher& hf, const key_equal& eql, const allocator_type& a); + +#include +#include + +#include "../../../NotConstructible.h" +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef std::unordered_set >, + test_compare >, + test_allocator + > C; + C c(7, + test_hash >(8), + test_compare >(9), + test_allocator(10) + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == (test_allocator(10))); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef std::unordered_set >, + test_compare >, + min_allocator + > C; + C c(7, + test_hash >(8), + test_compare >(9), + min_allocator() + ); + assert(c.bucket_count() == 7); + assert(c.hash_function() == test_hash >(8)); + assert(c.key_eq() == test_compare >(9)); + assert(c.get_allocator() == (min_allocator())); + assert(c.size() == 0); + assert(c.empty()); + assert(std::distance(c.begin(), c.end()) == 0); + assert(c.load_factor() == 0); + assert(c.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.swap/db_swap_1.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.swap/db_swap_1.pass.cpp new file mode 100644 index 00000000000..2e8250ef783 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.swap/db_swap_1.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// void swap(unordered_set& x, unordered_set& y); + +#if _LIBCPP_DEBUG >= 1 +#define _LIBCPP_ASSERT(x, m) ((x) ? (void)0 : std::exit(0)) +#endif + +#include +#include + +int main() +{ +#if _LIBCPP_DEBUG >= 1 + { + int a1[] = {1, 3, 7, 9, 10}; + int a2[] = {0, 2, 4, 5, 6, 8, 11}; + std::unordered_set c1(a1, a1+sizeof(a1)/sizeof(a1[0])); + std::unordered_set c2(a2, a2+sizeof(a2)/sizeof(a2[0])); + std::unordered_set::iterator i1 = c1.begin(); + std::unordered_set::iterator i2 = c2.begin(); + swap(c1, c2); + c1.erase(i2); + c2.erase(i1); + std::unordered_set::iterator j = i1; + c1.erase(i1); + assert(false); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.swap/swap_noexcept.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.swap/swap_noexcept.pass.cpp new file mode 100644 index 00000000000..359e2968cc2 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.swap/swap_noexcept.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// void swap(unordered_set& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable::value); + +// This tests a conforming extension + +#include +#include + +#include "../../../MoveOnly.h" +#include "test_allocator.h" + +template +struct some_comp +{ + typedef T value_type; + + some_comp() {} + some_comp(const some_comp&) {} +}; + +template +struct some_hash +{ + typedef T value_type; + some_hash() {} + some_hash(const some_hash&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::unordered_set C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_set, + std::equal_to, test_allocator> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_set, + std::equal_to, other_allocator> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_set> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { + typedef std::unordered_set, + some_comp> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/unord.set.swap/swap_non_member.pass.cpp b/libcxx/test/std/containers/unord/unord.set/unord.set.swap/swap_non_member.pass.cpp new file mode 100644 index 00000000000..7415e297771 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/unord.set.swap/swap_non_member.pass.cpp @@ -0,0 +1,571 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template , class Pred = equal_to, +// class Alloc = allocator> +// class unordered_set + +// void swap(unordered_set& x, unordered_set& y); + +#include +#include + +#include "../../../test_compare.h" +#include "../../../test_hash.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.count(1) == 1); + assert(c2.count(2) == 1); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef test_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(1)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.count(1) == 1); + assert(c2.count(2) == 1); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(2)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.count(1) == 1); + assert(c2.count(2) == 1); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef other_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc(1)); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc(2)); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc(2)); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.count(1) == 1); + assert(c2.count(2) == 1); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc(1)); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#if __cplusplus >= 201103L + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() == 0); + assert(c2.size() == 0); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() == 0); + assert(c1.size() == 0); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.count(1) == 1); + assert(c2.count(2) == 1); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } + { + typedef test_hash > Hash; + typedef test_compare > Compare; + typedef min_allocator Alloc; + typedef std::unordered_set C; + typedef int P; + P a1[] = + { + P(1), + P(2), + P(3), + P(4), + P(1), + P(2) + }; + P a2[] = + { + P(10), + P(20), + P(30), + P(40), + P(50), + P(60), + P(70), + P(80) + }; + C c1(std::begin(a1), std::end(a1), 0, Hash(1), Compare(1), Alloc()); + C c2(std::begin(a2), std::end(a2), 0, Hash(2), Compare(2), Alloc()); + c2.max_load_factor(2); + swap(c1, c2); + + assert(c1.bucket_count() >= 11); + assert(c1.size() == 8); + assert(*c1.find(10) == 10); + assert(*c1.find(20) == 20); + assert(*c1.find(30) == 30); + assert(*c1.find(40) == 40); + assert(*c1.find(50) == 50); + assert(*c1.find(60) == 60); + assert(*c1.find(70) == 70); + assert(*c1.find(80) == 80); + assert(c1.hash_function() == Hash(2)); + assert(c1.key_eq() == Compare(2)); + assert(c1.get_allocator() == Alloc()); + assert(std::distance(c1.begin(), c1.end()) == c1.size()); + assert(std::distance(c1.cbegin(), c1.cend()) == c1.size()); + assert(c1.max_load_factor() == 2); + + assert(c2.bucket_count() >= 5); + assert(c2.size() == 4); + assert(c2.count(1) == 1); + assert(c2.count(2) == 1); + assert(c2.count(3) == 1); + assert(c2.count(4) == 1); + assert(c2.hash_function() == Hash(1)); + assert(c2.key_eq() == Compare(1)); + assert(c2.get_allocator() == Alloc()); + assert(std::distance(c2.begin(), c2.end()) == c2.size()); + assert(std::distance(c2.cbegin(), c2.cend()) == c2.size()); + assert(c2.max_load_factor() == 1); + } +#endif +} diff --git a/libcxx/test/std/containers/unord/unord.set/version.pass.cpp b/libcxx/test/std/containers/unord/unord.set/version.pass.cpp new file mode 100644 index 00000000000..d651ebdfc45 --- /dev/null +++ b/libcxx/test/std/containers/unord/unord.set/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +#include + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} -- cgit v1.2.3