diff options
| author | Howard Hinnant <hhinnant@apple.com> | 2010-05-11 19:42:16 +0000 |
|---|---|---|
| committer | Howard Hinnant <hhinnant@apple.com> | 2010-05-11 19:42:16 +0000 |
| commit | 3e519524c118651123eecf60c2bbc5d65ad9bac3 (patch) | |
| tree | b2dd4168cfe448920a602cd7d2e40f95da187153 /libcxx/test/containers/associative | |
| parent | 9132c59d43b6c590c9bb33496eebf9f192d6857a (diff) | |
| download | bcm5719-llvm-3e519524c118651123eecf60c2bbc5d65ad9bac3.tar.gz bcm5719-llvm-3e519524c118651123eecf60c2bbc5d65ad9bac3.zip | |
libcxx initial import
llvm-svn: 103490
Diffstat (limited to 'libcxx/test/containers/associative')
173 files changed, 15074 insertions, 0 deletions
diff --git a/libcxx/test/containers/associative/map/map.access/at.pass.cpp b/libcxx/test/containers/associative/map/map.access/at.pass.cpp new file mode 100644 index 00000000000..28d14f60287 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.access/at.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// mapped_type& at(const key_type& k); +// const mapped_type& at(const key_type& k) const; + +#include <map> +#include <cassert> + +int main() +{ + { + typedef std::pair<const int, double> 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<int, double> 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<const int, double> 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<int, double> 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); + } +} diff --git a/libcxx/test/containers/associative/map/map.access/empty.pass.cpp b/libcxx/test/containers/associative/map/map.access/empty.pass.cpp new file mode 100644 index 00000000000..e347fe633f4 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.access/empty.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// bool empty() const; + +#include <map> +#include <cassert> + +int main() +{ + typedef std::map<int, double> M; + M m; + assert(m.empty()); + m.insert(M::value_type(1, 1.5)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); +} diff --git a/libcxx/test/containers/associative/map/map.access/index_key.pass.cpp b/libcxx/test/containers/associative/map/map.access/index_key.pass.cpp new file mode 100644 index 00000000000..1652169866e --- /dev/null +++ b/libcxx/test/containers/associative/map/map.access/index_key.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// mapped_type& operator[](const key_type& k); + +#include <map> +#include <cassert> + +int main() +{ + typedef std::pair<const int, double> 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<int, double> 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); +} diff --git a/libcxx/test/containers/associative/map/map.access/index_rv_key.pass.cpp b/libcxx/test/containers/associative/map/map.access/index_rv_key.pass.cpp new file mode 100644 index 00000000000..6c2766dfc41 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.access/index_rv_key.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// mapped_type& operator[](key_type&& k); + +#include <map> +#include <cassert> + +#include "../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef std::pair<MoveOnly, double> V; + std::map<MoveOnly, double> 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/containers/associative/map/map.access/iterator.pass.cpp b/libcxx/test/containers/associative/map/map.access/iterator.pass.cpp new file mode 100644 index 00000000000..0eefb758f6c --- /dev/null +++ b/libcxx/test/containers/associative/map/map.access/iterator.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// 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 <map> +#include <cassert> + +int main() +{ + { + typedef std::pair<const int, double> 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<int, double> 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<int, double>::iterator i = m.begin(); + std::map<int, double>::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<const int, double> 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<int, double> 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<int, double>::const_iterator i = m.begin(); + for (int j = 1; j <= m.size(); ++j, ++i) + { + assert(i->first == j); + assert(i->second == 1); + } + } +} diff --git a/libcxx/test/containers/associative/map/map.access/max_size.pass.cpp b/libcxx/test/containers/associative/map/map.access/max_size.pass.cpp new file mode 100644 index 00000000000..ee11af26298 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.access/max_size.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// size_type max_size() const; + +#include <map> +#include <cassert> + +int main() +{ + typedef std::map<int, double> M; + M m; + assert(m.max_size() != 0); +} diff --git a/libcxx/test/containers/associative/map/map.access/size.pass.cpp b/libcxx/test/containers/associative/map/map.access/size.pass.cpp new file mode 100644 index 00000000000..edbbdd95844 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.access/size.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// size_type size() const; + +#include <map> +#include <cassert> + +int main() +{ + typedef std::map<int, double> 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); +} diff --git a/libcxx/test/containers/associative/map/map.cons/alloc.pass.cpp b/libcxx/test/containers/associative/map/map.cons/alloc.pass.cpp new file mode 100644 index 00000000000..63d7b3b9493 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.cons/alloc.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// explicit map(const allocator_type& a); + +#include <map> +#include <cassert> + +#include "../../../test_allocator.h" + +int main() +{ + typedef std::less<int> C; + typedef test_allocator<std::pair<const int, double> > A; + std::map<int, double, C, A> m(A(5)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.get_allocator() == A(5)); +} diff --git a/libcxx/test/containers/associative/map/map.cons/assign_initializer_list.pass.cpp b/libcxx/test/containers/associative/map/map.cons/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..1947e5bbd09 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map& operator=(initializer_list<value_type> il); + +#include <map> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef std::pair<const int, double> V; + std::map<int, double> 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 +} diff --git a/libcxx/test/containers/associative/map/map.cons/compare.pass.cpp b/libcxx/test/containers/associative/map/map.cons/compare.pass.cpp new file mode 100644 index 00000000000..0235a345430 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.cons/compare.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// explicit map(const key_compare& comp); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" + +int main() +{ + typedef test_compare<std::less<int> > C; + std::map<int, double, C> m(C(3)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(3)); +} diff --git a/libcxx/test/containers/associative/map/map.cons/compare_alloc.pass.cpp b/libcxx/test/containers/associative/map/map.cons/compare_alloc.pass.cpp new file mode 100644 index 00000000000..924a906b080 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.cons/compare_alloc.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map(const key_compare& comp, const allocator_type& a); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ + typedef test_compare<std::less<int> > C; + typedef test_allocator<std::pair<const int, double> > A; + std::map<int, double, C, A> 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/containers/associative/map/map.cons/copy.pass.cpp b/libcxx/test/containers/associative/map/map.cons/copy.pass.cpp new file mode 100644 index 00000000000..a26c01540de --- /dev/null +++ b/libcxx/test/containers/associative/map/map.cons/copy.pass.cpp @@ -0,0 +1,94 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map(const map& m); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ + { + typedef std::pair<const int, double> 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<std::less<int> > C; + typedef test_allocator<V> A; + std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::map<int, double, C, A> 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<const int, double> 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<std::less<int> > C; + typedef other_allocator<V> A; + std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::map<int, double, C, A> 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 +} diff --git a/libcxx/test/containers/associative/map/map.cons/copy_alloc.pass.cpp b/libcxx/test/containers/associative/map/map.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..89337febec0 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.cons/copy_alloc.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map(const map& m, const allocator_type& a); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ + typedef std::pair<const int, double> 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<std::less<int> > C; + typedef test_allocator<V> A; + std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::map<int, double, C, A> 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)); +} diff --git a/libcxx/test/containers/associative/map/map.cons/copy_assign.pass.cpp b/libcxx/test/containers/associative/map/map.cons/copy_assign.pass.cpp new file mode 100644 index 00000000000..c350d4944ac --- /dev/null +++ b/libcxx/test/containers/associative/map/map.cons/copy_assign.pass.cpp @@ -0,0 +1,94 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map& operator=(const map& m); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ + { + typedef std::pair<const int, double> 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<std::less<int> > C; + typedef test_allocator<V> A; + std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2)); + std::map<int, double, C, A> 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<const int, double> 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<std::less<int> > C; + typedef other_allocator<V> A; + std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2)); + std::map<int, double, C, A> 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)); + } +} diff --git a/libcxx/test/containers/associative/map/map.cons/default.pass.cpp b/libcxx/test/containers/associative/map/map.cons/default.pass.cpp new file mode 100644 index 00000000000..b630c1e5fdf --- /dev/null +++ b/libcxx/test/containers/associative/map/map.cons/default.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map(); + +#include <map> +#include <cassert> + +int main() +{ + std::map<int, double> m; + assert(m.empty()); + assert(m.begin() == m.end()); +} diff --git a/libcxx/test/containers/associative/map/map.cons/initializer_list.pass.cpp b/libcxx/test/containers/associative/map/map.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..0d139e078d2 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.cons/initializer_list.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map(initializer_list<value_type> il); + +#include <map> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef std::pair<const int, double> V; + std::map<int, double> 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 +} diff --git a/libcxx/test/containers/associative/map/map.cons/initializer_list_compare.pass.cpp b/libcxx/test/containers/associative/map/map.cons/initializer_list_compare.pass.cpp new file mode 100644 index 00000000000..616d8afec2f --- /dev/null +++ b/libcxx/test/containers/associative/map/map.cons/initializer_list_compare.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map(initializer_list<value_type> il, const key_compare& comp); + +#include <map> +#include <cassert> +#include "../../../test_compare.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef std::pair<const int, double> V; + typedef test_compare<std::less<int> > C; + std::map<int, double, C> 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 +} diff --git a/libcxx/test/containers/associative/map/map.cons/initializer_list_compare_alloc.pass.cpp b/libcxx/test/containers/associative/map/map.cons/initializer_list_compare_alloc.pass.cpp new file mode 100644 index 00000000000..bfde3f711a3 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.cons/initializer_list_compare_alloc.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a); + +#include <map> +#include <cassert> +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef std::pair<const int, double> V; + typedef test_compare<std::less<int> > C; + typedef test_allocator<std::pair<const int, double> > A; + std::map<int, double, C, A> 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)); +#endif +} diff --git a/libcxx/test/containers/associative/map/map.cons/iter_iter.pass.cpp b/libcxx/test/containers/associative/map/map.cons/iter_iter.pass.cpp new file mode 100644 index 00000000000..d69249dc2a5 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.cons/iter_iter.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// template <class InputIterator> +// map(InputIterator first, InputIterator last); + +#include <map> +#include <cassert> + +int main() +{ + typedef std::pair<const int, double> 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<int, double> 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)); +} diff --git a/libcxx/test/containers/associative/map/map.cons/iter_iter_comp.pass.cpp b/libcxx/test/containers/associative/map/map.cons/iter_iter_comp.pass.cpp new file mode 100644 index 00000000000..6391c69fa79 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.cons/iter_iter_comp.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// template <class InputIterator> +// map(InputIterator first, InputIterator last, const key_compare& comp); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" + +int main() +{ + typedef std::pair<const int, double> 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<std::less<int> > C; + std::map<int, double, C> 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)); +} diff --git a/libcxx/test/containers/associative/map/map.cons/iter_iter_comp_alloc.pass.cpp b/libcxx/test/containers/associative/map/map.cons/iter_iter_comp_alloc.pass.cpp new file mode 100644 index 00000000000..86f86b21085 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.cons/iter_iter_comp_alloc.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// template <class InputIterator> +// map(InputIterator first, InputIterator last, +// const key_compare& comp, const allocator_type& a); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ + typedef std::pair<const int, double> 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<std::less<int> > C; + typedef test_allocator<V> A; + std::map<int, double, C, A> 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)); +} diff --git a/libcxx/test/containers/associative/map/map.cons/move.pass.cpp b/libcxx/test/containers/associative/map/map.cons/move.pass.cpp new file mode 100644 index 00000000000..4ead980838f --- /dev/null +++ b/libcxx/test/containers/associative/map/map.cons/move.pass.cpp @@ -0,0 +1,72 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map(map&& m); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef std::pair<const int, double> V; + { + typedef test_compare<std::less<int> > C; + typedef test_allocator<V> A; + std::map<int, double, C, A> mo(C(5), A(7)); + std::map<int, double, C, A> 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<std::less<int> > C; + typedef test_allocator<V> A; + std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::map<int, double, C, A> 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); + } +#endif +} diff --git a/libcxx/test/containers/associative/map/map.cons/move_alloc.pass.cpp b/libcxx/test/containers/associative/map/map.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..fbb88f647d3 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.cons/move_alloc.pass.cpp @@ -0,0 +1,144 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map(map&& m, const allocator_type& a); + +#include <map> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::pair<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef test_allocator<VC> A; + typedef std::map<MoveOnly, MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef test_allocator<VC> A; + typedef std::map<MoveOnly, MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef other_allocator<VC> A; + typedef std::map<MoveOnly, MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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()); + } +#endif +} diff --git a/libcxx/test/containers/associative/map/map.cons/move_assign.pass.cpp b/libcxx/test/containers/associative/map/map.cons/move_assign.pass.cpp new file mode 100644 index 00000000000..6222ce69730 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.cons/move_assign.pass.cpp @@ -0,0 +1,147 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map& operator=(map&& m); + +#include <map> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::pair<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef test_allocator<VC> A; + typedef std::map<MoveOnly, MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef test_allocator<VC> A; + typedef std::map<MoveOnly, MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef other_allocator<VC> A; + typedef std::map<MoveOnly, MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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()); + } +#endif +} diff --git a/libcxx/test/containers/associative/map/map.modifiers/clear.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/clear.pass.cpp new file mode 100644 index 00000000000..1c0fd4e6edd --- /dev/null +++ b/libcxx/test/containers/associative/map/map.modifiers/clear.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// void clear(); + +#include <map> +#include <cassert> + +int main() +{ + { + typedef std::map<int, double> M; + typedef std::pair<int, double> 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); + } +} diff --git a/libcxx/test/containers/associative/map/map.modifiers/emplace.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/emplace.pass.cpp new file mode 100644 index 00000000000..42abd814f6c --- /dev/null +++ b/libcxx/test/containers/associative/map/map.modifiers/emplace.pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// template <class... Args> +// pair<iterator, bool> emplace(Args&&... args); + +#include <map> +#include <cassert> + +#include "../../../Emplaceable.h" +#include "../../../DefaultOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::map<int, DefaultOnly> M; + typedef std::pair<M::iterator, bool> 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(1); + 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(1); + 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<int, Emplaceable> M; + typedef std::pair<M::iterator, bool> R; + M m; + R r = m.emplace(2); + 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(1, 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(1, 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<int, double> M; + typedef std::pair<M::iterator, bool> 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 +} diff --git a/libcxx/test/containers/associative/map/map.modifiers/emplace_hint.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/emplace_hint.pass.cpp new file mode 100644 index 00000000000..58827fdcb9a --- /dev/null +++ b/libcxx/test/containers/associative/map/map.modifiers/emplace_hint.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// template <class... Args> +// iterator emplace_hint(const_iterator position, Args&&... args); + +#include <map> +#include <cassert> + +#include "../../../Emplaceable.h" +#include "../../../DefaultOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::map<int, DefaultOnly> 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(), 1); + 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(), 1); + 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<int, Emplaceable> M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.end(), 2); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace_hint(m.end(), 1, 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(), 1, 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<int, double> 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 +} diff --git a/libcxx/test/containers/associative/map/map.modifiers/erase_iter.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/erase_iter.pass.cpp new file mode 100644 index 00000000000..045f8204422 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.modifiers/erase_iter.pass.cpp @@ -0,0 +1,127 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator erase(const_iterator position); + +#include <map> +#include <cassert> + +int main() +{ + { + typedef std::map<int, double> M; + typedef std::pair<int, double> 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()); + } +} diff --git a/libcxx/test/containers/associative/map/map.modifiers/erase_iter_iter.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..d7e375c36f2 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.modifiers/erase_iter_iter.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator erase(const_iterator first, const_iterator last); + +#include <map> +#include <cassert> + +int main() +{ + { + typedef std::map<int, double> M; + typedef std::pair<int, double> 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()); + } +} diff --git a/libcxx/test/containers/associative/map/map.modifiers/erase_key.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/erase_key.pass.cpp new file mode 100644 index 00000000000..6a184191ab0 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.modifiers/erase_key.pass.cpp @@ -0,0 +1,146 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// size_type erase(const key_type& k); + +#include <map> +#include <cassert> + +int main() +{ + { + typedef std::map<int, double> M; + typedef std::pair<int, double> 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); + } +} diff --git a/libcxx/test/containers/associative/map/map.modifiers/insert_cv.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/insert_cv.pass.cpp new file mode 100644 index 00000000000..41a80ecd4df --- /dev/null +++ b/libcxx/test/containers/associative/map/map.modifiers/insert_cv.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// pair<iterator, bool> insert(const value_type& v); + +#include <map> +#include <cassert> + +int main() +{ + { + typedef std::map<int, double> M; + typedef std::pair<M::iterator, bool> 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); + } +} diff --git a/libcxx/test/containers/associative/map/map.modifiers/insert_initializer_list.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/insert_initializer_list.pass.cpp new file mode 100644 index 00000000000..ff14a3e3e7b --- /dev/null +++ b/libcxx/test/containers/associative/map/map.modifiers/insert_initializer_list.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// void insert(initializer_list<value_type> il); + +#include <map> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef std::pair<const int, double> V; + std::map<int, double> 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 +} diff --git a/libcxx/test/containers/associative/map/map.modifiers/insert_iter_cv.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/insert_iter_cv.pass.cpp new file mode 100644 index 00000000000..d2f4d7eb3a6 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.modifiers/insert_iter_cv.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator insert(const_iterator position, const value_type& v); + +#include <map> +#include <cassert> + +int main() +{ + { + typedef std::map<int, double> 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); + } +} diff --git a/libcxx/test/containers/associative/map/map.modifiers/insert_iter_iter.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/insert_iter_iter.pass.cpp new file mode 100644 index 00000000000..10bf39ccf3b --- /dev/null +++ b/libcxx/test/containers/associative/map/map.modifiers/insert_iter_iter.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// template <class InputIterator> +// void insert(InputIterator first, InputIterator last); + +#include <map> +#include <cassert> + +#include "../../../iterators.h" + +int main() +{ + { + typedef std::map<int, double> M; + typedef std::pair<int, double> 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<P*>(ar), input_iterator<P*>(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); + } +} diff --git a/libcxx/test/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp new file mode 100644 index 00000000000..5aaffad94e9 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// template <class P> +// iterator insert(const_iterator position, P&& p); + +#include <map> +#include <cassert> + +#include "../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::map<int, MoveOnly> M; + typedef std::pair<int, MoveOnly> 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 +} diff --git a/libcxx/test/containers/associative/map/map.modifiers/insert_rv.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/insert_rv.pass.cpp new file mode 100644 index 00000000000..44fa49724f0 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.modifiers/insert_rv.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// template <class P> +// pair<iterator, bool> insert(P&& p); + +#include <map> +#include <cassert> + +#include "../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::map<int, MoveOnly> M; + typedef std::pair<M::iterator, bool> 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 +} diff --git a/libcxx/test/containers/associative/map/map.ops/count.pass.cpp b/libcxx/test/containers/associative/map/map.ops/count.pass.cpp new file mode 100644 index 00000000000..643d9a874a0 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.ops/count.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// size_type count(const key_type& k) const; + +#include <map> +#include <cassert> + +int main() +{ + typedef std::pair<const int, double> V; + typedef std::map<int, double> 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); + } +} diff --git a/libcxx/test/containers/associative/map/map.ops/equal_range.pass.cpp b/libcxx/test/containers/associative/map/map.ops/equal_range.pass.cpp new file mode 100644 index 00000000000..527a70b3103 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.ops/equal_range.pass.cpp @@ -0,0 +1,156 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// pair<iterator,iterator> equal_range(const key_type& k); +// pair<const_iterator,const_iterator> equal_range(const key_type& k) const; + +#include <map> +#include <cassert> + +int main() +{ + typedef std::pair<const int, double> V; + typedef std::map<int, double> M; + { + typedef std::pair<M::iterator, 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.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<M::const_iterator, 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.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)); + } +} diff --git a/libcxx/test/containers/associative/map/map.ops/find.pass.cpp b/libcxx/test/containers/associative/map/map.ops/find.pass.cpp new file mode 100644 index 00000000000..4566ce6460e --- /dev/null +++ b/libcxx/test/containers/associative/map/map.ops/find.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; + +#include <map> +#include <cassert> + +int main() +{ + typedef std::pair<const int, double> V; + typedef std::map<int, double> 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)); + } +} diff --git a/libcxx/test/containers/associative/map/map.ops/lower_bound.pass.cpp b/libcxx/test/containers/associative/map/map.ops/lower_bound.pass.cpp new file mode 100644 index 00000000000..11d58e036cb --- /dev/null +++ b/libcxx/test/containers/associative/map/map.ops/lower_bound.pass.cpp @@ -0,0 +1,122 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; + +#include <map> +#include <cassert> + +int main() +{ + typedef std::pair<const int, double> V; + typedef std::map<int, double> 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)); + } +} diff --git a/libcxx/test/containers/associative/map/map.ops/upper_bound.pass.cpp b/libcxx/test/containers/associative/map/map.ops/upper_bound.pass.cpp new file mode 100644 index 00000000000..1acb86a5226 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.ops/upper_bound.pass.cpp @@ -0,0 +1,122 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; + +#include <map> +#include <cassert> + +int main() +{ + typedef std::pair<const int, double> V; + typedef std::map<int, double> 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)); + } +} diff --git a/libcxx/test/containers/associative/map/map.special/member_swap.pass.cpp b/libcxx/test/containers/associative/map/map.special/member_swap.pass.cpp new file mode 100644 index 00000000000..cf7eb53fe3a --- /dev/null +++ b/libcxx/test/containers/associative/map/map.special/member_swap.pass.cpp @@ -0,0 +1,107 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// void swap(map& m); + +#include <map> +#include <cassert> + +int main() +{ + typedef std::pair<const int, double> V; + typedef std::map<int, double> 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); + } +} diff --git a/libcxx/test/containers/associative/map/map.special/non_member_swap.pass.cpp b/libcxx/test/containers/associative/map/map.special/non_member_swap.pass.cpp new file mode 100644 index 00000000000..516a6dc7770 --- /dev/null +++ b/libcxx/test/containers/associative/map/map.special/non_member_swap.pass.cpp @@ -0,0 +1,179 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// template <class Key, class T, class Compare, class Allocator> +// void +// swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y); + +#include <map> +#include <cassert> +#include "../../../test_allocator.h" +#include "../../../test_compare.h" + +int main() +{ + typedef std::pair<const int, double> V; + typedef std::map<int, double> 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<V> A; + typedef test_compare<std::less<int> > C; + typedef std::map<int, double, C, A> 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<V> A; + typedef test_compare<std::less<int> > C; + typedef std::map<int, double, C, A> 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)); + } +} diff --git a/libcxx/test/containers/associative/map/types.pass.cpp b/libcxx/test/containers/associative/map/types.pass.cpp new file mode 100644 index 00000000000..7898eae7dc6 --- /dev/null +++ b/libcxx/test/containers/associative/map/types.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// template <class Key, class T, class Compare = less<Key>, +// class Allocator = allocator<pair<const Key, T>>> +// class map +// { +// public: +// // types: +// typedef Key key_type; +// typedef T mapped_type; +// typedef pair<const key_type, mapped_type> 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 <map> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::map<int, double>::key_type, int>::value), ""); + static_assert((std::is_same<std::map<int, double>::mapped_type, double>::value), ""); + static_assert((std::is_same<std::map<int, double>::value_type, std::pair<const int, double> >::value), ""); + static_assert((std::is_same<std::map<int, double>::key_compare, std::less<int> >::value), ""); + static_assert((std::is_same<std::map<int, double>::allocator_type, std::allocator<std::pair<const int, double> > >::value), ""); + static_assert((std::is_same<std::map<int, double>::reference, std::pair<const int, double>&>::value), ""); + static_assert((std::is_same<std::map<int, double>::const_reference, const std::pair<const int, double>&>::value), ""); + static_assert((std::is_same<std::map<int, double>::pointer, std::pair<const int, double>*>::value), ""); + static_assert((std::is_same<std::map<int, double>::const_pointer, const std::pair<const int, double>*>::value), ""); + static_assert((std::is_same<std::map<int, double>::size_type, std::size_t>::value), ""); + static_assert((std::is_same<std::map<int, double>::difference_type, std::ptrdiff_t>::value), ""); +} diff --git a/libcxx/test/containers/associative/map/version.pass.cpp b/libcxx/test/containers/associative/map/version.pass.cpp new file mode 100644 index 00000000000..f4ba29c875e --- /dev/null +++ b/libcxx/test/containers/associative/map/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +#include <map> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/containers/associative/multimap/empty.pass.cpp b/libcxx/test/containers/associative/multimap/empty.pass.cpp new file mode 100644 index 00000000000..f837281188f --- /dev/null +++ b/libcxx/test/containers/associative/multimap/empty.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// bool empty() const; + +#include <map> +#include <cassert> + +int main() +{ + typedef std::multimap<int, double> M; + M m; + assert(m.empty()); + m.insert(M::value_type(1, 1.5)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); +} diff --git a/libcxx/test/containers/associative/multimap/iterator.pass.cpp b/libcxx/test/containers/associative/multimap/iterator.pass.cpp new file mode 100644 index 00000000000..70b95f5b8ee --- /dev/null +++ b/libcxx/test/containers/associative/multimap/iterator.pass.cpp @@ -0,0 +1,120 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// 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 <map> +#include <cassert> + +int main() +{ + { + typedef std::pair<const int, double> 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<int, double> 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<int, double>::iterator i = m.begin(); + std::multimap<int, double>::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<const int, double> 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<int, double> 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<int, double>::const_iterator 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); + } + } +} diff --git a/libcxx/test/containers/associative/multimap/max_size.pass.cpp b/libcxx/test/containers/associative/multimap/max_size.pass.cpp new file mode 100644 index 00000000000..e5c7ff0868f --- /dev/null +++ b/libcxx/test/containers/associative/multimap/max_size.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// size_type max_size() const; + +#include <map> +#include <cassert> + +int main() +{ + typedef std::multimap<int, double> M; + M m; + assert(m.max_size() != 0); +} diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/alloc.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/alloc.pass.cpp new file mode 100644 index 00000000000..d51a2ae7e7c --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.cons/alloc.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// explicit multimap(const allocator_type& a); + +#include <map> +#include <cassert> + +#include "../../../test_allocator.h" + +int main() +{ + typedef std::less<int> C; + typedef test_allocator<std::pair<const int, double> > A; + std::multimap<int, double, C, A> m(A(5)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.get_allocator() == A(5)); +} diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/assign_initializer_list.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..20172fef62f --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap& operator=(initializer_list<value_type> il); + +#include <map> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef std::multimap<int, double> 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 +} diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/compare.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/compare.pass.cpp new file mode 100644 index 00000000000..573ba1f69c1 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.cons/compare.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// explicit multimap(const key_compare& comp); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" + +int main() +{ + typedef test_compare<std::less<int> > C; + std::multimap<int, double, C> m(C(3)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(3)); +} diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/compare_alloc.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/compare_alloc.pass.cpp new file mode 100644 index 00000000000..9bf8e611e95 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.cons/compare_alloc.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap(const key_compare& comp, const allocator_type& a); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ + typedef test_compare<std::less<int> > C; + typedef test_allocator<std::pair<const int, double> > A; + std::multimap<int, double, C, A> 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/containers/associative/multimap/multimap.cons/copy.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/copy.pass.cpp new file mode 100644 index 00000000000..95fdf637f04 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.cons/copy.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap(const multimap& m); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ + { + typedef std::pair<const int, double> 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<std::less<int> > C; + typedef test_allocator<V> A; + std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::multimap<int, double, C, A> 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<const int, double> 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<std::less<int> > C; + typedef other_allocator<V> A; + std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::multimap<int, double, C, A> 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 +} diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/copy_alloc.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..d4a5bb5ca2d --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.cons/copy_alloc.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap(const multimap& m, const allocator_type& a); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ + typedef std::pair<const int, double> 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<std::less<int> > C; + typedef test_allocator<V> A; + std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::multimap<int, double, C, A> 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)); +} diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/copy_assign.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/copy_assign.pass.cpp new file mode 100644 index 00000000000..ca163836f18 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.cons/copy_assign.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap& operator=(const multimap& m); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ + { + typedef std::pair<const int, double> 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<std::less<int> > C; + typedef test_allocator<V> A; + std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2)); + std::multimap<int, double, C, A> 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<const int, double> 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<std::less<int> > C; + typedef other_allocator<V> A; + std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2)); + std::multimap<int, double, C, A> 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)); + } +} diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/default.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/default.pass.cpp new file mode 100644 index 00000000000..648331d7a75 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.cons/default.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap(); + +#include <map> +#include <cassert> + +int main() +{ + std::multimap<int, double> m; + assert(m.empty()); + assert(m.begin() == m.end()); +} diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..8f2444ffcfa --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap(initializer_list<value_type> il, const key_compare& comp = key_compare()); + +#include <map> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef std::multimap<int, double> 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 +} diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list_compare.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list_compare.pass.cpp new file mode 100644 index 00000000000..5ecea2f5ab2 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list_compare.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap(initializer_list<value_type> il, const key_compare& comp = key_compare()); + +#include <map> +#include <cassert> +#include "../../../test_compare.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef test_compare<std::less<int> > Cmp; + typedef std::multimap<int, double, Cmp> 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 +} diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list_compare_alloc.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list_compare_alloc.pass.cpp new file mode 100644 index 00000000000..ef4d4b39542 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list_compare_alloc.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a); + +#include <map> +#include <cassert> +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef test_compare<std::less<int> > Cmp; + typedef test_allocator<std::pair<const int, double> > A; + typedef std::multimap<int, double, Cmp, A> 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 +} diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter.pass.cpp new file mode 100644 index 00000000000..689c4ff99cf --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// template <class InputIterator> +// multimap(InputIterator first, InputIterator last); + +#include <map> +#include <cassert> + +int main() +{ + typedef std::pair<const int, double> 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<int, double> 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)); +} diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter_comp.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter_comp.pass.cpp new file mode 100644 index 00000000000..3dcfa4c520d --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter_comp.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// template <class InputIterator> +// multimap(InputIterator first, InputIterator last, +// const key_compare& comp); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" + +int main() +{ + typedef std::pair<const int, double> 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<std::less<int> > C; + std::multimap<int, double, C> 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)); +} diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter_comp_alloc.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter_comp_alloc.pass.cpp new file mode 100644 index 00000000000..c976a14613d --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter_comp_alloc.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// template <class InputIterator> +// multimap(InputIterator first, InputIterator last, +// const key_compare& comp, const allocator_type& a); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ + typedef std::pair<const int, double> 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<std::less<int> > C; + typedef test_allocator<V> A; + std::multimap<int, double, C, A> 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)); +} diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/move.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/move.pass.cpp new file mode 100644 index 00000000000..857d3907518 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.cons/move.pass.cpp @@ -0,0 +1,78 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap(multimap&& m); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef std::pair<const int, double> V; + { + typedef test_compare<std::less<int> > C; + typedef test_allocator<V> A; + std::multimap<int, double, C, A> mo(C(5), A(7)); + std::multimap<int, double, C, A> 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<std::less<int> > C; + typedef test_allocator<V> A; + std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::multimap<int, double, C, A> 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); + } +#endif +} diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/move_alloc.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..a70e19f8a04 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.cons/move_alloc.pass.cpp @@ -0,0 +1,144 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap(multimap&& m, const allocator_type& a); + +#include <map> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::pair<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef test_allocator<VC> A; + typedef std::multimap<MoveOnly, MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef test_allocator<VC> A; + typedef std::multimap<MoveOnly, MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef other_allocator<VC> A; + typedef std::multimap<MoveOnly, MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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()); + } +#endif +} diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/move_assign.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/move_assign.pass.cpp new file mode 100644 index 00000000000..ee72dc59b70 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.cons/move_assign.pass.cpp @@ -0,0 +1,147 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap& operator=(multimap&& m); + +#include <map> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::pair<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef test_allocator<VC> A; + typedef std::multimap<MoveOnly, MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef test_allocator<VC> A; + typedef std::multimap<MoveOnly, MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef other_allocator<VC> A; + typedef std::multimap<MoveOnly, MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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()); + } +#endif +} diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/clear.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/clear.pass.cpp new file mode 100644 index 00000000000..fe880e67979 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/clear.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// void clear(); + +#include <map> +#include <cassert> + +int main() +{ + { + typedef std::multimap<int, double> M; + typedef std::pair<int, double> 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); + } +} diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/emplace.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/emplace.pass.cpp new file mode 100644 index 00000000000..2544481839d --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/emplace.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// template <class... Args> +// iterator emplace(Args&&... args); + +#include <map> +#include <cassert> + +#include "../../../Emplaceable.h" +#include "../../../DefaultOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::multimap<int, DefaultOnly> 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(1); + 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(1); + 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<int, Emplaceable> M; + typedef M::iterator R; + M m; + R r = m.emplace(2); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace(1, 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(1, 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<int, double> 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 +} diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/emplace_hint.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/emplace_hint.pass.cpp new file mode 100644 index 00000000000..0e71b456f98 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/emplace_hint.pass.cpp @@ -0,0 +1,82 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// template <class... Args> +// iterator emplace_hint(const_iterator position, Args&&... args); + +#include <map> +#include <cassert> + +#include "../../../Emplaceable.h" +#include "../../../DefaultOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::multimap<int, DefaultOnly> 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(), 1); + 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(), 1); + 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<int, Emplaceable> M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.cend(), 2); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace_hint(m.cbegin(), 1, 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(), 1, 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<int, double> 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 +} diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_iter.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_iter.pass.cpp new file mode 100644 index 00000000000..830f3382788 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_iter.pass.cpp @@ -0,0 +1,148 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator erase(const_iterator position); + +#include <map> +#include <cassert> + +int main() +{ + { + typedef std::multimap<int, double> M; + typedef std::pair<int, double> 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()); + } +} diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_iter_iter.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..889664582f1 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_iter_iter.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator erase(const_iterator first, const_iterator last); + +#include <map> +#include <cassert> + +int main() +{ + { + typedef std::multimap<int, double> M; + typedef std::pair<int, double> 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()); + } +} diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_key.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_key.pass.cpp new file mode 100644 index 00000000000..2a9d5784ab6 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_key.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// size_type erase(const key_type& k); + +#include <map> +#include <cassert> + +int main() +{ + { + typedef std::multimap<int, double> M; + typedef std::pair<int, double> 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(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); + } +} diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_cv.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_cv.pass.cpp new file mode 100644 index 00000000000..81d752d628d --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_cv.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator insert(const value_type& v); + +#include <map> +#include <cassert> + +int main() +{ + { + typedef std::multimap<int, double> 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); + } +} diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_initializer_list.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_initializer_list.pass.cpp new file mode 100644 index 00000000000..82e7136308e --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_initializer_list.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// void insert(initializer_list<value_type> il); + +#include <map> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef std::multimap<int, double> 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 +} diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_cv.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_cv.pass.cpp new file mode 100644 index 00000000000..fd136659143 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_cv.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator insert(const_iterator position, const value_type& v); + +#include <map> +#include <cassert> + +int main() +{ + { + typedef std::multimap<int, double> 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); + } +} diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_iter.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_iter.pass.cpp new file mode 100644 index 00000000000..4d2ddf9c3a5 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_iter.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// template <class InputIterator> +// void insert(InputIterator first, InputIterator last); + +#include <map> +#include <cassert> + +#include "../../../iterators.h" + +int main() +{ + { + typedef std::multimap<int, double> M; + typedef std::pair<int, double> 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<P*>(ar), input_iterator<P*>(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); + } +} diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_rv.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_rv.pass.cpp new file mode 100644 index 00000000000..5429c16e877 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_rv.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// template <class P> +// iterator insert(const_iterator position, P&& p); + +#include <map> +#include <cassert> + +#include "../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::multimap<int, MoveOnly> M; + typedef std::pair<int, MoveOnly> 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 +} diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_rv.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_rv.pass.cpp new file mode 100644 index 00000000000..dc378b1110b --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_rv.pass.cpp @@ -0,0 +1,54 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// template <class P> +// iterator insert(P&& p); + +#include <map> +#include <cassert> + +#include "../../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::multimap<int, MoveOnly> 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 +} diff --git a/libcxx/test/containers/associative/multimap/multimap.ops/count.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.ops/count.pass.cpp new file mode 100644 index 00000000000..de49dab243e --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.ops/count.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// size_type count(const key_type& k) const; + +#include <map> +#include <cassert> + +int main() +{ + typedef std::pair<const int, double> V; + typedef std::multimap<int, double> 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); + } +} diff --git a/libcxx/test/containers/associative/multimap/multimap.ops/equal_range.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.ops/equal_range.pass.cpp new file mode 100644 index 00000000000..bcfe4cb326c --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.ops/equal_range.pass.cpp @@ -0,0 +1,98 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// pair<iterator, iterator> equal_range(const key_type& k); +// pair<const_iterator, const_iterator> equal_range(const key_type& k) const; + +#include <map> +#include <cassert> + +int main() +{ + typedef std::pair<const int, double> V; + typedef std::multimap<int, double> M; + { + typedef std::pair<M::iterator, 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.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<M::const_iterator, 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.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()); + } +} diff --git a/libcxx/test/containers/associative/multimap/multimap.ops/find.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.ops/find.pass.cpp new file mode 100644 index 00000000000..a5ea90fda94 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.ops/find.pass.cpp @@ -0,0 +1,80 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; + +#include <map> +#include <cassert> + +int main() +{ + typedef std::pair<const int, double> V; + typedef std::multimap<int, double> 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()); + } +} diff --git a/libcxx/test/containers/associative/multimap/multimap.ops/lower_bound.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.ops/lower_bound.pass.cpp new file mode 100644 index 00000000000..2d34ba10bd1 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.ops/lower_bound.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; + +#include <map> +#include <cassert> + +int main() +{ + typedef std::pair<const int, double> V; + typedef std::multimap<int, double> 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()); + } +} diff --git a/libcxx/test/containers/associative/multimap/multimap.ops/upper_bound.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.ops/upper_bound.pass.cpp new file mode 100644 index 00000000000..ed83342cea7 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.ops/upper_bound.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; + +#include <map> +#include <cassert> + +int main() +{ + typedef std::pair<const int, double> V; + typedef std::multimap<int, double> 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()); + } +} diff --git a/libcxx/test/containers/associative/multimap/multimap.special/member_swap.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.special/member_swap.pass.cpp new file mode 100644 index 00000000000..f623c613710 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.special/member_swap.pass.cpp @@ -0,0 +1,107 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// void swap(multimap& m); + +#include <map> +#include <cassert> + +int main() +{ + typedef std::pair<const int, double> V; + typedef std::multimap<int, double> 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); + } +} diff --git a/libcxx/test/containers/associative/multimap/multimap.special/non_member_swap.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.special/non_member_swap.pass.cpp new file mode 100644 index 00000000000..c37fc6060a7 --- /dev/null +++ b/libcxx/test/containers/associative/multimap/multimap.special/non_member_swap.pass.cpp @@ -0,0 +1,179 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// template <class Key, class T, class Compare, class Allocator> +// void +// swap(multimap<Key, T, Compare, Allocator>& x, multimap<Key, T, Compare, Allocator>& y); + +#include <map> +#include <cassert> +#include "../../../test_allocator.h" +#include "../../../test_compare.h" + +int main() +{ + typedef std::pair<const int, double> V; + typedef std::multimap<int, double> 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<V> A; + typedef test_compare<std::less<int> > C; + typedef std::multimap<int, double, C, A> 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<V> A; + typedef test_compare<std::less<int> > C; + typedef std::multimap<int, double, C, A> 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)); + } +} diff --git a/libcxx/test/containers/associative/multimap/size.pass.cpp b/libcxx/test/containers/associative/multimap/size.pass.cpp new file mode 100644 index 00000000000..e60b101005d --- /dev/null +++ b/libcxx/test/containers/associative/multimap/size.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// size_type size() const; + +#include <map> +#include <cassert> + +int main() +{ + typedef std::multimap<int, double> 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); +} diff --git a/libcxx/test/containers/associative/multimap/types.pass.cpp b/libcxx/test/containers/associative/multimap/types.pass.cpp new file mode 100644 index 00000000000..b805a70acea --- /dev/null +++ b/libcxx/test/containers/associative/multimap/types.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// template <class Key, class T, class Compare = less<Key>, +// class Allocator = allocator<pair<const Key, T>>> +// class multimap +// { +// public: +// // types: +// typedef Key key_type; +// typedef T mapped_type; +// typedef pair<const key_type, mapped_type> 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 <map> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::multimap<int, double>::key_type, int>::value), ""); + static_assert((std::is_same<std::multimap<int, double>::mapped_type, double>::value), ""); + static_assert((std::is_same<std::multimap<int, double>::value_type, std::pair<const int, double> >::value), ""); + static_assert((std::is_same<std::multimap<int, double>::key_compare, std::less<int> >::value), ""); + static_assert((std::is_same<std::multimap<int, double>::allocator_type, std::allocator<std::pair<const int, double> > >::value), ""); + static_assert((std::is_same<std::multimap<int, double>::reference, std::pair<const int, double>&>::value), ""); + static_assert((std::is_same<std::multimap<int, double>::const_reference, const std::pair<const int, double>&>::value), ""); + static_assert((std::is_same<std::multimap<int, double>::pointer, std::pair<const int, double>*>::value), ""); + static_assert((std::is_same<std::multimap<int, double>::const_pointer, const std::pair<const int, double>*>::value), ""); + static_assert((std::is_same<std::multimap<int, double>::size_type, std::size_t>::value), ""); + static_assert((std::is_same<std::multimap<int, double>::difference_type, std::ptrdiff_t>::value), ""); +} diff --git a/libcxx/test/containers/associative/multiset/clear.pass.cpp b/libcxx/test/containers/associative/multiset/clear.pass.cpp new file mode 100644 index 00000000000..c112aec753e --- /dev/null +++ b/libcxx/test/containers/associative/multiset/clear.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// void clear(); + +#include <set> +#include <cassert> + +int main() +{ + { + typedef std::multiset<int> 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); + } +} diff --git a/libcxx/test/containers/associative/multiset/count.pass.cpp b/libcxx/test/containers/associative/multiset/count.pass.cpp new file mode 100644 index 00000000000..930aedb3f9e --- /dev/null +++ b/libcxx/test/containers/associative/multiset/count.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// size_type count(const key_type& k) const; + +#include <set> +#include <cassert> + +int main() +{ + typedef int V; + typedef std::multiset<int> 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); + } +} diff --git a/libcxx/test/containers/associative/multiset/emplace.pass.cpp b/libcxx/test/containers/associative/multiset/emplace.pass.cpp new file mode 100644 index 00000000000..b1520e9bee5 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/emplace.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// template <class... Args> +// iterator emplace(Args&&... args); + +#include <set> +#include <cassert> + +#include "../../Emplaceable.h" +#include "../../DefaultOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::multiset<DefaultOnly> 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<Emplaceable> 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<int> 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 +} diff --git a/libcxx/test/containers/associative/multiset/emplace_hint.pass.cpp b/libcxx/test/containers/associative/multiset/emplace_hint.pass.cpp new file mode 100644 index 00000000000..4562249f225 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/emplace_hint.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// template <class... Args> +// iterator emplace_hint(const_iterator position, Args&&... args); + +#include <set> +#include <cassert> + +#include "../../Emplaceable.h" +#include "../../DefaultOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::multiset<DefaultOnly> 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<Emplaceable> 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<int> 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 +} diff --git a/libcxx/test/containers/associative/multiset/empty.pass.cpp b/libcxx/test/containers/associative/multiset/empty.pass.cpp new file mode 100644 index 00000000000..cc4052266e1 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/empty.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// bool empty() const; + +#include <set> +#include <cassert> + +int main() +{ + typedef std::multiset<int> M; + M m; + assert(m.empty()); + m.insert(M::value_type(1)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); +} diff --git a/libcxx/test/containers/associative/multiset/equal_range.pass.cpp b/libcxx/test/containers/associative/multiset/equal_range.pass.cpp new file mode 100644 index 00000000000..7abfa9282d3 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/equal_range.pass.cpp @@ -0,0 +1,98 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// pair<iterator,iterator> equal_range(const key_type& k); +// pair<const_iterator,const_iterator> equal_range(const key_type& k) const; + +#include <set> +#include <cassert> + +int main() +{ + typedef int V; + typedef std::multiset<int> M; + { + typedef std::pair<M::iterator, 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.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<M::const_iterator, M::const_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.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)); + } +} diff --git a/libcxx/test/containers/associative/multiset/erase_iter.pass.cpp b/libcxx/test/containers/associative/multiset/erase_iter.pass.cpp new file mode 100644 index 00000000000..0551ec92a4a --- /dev/null +++ b/libcxx/test/containers/associative/multiset/erase_iter.pass.cpp @@ -0,0 +1,99 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// iterator erase(const_iterator position); + +#include <set> +#include <cassert> + +int main() +{ + { + typedef std::multiset<int> 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()); + } +} diff --git a/libcxx/test/containers/associative/multiset/erase_iter_iter.pass.cpp b/libcxx/test/containers/associative/multiset/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..58eed89097c --- /dev/null +++ b/libcxx/test/containers/associative/multiset/erase_iter_iter.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// iterator erase(const_iterator first, const_iterator last); + +#include <set> +#include <cassert> + +int main() +{ + { + typedef std::multiset<int> 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()); + } +} diff --git a/libcxx/test/containers/associative/multiset/erase_key.pass.cpp b/libcxx/test/containers/associative/multiset/erase_key.pass.cpp new file mode 100644 index 00000000000..35273473276 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/erase_key.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// size_type erase(const key_type& k); + +#include <set> +#include <cassert> + +int main() +{ + { + typedef std::multiset<int> 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); + } +} diff --git a/libcxx/test/containers/associative/multiset/find.pass.cpp b/libcxx/test/containers/associative/multiset/find.pass.cpp new file mode 100644 index 00000000000..3cb1c51f3ca --- /dev/null +++ b/libcxx/test/containers/associative/multiset/find.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; + +#include <set> +#include <cassert> + +int main() +{ + typedef int V; + typedef std::multiset<int> 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)); + } +} diff --git a/libcxx/test/containers/associative/multiset/insert_cv.pass.cpp b/libcxx/test/containers/associative/multiset/insert_cv.pass.cpp new file mode 100644 index 00000000000..f17b4181572 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/insert_cv.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// iterator insert(const value_type& v); + +#include <set> +#include <cassert> + +int main() +{ + { + typedef std::multiset<int> 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); + } +} diff --git a/libcxx/test/containers/associative/multiset/insert_initializer_list.pass.cpp b/libcxx/test/containers/associative/multiset/insert_initializer_list.pass.cpp new file mode 100644 index 00000000000..3cf7bf16cd9 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/insert_initializer_list.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// void insert(initializer_list<value_type> il); + +#include <set> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef std::multiset<int> 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/containers/associative/multiset/insert_iter_cv.pass.cpp b/libcxx/test/containers/associative/multiset/insert_iter_cv.pass.cpp new file mode 100644 index 00000000000..a99e052cbf5 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/insert_iter_cv.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// iterator insert(const_iterator position, const value_type& v); + +#include <set> +#include <cassert> + +int main() +{ + { + typedef std::multiset<int> 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); + } +} diff --git a/libcxx/test/containers/associative/multiset/insert_iter_iter.pass.cpp b/libcxx/test/containers/associative/multiset/insert_iter_iter.pass.cpp new file mode 100644 index 00000000000..332574be18b --- /dev/null +++ b/libcxx/test/containers/associative/multiset/insert_iter_iter.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// template <class InputIterator> +// void insert(InputIterator first, InputIterator last); + +#include <set> +#include <cassert> + +#include "../../iterators.h" + +int main() +{ + { + typedef std::multiset<int> M; + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + M m; + m.insert(input_iterator<const V*>(ar), + input_iterator<const V*>(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); + } +} diff --git a/libcxx/test/containers/associative/multiset/insert_iter_rv.pass.cpp b/libcxx/test/containers/associative/multiset/insert_iter_rv.pass.cpp new file mode 100644 index 00000000000..f1179e7eb3a --- /dev/null +++ b/libcxx/test/containers/associative/multiset/insert_iter_rv.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// iterator insert(const_iterator position, value_type&& v); + +#include <set> +#include <cassert> + +#include "../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::multiset<MoveOnly> 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/containers/associative/multiset/insert_rv.pass.cpp b/libcxx/test/containers/associative/multiset/insert_rv.pass.cpp new file mode 100644 index 00000000000..1f722e41cc8 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/insert_rv.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// iterator insert(value_type&& v); + +#include <set> +#include <cassert> + +#include "../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::multiset<MoveOnly> 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/containers/associative/multiset/iterator.pass.cpp b/libcxx/test/containers/associative/multiset/iterator.pass.cpp new file mode 100644 index 00000000000..4a13f6b92e9 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/iterator.pass.cpp @@ -0,0 +1,112 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// 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 <set> +#include <cassert> + +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<int> 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<int>::iterator i = m.begin(); + std::multiset<int>::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<int> 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<int, double>::const_iterator i = m.begin(); + for (int j = 1; j <= 8; ++j) + for (int k = 0; k < 3; ++k, ++i) + assert(*i == j); + } +} diff --git a/libcxx/test/containers/associative/multiset/lower_bound.pass.cpp b/libcxx/test/containers/associative/multiset/lower_bound.pass.cpp new file mode 100644 index 00000000000..ec96e13b260 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/lower_bound.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; + +#include <set> +#include <cassert> + +int main() +{ + typedef int V; + typedef std::multiset<int> 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)); + } +} diff --git a/libcxx/test/containers/associative/multiset/max_size.pass.cpp b/libcxx/test/containers/associative/multiset/max_size.pass.cpp new file mode 100644 index 00000000000..0e0a8df2754 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/max_size.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// size_type max_size() const; + +#include <set> +#include <cassert> + +int main() +{ + typedef std::multiset<int> M; + M m; + assert(m.max_size() != 0); +} diff --git a/libcxx/test/containers/associative/multiset/multiset.cons/alloc.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/alloc.pass.cpp new file mode 100644 index 00000000000..df8fd063e83 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.cons/alloc.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// multiset(const allocator_type& a); + +#include <set> +#include <cassert> + +#include "../../../test_allocator.h" + +int main() +{ + typedef std::less<int> C; + typedef test_allocator<int> A; + std::multiset<int, C, A> m(A(5)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.get_allocator() == A(5)); +} diff --git a/libcxx/test/containers/associative/multiset/multiset.cons/assign_initializer_list.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..c47f6874171 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// multiset& operator=(initializer_list<value_type> il); + +#include <set> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef std::multiset<int> 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/containers/associative/multiset/multiset.cons/compare.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/compare.pass.cpp new file mode 100644 index 00000000000..7cba6d8df80 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.cons/compare.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// explicit multiset(const value_compare& comp); + +#include <set> +#include <cassert> + +#include "../../../test_compare.h" + +int main() +{ + typedef test_compare<std::less<int> > C; + std::multiset<int, C> m(C(3)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(3)); +} diff --git a/libcxx/test/containers/associative/multiset/multiset.cons/compare_alloc.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/compare_alloc.pass.cpp new file mode 100644 index 00000000000..c2d42325b3c --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.cons/compare_alloc.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// multiset(const value_compare& comp, const allocator_type& a); + +#include <set> +#include <cassert> + +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ + typedef test_compare<std::less<int> > C; + typedef test_allocator<int> A; + std::multiset<int, C, A> 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/containers/associative/multiset/multiset.cons/copy.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/copy.pass.cpp new file mode 100644 index 00000000000..8fb6b4ad8f9 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.cons/copy.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// multiset(const multiset& m); + +#include <set> +#include <cassert> + +#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<std::less<int> > C; + typedef test_allocator<V> A; + std::multiset<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::multiset<int, C, A> 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<std::less<int> > C; + typedef other_allocator<V> A; + std::multiset<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::multiset<int, C, A> 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 +} diff --git a/libcxx/test/containers/associative/multiset/multiset.cons/copy_alloc.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..6d60890ed35 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.cons/copy_alloc.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// multiset(const multiset& m, const allocator_type& a); + +#include <set> +#include <cassert> + +#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<std::less<int> > C; + typedef test_allocator<V> A; + std::multiset<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::multiset<int, C, A> 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/containers/associative/multiset/multiset.cons/copy_assign.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/copy_assign.pass.cpp new file mode 100644 index 00000000000..b52ed3b4126 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.cons/copy_assign.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// multiset& operator=(const multiset& s); + +#include <set> +#include <cassert> + +#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<std::less<int> > C; + typedef test_allocator<V> A; + std::multiset<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2)); + std::multiset<int, C, A> 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; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare<std::less<int> > C; + typedef other_allocator<V> A; + std::multiset<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2)); + std::multiset<int, C, A> 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/containers/associative/multiset/multiset.cons/default.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/default.pass.cpp new file mode 100644 index 00000000000..9f06fa9d82a --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.cons/default.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// multiset(); + +#include <set> +#include <cassert> + +int main() +{ + std::multiset<int> m; + assert(m.empty()); + assert(m.begin() == m.end()); +} diff --git a/libcxx/test/containers/associative/multiset/multiset.cons/initializer_list.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..802c6596305 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.cons/initializer_list.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// multiset(initializer_list<value_type> il, const key_compare& comp = key_compare()); + +#include <set> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef std::multiset<int> 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 +} diff --git a/libcxx/test/containers/associative/multiset/multiset.cons/initializer_list_compare.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/initializer_list_compare.pass.cpp new file mode 100644 index 00000000000..d5af1289574 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.cons/initializer_list_compare.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// multiset(initializer_list<value_type> il, const key_compare& comp = key_compare()); + +#include <set> +#include <cassert> +#include "../../../test_compare.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef test_compare<std::less<int> > Cmp; + typedef std::multiset<int, Cmp> 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 +} diff --git a/libcxx/test/containers/associative/multiset/multiset.cons/initializer_list_compare_alloc.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/initializer_list_compare_alloc.pass.cpp new file mode 100644 index 00000000000..7d78a2e25b6 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.cons/initializer_list_compare_alloc.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// multiset(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a); + +#include <set> +#include <cassert> +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef test_compare<std::less<int> > Cmp; + typedef test_allocator<int> A; + typedef std::multiset<int, Cmp, A> 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 +} diff --git a/libcxx/test/containers/associative/multiset/multiset.cons/iter_iter.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/iter_iter.pass.cpp new file mode 100644 index 00000000000..d7855f7c139 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.cons/iter_iter.pass.cpp @@ -0,0 +1,50 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// template <class InputIterator> +// multiset(InputIterator first, InputIterator last); + +#include <set> +#include <cassert> + +#include "../../../iterators.h" + +int main() +{ + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + std::multiset<V> m(input_iterator<const int*>(ar), + input_iterator<const int*>(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); +} diff --git a/libcxx/test/containers/associative/multiset/multiset.cons/iter_iter_alloc.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/iter_iter_alloc.pass.cpp new file mode 100644 index 00000000000..0b6cc43a6cf --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.cons/iter_iter_alloc.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// template <class InputIterator> +// multiset(InputIterator first, InputIterator last, +// const value_compare& comp, const allocator_type& a); + +#include <set> +#include <cassert> + +#include "../../../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<std::less<V> > C; + typedef test_allocator<V> A; + std::multiset<V, C, A> m(input_iterator<const V*>(ar), + input_iterator<const V*>(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); +} diff --git a/libcxx/test/containers/associative/multiset/multiset.cons/iter_iter_comp.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/iter_iter_comp.pass.cpp new file mode 100644 index 00000000000..06044eaac5c --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.cons/iter_iter_comp.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// template <class InputIterator> +// multiset(InputIterator first, InputIterator last, const value_compare& comp); + +#include <set> +#include <cassert> + +#include "../../../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<std::less<V> > C; + std::multiset<V, C> m(input_iterator<const V*>(ar), + input_iterator<const V*>(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/containers/associative/multiset/multiset.cons/move.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/move.pass.cpp new file mode 100644 index 00000000000..60ec113df59 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.cons/move.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// multiset(multiset&& s); + +#include <set> +#include <cassert> + +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef int V; + typedef test_compare<std::less<int> > C; + typedef test_allocator<V> A; + std::multiset<int, C, A> mo(C(5), A(7)); + std::multiset<int, C, A> 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<std::less<int> > C; + typedef test_allocator<V> A; + std::multiset<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::multiset<int, C, A> 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 +} diff --git a/libcxx/test/containers/associative/multiset/multiset.cons/move_alloc.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..c078bc5a761 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.cons/move_alloc.pass.cpp @@ -0,0 +1,141 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// multiset(multiset&& s, const allocator_type& a); + +#include <set> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef MoveOnly V; + typedef test_compare<std::less<MoveOnly> > C; + typedef test_allocator<V> A; + typedef std::multiset<MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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<std::less<MoveOnly> > C; + typedef test_allocator<V> A; + typedef std::multiset<MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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<std::less<MoveOnly> > C; + typedef other_allocator<V> A; + typedef std::multiset<MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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 +} diff --git a/libcxx/test/containers/associative/multiset/multiset.cons/move_assign.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/move_assign.pass.cpp new file mode 100644 index 00000000000..e4de43b9e3e --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.cons/move_assign.pass.cpp @@ -0,0 +1,144 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// multiset& operator=(multiset&& s); + +#include <set> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef MoveOnly V; + typedef test_compare<std::less<MoveOnly> > C; + typedef test_allocator<V> A; + typedef std::multiset<MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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<std::less<MoveOnly> > C; + typedef test_allocator<V> A; + typedef std::multiset<MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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<std::less<MoveOnly> > C; + typedef other_allocator<V> A; + typedef std::multiset<MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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 +} diff --git a/libcxx/test/containers/associative/multiset/multiset.special/member_swap.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.special/member_swap.pass.cpp new file mode 100644 index 00000000000..fdcfb26b3e0 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.special/member_swap.pass.cpp @@ -0,0 +1,107 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// void swap(multiset& m); + +#include <set> +#include <cassert> + +int main() +{ + typedef int V; + typedef std::multiset<int> 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); + } +} diff --git a/libcxx/test/containers/associative/multiset/multiset.special/non_member_swap.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.special/non_member_swap.pass.cpp new file mode 100644 index 00000000000..b4b0d06636d --- /dev/null +++ b/libcxx/test/containers/associative/multiset/multiset.special/non_member_swap.pass.cpp @@ -0,0 +1,177 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// void swap(multiset& m); + +#include <set> +#include <cassert> +#include "../../../test_allocator.h" +#include "../../../test_compare.h" + +int main() +{ + typedef int V; + typedef std::multiset<int> 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<V> A; + typedef test_compare<std::less<int> > C; + typedef std::set<int, C, A> 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<V> A; + typedef test_compare<std::less<int> > C; + typedef std::set<int, C, A> 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/containers/associative/multiset/size.pass.cpp b/libcxx/test/containers/associative/multiset/size.pass.cpp new file mode 100644 index 00000000000..7431701cfc5 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/size.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// size_type size() const; + +#include <set> +#include <cassert> + +int main() +{ + typedef std::multiset<int> 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); +} diff --git a/libcxx/test/containers/associative/multiset/types.pass.cpp b/libcxx/test/containers/associative/multiset/types.pass.cpp new file mode 100644 index 00000000000..f1ec41340d9 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/types.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// template <class Key, class Compare = less<Key>, +// class Allocator = allocator<Key>> +// 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 <set> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::multiset<int>::key_type, int>::value), ""); + static_assert((std::is_same<std::multiset<int>::value_type, int>::value), ""); + static_assert((std::is_same<std::multiset<int>::key_compare, std::less<int> >::value), ""); + static_assert((std::is_same<std::multiset<int>::value_compare, std::less<int> >::value), ""); + static_assert((std::is_same<std::multiset<int>::allocator_type, std::allocator<int> >::value), ""); + static_assert((std::is_same<std::multiset<int>::reference, int&>::value), ""); + static_assert((std::is_same<std::multiset<int>::const_reference, const int&>::value), ""); + static_assert((std::is_same<std::multiset<int>::pointer, int*>::value), ""); + static_assert((std::is_same<std::multiset<int>::const_pointer, const int*>::value), ""); + static_assert((std::is_same<std::multiset<int>::size_type, std::size_t>::value), ""); + static_assert((std::is_same<std::multiset<int>::difference_type, std::ptrdiff_t>::value), ""); +} diff --git a/libcxx/test/containers/associative/multiset/upper_bound.pass.cpp b/libcxx/test/containers/associative/multiset/upper_bound.pass.cpp new file mode 100644 index 00000000000..2244e7cca37 --- /dev/null +++ b/libcxx/test/containers/associative/multiset/upper_bound.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; + +#include <set> +#include <cassert> + +int main() +{ + typedef int V; + typedef std::multiset<int> 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)); + } +} diff --git a/libcxx/test/containers/associative/set/clear.pass.cpp b/libcxx/test/containers/associative/set/clear.pass.cpp new file mode 100644 index 00000000000..b3925217a01 --- /dev/null +++ b/libcxx/test/containers/associative/set/clear.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// void clear(); + +#include <set> +#include <cassert> + +int main() +{ + { + typedef std::set<int> 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); + } +} diff --git a/libcxx/test/containers/associative/set/count.pass.cpp b/libcxx/test/containers/associative/set/count.pass.cpp new file mode 100644 index 00000000000..b46242e8d1f --- /dev/null +++ b/libcxx/test/containers/associative/set/count.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// size_type count(const key_type& k) const; + +#include <set> +#include <cassert> + +int main() +{ + typedef int V; + typedef std::set<int> 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); + } +} diff --git a/libcxx/test/containers/associative/set/emplace.pass.cpp b/libcxx/test/containers/associative/set/emplace.pass.cpp new file mode 100644 index 00000000000..35f9856e3c9 --- /dev/null +++ b/libcxx/test/containers/associative/set/emplace.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// template <class... Args> +// pair<iterator, bool> emplace(Args&&... args); + +#include <set> +#include <cassert> + +#include "../../Emplaceable.h" +#include "../../DefaultOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::set<DefaultOnly> M; + typedef std::pair<M::iterator, bool> 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<Emplaceable> M; + typedef std::pair<M::iterator, bool> 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<int> M; + typedef std::pair<M::iterator, bool> 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 +} diff --git a/libcxx/test/containers/associative/set/emplace_hint.pass.cpp b/libcxx/test/containers/associative/set/emplace_hint.pass.cpp new file mode 100644 index 00000000000..af0439cacf3 --- /dev/null +++ b/libcxx/test/containers/associative/set/emplace_hint.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// template <class... Args> +// iterator emplace_hint(const_iterator position, Args&&... args); + +#include <set> +#include <cassert> + +#include "../../Emplaceable.h" +#include "../../DefaultOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::set<DefaultOnly> 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<Emplaceable> 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<int> 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 +} diff --git a/libcxx/test/containers/associative/set/empty.pass.cpp b/libcxx/test/containers/associative/set/empty.pass.cpp new file mode 100644 index 00000000000..a036656b7d6 --- /dev/null +++ b/libcxx/test/containers/associative/set/empty.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// bool empty() const; + +#include <set> +#include <cassert> + +int main() +{ + typedef std::set<int> M; + M m; + assert(m.empty()); + m.insert(M::value_type(1)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); +} diff --git a/libcxx/test/containers/associative/set/equal_range.pass.cpp b/libcxx/test/containers/associative/set/equal_range.pass.cpp new file mode 100644 index 00000000000..7c39821b2c8 --- /dev/null +++ b/libcxx/test/containers/associative/set/equal_range.pass.cpp @@ -0,0 +1,156 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// pair<iterator,iterator> equal_range(const key_type& k); +// pair<const_iterator,const_iterator> equal_range(const key_type& k) const; + +#include <set> +#include <cassert> + +int main() +{ + typedef int V; + typedef std::set<int> M; + { + typedef std::pair<M::iterator, 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.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<M::const_iterator, 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.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)); + } +} diff --git a/libcxx/test/containers/associative/set/erase_iter.pass.cpp b/libcxx/test/containers/associative/set/erase_iter.pass.cpp new file mode 100644 index 00000000000..f5a698db8a9 --- /dev/null +++ b/libcxx/test/containers/associative/set/erase_iter.pass.cpp @@ -0,0 +1,99 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// iterator erase(const_iterator position); + +#include <set> +#include <cassert> + +int main() +{ + { + typedef std::set<int> 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()); + } +} diff --git a/libcxx/test/containers/associative/set/erase_iter_iter.pass.cpp b/libcxx/test/containers/associative/set/erase_iter_iter.pass.cpp new file mode 100644 index 00000000000..1d02040cc92 --- /dev/null +++ b/libcxx/test/containers/associative/set/erase_iter_iter.pass.cpp @@ -0,0 +1,79 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// iterator erase(const_iterator first, const_iterator last); + +#include <set> +#include <cassert> + +int main() +{ + { + typedef std::set<int> 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()); + } +} diff --git a/libcxx/test/containers/associative/set/erase_key.pass.cpp b/libcxx/test/containers/associative/set/erase_key.pass.cpp new file mode 100644 index 00000000000..0c4c7b46b74 --- /dev/null +++ b/libcxx/test/containers/associative/set/erase_key.pass.cpp @@ -0,0 +1,110 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// size_type erase(const key_type& k); + +#include <set> +#include <cassert> + +int main() +{ + { + typedef std::set<int> 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); + } +} diff --git a/libcxx/test/containers/associative/set/find.pass.cpp b/libcxx/test/containers/associative/set/find.pass.cpp new file mode 100644 index 00000000000..885d6aafdf5 --- /dev/null +++ b/libcxx/test/containers/associative/set/find.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; + +#include <set> +#include <cassert> + +int main() +{ + typedef int V; + typedef std::set<int> 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)); + } +} diff --git a/libcxx/test/containers/associative/set/insert_cv.pass.cpp b/libcxx/test/containers/associative/set/insert_cv.pass.cpp new file mode 100644 index 00000000000..8fcc57da4b9 --- /dev/null +++ b/libcxx/test/containers/associative/set/insert_cv.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// pair<iterator, bool> insert(const value_type& v); + +#include <set> +#include <cassert> + +int main() +{ + { + typedef std::set<int> M; + typedef std::pair<M::iterator, bool> 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); + } +} diff --git a/libcxx/test/containers/associative/set/insert_initializer_list.pass.cpp b/libcxx/test/containers/associative/set/insert_initializer_list.pass.cpp new file mode 100644 index 00000000000..089238bf540 --- /dev/null +++ b/libcxx/test/containers/associative/set/insert_initializer_list.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// void insert(initializer_list<value_type> il); + +#include <set> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef std::set<int> 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/containers/associative/set/insert_iter_cv.pass.cpp b/libcxx/test/containers/associative/set/insert_iter_cv.pass.cpp new file mode 100644 index 00000000000..3940ff3fcf9 --- /dev/null +++ b/libcxx/test/containers/associative/set/insert_iter_cv.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// iterator insert(const_iterator position, const value_type& v); + +#include <set> +#include <cassert> + +int main() +{ + { + typedef std::set<int> 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); + } +} diff --git a/libcxx/test/containers/associative/set/insert_iter_iter.pass.cpp b/libcxx/test/containers/associative/set/insert_iter_iter.pass.cpp new file mode 100644 index 00000000000..dc7df9345cd --- /dev/null +++ b/libcxx/test/containers/associative/set/insert_iter_iter.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// template <class InputIterator> +// void insert(InputIterator first, InputIterator last); + +#include <set> +#include <cassert> + +#include "../../iterators.h" + +int main() +{ + { + typedef std::set<int> M; + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + M m; + m.insert(input_iterator<const V*>(ar), + input_iterator<const V*>(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); + } +} diff --git a/libcxx/test/containers/associative/set/insert_iter_rv.pass.cpp b/libcxx/test/containers/associative/set/insert_iter_rv.pass.cpp new file mode 100644 index 00000000000..4cbc2f95901 --- /dev/null +++ b/libcxx/test/containers/associative/set/insert_iter_rv.pass.cpp @@ -0,0 +1,49 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// iterator insert(const_iterator position, value_type&& v); + +#include <set> +#include <cassert> + +#include "../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::set<MoveOnly> 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/containers/associative/set/insert_rv.pass.cpp b/libcxx/test/containers/associative/set/insert_rv.pass.cpp new file mode 100644 index 00000000000..9605596b79b --- /dev/null +++ b/libcxx/test/containers/associative/set/insert_rv.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// pair<iterator, bool> insert(value_type&& v); + +#include <set> +#include <cassert> + +#include "../../MoveOnly.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef std::set<MoveOnly> M; + typedef std::pair<M::iterator, bool> 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/containers/associative/set/iterator.pass.cpp b/libcxx/test/containers/associative/set/iterator.pass.cpp new file mode 100644 index 00000000000..c94590c89ce --- /dev/null +++ b/libcxx/test/containers/associative/set/iterator.pass.cpp @@ -0,0 +1,110 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// 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 <set> +#include <cassert> + +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<int> 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<int>::iterator i = m.begin(); + std::set<int>::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<int> 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<int, double>::const_iterator i = m.begin(); + for (int j = 1; j <= m.size(); ++j, ++i) + assert(*i == j); + } +} diff --git a/libcxx/test/containers/associative/set/lower_bound.pass.cpp b/libcxx/test/containers/associative/set/lower_bound.pass.cpp new file mode 100644 index 00000000000..7f4b0e39516 --- /dev/null +++ b/libcxx/test/containers/associative/set/lower_bound.pass.cpp @@ -0,0 +1,122 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; + +#include <set> +#include <cassert> + +int main() +{ + typedef int V; + typedef std::set<int> 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)); + } +} diff --git a/libcxx/test/containers/associative/set/max_size.pass.cpp b/libcxx/test/containers/associative/set/max_size.pass.cpp new file mode 100644 index 00000000000..4f4861acbe8 --- /dev/null +++ b/libcxx/test/containers/associative/set/max_size.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// size_type max_size() const; + +#include <set> +#include <cassert> + +int main() +{ + typedef std::set<int> M; + M m; + assert(m.max_size() != 0); +} diff --git a/libcxx/test/containers/associative/set/set.cons/alloc.pass.cpp b/libcxx/test/containers/associative/set/set.cons/alloc.pass.cpp new file mode 100644 index 00000000000..ec64902ae4d --- /dev/null +++ b/libcxx/test/containers/associative/set/set.cons/alloc.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set(const allocator_type& a); + +#include <set> +#include <cassert> + +#include "../../../test_allocator.h" + +int main() +{ + typedef std::less<int> C; + typedef test_allocator<int> A; + std::set<int, C, A> m(A(5)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.get_allocator() == A(5)); +} diff --git a/libcxx/test/containers/associative/set/set.cons/assign_initializer_list.pass.cpp b/libcxx/test/containers/associative/set/set.cons/assign_initializer_list.pass.cpp new file mode 100644 index 00000000000..5d1836b976b --- /dev/null +++ b/libcxx/test/containers/associative/set/set.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set& operator=(initializer_list<value_type> il); + +#include <set> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef std::set<int> 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/containers/associative/set/set.cons/compare.pass.cpp b/libcxx/test/containers/associative/set/set.cons/compare.pass.cpp new file mode 100644 index 00000000000..00d3b921101 --- /dev/null +++ b/libcxx/test/containers/associative/set/set.cons/compare.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// explicit set(const value_compare& comp); + +#include <set> +#include <cassert> + +#include "../../../test_compare.h" + +int main() +{ + typedef test_compare<std::less<int> > C; + std::set<int, C> m(C(3)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(3)); +} diff --git a/libcxx/test/containers/associative/set/set.cons/compare_alloc.pass.cpp b/libcxx/test/containers/associative/set/set.cons/compare_alloc.pass.cpp new file mode 100644 index 00000000000..0b1d7a20346 --- /dev/null +++ b/libcxx/test/containers/associative/set/set.cons/compare_alloc.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set(const value_compare& comp, const allocator_type& a); + +#include <set> +#include <cassert> + +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ + typedef test_compare<std::less<int> > C; + typedef test_allocator<int> A; + std::set<int, C, A> 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/containers/associative/set/set.cons/copy.pass.cpp b/libcxx/test/containers/associative/set/set.cons/copy.pass.cpp new file mode 100644 index 00000000000..3ff1130cfa7 --- /dev/null +++ b/libcxx/test/containers/associative/set/set.cons/copy.pass.cpp @@ -0,0 +1,94 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set(const set& m); + +#include <set> +#include <cassert> + +#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<std::less<int> > C; + typedef test_allocator<V> A; + std::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::set<int, C, A> 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<std::less<int> > C; + typedef other_allocator<V> A; + std::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::set<int, C, A> 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 +} diff --git a/libcxx/test/containers/associative/set/set.cons/copy_alloc.pass.cpp b/libcxx/test/containers/associative/set/set.cons/copy_alloc.pass.cpp new file mode 100644 index 00000000000..c0b58ea2f0d --- /dev/null +++ b/libcxx/test/containers/associative/set/set.cons/copy_alloc.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set(const set& m, const allocator_type& a); + +#include <set> +#include <cassert> + +#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<std::less<int> > C; + typedef test_allocator<V> A; + std::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::set<int, C, A> 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/containers/associative/set/set.cons/copy_assign.pass.cpp b/libcxx/test/containers/associative/set/set.cons/copy_assign.pass.cpp new file mode 100644 index 00000000000..17e18dee5b7 --- /dev/null +++ b/libcxx/test/containers/associative/set/set.cons/copy_assign.pass.cpp @@ -0,0 +1,94 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set& operator=(const set& s); + +#include <set> +#include <cassert> + +#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<std::less<int> > C; + typedef test_allocator<V> A; + std::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2)); + std::set<int, C, A> 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; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare<std::less<int> > C; + typedef other_allocator<V> A; + std::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(2)); + std::set<int, C, A> 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/containers/associative/set/set.cons/default.pass.cpp b/libcxx/test/containers/associative/set/set.cons/default.pass.cpp new file mode 100644 index 00000000000..57c3243f48f --- /dev/null +++ b/libcxx/test/containers/associative/set/set.cons/default.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set(); + +#include <set> +#include <cassert> + +int main() +{ + std::set<int> m; + assert(m.empty()); + assert(m.begin() == m.end()); +} diff --git a/libcxx/test/containers/associative/set/set.cons/initializer_list.pass.cpp b/libcxx/test/containers/associative/set/set.cons/initializer_list.pass.cpp new file mode 100644 index 00000000000..dce2427b268 --- /dev/null +++ b/libcxx/test/containers/associative/set/set.cons/initializer_list.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set(initializer_list<value_type> il, const key_compare& comp = key_compare()); + +#include <set> +#include <cassert> + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef std::set<int> 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 +} diff --git a/libcxx/test/containers/associative/set/set.cons/initializer_list_compare.pass.cpp b/libcxx/test/containers/associative/set/set.cons/initializer_list_compare.pass.cpp new file mode 100644 index 00000000000..b11da1c7ab8 --- /dev/null +++ b/libcxx/test/containers/associative/set/set.cons/initializer_list_compare.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set(initializer_list<value_type> il, const key_compare& comp = key_compare()); + +#include <set> +#include <cassert> +#include "../../../test_compare.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef test_compare<std::less<int> > Cmp; + typedef std::set<int, Cmp> 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 +} diff --git a/libcxx/test/containers/associative/set/set.cons/initializer_list_compare_alloc.pass.cpp b/libcxx/test/containers/associative/set/set.cons/initializer_list_compare_alloc.pass.cpp new file mode 100644 index 00000000000..12c3f4417af --- /dev/null +++ b/libcxx/test/containers/associative/set/set.cons/initializer_list_compare_alloc.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a); + +#include <set> +#include <cassert> +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + typedef test_compare<std::less<int> > Cmp; + typedef test_allocator<int> A; + typedef std::set<int, Cmp, A> 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 +} diff --git a/libcxx/test/containers/associative/set/set.cons/iter_iter.pass.cpp b/libcxx/test/containers/associative/set/set.cons/iter_iter.pass.cpp new file mode 100644 index 00000000000..d62c7bceb35 --- /dev/null +++ b/libcxx/test/containers/associative/set/set.cons/iter_iter.pass.cpp @@ -0,0 +1,44 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// template <class InputIterator> +// set(InputIterator first, InputIterator last); + +#include <set> +#include <cassert> + +#include "../../../iterators.h" + +int main() +{ + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + std::set<V> m(input_iterator<const int*>(ar), + input_iterator<const int*>(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); +} diff --git a/libcxx/test/containers/associative/set/set.cons/iter_iter_alloc.pass.cpp b/libcxx/test/containers/associative/set/set.cons/iter_iter_alloc.pass.cpp new file mode 100644 index 00000000000..b84bece38cb --- /dev/null +++ b/libcxx/test/containers/associative/set/set.cons/iter_iter_alloc.pass.cpp @@ -0,0 +1,52 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// template <class InputIterator> +// set(InputIterator first, InputIterator last, +// const value_compare& comp, const allocator_type& a); + +#include <set> +#include <cassert> + +#include "../../../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<std::less<V> > C; + typedef test_allocator<V> A; + std::set<V, C, A> m(input_iterator<const V*>(ar), + input_iterator<const V*>(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); +} diff --git a/libcxx/test/containers/associative/set/set.cons/iter_iter_comp.pass.cpp b/libcxx/test/containers/associative/set/set.cons/iter_iter_comp.pass.cpp new file mode 100644 index 00000000000..8466eefbaaa --- /dev/null +++ b/libcxx/test/containers/associative/set/set.cons/iter_iter_comp.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// template <class InputIterator> +// set(InputIterator first, InputIterator last, const value_compare& comp); + +#include <set> +#include <cassert> + +#include "../../../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<std::less<V> > C; + std::set<V, C> m(input_iterator<const V*>(ar), + input_iterator<const V*>(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/containers/associative/set/set.cons/move.pass.cpp b/libcxx/test/containers/associative/set/set.cons/move.pass.cpp new file mode 100644 index 00000000000..4859b24c825 --- /dev/null +++ b/libcxx/test/containers/associative/set/set.cons/move.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set(set&& s); + +#include <set> +#include <cassert> + +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef int V; + typedef test_compare<std::less<int> > C; + typedef test_allocator<V> A; + std::set<int, C, A> mo(C(5), A(7)); + std::set<int, C, A> 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<std::less<int> > C; + typedef test_allocator<V> A; + std::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A(7)); + std::set<int, C, A> 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); + } +#endif +} diff --git a/libcxx/test/containers/associative/set/set.cons/move_alloc.pass.cpp b/libcxx/test/containers/associative/set/set.cons/move_alloc.pass.cpp new file mode 100644 index 00000000000..120707926a8 --- /dev/null +++ b/libcxx/test/containers/associative/set/set.cons/move_alloc.pass.cpp @@ -0,0 +1,141 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set(set&& s, const allocator_type& a); + +#include <set> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef MoveOnly V; + typedef test_compare<std::less<MoveOnly> > C; + typedef test_allocator<V> A; + typedef std::set<MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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<std::less<MoveOnly> > C; + typedef test_allocator<V> A; + typedef std::set<MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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<std::less<MoveOnly> > C; + typedef other_allocator<V> A; + typedef std::set<MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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 +} diff --git a/libcxx/test/containers/associative/set/set.cons/move_assign.pass.cpp b/libcxx/test/containers/associative/set/set.cons/move_assign.pass.cpp new file mode 100644 index 00000000000..d9261f0347f --- /dev/null +++ b/libcxx/test/containers/associative/set/set.cons/move_assign.pass.cpp @@ -0,0 +1,144 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set& operator=(set&& s); + +#include <set> +#include <cassert> + +#include "../../../MoveOnly.h" +#include "../../../test_compare.h" +#include "../../../test_allocator.h" + +int main() +{ +#ifdef _LIBCPP_MOVE + { + typedef MoveOnly V; + typedef test_compare<std::less<MoveOnly> > C; + typedef test_allocator<V> A; + typedef std::set<MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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<std::less<MoveOnly> > C; + typedef test_allocator<V> A; + typedef std::set<MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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<std::less<MoveOnly> > C; + typedef other_allocator<V> A; + typedef std::set<MoveOnly, C, A> M; + typedef std::move_iterator<V*> 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 +} diff --git a/libcxx/test/containers/associative/set/set.special/member_swap.pass.cpp b/libcxx/test/containers/associative/set/set.special/member_swap.pass.cpp new file mode 100644 index 00000000000..74b2a2b9c53 --- /dev/null +++ b/libcxx/test/containers/associative/set/set.special/member_swap.pass.cpp @@ -0,0 +1,107 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// void swap(set& m); + +#include <set> +#include <cassert> + +int main() +{ + typedef int V; + typedef std::set<int> 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); + } +} diff --git a/libcxx/test/containers/associative/set/set.special/non_member_swap.pass.cpp b/libcxx/test/containers/associative/set/set.special/non_member_swap.pass.cpp new file mode 100644 index 00000000000..bca756213f0 --- /dev/null +++ b/libcxx/test/containers/associative/set/set.special/non_member_swap.pass.cpp @@ -0,0 +1,177 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// void swap(set& m); + +#include <set> +#include <cassert> +#include "../../../test_allocator.h" +#include "../../../test_compare.h" + +int main() +{ + typedef int V; + typedef std::set<int> 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<V> A; + typedef test_compare<std::less<int> > C; + typedef std::multiset<int, C, A> 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<V> A; + typedef test_compare<std::less<int> > C; + typedef std::multiset<int, C, A> 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/containers/associative/set/size.pass.cpp b/libcxx/test/containers/associative/set/size.pass.cpp new file mode 100644 index 00000000000..a0c245842b0 --- /dev/null +++ b/libcxx/test/containers/associative/set/size.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// size_type size() const; + +#include <set> +#include <cassert> + +int main() +{ + typedef std::set<int> 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); +} diff --git a/libcxx/test/containers/associative/set/types.pass.cpp b/libcxx/test/containers/associative/set/types.pass.cpp new file mode 100644 index 00000000000..574825e0812 --- /dev/null +++ b/libcxx/test/containers/associative/set/types.pass.cpp @@ -0,0 +1,48 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// template <class Key, class Compare = less<Key>, +// class Allocator = allocator<Key>> +// 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 <set> +#include <type_traits> + +int main() +{ + static_assert((std::is_same<std::set<int>::key_type, int>::value), ""); + static_assert((std::is_same<std::set<int>::value_type, int>::value), ""); + static_assert((std::is_same<std::set<int>::key_compare, std::less<int> >::value), ""); + static_assert((std::is_same<std::set<int>::value_compare, std::less<int> >::value), ""); + static_assert((std::is_same<std::set<int>::allocator_type, std::allocator<int> >::value), ""); + static_assert((std::is_same<std::set<int>::reference, int&>::value), ""); + static_assert((std::is_same<std::set<int>::const_reference, const int&>::value), ""); + static_assert((std::is_same<std::set<int>::pointer, int*>::value), ""); + static_assert((std::is_same<std::set<int>::const_pointer, const int*>::value), ""); + static_assert((std::is_same<std::set<int>::size_type, std::size_t>::value), ""); + static_assert((std::is_same<std::set<int>::difference_type, std::ptrdiff_t>::value), ""); +} diff --git a/libcxx/test/containers/associative/set/upper_bound.pass.cpp b/libcxx/test/containers/associative/set/upper_bound.pass.cpp new file mode 100644 index 00000000000..398d8aa46c7 --- /dev/null +++ b/libcxx/test/containers/associative/set/upper_bound.pass.cpp @@ -0,0 +1,122 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; + +#include <set> +#include <cassert> + +int main() +{ + typedef int V; + typedef std::set<int> 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)); + } +} diff --git a/libcxx/test/containers/associative/set/version.pass.cpp b/libcxx/test/containers/associative/set/version.pass.cpp new file mode 100644 index 00000000000..6eac6e00669 --- /dev/null +++ b/libcxx/test/containers/associative/set/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +#include <set> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/libcxx/test/containers/associative/tree_balance_after_insert.pass.cpp b/libcxx/test/containers/associative/tree_balance_after_insert.pass.cpp new file mode 100644 index 00000000000..3ec1f1991d6 --- /dev/null +++ b/libcxx/test/containers/associative/tree_balance_after_insert.pass.cpp @@ -0,0 +1,1616 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Not a portable test + +// Precondition: __root->__is_black_ == true +// template <class _NodePtr> +// void +// __tree_balance_after_insert(_NodePtr __root, _NodePtr __x) + +#include <__tree> +#include <cassert> + +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/containers/associative/tree_left_rotate.pass.cpp b/libcxx/test/containers/associative/tree_left_rotate.pass.cpp new file mode 100644 index 00000000000..492619eab46 --- /dev/null +++ b/libcxx/test/containers/associative/tree_left_rotate.pass.cpp @@ -0,0 +1,98 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Not a portable test + +// Precondition: __x->__right_ != nullptr +// template <class _NodePtr> +// void +// __tree_left_rotate(_NodePtr __x); + +#include <__tree> +#include <cassert> + +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/containers/associative/tree_remove.pass.cpp b/libcxx/test/containers/associative/tree_remove.pass.cpp new file mode 100644 index 00000000000..03af737f7fe --- /dev/null +++ b/libcxx/test/containers/associative/tree_remove.pass.cpp @@ -0,0 +1,1648 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Not a portable test + +// Returns __tree_next(__z) +// template <class _NodePtr> +// void +// __tree_remove(_NodePtr __root, _NodePtr __z) + +#include <__tree> +#include <cassert> + +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/containers/associative/tree_right_rotate.pass.cpp b/libcxx/test/containers/associative/tree_right_rotate.pass.cpp new file mode 100644 index 00000000000..41721cf8d1b --- /dev/null +++ b/libcxx/test/containers/associative/tree_right_rotate.pass.cpp @@ -0,0 +1,98 @@ +//===----------------------------------------------------------------------===// +// +// ΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚΚThe LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Not a portable test + +// Precondition: __x->__left_ != nullptr +// template <class _NodePtr> +// void +// __tree_right_rotate(_NodePtr __x); + +#include <__tree> +#include <cassert> + +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(); +} |

