diff options
Diffstat (limited to 'test/std/containers/associative')
241 files changed, 27485 insertions, 0 deletions
diff --git a/test/std/containers/associative/map/compare.pass.cpp b/test/std/containers/associative/map/compare.pass.cpp new file mode 100644 index 0000000000000..aa4d5999ff466 --- /dev/null +++ b/test/std/containers/associative/map/compare.pass.cpp @@ -0,0 +1,32 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// template <class Key, class T, class Compare = less<Key>, +// class Allocator = allocator<pair<const Key, T>>> +// class map + +// http://llvm.org/bugs/show_bug.cgi?id=16538 +// http://llvm.org/bugs/show_bug.cgi?id=16549 + +#include <map> + +struct Key { + template <typename T> Key(const T&) {} + bool operator< (const Key&) const { return false; } +}; + +int +main() +{ + std::map<Key, int>::iterator it = std::map<Key, int>().find(Key(0)); + std::pair<std::map<Key, int>::iterator, bool> result = + std::map<Key, int>().insert(std::make_pair(Key(0), 0)); +} diff --git a/test/std/containers/associative/map/map.access/at.pass.cpp b/test/std/containers/associative/map/map.access/at.pass.cpp new file mode 100644 index 0000000000000..86b1e3d2dfa61 --- /dev/null +++ b/test/std/containers/associative/map/map.access/at.pass.cpp @@ -0,0 +1,154 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// mapped_type& at(const key_type& k); +// const mapped_type& at(const key_type& k) const; + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + 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, std::less<int>, min_allocator<V>> 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, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 7); + assert(m.at(1) == 1.5); + assert(m.at(2) == 2.5); + assert(m.at(3) == 3.5); + assert(m.at(4) == 4.5); + assert(m.at(5) == 5.5); + try + { + m.at(6); + assert(false); + } + catch (std::out_of_range&) + { + } + assert(m.at(7) == 7.5); + assert(m.at(8) == 8.5); + assert(m.size() == 7); + } +#endif +} diff --git a/test/std/containers/associative/map/map.access/empty.pass.cpp b/test/std/containers/associative/map/map.access/empty.pass.cpp new file mode 100644 index 0000000000000..b11e94c8042ca --- /dev/null +++ b/test/std/containers/associative/map/map.access/empty.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// bool empty() const; + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +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()); + } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + M m; + assert(m.empty()); + m.insert(M::value_type(1, 1.5)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); + } +#endif +} diff --git a/test/std/containers/associative/map/map.access/index_key.pass.cpp b/test/std/containers/associative/map/map.access/index_key.pass.cpp new file mode 100644 index 0000000000000..ab1144c60afda --- /dev/null +++ b/test/std/containers/associative/map/map.access/index_key.pass.cpp @@ -0,0 +1,105 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// mapped_type& operator[](const key_type& k); + +#include <map> +#include <cassert> + +#include "min_allocator.h" +#include "private_constructor.hpp" + +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); + } +#if __cplusplus >= 201103L + { + 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, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 7); + assert(m[1] == 1.5); + assert(m.size() == 7); + const int i = 1; + m[i] = -1.5; + assert(m[1] == -1.5); + assert(m.size() == 7); + assert(m[6] == 0); + assert(m.size() == 8); + m[6] = 6.5; + assert(m[6] == 6.5); + assert(m.size() == 8); + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<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, std::less<>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + + assert(m.size() == 7); + assert(m[1] == 1.5); + assert(m.size() == 7); + m[1] = -1.5; + assert(m[1] == -1.5); + assert(m.size() == 7); + assert(m[6] == 0); + assert(m.size() == 8); + m[6] = 6.5; + assert(m[6] == 6.5); + assert(m.size() == 8); + } +#endif +} diff --git a/test/std/containers/associative/map/map.access/index_rv_key.pass.cpp b/test/std/containers/associative/map/map.access/index_rv_key.pass.cpp new file mode 100644 index 0000000000000..d14603e1a281a --- /dev/null +++ b/test/std/containers/associative/map/map.access/index_rv_key.pass.cpp @@ -0,0 +1,58 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// mapped_type& operator[](key_type&& k); + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::pair<MoveOnly, double> V; + std::map<MoveOnly, double, std::less<MoveOnly>, min_allocator<V>> 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/test/std/containers/associative/map/map.access/index_tuple.pass.cpp b/test/std/containers/associative/map/map.access/index_tuple.pass.cpp new file mode 100644 index 0000000000000..9a00829eadd63 --- /dev/null +++ b/test/std/containers/associative/map/map.access/index_tuple.pass.cpp @@ -0,0 +1,33 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// mapped_type& operator[](const key_type& k); + +// http://llvm.org/bugs/show_bug.cgi?id=16542 + +#include <map> + +#ifndef _LIBCPP_HAS_NO_VARIADICS + +#include <tuple> + +#endif + +int main() +{ +#ifndef _LIBCPP_HAS_NO_VARIADICS + using namespace std; + map<tuple<int,int>, size_t> m; + m[make_tuple(2,3)]=7; +#endif +} diff --git a/test/std/containers/associative/map/map.access/iterator.pass.cpp b/test/std/containers/associative/map/map.access/iterator.pass.cpp new file mode 100644 index 0000000000000..552e87d8fc8d3 --- /dev/null +++ b/test/std/containers/associative/map/map.access/iterator.pass.cpp @@ -0,0 +1,227 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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> + +#include "min_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), + 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; + 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; + i = m.begin(); + for (int j = 1; j <= m.size(); ++j, ++i) + { + assert(i->first == j); + assert(i->second == 1); + } + } +#if __cplusplus >= 201103L + { + typedef std::pair<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, std::less<int>, min_allocator<V>> 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, std::less<int>, min_allocator<V>>::iterator i; + i = m.begin(); + std::map<int, double, std::less<int>, min_allocator<V>>::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, std::less<int>, min_allocator<V>> 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, std::less<int>, min_allocator<V>>::const_iterator i; + i = m.begin(); + for (int j = 1; j <= m.size(); ++j, ++i) + { + assert(i->first == j); + assert(i->second == 1); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + typedef std::map<int, double> C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + } +#endif +} diff --git a/test/std/containers/associative/map/map.access/max_size.pass.cpp b/test/std/containers/associative/map/map.access/max_size.pass.cpp new file mode 100644 index 0000000000000..551120d331e17 --- /dev/null +++ b/test/std/containers/associative/map/map.access/max_size.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// size_type max_size() const; + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::map<int, double> M; + M m; + assert(m.max_size() != 0); + } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + M m; + assert(m.max_size() != 0); + } +#endif +} diff --git a/test/std/containers/associative/map/map.access/size.pass.cpp b/test/std/containers/associative/map/map.access/size.pass.cpp new file mode 100644 index 0000000000000..07c12322a460b --- /dev/null +++ b/test/std/containers/associative/map/map.access/size.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// size_type size() const; + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const 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); + } +#endif +} diff --git a/test/std/containers/associative/map/map.cons/alloc.pass.cpp b/test/std/containers/associative/map/map.cons/alloc.pass.cpp new file mode 100644 index 0000000000000..2292c47ef74ba --- /dev/null +++ b/test/std/containers/associative/map/map.cons/alloc.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// explicit map(const allocator_type& a); + +#include <map> +#include <cassert> + +#include "test_allocator.h" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + typedef std::less<int> C; + typedef min_allocator<std::pair<const int, double> > A; + std::map<int, double, C, A> m(A{}); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.get_allocator() == A()); + } +#endif +} diff --git a/test/std/containers/associative/map/map.cons/assign_initializer_list.pass.cpp b/test/std/containers/associative/map/map.cons/assign_initializer_list.pass.cpp new file mode 100644 index 0000000000000..482d1acff840c --- /dev/null +++ b/test/std/containers/associative/map/map.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,75 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map& operator=(initializer_list<value_type> il); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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)); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + std::map<int, double, std::less<int>, min_allocator<V>> m = + { + {20, 1}, + }; + m = + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }; + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/associative/map/map.cons/compare.pass.cpp b/test/std/containers/associative/map/map.cons/compare.pass.cpp new file mode 100644 index 0000000000000..5a213c8e8b8f6 --- /dev/null +++ b/test/std/containers/associative/map/map.cons/compare.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// explicit map(const key_compare& comp); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "min_allocator.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)); + } +#if __cplusplus >= 201103L + { + typedef test_compare<std::less<int> > C; + std::map<int, double, C, min_allocator<std::pair<const int, double>>> m(C(3)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(3)); + } +#endif +} diff --git a/test/std/containers/associative/map/map.cons/compare_alloc.pass.cpp b/test/std/containers/associative/map/map.cons/compare_alloc.pass.cpp new file mode 100644 index 0000000000000..56b3c3315e084 --- /dev/null +++ b/test/std/containers/associative/map/map.cons/compare_alloc.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map(const key_compare& comp, const allocator_type& a); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + typedef test_compare<std::less<int> > C; + typedef min_allocator<std::pair<const int, double> > A; + std::map<int, double, C, A> m(C(4), A()); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(4)); + assert(m.get_allocator() == A()); + } +#endif +} diff --git a/test/std/containers/associative/map/map.cons/copy.pass.cpp b/test/std/containers/associative/map/map.cons/copy.pass.cpp new file mode 100644 index 0000000000000..be52741330821 --- /dev/null +++ b/test/std/containers/associative/map/map.cons/copy.pass.cpp @@ -0,0 +1,131 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map(const map& m); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_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 // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + 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 min_allocator<V> A; + std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::map<int, double, C, A> m = mo; + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == V(1, 1)); + assert(*next(mo.begin()) == V(2, 1)); + assert(*next(mo.begin(), 2) == V(3, 1)); + } +#endif +} diff --git a/test/std/containers/associative/map/map.cons/copy_alloc.pass.cpp b/test/std/containers/associative/map/map.cons/copy_alloc.pass.cpp new file mode 100644 index 0000000000000..fcbe5976d6da4 --- /dev/null +++ b/test/std/containers/associative/map/map.cons/copy_alloc.pass.cpp @@ -0,0 +1,95 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map(const map& m, const allocator_type& a); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + 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 min_allocator<V> A; + std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::map<int, double, C, A> m(mo, A()); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == V(1, 1)); + assert(*next(mo.begin()) == V(2, 1)); + assert(*next(mo.begin(), 2) == V(3, 1)); + } +#endif +} diff --git a/test/std/containers/associative/map/map.cons/copy_assign.pass.cpp b/test/std/containers/associative/map/map.cons/copy_assign.pass.cpp new file mode 100644 index 0000000000000..a1bcb30f42949 --- /dev/null +++ b/test/std/containers/associative/map/map.cons/copy_assign.pass.cpp @@ -0,0 +1,182 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map& operator=(const map& m); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_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; + const V ar[] = + { + V(1, 1), + V(2, 1), + V(3, 1), + }; + std::map<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + std::map<int, double> *p = &m; + m = *p; + + assert(m.size() == 3); + assert(std::equal(m.begin(), m.end(), ar)); + } + { + 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)); + } +#if __cplusplus >= 201103L + { + 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 min_allocator<V> A; + std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A()); + m = mo; + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == V(1, 1)); + assert(*next(mo.begin()) == V(2, 1)); + assert(*next(mo.begin(), 2) == V(3, 1)); + } + { + typedef std::pair<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 min_allocator<V> A; + std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A()); + m = mo; + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == V(1, 1)); + assert(*next(mo.begin()) == V(2, 1)); + assert(*next(mo.begin(), 2) == V(3, 1)); + } +#endif +} diff --git a/test/std/containers/associative/map/map.cons/default.pass.cpp b/test/std/containers/associative/map/map.cons/default.pass.cpp new file mode 100644 index 0000000000000..1832a32fffb3a --- /dev/null +++ b/test/std/containers/associative/map/map.cons/default.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map(); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + std::map<int, double> m; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#if __cplusplus >= 201103L + { + std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> m; + assert(m.empty()); + assert(m.begin() == m.end()); + } + { + std::map<int, double> m = {}; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#endif +} diff --git a/test/std/containers/associative/map/map.cons/default_noexcept.pass.cpp b/test/std/containers/associative/map/map.cons/default_noexcept.pass.cpp new file mode 100644 index 0000000000000..1f11fc9582edf --- /dev/null +++ b/test/std/containers/associative/map/map.cons/default_noexcept.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// map() +// noexcept( +// is_nothrow_default_constructible<allocator_type>::value && +// is_nothrow_default_constructible<key_compare>::value && +// is_nothrow_copy_constructible<key_compare>::value); + +// This tests a conforming extension + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + some_comp(); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::map<MoveOnly, MoveOnly> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::map<MoveOnly, MoveOnly, some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/associative/map/map.cons/default_recursive.pass.cpp b/test/std/containers/associative/map/map.cons/default_recursive.pass.cpp new file mode 100644 index 0000000000000..b4b72725fd6ed --- /dev/null +++ b/test/std/containers/associative/map/map.cons/default_recursive.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map(); + +#include <map> + +struct X +{ + std::map<int, X> m; + std::map<int, X>::iterator i; + std::map<int, X>::const_iterator ci; + std::map<int, X>::reverse_iterator ri; + std::map<int, X>::const_reverse_iterator cri; +}; + +int main() +{ +} diff --git a/test/std/containers/associative/map/map.cons/dtor_noexcept.pass.cpp b/test/std/containers/associative/map/map.cons/dtor_noexcept.pass.cpp new file mode 100644 index 0000000000000..eed26d3a61360 --- /dev/null +++ b/test/std/containers/associative/map/map.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// ~map() // implied noexcept; + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template <class T> +struct some_comp +{ + typedef T value_type; + ~some_comp() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::map<MoveOnly, MoveOnly> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::map<MoveOnly, MoveOnly, some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_destructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/associative/map/map.cons/initializer_list.pass.cpp b/test/std/containers/associative/map/map.cons/initializer_list.pass.cpp new file mode 100644 index 0000000000000..196943653a145 --- /dev/null +++ b/test/std/containers/associative/map/map.cons/initializer_list.pass.cpp @@ -0,0 +1,67 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map(initializer_list<value_type> il); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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)); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + std::map<int, double, std::less<int>, min_allocator<V>> m = + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }; + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/associative/map/map.cons/initializer_list_compare.pass.cpp b/test/std/containers/associative/map/map.cons/initializer_list_compare.pass.cpp new file mode 100644 index 0000000000000..08f8a529f030a --- /dev/null +++ b/test/std/containers/associative/map/map.cons/initializer_list_compare.pass.cpp @@ -0,0 +1,69 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map(initializer_list<value_type> il, const key_compare& comp); + +#include <map> +#include <cassert> +#include "../../../test_compare.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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)); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + typedef test_compare<std::less<int> > C; + std::map<int, double, C, min_allocator<std::pair<const int, double>>> m({ + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }, C(3)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + assert(m.key_comp() == C(3)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/associative/map/map.cons/initializer_list_compare_alloc.pass.cpp b/test/std/containers/associative/map/map.cons/initializer_list_compare_alloc.pass.cpp new file mode 100644 index 0000000000000..765428a631e5b --- /dev/null +++ b/test/std/containers/associative/map/map.cons/initializer_list_compare_alloc.pass.cpp @@ -0,0 +1,100 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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)); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + typedef test_compare<std::less<int> > C; + typedef min_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()); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + assert(m.key_comp() == C(3)); + assert(m.get_allocator() == A()); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<const int, double> V; + typedef min_allocator<V> A; + typedef test_compare<std::less<int> > C; + typedef std::map<int, double, C, A> M; + A a; + M m ({ {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }, a); + + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + assert(m.get_allocator() == a); + } +#endif +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/associative/map/map.cons/iter_iter.pass.cpp b/test/std/containers/associative/map/map.cons/iter_iter.pass.cpp new file mode 100644 index 0000000000000..c1029af6889e3 --- /dev/null +++ b/test/std/containers/associative/map/map.cons/iter_iter.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// template <class InputIterator> +// map(InputIterator first, InputIterator last); + +#include <map> +#include <cassert> + +#include "min_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), + }; + 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)); + } +#if __cplusplus >= 201103L + { + 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, std::less<int>, min_allocator<std::pair<const 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)); + } +#endif +} diff --git a/test/std/containers/associative/map/map.cons/iter_iter_comp.pass.cpp b/test/std/containers/associative/map/map.cons/iter_iter_comp.pass.cpp new file mode 100644 index 0000000000000..837fa8c6cdeaa --- /dev/null +++ b/test/std/containers/associative/map/map.cons/iter_iter_comp.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// template <class InputIterator> +// map(InputIterator first, InputIterator last, const key_compare& comp); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "min_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; + 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)); + } +#if __cplusplus >= 201103L + { + 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, min_allocator<std::pair<const int, double>>> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5)); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#endif +} diff --git a/test/std/containers/associative/map/map.cons/iter_iter_comp_alloc.pass.cpp b/test/std/containers/associative/map/map.cons/iter_iter_comp_alloc.pass.cpp new file mode 100644 index 0000000000000..67fb5d6447623 --- /dev/null +++ b/test/std/containers/associative/map/map.cons/iter_iter_comp_alloc.pass.cpp @@ -0,0 +1,108 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + 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 min_allocator<V> A; + std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<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 std::pair<const int, double> V; + typedef min_allocator<V> A; + typedef test_compare<std::less<int> > C; + A a; + std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), a ); + + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + assert(m.get_allocator() == a); + } +#endif +#endif +} diff --git a/test/std/containers/associative/map/map.cons/move.pass.cpp b/test/std/containers/associative/map/map.cons/move.pass.cpp new file mode 100644 index 0000000000000..c06f2ee5021bc --- /dev/null +++ b/test/std/containers/associative/map/map.cons/move.pass.cpp @@ -0,0 +1,120 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map(map&& m); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + 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); + } +#if __cplusplus >= 201103L + { + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::map<int, double, C, A> mo(C(5), A()); + std::map<int, double, C, A> m = std::move(mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 0); + assert(distance(m.begin(), m.end()) == 0); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } + { + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::map<int, double, C, A> m = std::move(mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/map/map.cons/move_alloc.pass.cpp b/test/std/containers/associative/map/map.cons/move_alloc.pass.cpp new file mode 100644 index 0000000000000..e5d43f266c08c --- /dev/null +++ b/test/std/containers/associative/map/map.cons/move_alloc.pass.cpp @@ -0,0 +1,234 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map(map&& m, const allocator_type& a); + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" +#include "Counter.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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()); + } + { + typedef Counter<int> T; + typedef std::pair<int, T> V; + typedef std::pair<const int, T> VC; + typedef test_allocator<VC> A; + typedef std::less<int> C; + typedef std::map<const int, T, C, A> M; + typedef V* I; + Counter_base::gConstructed = 0; + { + 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) + }; + const size_t num = sizeof(a1)/sizeof(a1[0]); + assert(Counter_base::gConstructed == num); + + M m1(I(a1), I(a1+num), C(), A()); + assert(Counter_base::gConstructed == num+3); + + M m2(m1); + assert(m2 == m1); + assert(Counter_base::gConstructed == num+6); + + M m3(std::move(m1), A()); + assert(m3 == m2); + assert(m1.empty()); + assert(Counter_base::gConstructed == num+6); + + { + M m4(std::move(m2), A(5)); + assert(Counter_base::gConstructed == num+6); + assert(m4 == m3); + assert(m2.empty()); + } + assert(Counter_base::gConstructed == num+3); + } + assert(Counter_base::gConstructed == 0); + } +#if __cplusplus >= 201103L + { + typedef std::pair<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef min_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()); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A()); + M m3(std::move(m1), A()); + assert(m3 == m2); + assert(m3.get_allocator() == A()); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/map/map.cons/move_assign.pass.cpp b/test/std/containers/associative/map/map.cons/move_assign.pass.cpp new file mode 100644 index 0000000000000..8ae8265cdc123 --- /dev/null +++ b/test/std/containers/associative/map/map.cons/move_assign.pass.cpp @@ -0,0 +1,190 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// map& operator=(map&& m); + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::pair<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()); + } +#if __cplusplus >= 201103L + { + typedef std::pair<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef min_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()); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A()); + M m3(C(3), A()); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A()); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/map/map.cons/move_assign_noexcept.pass.cpp b/test/std/containers/associative/map/map.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 0000000000000..f80b1d323178f --- /dev/null +++ b/test/std/containers/associative/map/map.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// map& operator=(map&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable<allocator_type>::value && +// is_nothrow_move_assignable<key_compare>::value); + +// This tests a conforming extension + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + some_comp& operator=(const some_comp&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::map<MoveOnly, MoveOnly> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::map<MoveOnly, MoveOnly, some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/associative/map/map.cons/move_noexcept.pass.cpp b/test/std/containers/associative/map/map.cons/move_noexcept.pass.cpp new file mode 100644 index 0000000000000..9347b8329ae3b --- /dev/null +++ b/test/std/containers/associative/map/map.cons/move_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// map(map&&) +// noexcept(is_nothrow_move_constructible<allocator_type>::value && +// is_nothrow_move_constructible<key_compare>::value); + +// This tests a conforming extension + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + some_comp(const some_comp&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::map<MoveOnly, MoveOnly> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::map<MoveOnly, MoveOnly, some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_move_constructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/associative/map/map.modifiers/clear.pass.cpp b/test/std/containers/associative/map/map.modifiers/clear.pass.cpp new file mode 100644 index 0000000000000..c37499df307a3 --- /dev/null +++ b/test/std/containers/associative/map/map.modifiers/clear.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// void clear(); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const 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); + } +#endif +} diff --git a/test/std/containers/associative/map/map.modifiers/emplace.pass.cpp b/test/std/containers/associative/map/map.modifiers/emplace.pass.cpp new file mode 100644 index 0000000000000..81846c6647c6b --- /dev/null +++ b/test/std/containers/associative/map/map.modifiers/emplace.pass.cpp @@ -0,0 +1,165 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// template <class... Args> +// pair<iterator, bool> emplace(Args&&... args); + +#include <map> +#include <cassert> +#include <tuple> + +#include "../../../Emplaceable.h" +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r.second); + assert(r.first == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(!r.second); + assert(r.first == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + } + assert(DefaultOnly::count == 0); + { + typedef std::map<int, Emplaceable> M; + typedef std::pair<M::iterator, bool> R; + M m; + R r = m.emplace(std::piecewise_construct, std::forward_as_tuple(2), + std::forward_as_tuple()); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(!r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + } + { + typedef std::map<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); + } +#if __cplusplus >= 201103L + { + typedef std::map<int, DefaultOnly, std::less<int>, min_allocator<std::pair<const 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(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r.second); + assert(r.first == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(!r.second); + assert(r.first == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + } + assert(DefaultOnly::count == 0); + { + typedef std::map<int, Emplaceable, std::less<int>, min_allocator<std::pair<const int, Emplaceable>>> M; + typedef std::pair<M::iterator, bool> R; + M m; + R r = m.emplace(std::piecewise_construct, std::forward_as_tuple(2), + std::forward_as_tuple()); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(!r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + } + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const 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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/map/map.modifiers/emplace_hint.pass.cpp b/test/std/containers/associative/map/map.modifiers/emplace_hint.pass.cpp new file mode 100644 index 0000000000000..15f74b17e7864 --- /dev/null +++ b/test/std/containers/associative/map/map.modifiers/emplace_hint.pass.cpp @@ -0,0 +1,160 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// template <class... Args> +// iterator emplace_hint(const_iterator position, Args&&... args); + +#include <map> +#include <cassert> + +#include "../../../Emplaceable.h" +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + } + assert(DefaultOnly::count == 0); + { + typedef std::map<int, Emplaceable> M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(2), + std::forward_as_tuple()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + } + { + typedef std::map<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); + } +#if __cplusplus >= 201103L + { + typedef std::map<int, DefaultOnly, std::less<int>, min_allocator<std::pair<const 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(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + } + assert(DefaultOnly::count == 0); + { + typedef std::map<int, Emplaceable, std::less<int>, min_allocator<std::pair<const int, Emplaceable>>> M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(2), + std::forward_as_tuple()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + } + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const 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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/map/map.modifiers/erase_iter.pass.cpp b/test/std/containers/associative/map/map.modifiers/erase_iter.pass.cpp new file mode 100644 index 0000000000000..15c5ce041b688 --- /dev/null +++ b/test/std/containers/associative/map/map.modifiers/erase_iter.pass.cpp @@ -0,0 +1,259 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator erase(const_iterator position); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +struct TemplateConstructor +{ + template<typename T> + TemplateConstructor (const T&) {} +}; + +bool operator<(const TemplateConstructor&, const TemplateConstructor&) { return false; } + +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()); + } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const 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()); + } +#endif +#if __cplusplus >= 201402L + { + // This is LWG #2059 + typedef TemplateConstructor T; + typedef std::map<T, int> C; + typedef C::iterator I; + + C c; + T a{0}; + I it = c.find(a); + if (it != c.end()) + c.erase(it); + } +#endif +} diff --git a/test/std/containers/associative/map/map.modifiers/erase_iter_iter.pass.cpp b/test/std/containers/associative/map/map.modifiers/erase_iter_iter.pass.cpp new file mode 100644 index 0000000000000..1b49956d8a5ad --- /dev/null +++ b/test/std/containers/associative/map/map.modifiers/erase_iter_iter.pass.cpp @@ -0,0 +1,157 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator erase(const_iterator first, const_iterator last); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +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()); + } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const 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()); + } +#endif +} diff --git a/test/std/containers/associative/map/map.modifiers/erase_key.pass.cpp b/test/std/containers/associative/map/map.modifiers/erase_key.pass.cpp new file mode 100644 index 0000000000000..e41f5129140e6 --- /dev/null +++ b/test/std/containers/associative/map/map.modifiers/erase_key.pass.cpp @@ -0,0 +1,275 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// size_type erase(const key_type& k); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const 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); + } +#endif +} diff --git a/test/std/containers/associative/map/map.modifiers/insert_cv.pass.cpp b/test/std/containers/associative/map/map.modifiers/insert_cv.pass.cpp new file mode 100644 index 0000000000000..3d28242fd3228 --- /dev/null +++ b/test/std/containers/associative/map/map.modifiers/insert_cv.pass.cpp @@ -0,0 +1,89 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// pair<iterator, bool> insert(const value_type& v); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const 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); + } +#endif +} diff --git a/test/std/containers/associative/map/map.modifiers/insert_initializer_list.pass.cpp b/test/std/containers/associative/map/map.modifiers/insert_initializer_list.pass.cpp new file mode 100644 index 0000000000000..ab325ed45bfcc --- /dev/null +++ b/test/std/containers/associative/map/map.modifiers/insert_initializer_list.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// void insert(initializer_list<value_type> il); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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)); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + std::map<int, double, std::less<int>, min_allocator<V>> m = + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }; + m.insert({ + {2, 1}, + {2, 1.5}, + {2, 2}, + }); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/associative/map/map.modifiers/insert_iter_cv.pass.cpp b/test/std/containers/associative/map/map.modifiers/insert_iter_cv.pass.cpp new file mode 100644 index 0000000000000..278db4631a8ca --- /dev/null +++ b/test/std/containers/associative/map/map.modifiers/insert_iter_cv.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator insert(const_iterator position, const value_type& v); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const 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); + } +#endif +} diff --git a/test/std/containers/associative/map/map.modifiers/insert_iter_iter.pass.cpp b/test/std/containers/associative/map/map.modifiers/insert_iter_iter.pass.cpp new file mode 100644 index 0000000000000..964738b4a68aa --- /dev/null +++ b/test/std/containers/associative/map/map.modifiers/insert_iter_iter.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// template <class InputIterator> +// void insert(InputIterator first, InputIterator last); + +#include <map> +#include <cassert> + +#include "test_iterators.h" +#include "min_allocator.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); + } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const 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); + } +#endif +} diff --git a/test/std/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp b/test/std/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp new file mode 100644 index 0000000000000..42b41fd7b8674 --- /dev/null +++ b/test/std/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// template <class P> +// iterator insert(const_iterator position, P&& p); + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } +#if __cplusplus >= 201103L + { + typedef std::map<int, MoveOnly, std::less<int>, min_allocator<std::pair<const 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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/map/map.modifiers/insert_or_assign.pass.cpp b/test/std/containers/associative/map/map.modifiers/insert_or_assign.pass.cpp new file mode 100644 index 0000000000000..484ed06247d17 --- /dev/null +++ b/test/std/containers/associative/map/map.modifiers/insert_or_assign.pass.cpp @@ -0,0 +1,192 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: c++03, c++11, c++14 + +// <map> + +// class map + +// template <class M> +// pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); // C++17 +// template <class M> +// pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); // C++17 +// template <class M> +// iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); // C++17 +// template <class M> +// iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); // C++17 + +#include <__config> +#include <map> +#include <cassert> +#include <tuple> + +#include <iostream> + +class Moveable +{ + Moveable(const Moveable&); + Moveable& operator=(const Moveable&); + + int int_; + double double_; +public: + Moveable() : int_(0), double_(0) {} + Moveable(int i, double d) : int_(i), double_(d) {} + Moveable(Moveable&& x) + : int_(x.int_), double_(x.double_) + {x.int_ = -1; x.double_ = -1;} + Moveable& operator=(Moveable&& x) + {int_ = x.int_; x.int_ = -1; + double_ = x.double_; x.double_ = -1; + return *this; + } + + bool operator==(const Moveable& x) const + {return int_ == x.int_ && double_ == x.double_;} + bool operator<(const Moveable& x) const + {return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);} + + int get() const {return int_;} + bool moved() const {return int_ == -1;} +}; + + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_VARIADICS + + { // pair<iterator, bool> insert_or_assign(const key_type& k, M&& obj); + typedef std::map<int, Moveable> M; + typedef std::pair<M::iterator, bool> R; + M m; + R r; + for ( int i = 0; i < 20; i += 2 ) + m.emplace ( i, Moveable(i, (double) i)); + assert(m.size() == 10); + + for (int i=0; i < 20; i += 2) + { + Moveable mv(i+1, i+1); + r = m.insert_or_assign(i, std::move(mv)); + assert(m.size() == 10); + assert(!r.second); // was not inserted + assert(mv.moved()); // was moved from + assert(r.first->first == i); // key + assert(r.first->second.get() == i+1); // value + } + + Moveable mv1(5, 5.0); + r = m.insert_or_assign(-1, std::move(mv1)); + assert(m.size() == 11); + assert(r.second); // was inserted + assert(mv1.moved()); // was moved from + assert(r.first->first == -1); // key + assert(r.first->second.get() == 5); // value + + Moveable mv2(9, 9.0); + r = m.insert_or_assign(3, std::move(mv2)); + assert(m.size() == 12); + assert(r.second); // was inserted + assert(mv2.moved()); // was moved from + assert(r.first->first == 3); // key + assert(r.first->second.get() == 9); // value + + Moveable mv3(-1, 5.0); + r = m.insert_or_assign(117, std::move(mv3)); + assert(m.size() == 13); + assert(r.second); // was inserted + assert(mv3.moved()); // was moved from + assert(r.first->first == 117); // key + assert(r.first->second.get() == -1); // value + } + { // pair<iterator, bool> insert_or_assign(key_type&& k, M&& obj); + typedef std::map<Moveable, Moveable> M; + typedef std::pair<M::iterator, bool> R; + M m; + R r; + for ( int i = 0; i < 20; i += 2 ) + m.emplace ( Moveable(i, (double) i), Moveable(i+1, (double) i+1)); + assert(m.size() == 10); + + Moveable mvkey1(2, 2.0); + Moveable mv1(4, 4.0); + r = m.insert_or_assign(std::move(mvkey1), std::move(mv1)); + assert(m.size() == 10); + assert(!r.second); // was not inserted + assert(!mvkey1.moved()); // was not moved from + assert(mv1.moved()); // was moved from + assert(r.first->first == mvkey1); // key + assert(r.first->second.get() == 4); // value + + Moveable mvkey2(3, 3.0); + Moveable mv2(5, 5.0); + r = m.try_emplace(std::move(mvkey2), std::move(mv2)); + assert(m.size() == 11); + assert(r.second); // was inserted + assert(mv2.moved()); // was moved from + assert(mvkey2.moved()); // was moved from + assert(r.first->first.get() == 3); // key + assert(r.first->second.get() == 5); // value + } + { // iterator insert_or_assign(const_iterator hint, const key_type& k, M&& obj); + typedef std::map<int, Moveable> M; + M m; + M::iterator r; + for ( int i = 0; i < 20; i += 2 ) + m.emplace ( i, Moveable(i, (double) i)); + assert(m.size() == 10); + M::const_iterator it = m.find(2); + + Moveable mv1(3, 3.0); + r = m.insert_or_assign(it, 2, std::move(mv1)); + assert(m.size() == 10); + assert(mv1.moved()); // was moved from + assert(r->first == 2); // key + assert(r->second.get() == 3); // value + + Moveable mv2(5, 5.0); + r = m.insert_or_assign(it, 3, std::move(mv2)); + assert(m.size() == 11); + assert(mv2.moved()); // was moved from + assert(r->first == 3); // key + assert(r->second.get() == 5); // value + } + { // iterator insert_or_assign(const_iterator hint, key_type&& k, M&& obj); + typedef std::map<Moveable, Moveable> M; + M m; + M::iterator r; + for ( int i = 0; i < 20; i += 2 ) + m.emplace ( Moveable(i, (double) i), Moveable(i+1, (double) i+1)); + assert(m.size() == 10); + M::const_iterator it = std::next(m.cbegin()); + + Moveable mvkey1(2, 2.0); + Moveable mv1(4, 4.0); + r = m.insert_or_assign(it, std::move(mvkey1), std::move(mv1)); + assert(m.size() == 10); + assert(mv1.moved()); // was moved from + assert(!mvkey1.moved()); // was not moved from + assert(r->first == mvkey1); // key + assert(r->second.get() == 4); // value + + Moveable mvkey2(3, 3.0); + Moveable mv2(5, 5.0); + r = m.insert_or_assign(it, std::move(mvkey2), std::move(mv2)); + assert(m.size() == 11); + assert(mv2.moved()); // was moved from + assert(mvkey2.moved()); // was moved from + assert(r->first.get() == 3); // key + assert(r->second.get() == 5); // value + } + +#endif // _LIBCPP_HAS_NO_VARIADICS +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +}
\ No newline at end of file diff --git a/test/std/containers/associative/map/map.modifiers/insert_rv.pass.cpp b/test/std/containers/associative/map/map.modifiers/insert_rv.pass.cpp new file mode 100644 index 0000000000000..a9d3277e6d947 --- /dev/null +++ b/test/std/containers/associative/map/map.modifiers/insert_rv.pass.cpp @@ -0,0 +1,93 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// template <class P> +// pair<iterator, bool> insert(P&& p); + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } +#if __cplusplus >= 201103L + { + typedef std::map<int, MoveOnly, std::less<int>, min_allocator<std::pair<const 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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/map/map.modifiers/try.emplace.pass.cpp b/test/std/containers/associative/map/map.modifiers/try.emplace.pass.cpp new file mode 100644 index 0000000000000..8e0dd7577bbd6 --- /dev/null +++ b/test/std/containers/associative/map/map.modifiers/try.emplace.pass.cpp @@ -0,0 +1,189 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// UNSUPPORTED: c++03, c++11, c++14 + +// <map> + +// class map + +// template <class... Args> +// pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); // C++17 +// template <class... Args> +// pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); // C++17 +// template <class... Args> +// iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); // C++17 +// template <class... Args> +// iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); // C++17 + +#include <__config> +#include <map> +#include <cassert> +#include <tuple> + +class Moveable +{ + Moveable(const Moveable&); + Moveable& operator=(const Moveable&); + + int int_; + double double_; +public: + Moveable() : int_(0), double_(0) {} + Moveable(int i, double d) : int_(i), double_(d) {} + Moveable(Moveable&& x) + : int_(x.int_), double_(x.double_) + {x.int_ = -1; x.double_ = -1;} + Moveable& operator=(Moveable&& x) + {int_ = x.int_; x.int_ = -1; + double_ = x.double_; x.double_ = -1; + return *this; + } + + bool operator==(const Moveable& x) const + {return int_ == x.int_ && double_ == x.double_;} + bool operator<(const Moveable& x) const + {return int_ < x.int_ || (int_ == x.int_ && double_ < x.double_);} + + int get() const {return int_;} + bool moved() const {return int_ == -1;} +}; + + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES +#ifndef _LIBCPP_HAS_NO_VARIADICS + + { // pair<iterator, bool> try_emplace(const key_type& k, Args&&... args); + typedef std::map<int, Moveable> M; + typedef std::pair<M::iterator, bool> R; + M m; + R r; + for (int i = 0; i < 20; i += 2) + m.emplace (i, Moveable(i, (double) i)); + assert(m.size() == 10); + + Moveable mv1(3, 3.0); + for (int i=0; i < 20; i += 2) + { + r = m.try_emplace(i, std::move(mv1)); + assert(m.size() == 10); + assert(!r.second); // was not inserted + assert(!mv1.moved()); // was not moved from + assert(r.first->first == i); // key + } + + r = m.try_emplace(-1, std::move(mv1)); + assert(m.size() == 11); + assert(r.second); // was inserted + assert(mv1.moved()); // was moved from + assert(r.first->first == -1); // key + assert(r.first->second.get() == 3); // value + + Moveable mv2(5, 3.0); + r = m.try_emplace(5, std::move(mv2)); + assert(m.size() == 12); + assert(r.second); // was inserted + assert(mv2.moved()); // was moved from + assert(r.first->first == 5); // key + assert(r.first->second.get() == 5); // value + + Moveable mv3(-1, 3.0); + r = m.try_emplace(117, std::move(mv2)); + assert(m.size() == 13); + assert(r.second); // was inserted + assert(mv2.moved()); // was moved from + assert(r.first->first == 117); // key + assert(r.first->second.get() == -1); // value + } + + { // pair<iterator, bool> try_emplace(key_type&& k, Args&&... args); + typedef std::map<Moveable, Moveable> M; + typedef std::pair<M::iterator, bool> R; + M m; + R r; + for ( int i = 0; i < 20; i += 2 ) + m.emplace ( Moveable(i, (double) i), Moveable(i+1, (double) i+1)); + assert(m.size() == 10); + + Moveable mvkey1(2, 2.0); + Moveable mv1(4, 4.0); + r = m.try_emplace(std::move(mvkey1), std::move(mv1)); + assert(m.size() == 10); + assert(!r.second); // was not inserted + assert(!mv1.moved()); // was not moved from + assert(!mvkey1.moved()); // was not moved from + assert(r.first->first == mvkey1); // key + + Moveable mvkey2(3, 3.0); + r = m.try_emplace(std::move(mvkey2), std::move(mv1)); + assert(m.size() == 11); + assert(r.second); // was inserted + assert(mv1.moved()); // was moved from + assert(mvkey2.moved()); // was moved from + assert(r.first->first.get() == 3); // key + assert(r.first->second.get() == 4); // value + } + + { // iterator try_emplace(const_iterator hint, const key_type& k, Args&&... args); + typedef std::map<int, Moveable> M; + M m; + M::iterator r; + for ( int i = 0; i < 20; i += 2 ) + m.try_emplace ( i, Moveable(i, (double) i)); + assert(m.size() == 10); + M::const_iterator it = m.find(2); + + Moveable mv1(3, 3.0); + for (int i=0; i < 20; i += 2) + { + r = m.try_emplace(it, i, std::move(mv1)); + assert(m.size() == 10); + assert(!mv1.moved()); // was not moved from + assert(r->first == i); // key + assert(r->second.get() == i); // value + } + + r = m.try_emplace(it, 3, std::move(mv1)); + assert(m.size() == 11); + assert(mv1.moved()); // was moved from + assert(r->first == 3); // key + assert(r->second.get() == 3); // value + } + + { // iterator try_emplace(const_iterator hint, key_type&& k, Args&&... args); + typedef std::map<Moveable, Moveable> M; + M m; + M::iterator r; + for ( int i = 0; i < 20; i += 2 ) + m.emplace ( Moveable(i, (double) i), Moveable(i+1, (double) i+1)); + assert(m.size() == 10); + M::const_iterator it = std::next(m.cbegin()); + + Moveable mvkey1(2, 2.0); + Moveable mv1(4, 4.0); + r = m.try_emplace(it, std::move(mvkey1), std::move(mv1)); + assert(m.size() == 10); + assert(!mv1.moved()); // was not moved from + assert(!mvkey1.moved()); // was not moved from + assert(r->first == mvkey1); // key + + Moveable mvkey2(3, 3.0); + r = m.try_emplace(it, std::move(mvkey2), std::move(mv1)); + assert(m.size() == 11); + assert(mv1.moved()); // was moved from + assert(mvkey2.moved()); // was moved from + assert(r->first.get() == 3); // key + assert(r->second.get() == 4); // value + } + +#endif // _LIBCPP_HAS_NO_VARIADICS +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/map/map.ops/count.pass.cpp b/test/std/containers/associative/map/map.ops/count.pass.cpp new file mode 100644 index 0000000000000..ae87ae8345e97 --- /dev/null +++ b/test/std/containers/associative/map/map.ops/count.pass.cpp @@ -0,0 +1,193 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// size_type count(const key_type& k) const; + +#include <map> +#include <cassert> + +#include "min_allocator.h" +#include "private_constructor.hpp" +#include "is_transparent.h" + +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); + } + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + typedef std::map<int, double, std::less<int>, min_allocator<V>> M; + { + typedef M::size_type R; + V ar[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.count(5); + assert(r == 1); + r = m.count(6); + assert(r == 1); + r = m.count(7); + assert(r == 1); + r = m.count(8); + assert(r == 1); + r = m.count(9); + assert(r == 1); + r = m.count(10); + assert(r == 1); + r = m.count(11); + assert(r == 1); + r = m.count(12); + assert(r == 1); + r = m.count(4); + assert(r == 0); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<const int, double> V; + typedef std::map<int, double, std::less <>> 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); + + r = m.count(C2Int(5)); + assert(r == 1); + r = m.count(C2Int(6)); + assert(r == 1); + r = m.count(C2Int(7)); + assert(r == 1); + r = m.count(C2Int(8)); + assert(r == 1); + r = m.count(C2Int(9)); + assert(r == 1); + r = m.count(C2Int(10)); + assert(r == 1); + r = m.count(C2Int(11)); + assert(r == 1); + r = m.count(C2Int(12)); + assert(r == 1); + r = m.count(C2Int(4)); + assert(r == 0); + } + + { + typedef PrivateConstructor PC; + typedef std::map<PC, double, std::less<>> M; + typedef M::size_type R; + + M m; + m [ PC::make(5) ] = 5; + m [ PC::make(6) ] = 6; + m [ PC::make(7) ] = 7; + m [ PC::make(8) ] = 8; + m [ PC::make(9) ] = 9; + m [ PC::make(10) ] = 10; + m [ PC::make(11) ] = 11; + m [ PC::make(12) ] = 12; + + R r = m.count(5); + assert(r == 1); + r = m.count(6); + assert(r == 1); + r = m.count(7); + assert(r == 1); + r = m.count(8); + assert(r == 1); + r = m.count(9); + assert(r == 1); + r = m.count(10); + assert(r == 1); + r = m.count(11); + assert(r == 1); + r = m.count(12); + assert(r == 1); + r = m.count(4); + assert(r == 0); + } +#endif +} diff --git a/test/std/containers/associative/map/map.ops/count0.pass.cpp b/test/std/containers/associative/map/map.ops/count0.pass.cpp new file mode 100644 index 0000000000000..ce549366e7ab0 --- /dev/null +++ b/test/std/containers/associative/map/map.ops/count0.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// XFAIL: c++03, c++11 + +// <map> + +// class map + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +int main() +{ + typedef std::map<int, double, transparent_less> M; + + M().count(C2Int{5}); +} diff --git a/test/std/containers/associative/map/map.ops/count1.fail.cpp b/test/std/containers/associative/map/map.ops/count1.fail.cpp new file mode 100644 index 0000000000000..9c15059d490eb --- /dev/null +++ b/test/std/containers/associative/map/map.ops/count1.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::map<int, double, transparent_less_no_type> M; + + M().count(C2Int{5}); + } +} +#endif
\ No newline at end of file diff --git a/test/std/containers/associative/map/map.ops/count2.fail.cpp b/test/std/containers/associative/map/map.ops/count2.fail.cpp new file mode 100644 index 0000000000000..7aa1553ef47a9 --- /dev/null +++ b/test/std/containers/associative/map/map.ops/count2.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::map<int, double, transparent_less_private> M; + + M().count(C2Int{5}); + } +} +#endif
\ No newline at end of file diff --git a/test/std/containers/associative/map/map.ops/count3.fail.cpp b/test/std/containers/associative/map/map.ops/count3.fail.cpp new file mode 100644 index 0000000000000..7e7bb8f6d3709 --- /dev/null +++ b/test/std/containers/associative/map/map.ops/count3.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::map<int, double, transparent_less_not_a_type> M; + + M().count(C2Int{5}); + } +} +#endif
\ No newline at end of file diff --git a/test/std/containers/associative/map/map.ops/equal_range.pass.cpp b/test/std/containers/associative/map/map.ops/equal_range.pass.cpp new file mode 100644 index 0000000000000..a71149a472125 --- /dev/null +++ b/test/std/containers/associative/map/map.ops/equal_range.pass.cpp @@ -0,0 +1,490 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// 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> + +#include "min_allocator.h" +#include "private_constructor.hpp" +#include "is_transparent.h" + +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)); + } + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + typedef std::map<int, double, std::less<int>, min_allocator<V>> 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)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<const int, double> V; + typedef std::map<int, double, std::less<>> 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)); + + r = m.equal_range(C2Int(5)); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(C2Int(7)); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(C2Int(9)); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(C2Int(11)); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(C2Int(13)); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(C2Int(15)); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(C2Int(17)); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(C2Int(19)); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 8)); + r = m.equal_range(C2Int(4)); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(C2Int(6)); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(C2Int(8)); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(C2Int(10)); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(C2Int(12)); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(C2Int(14)); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(C2Int(16)); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(C2Int(18)); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(C2Int(20)); + assert(r.first == next(m.begin(), 8)); + assert(r.second == next(m.begin(), 8)); + } + { + typedef PrivateConstructor PC; + typedef std::map<PC, double, std::less<>> M; + typedef std::pair<M::iterator, M::iterator> R; + + M m; + m [ PC::make(5) ] = 5; + m [ PC::make(7) ] = 6; + m [ PC::make(9) ] = 7; + m [ PC::make(11) ] = 8; + m [ PC::make(13) ] = 9; + m [ PC::make(15) ] = 10; + m [ PC::make(17) ] = 11; + m [ PC::make(19) ] = 12; + + R r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(11); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(13); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(15); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(17); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(19); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 8)); + r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(12); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(14); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(16); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(18); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(20); + assert(r.first == next(m.begin(), 8)); + assert(r.second == next(m.begin(), 8)); + } +#endif +} diff --git a/test/std/containers/associative/map/map.ops/equal_range0.pass.cpp b/test/std/containers/associative/map/map.ops/equal_range0.pass.cpp new file mode 100644 index 0000000000000..c95c3dffa9a55 --- /dev/null +++ b/test/std/containers/associative/map/map.ops/equal_range0.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// XFAIL: c++03, c++11 + +// <map> + +// class map + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +int main() +{ + typedef std::map<int, double, transparent_less> M; + + M().equal_range(C2Int{5}); +} diff --git a/test/std/containers/associative/map/map.ops/equal_range1.fail.cpp b/test/std/containers/associative/map/map.ops/equal_range1.fail.cpp new file mode 100644 index 0000000000000..8f0da08eb3221 --- /dev/null +++ b/test/std/containers/associative/map/map.ops/equal_range1.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::map<int, double, transparent_less_no_type> M; + + M().equal_range(C2Int{5}); + } +} +#endif
\ No newline at end of file diff --git a/test/std/containers/associative/map/map.ops/equal_range2.fail.cpp b/test/std/containers/associative/map/map.ops/equal_range2.fail.cpp new file mode 100644 index 0000000000000..e73122d6533b9 --- /dev/null +++ b/test/std/containers/associative/map/map.ops/equal_range2.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::map<int, double, transparent_less_private> M; + + M().equal_range(C2Int{5}); + } +} +#endif
\ No newline at end of file diff --git a/test/std/containers/associative/map/map.ops/equal_range3.fail.cpp b/test/std/containers/associative/map/map.ops/equal_range3.fail.cpp new file mode 100644 index 0000000000000..bb72e9e7a6d43 --- /dev/null +++ b/test/std/containers/associative/map/map.ops/equal_range3.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::map<int, double, transparent_less_not_a_type> M; + + M().equal_range(C2Int{5}); + } +} +#endif
\ No newline at end of file diff --git a/test/std/containers/associative/map/map.ops/find.pass.cpp b/test/std/containers/associative/map/map.ops/find.pass.cpp new file mode 100644 index 0000000000000..17463b65740f2 --- /dev/null +++ b/test/std/containers/associative/map/map.ops/find.pass.cpp @@ -0,0 +1,260 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; + +#include <map> +#include <cassert> + +#include "min_allocator.h" +#include "private_constructor.hpp" +#include "is_transparent.h" + +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)); + } + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + typedef std::map<int, double, std::less<int>, min_allocator<V>> M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<const int, double> V; + typedef std::map<int, double, std::less<>> 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)); + + r = m.find(C2Int(5)); + assert(r == m.begin()); + r = m.find(C2Int(6)); + assert(r == next(m.begin())); + r = m.find(C2Int(7)); + assert(r == next(m.begin(), 2)); + r = m.find(C2Int(8)); + assert(r == next(m.begin(), 3)); + r = m.find(C2Int(9)); + assert(r == next(m.begin(), 4)); + r = m.find(C2Int(10)); + assert(r == next(m.begin(), 5)); + r = m.find(C2Int(11)); + assert(r == next(m.begin(), 6)); + r = m.find(C2Int(12)); + assert(r == next(m.begin(), 7)); + r = m.find(C2Int(4)); + assert(r == next(m.begin(), 8)); + } + + { + typedef PrivateConstructor PC; + typedef std::map<PC, double, std::less<>> M; + typedef M::iterator R; + + M m; + m [ PC::make(5) ] = 5; + m [ PC::make(6) ] = 6; + m [ PC::make(7) ] = 7; + m [ PC::make(8) ] = 8; + m [ PC::make(9) ] = 9; + m [ PC::make(10) ] = 10; + m [ PC::make(11) ] = 11; + m [ PC::make(12) ] = 12; + + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } +#endif +} diff --git a/test/std/containers/associative/map/map.ops/find0.pass.cpp b/test/std/containers/associative/map/map.ops/find0.pass.cpp new file mode 100644 index 0000000000000..5f310b07c599d --- /dev/null +++ b/test/std/containers/associative/map/map.ops/find0.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// XFAIL: c++03, c++11 + +// <map> + +// class map + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +int main() +{ + typedef std::map<int, double, transparent_less> M; + + M().find(C2Int{5}); +} diff --git a/test/std/containers/associative/map/map.ops/find1.fail.cpp b/test/std/containers/associative/map/map.ops/find1.fail.cpp new file mode 100644 index 0000000000000..c33b5a9a34cf8 --- /dev/null +++ b/test/std/containers/associative/map/map.ops/find1.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::map<int, double, transparent_less_no_type> M; + + M().find(C2Int{5}); + } +} +#endif
\ No newline at end of file diff --git a/test/std/containers/associative/map/map.ops/find2.fail.cpp b/test/std/containers/associative/map/map.ops/find2.fail.cpp new file mode 100644 index 0000000000000..40bf323a45384 --- /dev/null +++ b/test/std/containers/associative/map/map.ops/find2.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::map<int, double, transparent_less_private> M; + + M().find(C2Int{5}); + } +} +#endif
\ No newline at end of file diff --git a/test/std/containers/associative/map/map.ops/find3.fail.cpp b/test/std/containers/associative/map/map.ops/find3.fail.cpp new file mode 100644 index 0000000000000..9526c0e24d9ec --- /dev/null +++ b/test/std/containers/associative/map/map.ops/find3.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::map<int, double, transparent_less_not_a_type> M; + + M().find(C2Int{5}); + } +} +#endif
\ No newline at end of file diff --git a/test/std/containers/associative/map/map.ops/lower_bound.pass.cpp b/test/std/containers/associative/map/map.ops/lower_bound.pass.cpp new file mode 100644 index 0000000000000..3cbfbf7d869f2 --- /dev/null +++ b/test/std/containers/associative/map/map.ops/lower_bound.pass.cpp @@ -0,0 +1,372 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; + +#include <map> +#include <cassert> + +#include "min_allocator.h" +#include "private_constructor.hpp" +#include "is_transparent.h" + +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)); + } + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + typedef std::map<int, double, std::less<int>, min_allocator<V>> M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<const int, double> V; + typedef std::map<int, double, std::less <>> 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)); + + r = m.lower_bound(C2Int(5)); + assert(r == m.begin()); + r = m.lower_bound(C2Int(7)); + assert(r == next(m.begin())); + r = m.lower_bound(C2Int(9)); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(C2Int(11)); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(C2Int(13)); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(C2Int(15)); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(C2Int(17)); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(C2Int(19)); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(C2Int(4)); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(C2Int(6)); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(C2Int(8)); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(C2Int(10)); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(C2Int(12)); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(C2Int(14)); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(C2Int(16)); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(C2Int(18)); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(C2Int(20)); + assert(r == next(m.begin(), 8)); + } + + { + typedef PrivateConstructor PC; + typedef std::map<PC, double, std::less<>> M; + typedef M::iterator R; + + M m; + m [ PC::make(5) ] = 5; + m [ PC::make(7) ] = 6; + m [ PC::make(9) ] = 7; + m [ PC::make(11) ] = 8; + m [ PC::make(13) ] = 9; + m [ PC::make(15) ] = 10; + m [ PC::make(17) ] = 11; + m [ PC::make(19) ] = 12; + + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } +#endif +} diff --git a/test/std/containers/associative/map/map.ops/lower_bound0.pass.cpp b/test/std/containers/associative/map/map.ops/lower_bound0.pass.cpp new file mode 100644 index 0000000000000..2fc095a8f2c1d --- /dev/null +++ b/test/std/containers/associative/map/map.ops/lower_bound0.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// XFAIL: c++03, c++11 + +// <map> + +// class map + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +int main() +{ + typedef std::map<int, double, transparent_less> M; + + M().lower_bound(C2Int{5}); +} diff --git a/test/std/containers/associative/map/map.ops/lower_bound1.fail.cpp b/test/std/containers/associative/map/map.ops/lower_bound1.fail.cpp new file mode 100644 index 0000000000000..a4a986c1a7a43 --- /dev/null +++ b/test/std/containers/associative/map/map.ops/lower_bound1.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::map<int, double, transparent_less_no_type> M; + + M().lower_bound(C2Int{5}); + } +} +#endif diff --git a/test/std/containers/associative/map/map.ops/lower_bound2.fail.cpp b/test/std/containers/associative/map/map.ops/lower_bound2.fail.cpp new file mode 100644 index 0000000000000..3f6380e5e25ff --- /dev/null +++ b/test/std/containers/associative/map/map.ops/lower_bound2.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::map<int, double, transparent_less_private> M; + + M().lower_bound(C2Int{5}); + } +} +#endif diff --git a/test/std/containers/associative/map/map.ops/lower_bound3.fail.cpp b/test/std/containers/associative/map/map.ops/lower_bound3.fail.cpp new file mode 100644 index 0000000000000..18f2c7b71fde6 --- /dev/null +++ b/test/std/containers/associative/map/map.ops/lower_bound3.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::map<int, double, transparent_less_not_a_type> M; + + M().lower_bound(C2Int{5}); + } +} +#endif diff --git a/test/std/containers/associative/map/map.ops/upper_bound.pass.cpp b/test/std/containers/associative/map/map.ops/upper_bound.pass.cpp new file mode 100644 index 0000000000000..037ceb962cd8d --- /dev/null +++ b/test/std/containers/associative/map/map.ops/upper_bound.pass.cpp @@ -0,0 +1,335 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; + +#include <map> +#include <cassert> + +#include "min_allocator.h" +#include "private_constructor.hpp" + +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)); + } + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + typedef std::map<int, double, std::less<int>, min_allocator<V>> M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<const int, double> V; + typedef std::map<int, double, std::less<>> M; + typedef M::iterator R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } + + { + typedef PrivateConstructor PC; + typedef std::map<PC, double, std::less<>> M; + typedef M::iterator R; + + M m; + m [ PC::make(5) ] = 5; + m [ PC::make(7) ] = 6; + m [ PC::make(9) ] = 7; + m [ PC::make(11) ] = 8; + m [ PC::make(13) ] = 9; + m [ PC::make(15) ] = 10; + m [ PC::make(17) ] = 11; + m [ PC::make(19) ] = 12; + + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } +#endif +} diff --git a/test/std/containers/associative/map/map.ops/upper_bound0.pass.cpp b/test/std/containers/associative/map/map.ops/upper_bound0.pass.cpp new file mode 100644 index 0000000000000..c58e55f297933 --- /dev/null +++ b/test/std/containers/associative/map/map.ops/upper_bound0.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// XFAIL: c++03, c++11 + +// <map> + +// class map + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +int main() +{ + typedef std::map<int, double, transparent_less> M; + + M().upper_bound(C2Int{5}); +} diff --git a/test/std/containers/associative/map/map.ops/upper_bound1.fail.cpp b/test/std/containers/associative/map/map.ops/upper_bound1.fail.cpp new file mode 100644 index 0000000000000..4647681b5cd19 --- /dev/null +++ b/test/std/containers/associative/map/map.ops/upper_bound1.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::map<int, double, transparent_less_no_type> M; + + M().upper_bound(C2Int{5}); + } +} +#endif diff --git a/test/std/containers/associative/map/map.ops/upper_bound2.fail.cpp b/test/std/containers/associative/map/map.ops/upper_bound2.fail.cpp new file mode 100644 index 0000000000000..11852fe0cc9ff --- /dev/null +++ b/test/std/containers/associative/map/map.ops/upper_bound2.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::map<int, double, transparent_less_private> M; + + M().upper_bound(C2Int{5}); + } +} +#endif diff --git a/test/std/containers/associative/map/map.ops/upper_bound3.fail.cpp b/test/std/containers/associative/map/map.ops/upper_bound3.fail.cpp new file mode 100644 index 0000000000000..9cddeb8acbdc8 --- /dev/null +++ b/test/std/containers/associative/map/map.ops/upper_bound3.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::map<int, double, transparent_less_not_a_type> M; + + M().upper_bound(C2Int{5}); + } +} +#endif diff --git a/test/std/containers/associative/map/map.special/member_swap.pass.cpp b/test/std/containers/associative/map/map.special/member_swap.pass.cpp new file mode 100644 index 0000000000000..7c3ad9d50ae41 --- /dev/null +++ b/test/std/containers/associative/map/map.special/member_swap.pass.cpp @@ -0,0 +1,176 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// void swap(map& m); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + typedef std::pair<const int, double> V; + { + typedef std::map<int, double> M; + { + M m1; + M m2; + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + 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; + 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) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2; + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<V>> M; + { + M m1; + M m2; + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + 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; + 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) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2; + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#endif +} diff --git a/test/std/containers/associative/map/map.special/non_member_swap.pass.cpp b/test/std/containers/associative/map/map.special/non_member_swap.pass.cpp new file mode 100644 index 0000000000000..b042a4878f8a2 --- /dev/null +++ b/test/std/containers/associative/map/map.special/non_member_swap.pass.cpp @@ -0,0 +1,281 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// 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" +#include "min_allocator.h" + +int main() +{ + typedef std::pair<const int, double> V; + { + typedef std::map<int, double> M; + { + M m1; + M m2; + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + 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; + 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) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2; + 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)); + } + } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<V>> M; + { + M m1; + M m2; + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + 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; + 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) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2; + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + typedef min_allocator<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()); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A()); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + assert(m1.key_comp() == C(2)); + assert(m1.get_allocator() == A()); + assert(m2.key_comp() == C(1)); + assert(m2.get_allocator() == A()); + } + } +#endif +} diff --git a/test/std/containers/associative/map/map.special/swap_noexcept.pass.cpp b/test/std/containers/associative/map/map.special/swap_noexcept.pass.cpp new file mode 100644 index 0000000000000..4598e9945d4e1 --- /dev/null +++ b/test/std/containers/associative/map/map.special/swap_noexcept.pass.cpp @@ -0,0 +1,148 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// void swap(map& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable<allocator_type>::value); +// +// In C++17, the standard says that swap shall have: +// noexcept(allocator_traits<Allocator>::is_always_equal::value && +// noexcept(swap(declval<Compare&>(), declval<Compare&>()))); + +// This tests a conforming extension + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + + some_comp() {} + some_comp(const some_comp&) {} + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +template <class T> +struct some_comp2 +{ + typedef T value_type; + + some_comp2() {} + some_comp2(const some_comp2&) {} + void deallocate(void*, unsigned) {} + typedef std::true_type propagate_on_container_swap; +}; + +#if TEST_STD_VER >= 14 +template <typename T> +void swap(some_comp2<T>&, some_comp2<T>&) noexcept {} +#endif + +template <class T> +struct some_alloc +{ + typedef T value_type; + + some_alloc() {} + some_alloc(const some_alloc&); + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +template <class T> +struct some_alloc2 +{ + typedef T value_type; + + some_alloc2() {} + some_alloc2(const some_alloc2&); + void deallocate(void*, unsigned) {} + + typedef std::false_type propagate_on_container_swap; + typedef std::true_type is_always_equal; +}; + +template <class T> +struct some_alloc3 +{ + typedef T value_type; + + some_alloc3() {} + some_alloc3(const some_alloc3&); + void deallocate(void*, unsigned) {} + + typedef std::false_type propagate_on_container_swap; + typedef std::false_type is_always_equal; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::map<MoveOnly, MoveOnly> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::map<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::map<MoveOnly, MoveOnly, some_comp<MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + +#if TEST_STD_VER >= 14 + { // POCS allocator, throwable swap for comp + typedef std::map<MoveOnly, MoveOnly, some_comp <MoveOnly>, some_alloc <MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { // always equal allocator, throwable swap for comp + typedef std::map<MoveOnly, MoveOnly, some_comp <MoveOnly>, some_alloc2<MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { // POCS allocator, nothrow swap for comp + typedef std::map<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc <MoveOnly>> C; + C c1, c2; + static_assert( noexcept(swap(c1, c2)), ""); + } + { // always equal allocator, nothrow swap for comp + typedef std::map<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc2<MoveOnly>> C; + C c1, c2; + static_assert( noexcept(swap(c1, c2)), ""); + } + + { // NOT always equal allocator, nothrow swap for comp + typedef std::map<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc3<MoveOnly>> C; + C c1, c2; + static_assert( noexcept(swap(c1, c2)), ""); + } +#endif + +#endif +} diff --git a/test/std/containers/associative/map/types.pass.cpp b/test/std/containers/associative/map/types.pass.cpp new file mode 100644 index 0000000000000..d117deff693d1 --- /dev/null +++ b/test/std/containers/associative/map/types.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::map<int, double> C; + static_assert((std::is_same<C::key_type, int>::value), ""); + static_assert((std::is_same<C::mapped_type, double>::value), ""); + static_assert((std::is_same<C::value_type, std::pair<const int, double> >::value), ""); + static_assert((std::is_same<C::key_compare, std::less<int> >::value), ""); + static_assert((std::is_same<C::allocator_type, std::allocator<std::pair<const int, double> > >::value), ""); + static_assert((std::is_same<C::reference, std::pair<const int, double>&>::value), ""); + static_assert((std::is_same<C::const_reference, const std::pair<const int, double>&>::value), ""); + static_assert((std::is_same<C::pointer, std::pair<const int, double>*>::value), ""); + static_assert((std::is_same<C::const_pointer, const std::pair<const int, double>*>::value), ""); + static_assert((std::is_same<C::size_type, std::size_t>::value), ""); + static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), ""); + } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> C; + static_assert((std::is_same<C::key_type, int>::value), ""); + static_assert((std::is_same<C::mapped_type, double>::value), ""); + static_assert((std::is_same<C::value_type, std::pair<const int, double> >::value), ""); + static_assert((std::is_same<C::key_compare, std::less<int> >::value), ""); + static_assert((std::is_same<C::allocator_type, min_allocator<std::pair<const int, double> > >::value), ""); + static_assert((std::is_same<C::reference, std::pair<const int, double>&>::value), ""); + static_assert((std::is_same<C::const_reference, const std::pair<const int, double>&>::value), ""); + static_assert((std::is_same<C::pointer, min_pointer<std::pair<const int, double>>>::value), ""); + static_assert((std::is_same<C::const_pointer, min_pointer<const std::pair<const int, double>>>::value), ""); +// min_allocator doesn't have a size_type, so one gets synthesized + static_assert((std::is_same<C::size_type, std::make_unsigned<C::difference_type>::type>::value), ""); + static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), ""); + } +#endif +} diff --git a/test/std/containers/associative/map/version.pass.cpp b/test/std/containers/associative/map/version.pass.cpp new file mode 100644 index 0000000000000..b2e3fa43e7879 --- /dev/null +++ b/test/std/containers/associative/map/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +#include <map> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/containers/associative/multimap/empty.pass.cpp b/test/std/containers/associative/multimap/empty.pass.cpp new file mode 100644 index 0000000000000..2384960d10dbd --- /dev/null +++ b/test/std/containers/associative/multimap/empty.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// bool empty() const; + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +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()); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + M m; + assert(m.empty()); + m.insert(M::value_type(1, 1.5)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); + } +#endif +} diff --git a/test/std/containers/associative/multimap/iterator.pass.cpp b/test/std/containers/associative/multimap/iterator.pass.cpp new file mode 100644 index 0000000000000..2763129acc2ab --- /dev/null +++ b/test/std/containers/associative/multimap/iterator.pass.cpp @@ -0,0 +1,231 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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> + +#include "min_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), + 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; + 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; + i = m.begin(); + for (int j = 1; j <= 8; ++j) + for (double d = 1; d <= 2; d += .5, ++i) + { + assert(i->first == j); + assert(i->second == d); + } + } +#if __cplusplus >= 201103L + { + typedef std::pair<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, std::less<int>, min_allocator<V>> 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, std::less<int>, min_allocator<V>>::iterator i; + i = m.begin(); + std::multimap<int, double, std::less<int>, min_allocator<V>>::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, std::less<int>, min_allocator<V>> 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, std::less<int>, min_allocator<V>>::const_iterator i; + i = m.begin(); + for (int j = 1; j <= 8; ++j) + for (double d = 1; d <= 2; d += .5, ++i) + { + assert(i->first == j); + assert(i->second == d); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + typedef std::multimap<int, double> C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + } +#endif +} diff --git a/test/std/containers/associative/multimap/max_size.pass.cpp b/test/std/containers/associative/multimap/max_size.pass.cpp new file mode 100644 index 0000000000000..ccd8b10638c19 --- /dev/null +++ b/test/std/containers/associative/multimap/max_size.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// size_type max_size() const; + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multimap<int, double> M; + M m; + assert(m.max_size() != 0); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + M m; + assert(m.max_size() != 0); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.cons/alloc.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/alloc.pass.cpp new file mode 100644 index 0000000000000..87bf0447e5be5 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/alloc.pass.cpp @@ -0,0 +1,42 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// explicit multimap(const allocator_type& a); + +#include <map> +#include <cassert> + +#include "test_allocator.h" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + typedef std::less<int> C; + typedef min_allocator<std::pair<const int, double> > A; + std::multimap<int, double, C, A> m(A{}); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.get_allocator() == A()); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.cons/assign_initializer_list.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/assign_initializer_list.pass.cpp new file mode 100644 index 0000000000000..0c89918325297 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap& operator=(initializer_list<value_type> il); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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)); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const 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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/associative/multimap/multimap.cons/compare.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/compare.pass.cpp new file mode 100644 index 0000000000000..9a4e0f987fd00 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/compare.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// explicit multimap(const key_compare& comp); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "min_allocator.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)); + } +#if __cplusplus >= 201103L + { + typedef test_compare<std::less<int> > C; + std::multimap<int, double, C, min_allocator<std::pair<const int, double>>> m(C(3)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(3)); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.cons/compare_alloc.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/compare_alloc.pass.cpp new file mode 100644 index 0000000000000..1224884939cfa --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/compare_alloc.pass.cpp @@ -0,0 +1,45 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap(const key_compare& comp, const allocator_type& a); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + typedef test_compare<std::less<int> > C; + typedef min_allocator<std::pair<const int, double> > A; + std::multimap<int, double, C, A> m(C(4), A()); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(4)); + assert(m.get_allocator() == A()); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.cons/copy.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/copy.pass.cpp new file mode 100644 index 0000000000000..3d6626eaadbb0 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/copy.pass.cpp @@ -0,0 +1,104 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap(const multimap& m); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_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 // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + 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 min_allocator<V> A; + std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::multimap<int, double, C, A> m = mo; + assert(m == mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.cons/copy_alloc.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/copy_alloc.pass.cpp new file mode 100644 index 0000000000000..22594e32d7188 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/copy_alloc.pass.cpp @@ -0,0 +1,77 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap(const multimap& m, const allocator_type& a); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + 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 min_allocator<V> A; + std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::multimap<int, double, C, A> m(mo, A()); + assert(m == mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.cons/copy_assign.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/copy_assign.pass.cpp new file mode 100644 index 0000000000000..2bdc4d6a70ab5 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/copy_assign.pass.cpp @@ -0,0 +1,125 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap& operator=(const multimap& m); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_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; + const V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + std::multimap<int, double> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + std::multimap<int, double> *p = &m; + m = *p; + assert(m.size() == sizeof(ar)/sizeof(ar[0])); + assert(std::equal(m.begin(), m.end(), ar)); + } + { + 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)); + } +#if __cplusplus >= 201103L + { + 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 min_allocator<V> A; + std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::multimap<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A()); + m = mo; + assert(m == mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.cons/default.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/default.pass.cpp new file mode 100644 index 0000000000000..1c3ab8ce6c4b0 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/default.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap(); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + std::multimap<int, double> m; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#if __cplusplus >= 201103L + { + std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> m; + assert(m.empty()); + assert(m.begin() == m.end()); + } + { + std::multimap<int, double> m = {}; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.cons/default_noexcept.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/default_noexcept.pass.cpp new file mode 100644 index 0000000000000..d1db40b1fc7a8 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/default_noexcept.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// multimap() +// noexcept( +// is_nothrow_default_constructible<allocator_type>::value && +// is_nothrow_default_constructible<key_compare>::value && +// is_nothrow_copy_constructible<key_compare>::value); + +// This tests a conforming extension + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + some_comp(); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multimap<MoveOnly, MoveOnly> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::multimap<MoveOnly, MoveOnly, some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.cons/default_recursive.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/default_recursive.pass.cpp new file mode 100644 index 0000000000000..08ca8a441e3b7 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/default_recursive.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap(); + +#include <map> + +struct X +{ + std::multimap<int, X> m; + std::multimap<int, X>::iterator i; + std::multimap<int, X>::const_iterator ci; + std::multimap<int, X>::reverse_iterator ri; + std::multimap<int, X>::const_reverse_iterator cri; +}; + +int main() +{ +} diff --git a/test/std/containers/associative/multimap/multimap.cons/dtor_noexcept.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/dtor_noexcept.pass.cpp new file mode 100644 index 0000000000000..cb55e3fb33ec3 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// ~multimap() // implied noexcept; + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template <class T> +struct some_comp +{ + typedef T value_type; + ~some_comp() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multimap<MoveOnly, MoveOnly> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::multimap<MoveOnly, MoveOnly, some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_destructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.cons/initializer_list.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/initializer_list.pass.cpp new file mode 100644 index 0000000000000..937a202a55ea0 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/initializer_list.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap(initializer_list<value_type> il, const key_compare& comp = key_compare()); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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)); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const 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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/associative/multimap/multimap.cons/initializer_list_compare.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/initializer_list_compare.pass.cpp new file mode 100644 index 0000000000000..e6677039c90c8 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/initializer_list_compare.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap(initializer_list<value_type> il, const key_compare& comp = key_compare()); + +#include <map> +#include <cassert> +#include "../../../test_compare.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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)); + } +#if __cplusplus >= 201103L + { + typedef test_compare<std::less<int> > Cmp; + typedef std::multimap<int, double, Cmp, min_allocator<std::pair<const 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} + }, + Cmp(4) + ); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + C::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(1, 2)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(2, 2)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 1.5)); + assert(*++i == V(3, 2)); + assert(m.key_comp() == Cmp(4)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/associative/multimap/multimap.cons/initializer_list_compare_alloc.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/initializer_list_compare_alloc.pass.cpp new file mode 100644 index 0000000000000..0e73f72793e56 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/initializer_list_compare_alloc.pass.cpp @@ -0,0 +1,129 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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 // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#if __cplusplus >= 201103L + { + typedef test_compare<std::less<int> > Cmp; + typedef min_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() + ); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + C::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(1, 2)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(2, 2)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 1.5)); + assert(*++i == V(3, 2)); + assert(m.key_comp() == Cmp(4)); + assert(m.get_allocator() == A()); + } +#if _LIBCPP_STD_VER > 11 + { + typedef test_compare<std::less<int> > C; + typedef std::pair<const int, double> V; + typedef min_allocator<V> A; + typedef std::multimap<int, double, C, A> M; + A a; + M m ({ {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }, a); + + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + M::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(1, 2)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(2, 2)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 1.5)); + assert(*++i == V(3, 2)); + assert(m.get_allocator() == a); + } +#endif +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.cons/iter_iter.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/iter_iter.pass.cpp new file mode 100644 index 0000000000000..fa062e2be0b8f --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/iter_iter.pass.cpp @@ -0,0 +1,112 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// template <class InputIterator> +// multimap(InputIterator first, InputIterator last); + +#include <map> +#include <cassert> + +#include "min_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), + }; + 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)); + } +#if __cplusplus >= 201103L + { + 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, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(1, 1.5)); + assert(*next(m.begin(), 2) == V(1, 2)); + assert(*next(m.begin(), 3) == V(2, 1)); + assert(*next(m.begin(), 4) == V(2, 1.5)); + assert(*next(m.begin(), 5) == V(2, 2)); + assert(*next(m.begin(), 6) == V(3, 1)); + assert(*next(m.begin(), 7) == V(3, 1.5)); + assert(*next(m.begin(), 8) == V(3, 2)); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<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 min_allocator<std::pair<const int, double>> A; + A a; + std::multimap<int, double, std::less<int>, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), a); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(1, 1.5)); + assert(*next(m.begin(), 2) == V(1, 2)); + assert(*next(m.begin(), 3) == V(2, 1)); + assert(*next(m.begin(), 4) == V(2, 1.5)); + assert(*next(m.begin(), 5) == V(2, 2)); + assert(*next(m.begin(), 6) == V(3, 1)); + assert(*next(m.begin(), 7) == V(3, 1.5)); + assert(*next(m.begin(), 8) == V(3, 2)); + assert(m.get_allocator() == a); + } +#endif +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.cons/iter_iter_comp.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/iter_iter_comp.pass.cpp new file mode 100644 index 0000000000000..d6de59428dd6a --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/iter_iter_comp.pass.cpp @@ -0,0 +1,86 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// template <class InputIterator> +// multimap(InputIterator first, InputIterator last, +// const key_compare& comp); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "min_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; + 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)); + } +#if __cplusplus >= 201103L + { + 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, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5)); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(1, 1.5)); + assert(*next(m.begin(), 2) == V(1, 2)); + assert(*next(m.begin(), 3) == V(2, 1)); + assert(*next(m.begin(), 4) == V(2, 1.5)); + assert(*next(m.begin(), 5) == V(2, 2)); + assert(*next(m.begin(), 6) == V(3, 1)); + assert(*next(m.begin(), 7) == V(3, 1.5)); + assert(*next(m.begin(), 8) == V(3, 2)); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.cons/iter_iter_comp_alloc.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/iter_iter_comp_alloc.pass.cpp new file mode 100644 index 0000000000000..259fbd145ff6d --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/iter_iter_comp_alloc.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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" +#include "min_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)); + } +#if __cplusplus >= 201103L + { + 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 min_allocator<V> A; + std::multimap<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(1, 1.5)); + assert(*next(m.begin(), 2) == V(1, 2)); + assert(*next(m.begin(), 3) == V(2, 1)); + assert(*next(m.begin(), 4) == V(2, 1.5)); + assert(*next(m.begin(), 5) == V(2, 2)); + assert(*next(m.begin(), 6) == V(3, 1)); + assert(*next(m.begin(), 7) == V(3, 1.5)); + assert(*next(m.begin(), 8) == V(3, 2)); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.cons/move.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/move.pass.cpp new file mode 100644 index 0000000000000..aed08867c3ccf --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/move.pass.cpp @@ -0,0 +1,132 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap(multimap&& m); + +#include <map> +#include <cassert> + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + 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); + } +#if __cplusplus >= 201103L + { + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::multimap<int, double, C, A> mo(C(5), A()); + std::multimap<int, double, C, A> m = std::move(mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 0); + assert(distance(m.begin(), m.end()) == 0); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } + { + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::multimap<int, double, C, A> m = std::move(mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(1, 1.5)); + assert(*next(m.begin(), 2) == V(1, 2)); + assert(*next(m.begin(), 3) == V(2, 1)); + assert(*next(m.begin(), 4) == V(2, 1.5)); + assert(*next(m.begin(), 5) == V(2, 2)); + assert(*next(m.begin(), 6) == V(3, 1)); + assert(*next(m.begin(), 7) == V(3, 1.5)); + assert(*next(m.begin(), 8) == V(3, 2)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/multimap/multimap.cons/move_alloc.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/move_alloc.pass.cpp new file mode 100644 index 0000000000000..3ec79eea3554f --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/move_alloc.pass.cpp @@ -0,0 +1,234 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap(multimap&& m, const allocator_type& a); + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" +#include "Counter.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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()); + } + { + typedef Counter<int> T; + typedef std::pair<int, T> V; + typedef std::pair<const int, T> VC; + typedef test_allocator<VC> A; + typedef std::less<int> C; + typedef std::multimap<const int, T, C, A> M; + typedef V* I; + Counter_base::gConstructed = 0; + { + 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) + }; + const size_t num = sizeof(a1)/sizeof(a1[0]); + assert(Counter_base::gConstructed == num); + + M m1(I(a1), I(a1+num), C(), A()); + assert(Counter_base::gConstructed == 2*num); + + M m2(m1); + assert(m2 == m1); + assert(Counter_base::gConstructed == 3*num); + + M m3(std::move(m1), A()); + assert(m3 == m2); + assert(m1.empty()); + assert(Counter_base::gConstructed == 3*num); + + { + M m4(std::move(m2), A(5)); + assert(Counter_base::gConstructed == 3*num); + assert(m4 == m3); + assert(m2.empty()); + } + assert(Counter_base::gConstructed == 2*num); + } + assert(Counter_base::gConstructed == 0); + } +#if __cplusplus >= 201103L + { + typedef std::pair<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef min_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()); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A()); + M m3(std::move(m1), A()); + assert(m3 == m2); + assert(m3.get_allocator() == A()); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/multimap/multimap.cons/move_assign.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/move_assign.pass.cpp new file mode 100644 index 0000000000000..48854e388e10a --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/move_assign.pass.cpp @@ -0,0 +1,190 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// multimap& operator=(multimap&& m); + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef std::pair<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()); + } +#if __cplusplus >= 201103L + { + typedef std::pair<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef min_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()); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A()); + M m3(C(3), A()); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A()); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/multimap/multimap.cons/move_assign_noexcept.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 0000000000000..8ad9e8b82fd15 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// multimap& operator=(multimap&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable<allocator_type>::value && +// is_nothrow_move_assignable<key_compare>::value); + +// This tests a conforming extension + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + some_comp& operator=(const some_comp&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multimap<MoveOnly, MoveOnly> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::multimap<MoveOnly, MoveOnly, some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.cons/move_noexcept.pass.cpp b/test/std/containers/associative/multimap/multimap.cons/move_noexcept.pass.cpp new file mode 100644 index 0000000000000..66ea8737fb751 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.cons/move_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// multimap(multimap&&) +// noexcept(is_nothrow_move_constructible<allocator_type>::value && +// is_nothrow_move_constructible<key_compare>::value); + +// This tests a conforming extension + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + some_comp(const some_comp&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multimap<MoveOnly, MoveOnly> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::multimap<MoveOnly, MoveOnly, some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_move_constructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.modifiers/clear.pass.cpp b/test/std/containers/associative/multimap/multimap.modifiers/clear.pass.cpp new file mode 100644 index 0000000000000..fe9b8c8ba1287 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.modifiers/clear.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// void clear(); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const 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); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.modifiers/emplace.pass.cpp b/test/std/containers/associative/multimap/multimap.modifiers/emplace.pass.cpp new file mode 100644 index 0000000000000..03da4af593720 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.modifiers/emplace.pass.cpp @@ -0,0 +1,150 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// template <class... Args> +// iterator emplace(Args&&... args); + +#include <map> +#include <cassert> + +#include "../../../Emplaceable.h" +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin(), 2)); + assert(m.size() == 3); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == DefaultOnly()); + assert(DefaultOnly::count == 3); + } + assert(DefaultOnly::count == 0); + { + typedef std::multimap<int, Emplaceable> M; + typedef M::iterator R; + M m; + R r = m.emplace(std::piecewise_construct, std::forward_as_tuple(2), + std::forward_as_tuple()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(3, 3.5)); + assert(r == next(m.begin())); + assert(m.size() == 3); + assert(r->first == 1); + assert(r->second == Emplaceable(3, 3.5)); + } + { + typedef std::multimap<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); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, DefaultOnly, std::less<int>, min_allocator<std::pair<const 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(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin(), 2)); + assert(m.size() == 3); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == DefaultOnly()); + assert(DefaultOnly::count == 3); + } + assert(DefaultOnly::count == 0); + { + typedef std::multimap<int, Emplaceable, std::less<int>, min_allocator<std::pair<const int, Emplaceable>>> M; + typedef M::iterator R; + M m; + R r = m.emplace(std::piecewise_construct, std::forward_as_tuple(2), + std::forward_as_tuple()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(3, 3.5)); + assert(r == next(m.begin())); + assert(m.size() == 3); + assert(r->first == 1); + assert(r->second == Emplaceable(3, 3.5)); + } + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const 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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/multimap/multimap.modifiers/emplace_hint.pass.cpp b/test/std/containers/associative/multimap/multimap.modifiers/emplace_hint.pass.cpp new file mode 100644 index 0000000000000..846d5999a17ee --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.modifiers/emplace_hint.pass.cpp @@ -0,0 +1,160 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// template <class... Args> +// iterator emplace_hint(const_iterator position, Args&&... args); + +#include <map> +#include <cassert> + +#include "../../../Emplaceable.h" +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace_hint(m.cend(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin(), 2)); + assert(m.size() == 3); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == DefaultOnly()); + assert(DefaultOnly::count == 3); + } + assert(DefaultOnly::count == 0); + { + typedef std::multimap<int, Emplaceable> M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.cend(), std::piecewise_construct, + std::forward_as_tuple(2), + std::forward_as_tuple()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace_hint(m.cbegin(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace_hint(m.cbegin(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(3, 3.5)); + assert(r == m.begin()); + assert(m.size() == 3); + assert(r->first == 1); + assert(r->second == Emplaceable(3, 3.5)); + } + { + typedef std::multimap<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); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, DefaultOnly, std::less<int>, min_allocator<std::pair<const 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(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace_hint(m.cend(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple()); + assert(r == next(m.begin(), 2)); + assert(m.size() == 3); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == DefaultOnly()); + assert(DefaultOnly::count == 3); + } + assert(DefaultOnly::count == 0); + { + typedef std::multimap<int, Emplaceable, std::less<int>, min_allocator<std::pair<const int, Emplaceable>>> M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.cend(), std::piecewise_construct, + std::forward_as_tuple(2), + std::forward_as_tuple()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace_hint(m.cbegin(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace_hint(m.cbegin(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(3, 3.5)); + assert(r == m.begin()); + assert(m.size() == 3); + assert(r->first == 1); + assert(r->second == Emplaceable(3, 3.5)); + } + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const 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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/multimap/multimap.modifiers/erase_iter.pass.cpp b/test/std/containers/associative/multimap/multimap.modifiers/erase_iter.pass.cpp new file mode 100644 index 0000000000000..ba55351c0bde1 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.modifiers/erase_iter.pass.cpp @@ -0,0 +1,301 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator erase(const_iterator position); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +struct TemplateConstructor +{ + template<typename T> + TemplateConstructor (const T&) {} +}; + +bool operator<(const TemplateConstructor&, const TemplateConstructor&) { return false; } + +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()); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const 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()); + } +#endif +#if __cplusplus >= 201402L + { + // This is LWG #2059 + typedef TemplateConstructor T; + typedef std::multimap<T, int> C; + typedef C::iterator I; + + C c; + T a{0}; + I it = c.find(a); + if (it != c.end()) + c.erase(it); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.modifiers/erase_iter_iter.pass.cpp b/test/std/containers/associative/multimap/multimap.modifiers/erase_iter_iter.pass.cpp new file mode 100644 index 0000000000000..4d3789493110b --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.modifiers/erase_iter_iter.pass.cpp @@ -0,0 +1,157 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator erase(const_iterator first, const_iterator last); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +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()); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const 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()); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.modifiers/erase_key.pass.cpp b/test/std/containers/associative/multimap/multimap.modifiers/erase_key.pass.cpp new file mode 100644 index 0000000000000..33821d3e35962 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.modifiers/erase_key.pass.cpp @@ -0,0 +1,153 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// size_type erase(const key_type& k); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +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(i == 3); + assert(m.size() == 3); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1); + assert(next(m.begin(), 1)->first == 1); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == 2); + + i = m.erase(1); + assert(m.size() == 0); + assert(i == 3); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const 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(i == 3); + assert(m.size() == 3); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1); + assert(next(m.begin(), 1)->first == 1); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == 2); + + i = m.erase(1); + assert(m.size() == 0); + assert(i == 3); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.modifiers/insert_cv.pass.cpp b/test/std/containers/associative/multimap/multimap.modifiers/insert_cv.pass.cpp new file mode 100644 index 0000000000000..d9afc9d0fdf0e --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.modifiers/insert_cv.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator insert(const value_type& v); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const 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); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.modifiers/insert_initializer_list.pass.cpp b/test/std/containers/associative/multimap/multimap.modifiers/insert_initializer_list.pass.cpp new file mode 100644 index 0000000000000..5e1a1d4125ef4 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.modifiers/insert_initializer_list.pass.cpp @@ -0,0 +1,91 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// void insert(initializer_list<value_type> il); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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)); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const 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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_cv.pass.cpp b/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_cv.pass.cpp new file mode 100644 index 0000000000000..b83c802c04cf6 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_cv.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator insert(const_iterator position, const value_type& v); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const 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); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_iter.pass.cpp b/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_iter.pass.cpp new file mode 100644 index 0000000000000..70ff7ef6d6b89 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_iter.pass.cpp @@ -0,0 +1,101 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// template <class InputIterator> +// void insert(InputIterator first, InputIterator last); + +#include <map> +#include <cassert> + +#include "test_iterators.h" +#include "min_allocator.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); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const 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); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_rv.pass.cpp b/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_rv.pass.cpp new file mode 100644 index 0000000000000..b44f46429ec89 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_rv.pass.cpp @@ -0,0 +1,87 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// template <class P> +// iterator insert(const_iterator position, P&& p); + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, MoveOnly, std::less<int>, min_allocator<std::pair<const 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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/multimap/multimap.modifiers/insert_rv.pass.cpp b/test/std/containers/associative/multimap/multimap.modifiers/insert_rv.pass.cpp new file mode 100644 index 0000000000000..b1c043586d65c --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.modifiers/insert_rv.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// template <class P> +// iterator insert(P&& p); + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, MoveOnly, std::less<int>, min_allocator<std::pair<const 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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/multimap/multimap.ops/count.pass.cpp b/test/std/containers/associative/multimap/multimap.ops/count.pass.cpp new file mode 100644 index 0000000000000..c666c295f3a07 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/count.pass.cpp @@ -0,0 +1,175 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// size_type count(const key_type& k) const; + +#include <map> +#include <cassert> + +#include "min_allocator.h" +#include "private_constructor.hpp" +#include "is_transparent.h" + +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); + } + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const 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); + } + } +#endif + +#if _LIBCPP_STD_VER > 11 + { + typedef std::multimap<int, double, std::less<>> 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); + + r = m.count(C2Int(4)); + assert(r == 0); + r = m.count(C2Int(5)); + assert(r == 3); + r = m.count(C2Int(6)); + assert(r == 0); + r = m.count(C2Int(7)); + assert(r == 3); + r = m.count(C2Int(8)); + assert(r == 0); + r = m.count(C2Int(9)); + assert(r == 3); + r = m.count(C2Int(10)); + assert(r == 0); + } + + { + typedef PrivateConstructor PC; + typedef std::multimap<PC, double, std::less<>> M; + typedef M::size_type R; + + M m; + m.insert ( std::make_pair<PC, double> ( PC::make(5), 1 )); + m.insert ( std::make_pair<PC, double> ( PC::make(5), 2 )); + m.insert ( std::make_pair<PC, double> ( PC::make(5), 3 )); + m.insert ( std::make_pair<PC, double> ( PC::make(7), 1 )); + m.insert ( std::make_pair<PC, double> ( PC::make(7), 2 )); + m.insert ( std::make_pair<PC, double> ( PC::make(7), 3 )); + m.insert ( std::make_pair<PC, double> ( PC::make(9), 1 )); + m.insert ( std::make_pair<PC, double> ( PC::make(9), 2 )); + m.insert ( std::make_pair<PC, double> ( PC::make(9), 3 )); + + R r = m.count(4); + assert(r == 0); + r = m.count(5); + assert(r == 3); + r = m.count(6); + assert(r == 0); + r = m.count(7); + assert(r == 3); + r = m.count(8); + assert(r == 0); + r = m.count(9); + assert(r == 3); + r = m.count(10); + assert(r == 0); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.ops/count0.pass.cpp b/test/std/containers/associative/multimap/multimap.ops/count0.pass.cpp new file mode 100644 index 0000000000000..7da13bb0d66dc --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/count0.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// XFAIL: c++03, c++11 + +// <map> + +// class multimap + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +int main() +{ + typedef std::multimap<int, double, transparent_less> M; + + M().count(C2Int{5}); +} diff --git a/test/std/containers/associative/multimap/multimap.ops/count1.fail.cpp b/test/std/containers/associative/multimap/multimap.ops/count1.fail.cpp new file mode 100644 index 0000000000000..f30d1bfd88d62 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/count1.fail.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + typedef std::multimap<int, double, transparent_less_no_type> M; + + M().count(C2Int{5}); +} +#endif
\ No newline at end of file diff --git a/test/std/containers/associative/multimap/multimap.ops/count2.fail.cpp b/test/std/containers/associative/multimap/multimap.ops/count2.fail.cpp new file mode 100644 index 0000000000000..ffb7eb6a559a6 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/count2.fail.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + typedef std::multimap<int, double, transparent_less_private> M; + + M().count(C2Int{5}); +} +#endif
\ No newline at end of file diff --git a/test/std/containers/associative/multimap/multimap.ops/count3.fail.cpp b/test/std/containers/associative/multimap/multimap.ops/count3.fail.cpp new file mode 100644 index 0000000000000..4bb9d14634f31 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/count3.fail.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + typedef std::multimap<int, double, transparent_less_not_a_type> M; + + M().count(C2Int{5}); +} +#endif
\ No newline at end of file diff --git a/test/std/containers/associative/multimap/multimap.ops/equal_range.pass.cpp b/test/std/containers/associative/multimap/multimap.ops/equal_range.pass.cpp new file mode 100644 index 0000000000000..5a071042461a7 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/equal_range.pass.cpp @@ -0,0 +1,287 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <multimap> + +// 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> + +#include "min_allocator.h" +#include "private_constructor.hpp" +#include "is_transparent.h" + +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()); + } + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const 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()); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<const int, double> V; + typedef std::multimap<int, double, std::less<>> 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()); + + r = m.equal_range(C2Int(4)); + assert(r.first == m.begin()); + assert(r.second == m.begin()); + r = m.equal_range(C2Int(5)); + assert(r.first == m.begin()); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(C2Int(6)); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(C2Int(7)); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(C2Int(8)); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(C2Int(9)); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(C2Int(10)); + assert(r.first == m.end()); + assert(r.second == m.end()); + } + + { + typedef PrivateConstructor PC; + typedef std::multimap<PC, double, std::less<>> M; + typedef std::pair<M::iterator, M::iterator> R; + + M m; + m.insert ( std::make_pair<PC, double> ( PC::make(5), 1 )); + m.insert ( std::make_pair<PC, double> ( PC::make(5), 2 )); + m.insert ( std::make_pair<PC, double> ( PC::make(5), 3 )); + m.insert ( std::make_pair<PC, double> ( PC::make(7), 1 )); + m.insert ( std::make_pair<PC, double> ( PC::make(7), 2 )); + m.insert ( std::make_pair<PC, double> ( PC::make(7), 3 )); + m.insert ( std::make_pair<PC, double> ( PC::make(9), 1 )); + m.insert ( std::make_pair<PC, double> ( PC::make(9), 2 )); + m.insert ( std::make_pair<PC, double> ( PC::make(9), 3 )); + +// assert(m.size() == 9); + R r = m.equal_range(4); + assert(r.first == m.begin()); + assert(r.second == m.begin()); + r = m.equal_range(5); + assert(r.first == m.begin()); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(10); + assert(r.first == m.end()); + assert(r.second == m.end()); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.ops/equal_range0.pass.cpp b/test/std/containers/associative/multimap/multimap.ops/equal_range0.pass.cpp new file mode 100644 index 0000000000000..c0f07468ec5ed --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/equal_range0.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// XFAIL: c++03, c++11 + +// <map> + +// class multimap + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +int main() +{ + typedef std::multimap<int, double, transparent_less> M; + + M().equal_range(C2Int{5}); +} diff --git a/test/std/containers/associative/multimap/multimap.ops/equal_range1.fail.cpp b/test/std/containers/associative/multimap/multimap.ops/equal_range1.fail.cpp new file mode 100644 index 0000000000000..f022e94324fd9 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/equal_range1.fail.cpp @@ -0,0 +1,37 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + typedef std::multimap<int, double, transparent_less_no_type> M; + + M().equal_range(C2Int{5}); +} +#endif
\ No newline at end of file diff --git a/test/std/containers/associative/multimap/multimap.ops/equal_range2.fail.cpp b/test/std/containers/associative/multimap/multimap.ops/equal_range2.fail.cpp new file mode 100644 index 0000000000000..695e71703e3b9 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/equal_range2.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::multimap<int, double, transparent_less_private> M; + + M().equal_range(C2Int{5}); + } +} +#endif
\ No newline at end of file diff --git a/test/std/containers/associative/multimap/multimap.ops/equal_range3.fail.cpp b/test/std/containers/associative/multimap/multimap.ops/equal_range3.fail.cpp new file mode 100644 index 0000000000000..59c2855e8f695 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/equal_range3.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::multimap<int, double, transparent_less_not_a_type> M; + + M().equal_range(C2Int{5}); + } +} +#endif
\ No newline at end of file diff --git a/test/std/containers/associative/multimap/multimap.ops/find.pass.cpp b/test/std/containers/associative/multimap/multimap.ops/find.pass.cpp new file mode 100644 index 0000000000000..a60e42cf8592d --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/find.pass.cpp @@ -0,0 +1,223 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; + +#include <map> +#include <cassert> + +#include "min_allocator.h" +#include "private_constructor.hpp" +#include "is_transparent.h" + +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()); + } + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const 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()); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<const int, double> V; + typedef std::multimap<int, double, std::less<>> 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()); + + r = m.find(C2Int(5)); + assert(r == m.begin()); + r = m.find(C2Int(6)); + assert(r == m.end()); + r = m.find(C2Int(7)); + assert(r == next(m.begin(), 3)); + r = m.find(C2Int(8)); + assert(r == m.end()); + r = m.find(C2Int(9)); + assert(r == next(m.begin(), 6)); + r = m.find(C2Int(10)); + assert(r == m.end()); + } + + { + typedef PrivateConstructor PC; + typedef std::multimap<PC, double, std::less<>> M; + typedef M::iterator R; + + M m; + m.insert ( std::make_pair<PC, double> ( PC::make(5), 1 )); + m.insert ( std::make_pair<PC, double> ( PC::make(5), 2 )); + m.insert ( std::make_pair<PC, double> ( PC::make(5), 3 )); + m.insert ( std::make_pair<PC, double> ( PC::make(7), 1 )); + m.insert ( std::make_pair<PC, double> ( PC::make(7), 2 )); + m.insert ( std::make_pair<PC, double> ( PC::make(7), 3 )); + m.insert ( std::make_pair<PC, double> ( PC::make(9), 1 )); + m.insert ( std::make_pair<PC, double> ( PC::make(9), 2 )); + m.insert ( std::make_pair<PC, double> ( PC::make(9), 3 )); + + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == m.end()); + r = m.find(7); + assert(r == next(m.begin(), 3)); + r = m.find(8); + assert(r == m.end()); + r = m.find(9); + assert(r == next(m.begin(), 6)); + r = m.find(10); + assert(r == m.end()); + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.ops/find0.pass.cpp b/test/std/containers/associative/multimap/multimap.ops/find0.pass.cpp new file mode 100644 index 0000000000000..4f3369870c8f2 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/find0.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// XFAIL: c++03, c++11 + +// <map> + +// class multimap + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +int main() +{ + typedef std::multimap<int, double, transparent_less> M; + + M().find(C2Int{5}); +} diff --git a/test/std/containers/associative/multimap/multimap.ops/find1.fail.cpp b/test/std/containers/associative/multimap/multimap.ops/find1.fail.cpp new file mode 100644 index 0000000000000..e1eef034064d0 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/find1.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::multimap<int, double, transparent_less_no_type> M; + + M().find(C2Int{5}); + } +} +#endif
\ No newline at end of file diff --git a/test/std/containers/associative/multimap/multimap.ops/find2.fail.cpp b/test/std/containers/associative/multimap/multimap.ops/find2.fail.cpp new file mode 100644 index 0000000000000..4c03f583fa1c0 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/find2.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::multimap<int, double, transparent_less_private> M; + + M().find(C2Int{5}); + } +} +#endif
\ No newline at end of file diff --git a/test/std/containers/associative/multimap/multimap.ops/find3.fail.cpp b/test/std/containers/associative/multimap/multimap.ops/find3.fail.cpp new file mode 100644 index 0000000000000..f10bc60aa8641 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/find3.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::multimap<int, double, transparent_less_not_a_type> M; + + M().find(C2Int{5}); + } +} +#endif
\ No newline at end of file diff --git a/test/std/containers/associative/multimap/multimap.ops/lower_bound.pass.cpp b/test/std/containers/associative/multimap/multimap.ops/lower_bound.pass.cpp new file mode 100644 index 0000000000000..38b931802f8e4 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/lower_bound.pass.cpp @@ -0,0 +1,237 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; + +#include <map> +#include <cassert> + +#include "min_allocator.h" +#include "private_constructor.hpp" +#include "is_transparent.h" + +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()); + } + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const 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()); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<const int, double> V; + typedef std::multimap<int, double, std::less<>> 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()); + + r = m.lower_bound(C2Int(4)); + assert(r == m.begin()); + r = m.lower_bound(C2Int(5)); + assert(r == m.begin()); + r = m.lower_bound(C2Int(6)); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(C2Int(7)); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(C2Int(8)); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(C2Int(9)); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(C2Int(10)); + assert(r == m.end()); + } + + { + typedef PrivateConstructor PC; + typedef std::multimap<PC, double, std::less<>> M; + typedef M::iterator R; + + M m; + m.insert ( std::make_pair<PC, double> ( PC::make(5), 1 )); + m.insert ( std::make_pair<PC, double> ( PC::make(5), 2 )); + m.insert ( std::make_pair<PC, double> ( PC::make(5), 3 )); + m.insert ( std::make_pair<PC, double> ( PC::make(7), 1 )); + m.insert ( std::make_pair<PC, double> ( PC::make(7), 2 )); + m.insert ( std::make_pair<PC, double> ( PC::make(7), 3 )); + m.insert ( std::make_pair<PC, double> ( PC::make(9), 1 )); + m.insert ( std::make_pair<PC, double> ( PC::make(9), 2 )); + m.insert ( std::make_pair<PC, double> ( PC::make(9), 3 )); + + R r = m.lower_bound(4); + assert(r == m.begin()); + r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(10); + assert(r == m.end()); + } + +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.ops/lower_bound0.pass.cpp b/test/std/containers/associative/multimap/multimap.ops/lower_bound0.pass.cpp new file mode 100644 index 0000000000000..c5271f65d7e51 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/lower_bound0.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// XFAIL: c++03, c++11 + +// <map> + +// class multimap + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +int main() +{ + typedef std::multimap<int, double, transparent_less> M; + + M().lower_bound(C2Int{5}); +} diff --git a/test/std/containers/associative/multimap/multimap.ops/lower_bound1.fail.cpp b/test/std/containers/associative/multimap/multimap.ops/lower_bound1.fail.cpp new file mode 100644 index 0000000000000..b452be864e2bc --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/lower_bound1.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::multimap<int, double, transparent_less_no_type> M; + + M().lower_bound(C2Int{5}); + } +} +#endif diff --git a/test/std/containers/associative/multimap/multimap.ops/lower_bound2.fail.cpp b/test/std/containers/associative/multimap/multimap.ops/lower_bound2.fail.cpp new file mode 100644 index 0000000000000..a2ba30236a40d --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/lower_bound2.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::multimap<int, double, transparent_less_private> M; + + M().lower_bound(C2Int{5}); + } +} +#endif diff --git a/test/std/containers/associative/multimap/multimap.ops/lower_bound3.fail.cpp b/test/std/containers/associative/multimap/multimap.ops/lower_bound3.fail.cpp new file mode 100644 index 0000000000000..50d9fca91ad90 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/lower_bound3.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::multimap<int, double, transparent_less_not_a_type> M; + + M().lower_bound(C2Int{5}); + } +} +#endif diff --git a/test/std/containers/associative/multimap/multimap.ops/upper_bound.pass.cpp b/test/std/containers/associative/multimap/multimap.ops/upper_bound.pass.cpp new file mode 100644 index 0000000000000..7c647a9426cbe --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/upper_bound.pass.cpp @@ -0,0 +1,236 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; + +#include <map> +#include <cassert> + +#include "min_allocator.h" +#include "private_constructor.hpp" +#include "is_transparent.h" + +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()); + } + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const 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()); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef std::pair<const int, double> V; + typedef std::multimap<int, double, std::less<>> 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()); + + r = m.upper_bound(C2Int(4)); + assert(r == m.begin()); + r = m.upper_bound(C2Int(5)); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(C2Int(6)); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(C2Int(7)); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(C2Int(8)); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(C2Int(9)); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(C2Int(10)); + } + + { + typedef PrivateConstructor PC; + typedef std::multimap<PC, double, std::less<>> M; + typedef M::iterator R; + + M m; + m.insert ( std::make_pair<PC, double> ( PC::make(5), 1 )); + m.insert ( std::make_pair<PC, double> ( PC::make(5), 2 )); + m.insert ( std::make_pair<PC, double> ( PC::make(5), 3 )); + m.insert ( std::make_pair<PC, double> ( PC::make(7), 1 )); + m.insert ( std::make_pair<PC, double> ( PC::make(7), 2 )); + m.insert ( std::make_pair<PC, double> ( PC::make(7), 3 )); + m.insert ( std::make_pair<PC, double> ( PC::make(9), 1 )); + m.insert ( std::make_pair<PC, double> ( PC::make(9), 2 )); + m.insert ( std::make_pair<PC, double> ( PC::make(9), 3 )); + + R r = m.upper_bound(4); + assert(r == m.begin()); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(10); + assert(r == m.end()); + } + +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.ops/upper_bound0.pass.cpp b/test/std/containers/associative/multimap/multimap.ops/upper_bound0.pass.cpp new file mode 100644 index 0000000000000..322c6f55130c8 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/upper_bound0.pass.cpp @@ -0,0 +1,34 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// XFAIL: c++03, c++11 + +// <map> + +// class multimap + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +int main() +{ + typedef std::multimap<int, double, transparent_less> M; + + M().upper_bound(C2Int{5}); +} diff --git a/test/std/containers/associative/multimap/multimap.ops/upper_bound1.fail.cpp b/test/std/containers/associative/multimap/multimap.ops/upper_bound1.fail.cpp new file mode 100644 index 0000000000000..bb78ad6981601 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/upper_bound1.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::multimap<int, double, transparent_less_no_type> M; + + M().upper_bound(C2Int{5}); + } +} +#endif diff --git a/test/std/containers/associative/multimap/multimap.ops/upper_bound2.fail.cpp b/test/std/containers/associative/multimap/multimap.ops/upper_bound2.fail.cpp new file mode 100644 index 0000000000000..a79d5938e56e4 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/upper_bound2.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::multimap<int, double, transparent_less_private> M; + + M().upper_bound(C2Int{5}); + } +} +#endif diff --git a/test/std/containers/associative/multimap/multimap.ops/upper_bound3.fail.cpp b/test/std/containers/associative/multimap/multimap.ops/upper_bound3.fail.cpp new file mode 100644 index 0000000000000..1c1dc74b72c79 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.ops/upper_bound3.fail.cpp @@ -0,0 +1,39 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; +// +// The member function templates find, count, lower_bound, upper_bound, and +// equal_range shall not participate in overload resolution unless the +// qualified-id Compare::is_transparent is valid and denotes a type + + +#include <map> +#include <cassert> + +#include "is_transparent.h" + +#if _LIBCPP_STD_VER <= 11 +#error "This test requires is C++14 (or later)" +#else + +int main() +{ + { + typedef std::multimap<int, double, transparent_less_not_a_type> M; + + M().upper_bound(C2Int{5}); + } +} +#endif diff --git a/test/std/containers/associative/multimap/multimap.special/member_swap.pass.cpp b/test/std/containers/associative/multimap/multimap.special/member_swap.pass.cpp new file mode 100644 index 0000000000000..fb17e7340bd4f --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.special/member_swap.pass.cpp @@ -0,0 +1,176 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// void swap(multimap& m); + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + typedef std::pair<const int, double> V; + { + typedef std::multimap<int, double> M; + { + M m1; + M m2; + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + 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; + 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) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2; + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + { + M m1; + M m2; + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + 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; + 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) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2; + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.special/non_member_swap.pass.cpp b/test/std/containers/associative/multimap/multimap.special/non_member_swap.pass.cpp new file mode 100644 index 0000000000000..a91dfebb14a9d --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.special/non_member_swap.pass.cpp @@ -0,0 +1,281 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// 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" +#include "min_allocator.h" + +int main() +{ + typedef std::pair<const int, double> V; + { + typedef std::multimap<int, double> M; + { + M m1; + M m2; + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + 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; + 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) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2; + 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)); + } + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + { + M m1; + M m2; + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + 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; + 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) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2; + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + typedef min_allocator<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()); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A()); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + assert(m1.key_comp() == C(2)); + assert(m1.get_allocator() == A()); + assert(m2.key_comp() == C(1)); + assert(m2.get_allocator() == A()); + } + } +#endif +} diff --git a/test/std/containers/associative/multimap/multimap.special/swap_noexcept.pass.cpp b/test/std/containers/associative/multimap/multimap.special/swap_noexcept.pass.cpp new file mode 100644 index 0000000000000..1013c62804b87 --- /dev/null +++ b/test/std/containers/associative/multimap/multimap.special/swap_noexcept.pass.cpp @@ -0,0 +1,148 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// void swap(multimap& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable<allocator_type>::value); +// +// In C++17, the standard says that swap shall have: +// noexcept(allocator_traits<Allocator>::is_always_equal::value && +// noexcept(swap(declval<Compare&>(), declval<Compare&>()))); + +// This tests a conforming extension + +#include <map> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + + some_comp() {} + some_comp(const some_comp&) {} + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +template <class T> +struct some_comp2 +{ + typedef T value_type; + + some_comp2() {} + some_comp2(const some_comp2&) {} + void deallocate(void*, unsigned) {} + typedef std::true_type propagate_on_container_swap; +}; + +#if TEST_STD_VER >= 14 +template <typename T> +void swap(some_comp2<T>&, some_comp2<T>&) noexcept {} +#endif + +template <class T> +struct some_alloc +{ + typedef T value_type; + + some_alloc() {} + some_alloc(const some_alloc&); + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +template <class T> +struct some_alloc2 +{ + typedef T value_type; + + some_alloc2() {} + some_alloc2(const some_alloc2&); + void deallocate(void*, unsigned) {} + + typedef std::false_type propagate_on_container_swap; + typedef std::true_type is_always_equal; +}; + +template <class T> +struct some_alloc3 +{ + typedef T value_type; + + some_alloc3() {} + some_alloc3(const some_alloc3&); + void deallocate(void*, unsigned) {} + + typedef std::false_type propagate_on_container_swap; + typedef std::false_type is_always_equal; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multimap<MoveOnly, MoveOnly> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::multimap<MoveOnly, MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::multimap<MoveOnly, MoveOnly, some_comp<MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + +#if TEST_STD_VER >= 14 + { // POCS allocator, throwable swap for comp + typedef std::multimap<MoveOnly, MoveOnly, some_comp <MoveOnly>, some_alloc <MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { // always equal allocator, throwable swap for comp + typedef std::multimap<MoveOnly, MoveOnly, some_comp <MoveOnly>, some_alloc2<MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { // POCS allocator, nothrow swap for comp + typedef std::multimap<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc <MoveOnly>> C; + C c1, c2; + static_assert( noexcept(swap(c1, c2)), ""); + } + { // always equal allocator, nothrow swap for comp + typedef std::multimap<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc2<MoveOnly>> C; + C c1, c2; + static_assert( noexcept(swap(c1, c2)), ""); + } + + { // NOT always equal allocator, nothrow swap for comp + typedef std::map<MoveOnly, MoveOnly, some_comp2<MoveOnly>, some_alloc3<MoveOnly>> C; + C c1, c2; + static_assert( noexcept(swap(c1, c2)), ""); + } +#endif + +#endif +} diff --git a/test/std/containers/associative/multimap/scary.pass.cpp b/test/std/containers/associative/multimap/scary.pass.cpp new file mode 100644 index 0000000000000..b99d9bc2df911 --- /dev/null +++ b/test/std/containers/associative/multimap/scary.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class map class multimap + +// Extension: SCARY/N2913 iterator compatibility between map and multimap + +#include <map> + +int main() +{ + typedef std::map<int, int> M1; + typedef std::multimap<int, int> M2; + M2::iterator i; + M1::iterator j = i; +} diff --git a/test/std/containers/associative/multimap/size.pass.cpp b/test/std/containers/associative/multimap/size.pass.cpp new file mode 100644 index 0000000000000..ac71d4c95b641 --- /dev/null +++ b/test/std/containers/associative/multimap/size.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <map> + +// class multimap + +// size_type size() const; + +#include <map> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const 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); + } +#endif +} diff --git a/test/std/containers/associative/multimap/types.pass.cpp b/test/std/containers/associative/multimap/types.pass.cpp new file mode 100644 index 0000000000000..a0f4db056a83b --- /dev/null +++ b/test/std/containers/associative/multimap/types.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multimap<int, double> C; + static_assert((std::is_same<C::key_type, int>::value), ""); + static_assert((std::is_same<C::mapped_type, double>::value), ""); + static_assert((std::is_same<C::value_type, std::pair<const int, double> >::value), ""); + static_assert((std::is_same<C::key_compare, std::less<int> >::value), ""); + static_assert((std::is_same<C::allocator_type, std::allocator<std::pair<const int, double> > >::value), ""); + static_assert((std::is_same<C::reference, std::pair<const int, double>&>::value), ""); + static_assert((std::is_same<C::const_reference, const std::pair<const int, double>&>::value), ""); + static_assert((std::is_same<C::pointer, std::pair<const int, double>*>::value), ""); + static_assert((std::is_same<C::const_pointer, const std::pair<const int, double>*>::value), ""); + static_assert((std::is_same<C::size_type, std::size_t>::value), ""); + static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), ""); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> C; + static_assert((std::is_same<C::key_type, int>::value), ""); + static_assert((std::is_same<C::mapped_type, double>::value), ""); + static_assert((std::is_same<C::value_type, std::pair<const int, double> >::value), ""); + static_assert((std::is_same<C::key_compare, std::less<int> >::value), ""); + static_assert((std::is_same<C::allocator_type, min_allocator<std::pair<const int, double> > >::value), ""); + static_assert((std::is_same<C::reference, std::pair<const int, double>&>::value), ""); + static_assert((std::is_same<C::const_reference, const std::pair<const int, double>&>::value), ""); + static_assert((std::is_same<C::pointer, min_pointer<std::pair<const int, double>>>::value), ""); + static_assert((std::is_same<C::const_pointer, min_pointer<const std::pair<const int, double>>>::value), ""); +// min_allocator doesn't have a size_type, so one gets synthesized + static_assert((std::is_same<C::size_type, std::make_unsigned<C::difference_type>::type>::value), ""); + static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), ""); + } +#endif +} diff --git a/test/std/containers/associative/multiset/clear.pass.cpp b/test/std/containers/associative/multiset/clear.pass.cpp new file mode 100644 index 0000000000000..3069de5a300d9 --- /dev/null +++ b/test/std/containers/associative/multiset/clear.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// void clear(); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<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); + } +#endif +} diff --git a/test/std/containers/associative/multiset/count.pass.cpp b/test/std/containers/associative/multiset/count.pass.cpp new file mode 100644 index 0000000000000..93bd6f80eaad2 --- /dev/null +++ b/test/std/containers/associative/multiset/count.pass.cpp @@ -0,0 +1,160 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// size_type count(const key_type& k) const; + +#include <set> +#include <cassert> + +#include "min_allocator.h" +#include "private_constructor.hpp" + +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); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::multiset<int, std::less<int>, min_allocator<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); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::multiset<int, std::less<>> M; + typedef M::size_type R; + V ar[] = + { + 5, + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.count(4); + assert(r == 0); + r = m.count(5); + assert(r == 4); + r = m.count(6); + assert(r == 0); + r = m.count(7); + assert(r == 3); + r = m.count(8); + assert(r == 0); + r = m.count(9); + assert(r == 2); + r = m.count(10); + assert(r == 0); + } + + { + typedef PrivateConstructor V; + typedef std::multiset<V, std::less<>> M; + typedef M::size_type R; + + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 9 )); + + R r = m.count(4); + assert(r == 0); + r = m.count(5); + assert(r == 4); + r = m.count(6); + assert(r == 0); + r = m.count(7); + assert(r == 3); + r = m.count(8); + assert(r == 0); + r = m.count(9); + assert(r == 2); + r = m.count(10); + assert(r == 0); + } +#endif +} diff --git a/test/std/containers/associative/multiset/emplace.pass.cpp b/test/std/containers/associative/multiset/emplace.pass.cpp new file mode 100644 index 0000000000000..450ee6cd35a39 --- /dev/null +++ b/test/std/containers/associative/multiset/emplace.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// template <class... Args> +// iterator emplace(Args&&... args); + +#include <set> +#include <cassert> + +#include "../../Emplaceable.h" +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/multiset/emplace_hint.pass.cpp b/test/std/containers/associative/multiset/emplace_hint.pass.cpp new file mode 100644 index 0000000000000..194adf761c4c2 --- /dev/null +++ b/test/std/containers/associative/multiset/emplace_hint.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// template <class... Args> +// iterator emplace_hint(const_iterator position, Args&&... args); + +#include <set> +#include <cassert> + +#include "../../Emplaceable.h" +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/multiset/empty.pass.cpp b/test/std/containers/associative/multiset/empty.pass.cpp new file mode 100644 index 0000000000000..32aef90d41886 --- /dev/null +++ b/test/std/containers/associative/multiset/empty.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// bool empty() const; + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +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()); + } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + M m; + assert(m.empty()); + m.insert(M::value_type(1)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); + } +#endif +} diff --git a/test/std/containers/associative/multiset/equal_range.pass.cpp b/test/std/containers/associative/multiset/equal_range.pass.cpp new file mode 100644 index 0000000000000..8c69d0c61ec54 --- /dev/null +++ b/test/std/containers/associative/multiset/equal_range.pass.cpp @@ -0,0 +1,263 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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> + +#include "min_allocator.h" +#include "private_constructor.hpp" + +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)); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::multiset<int, std::less<int>, min_allocator<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)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::multiset<V, std::less<>> 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 PrivateConstructor V; + typedef std::multiset<V, std::less<>> M; + typedef std::pair<M::iterator, M::iterator> R; + + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 9 )); + + R r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 9)); + assert(r.second == next(m.begin(), 9)); + } +#endif +} diff --git a/test/std/containers/associative/multiset/erase_iter.pass.cpp b/test/std/containers/associative/multiset/erase_iter.pass.cpp new file mode 100644 index 0000000000000..1d41540edb8a7 --- /dev/null +++ b/test/std/containers/associative/multiset/erase_iter.pass.cpp @@ -0,0 +1,203 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// iterator erase(const_iterator position); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +struct TemplateConstructor +{ + template<typename T> + TemplateConstructor (const T&) {} +}; + +bool operator<(const TemplateConstructor&, const TemplateConstructor&) { return false; } + +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()); + } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<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()); + } +#endif +#if __cplusplus >= 201402L + { + // This is LWG #2059 + typedef TemplateConstructor T; + typedef std::multiset<T> C; + typedef C::iterator I; + + C c; + T a{0}; + I it = c.find(a); + if (it != c.end()) + c.erase(it); + } +#endif +} diff --git a/test/std/containers/associative/multiset/erase_iter_iter.pass.cpp b/test/std/containers/associative/multiset/erase_iter_iter.pass.cpp new file mode 100644 index 0000000000000..e1d7090d816f0 --- /dev/null +++ b/test/std/containers/associative/multiset/erase_iter_iter.pass.cpp @@ -0,0 +1,141 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// iterator erase(const_iterator first, const_iterator last); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +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()); + } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<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()); + } +#endif +} diff --git a/test/std/containers/associative/multiset/erase_key.pass.cpp b/test/std/containers/associative/multiset/erase_key.pass.cpp new file mode 100644 index 0000000000000..e9bce1e1b6402 --- /dev/null +++ b/test/std/containers/associative/multiset/erase_key.pass.cpp @@ -0,0 +1,129 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// size_type erase(const key_type& k); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<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); + } +#endif +} diff --git a/test/std/containers/associative/multiset/find.pass.cpp b/test/std/containers/associative/multiset/find.pass.cpp new file mode 100644 index 0000000000000..364460a6ca3af --- /dev/null +++ b/test/std/containers/associative/multiset/find.pass.cpp @@ -0,0 +1,240 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; + +#include <set> +#include <cassert> + +#include "min_allocator.h" +#include "private_constructor.hpp" + +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)); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::multiset<int, std::less<int>, min_allocator<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)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::multiset<V, std::less<>> M; + typedef M::iterator R; + + V ar[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + + { + typedef PrivateConstructor V; + typedef std::multiset<V, std::less<>> M; + typedef M::iterator R; + + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 6 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 8 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 10 )); + m.insert ( V::make ( 11 )); + m.insert ( V::make ( 12 )); + + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } +#endif +} diff --git a/test/std/containers/associative/multiset/insert_cv.pass.cpp b/test/std/containers/associative/multiset/insert_cv.pass.cpp new file mode 100644 index 0000000000000..179715753ab02 --- /dev/null +++ b/test/std/containers/associative/multiset/insert_cv.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// iterator insert(const value_type& v); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<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); + } +#endif +} diff --git a/test/std/containers/associative/multiset/insert_initializer_list.pass.cpp b/test/std/containers/associative/multiset/insert_initializer_list.pass.cpp new file mode 100644 index 0000000000000..7e923f2516ddc --- /dev/null +++ b/test/std/containers/associative/multiset/insert_initializer_list.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// void insert(initializer_list<value_type> il); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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 // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<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/test/std/containers/associative/multiset/insert_iter_cv.pass.cpp b/test/std/containers/associative/multiset/insert_iter_cv.pass.cpp new file mode 100644 index 0000000000000..7d204024c212b --- /dev/null +++ b/test/std/containers/associative/multiset/insert_iter_cv.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// iterator insert(const_iterator position, const value_type& v); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<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); + } +#endif +} diff --git a/test/std/containers/associative/multiset/insert_iter_iter.pass.cpp b/test/std/containers/associative/multiset/insert_iter_iter.pass.cpp new file mode 100644 index 0000000000000..189c454986697 --- /dev/null +++ b/test/std/containers/associative/multiset/insert_iter_iter.pass.cpp @@ -0,0 +1,85 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// template <class InputIterator> +// void insert(InputIterator first, InputIterator last); + +#include <set> +#include <cassert> + +#include "test_iterators.h" +#include "min_allocator.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); + } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<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); + } +#endif +} diff --git a/test/std/containers/associative/multiset/insert_iter_rv.pass.cpp b/test/std/containers/associative/multiset/insert_iter_rv.pass.cpp new file mode 100644 index 0000000000000..ee631f005c931 --- /dev/null +++ b/test/std/containers/associative/multiset/insert_iter_rv.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// iterator insert(const_iterator position, value_type&& v); + +#include <set> +#include <cassert> + +#include "MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::multiset<MoveOnly, std::less<MoveOnly>, min_allocator<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/test/std/containers/associative/multiset/insert_rv.pass.cpp b/test/std/containers/associative/multiset/insert_rv.pass.cpp new file mode 100644 index 0000000000000..29c233e9a119a --- /dev/null +++ b/test/std/containers/associative/multiset/insert_rv.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// iterator insert(value_type&& v); + +#include <set> +#include <cassert> + +#include "MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::multiset<MoveOnly, std::less<MoveOnly>, min_allocator<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/test/std/containers/associative/multiset/iterator.pass.cpp b/test/std/containers/associative/multiset/iterator.pass.cpp new file mode 100644 index 0000000000000..d1f0ecfd6aa06 --- /dev/null +++ b/test/std/containers/associative/multiset/iterator.pass.cpp @@ -0,0 +1,215 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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> + +#include "min_allocator.h" + +int main() +{ + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3, + 4, + 4, + 4, + 5, + 5, + 5, + 6, + 6, + 6, + 7, + 7, + 7, + 8, + 8, + 8 + }; + std::multiset<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; + 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>::const_iterator i; + i = m.begin(); + for (int j = 1; j <= 8; ++j) + for (int k = 0; k < 3; ++k, ++i) + assert(*i == j); + } +#if __cplusplus >= 201103L + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3, + 4, + 4, + 4, + 5, + 5, + 5, + 6, + 6, + 6, + 7, + 7, + 7, + 8, + 8, + 8 + }; + std::multiset<int, std::less<int>, min_allocator<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, std::less<int>, min_allocator<int>>::iterator i; + i = m.begin(); + std::multiset<int, std::less<int>, min_allocator<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, std::less<int>, min_allocator<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, std::less<int>, min_allocator<int>>::const_iterator i; + i = m.begin(); + for (int j = 1; j <= 8; ++j) + for (int k = 0; k < 3; ++k, ++i) + assert(*i == j); + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + typedef std::multiset<int> C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + } +#endif +} diff --git a/test/std/containers/associative/multiset/lower_bound.pass.cpp b/test/std/containers/associative/multiset/lower_bound.pass.cpp new file mode 100644 index 0000000000000..e466791d9356f --- /dev/null +++ b/test/std/containers/associative/multiset/lower_bound.pass.cpp @@ -0,0 +1,223 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; + +#include <set> +#include <cassert> + +#include "min_allocator.h" +#include "private_constructor.hpp" + +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)); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::multiset<int, std::less<int>, min_allocator<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)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::multiset<V, std::less<>> M; + + typedef M::iterator R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + + R r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(5); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 9)); + } + + { + typedef PrivateConstructor V; + typedef std::multiset<V, std::less<>> M; + typedef M::iterator R; + + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 9 )); + + R r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(5); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 9)); + } +#endif +} diff --git a/test/std/containers/associative/multiset/max_size.pass.cpp b/test/std/containers/associative/multiset/max_size.pass.cpp new file mode 100644 index 0000000000000..5524f771b341a --- /dev/null +++ b/test/std/containers/associative/multiset/max_size.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// size_type max_size() const; + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multiset<int> M; + M m; + assert(m.max_size() != 0); + } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + M m; + assert(m.max_size() != 0); + } +#endif +} diff --git a/test/std/containers/associative/multiset/multiset.cons/alloc.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/alloc.pass.cpp new file mode 100644 index 0000000000000..0a7572275afa5 --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/alloc.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/test/std/containers/associative/multiset/multiset.cons/assign_initializer_list.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/assign_initializer_list.pass.cpp new file mode 100644 index 0000000000000..7d76581d6d8e7 --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// multiset& operator=(initializer_list<value_type> il); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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 // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<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/test/std/containers/associative/multiset/multiset.cons/compare.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/compare.pass.cpp new file mode 100644 index 0000000000000..84038ca1e142c --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/compare.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/test/std/containers/associative/multiset/multiset.cons/compare_alloc.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/compare_alloc.pass.cpp new file mode 100644 index 0000000000000..76c9f8b2a8a19 --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/compare_alloc.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/test/std/containers/associative/multiset/multiset.cons/copy.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/copy.pass.cpp new file mode 100644 index 0000000000000..dde362872109e --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/copy.pass.cpp @@ -0,0 +1,118 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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 // _LIBCPP_HAS_NO_ADVANCED_SFINAE +} diff --git a/test/std/containers/associative/multiset/multiset.cons/copy_alloc.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/copy_alloc.pass.cpp new file mode 100644 index 0000000000000..04a769e733284 --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/copy_alloc.pass.cpp @@ -0,0 +1,68 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/test/std/containers/associative/multiset/multiset.cons/copy_assign.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/copy_assign.pass.cpp new file mode 100644 index 0000000000000..cca636325ffcc --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/copy_assign.pass.cpp @@ -0,0 +1,138 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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; + const V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + std::multiset<int> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + std::multiset<int> *p = &m; + m = *p; + assert(m.size() == 9); + assert(std::equal(m.begin(), m.end(), ar)); + } + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare<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/test/std/containers/associative/multiset/multiset.cons/default.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/default.pass.cpp new file mode 100644 index 0000000000000..5bb0312f012b6 --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/default.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// multiset(); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + std::multiset<int> m; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#if __cplusplus >= 201103L + { + std::multiset<int, std::less<int>, min_allocator<int>> m; + assert(m.empty()); + assert(m.begin() == m.end()); + } + { + std::multiset<int> m = {}; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#endif +} diff --git a/test/std/containers/associative/multiset/multiset.cons/default_noexcept.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/default_noexcept.pass.cpp new file mode 100644 index 0000000000000..bf8c53b9ee5d6 --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/default_noexcept.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// multiset() +// noexcept( +// is_nothrow_default_constructible<allocator_type>::value && +// is_nothrow_default_constructible<key_compare>::value && +// is_nothrow_copy_constructible<key_compare>::value); + +// This tests a conforming extension + +#include <set> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + some_comp(); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multiset<MoveOnly> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::multiset<MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::multiset<MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::multiset<MoveOnly, some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/associative/multiset/multiset.cons/dtor_noexcept.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/dtor_noexcept.pass.cpp new file mode 100644 index 0000000000000..fd612c06dbbc1 --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// ~multiset() // implied noexcept; + +#include <set> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template <class T> +struct some_comp +{ + typedef T value_type; + ~some_comp() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multiset<MoveOnly> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::multiset<MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::multiset<MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::multiset<MoveOnly, some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_destructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/associative/multiset/multiset.cons/initializer_list.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/initializer_list.pass.cpp new file mode 100644 index 0000000000000..dadafec7c3b1c --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/initializer_list.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// multiset(initializer_list<value_type> il, const key_compare& comp = key_compare()); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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 // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<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)); + } +#if _LIBCPP_STD_VER > 11 + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> C; + typedef C::value_type V; + min_allocator<int> a; + C m ({1, 2, 3, 4, 5, 6}, a); + assert(m.size() == 6); + assert(distance(m.begin(), m.end()) == 6); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + assert(m.get_allocator() == a); + } +#endif +#endif +} diff --git a/test/std/containers/associative/multiset/multiset.cons/initializer_list_compare.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/initializer_list_compare.pass.cpp new file mode 100644 index 0000000000000..c67657aff8ace --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/initializer_list_compare.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + 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 // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/associative/multiset/multiset.cons/initializer_list_compare_alloc.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/initializer_list_compare_alloc.pass.cpp new file mode 100644 index 0000000000000..83114893a1b26 --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/initializer_list_compare_alloc.pass.cpp @@ -0,0 +1,41 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + 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 // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/associative/multiset/multiset.cons/iter_iter.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/iter_iter.pass.cpp new file mode 100644 index 0000000000000..f6c1fd76de146 --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/iter_iter.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// template <class InputIterator> +// multiset(InputIterator first, InputIterator last); + +#include <set> +#include <cassert> + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + std::multiset<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); + } +#if __cplusplus >= 201103L + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + std::multiset<V, std::less<V>, min_allocator<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); + } +#endif +} diff --git a/test/std/containers/associative/multiset/multiset.cons/iter_iter_alloc.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/iter_iter_alloc.pass.cpp new file mode 100644 index 0000000000000..4ed00c7124cc0 --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/iter_iter_alloc.pass.cpp @@ -0,0 +1,92 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// template <class InputIterator> +// multiset(InputIterator first, InputIterator last, +// const value_compare& comp, const allocator_type& a); + +#include <set> +#include <cassert> + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "test_allocator.h" + +int main() +{ + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare<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); +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_allocator<V> A; + typedef test_compare<std::less<int> > C; + A a; + std::multiset<V, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), a); + + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); + assert(m.get_allocator() == a); + } +#endif +} diff --git a/test/std/containers/associative/multiset/multiset.cons/iter_iter_comp.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/iter_iter_comp.pass.cpp new file mode 100644 index 0000000000000..0bbaaf12eab3b --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/iter_iter_comp.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// template <class InputIterator> +// multiset(InputIterator first, InputIterator last, const value_compare& comp); + +#include <set> +#include <cassert> + +#include "test_iterators.h" +#include "../../../test_compare.h" + +int main() +{ + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare<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/test/std/containers/associative/multiset/multiset.cons/move.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/move.pass.cpp new file mode 100644 index 0000000000000..40321cd247e19 --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/move.pass.cpp @@ -0,0 +1,119 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// multiset(multiset&& s); + +#include <set> +#include <cassert> + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef int V; + typedef test_compare<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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::multiset<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::multiset<int, C, A> m = std::move(mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } +#endif +} diff --git a/test/std/containers/associative/multiset/multiset.cons/move_alloc.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/move_alloc.pass.cpp new file mode 100644 index 0000000000000..4408208f2ac44 --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/move_alloc.pass.cpp @@ -0,0 +1,187 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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" +#include "Counter.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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()); + } + { + typedef Counter<int> V; + typedef std::less<V> C; + typedef test_allocator<V> A; + typedef std::multiset<V, C, A> M; + typedef V* I; + Counter_base::gConstructed = 0; + { + V a1[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + const size_t num = sizeof(a1)/sizeof(a1[0]); + assert(Counter_base::gConstructed == num); + + M m1(I(a1), I(a1+num), C(), A()); + assert(Counter_base::gConstructed == 2*num); + + M m2(m1); + assert(m2 == m1); + assert(Counter_base::gConstructed == 3*num); + + M m3(std::move(m1), A()); + assert(m3 == m2); + assert(m1.empty()); + assert(Counter_base::gConstructed == 3*num); + + { + M m4(std::move(m2), A(5)); + assert(Counter_base::gConstructed == 3*num); + assert(m4 == m3); + assert(m2.empty()); + } + assert(Counter_base::gConstructed == 2*num); + } + assert(Counter_base::gConstructed == 0); + } +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/multiset/multiset.cons/move_assign.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/move_assign.pass.cpp new file mode 100644 index 0000000000000..ca1ba971f5a46 --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/move_assign.pass.cpp @@ -0,0 +1,186 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// multiset& operator=(multiset&& s); + +#include <set> +#include <cassert> + +#include "MoveOnly.h" +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef MoveOnly V; + typedef test_compare<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 // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef MoveOnly V; + typedef test_compare<std::less<MoveOnly> > C; + typedef min_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()); + V a2[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A()); + M m3(C(3), A()); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A()); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif +} diff --git a/test/std/containers/associative/multiset/multiset.cons/move_assign_noexcept.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 0000000000000..211bb36e7e953 --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// multiset& operator=(multiset&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable<allocator_type>::value && +// is_nothrow_move_assignable<key_compare>::value); + +// This tests a conforming extension + +#include <set> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + some_comp& operator=(const some_comp&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multiset<MoveOnly> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::multiset<MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::multiset<MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::multiset<MoveOnly, some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/associative/multiset/multiset.cons/move_noexcept.pass.cpp b/test/std/containers/associative/multiset/multiset.cons/move_noexcept.pass.cpp new file mode 100644 index 0000000000000..31a34cbde3061 --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.cons/move_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// multiset(multiset&&) +// noexcept(is_nothrow_move_constructible<allocator_type>::value && +// is_nothrow_move_constructible<key_compare>::value); + +// This tests a conforming extension + +#include <set> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + some_comp(const some_comp&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multiset<MoveOnly> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::multiset<MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::multiset<MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::multiset<MoveOnly, some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_move_constructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/associative/multiset/multiset.special/member_swap.pass.cpp b/test/std/containers/associative/multiset/multiset.special/member_swap.pass.cpp new file mode 100644 index 0000000000000..7745ddab78c36 --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.special/member_swap.pass.cpp @@ -0,0 +1,177 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// void swap(multiset& m); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef int V; + typedef std::multiset<int> M; + { + M m1; + M m2; + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1; + 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 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2; + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + { + M m1; + M m2; + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1; + 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 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2; + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#endif +} diff --git a/test/std/containers/associative/multiset/multiset.special/non_member_swap.pass.cpp b/test/std/containers/associative/multiset/multiset.special/non_member_swap.pass.cpp new file mode 100644 index 0000000000000..f456de7f62438 --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.special/non_member_swap.pass.cpp @@ -0,0 +1,165 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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; + { + M m1; + M m2; + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1; + 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 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2; + 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/test/std/containers/associative/multiset/multiset.special/swap_noexcept.pass.cpp b/test/std/containers/associative/multiset/multiset.special/swap_noexcept.pass.cpp new file mode 100644 index 0000000000000..8e2c67c9b5ec6 --- /dev/null +++ b/test/std/containers/associative/multiset/multiset.special/swap_noexcept.pass.cpp @@ -0,0 +1,148 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// void swap(multiset& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable<allocator_type>::value); +// +// In C++17, the standard says that swap shall have: +// noexcept(allocator_traits<Allocator>::is_always_equal::value && +// noexcept(swap(declval<Compare&>(), declval<Compare&>()))); + +// This tests a conforming extension + +#include <set> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + + some_comp() {} + some_comp(const some_comp&) {} + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +template <class T> +struct some_comp2 +{ + typedef T value_type; + + some_comp2() {} + some_comp2(const some_comp2&) {} + void deallocate(void*, unsigned) {} + typedef std::true_type propagate_on_container_swap; +}; + +#if TEST_STD_VER >= 14 +template <typename T> +void swap(some_comp2<T>&, some_comp2<T>&) noexcept {} +#endif + +template <class T> +struct some_alloc +{ + typedef T value_type; + + some_alloc() {} + some_alloc(const some_alloc&); + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +template <class T> +struct some_alloc2 +{ + typedef T value_type; + + some_alloc2() {} + some_alloc2(const some_alloc2&); + void deallocate(void*, unsigned) {} + + typedef std::false_type propagate_on_container_swap; + typedef std::true_type is_always_equal; +}; + +template <class T> +struct some_alloc3 +{ + typedef T value_type; + + some_alloc3() {} + some_alloc3(const some_alloc3&); + void deallocate(void*, unsigned) {} + + typedef std::false_type propagate_on_container_swap; + typedef std::false_type is_always_equal; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::multiset<MoveOnly> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::multiset<MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::multiset<MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::multiset<MoveOnly, some_comp<MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + +#if TEST_STD_VER >= 14 + { // POCS allocator, throwable swap for comp + typedef std::multiset<MoveOnly, some_comp <MoveOnly>, some_alloc <MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { // always equal allocator, throwable swap for comp + typedef std::multiset<MoveOnly, some_comp <MoveOnly>, some_alloc2<MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { // POCS allocator, nothrow swap for comp + typedef std::multiset<MoveOnly, some_comp2<MoveOnly>, some_alloc <MoveOnly>> C; + C c1, c2; + static_assert( noexcept(swap(c1, c2)), ""); + } + { // always equal allocator, nothrow swap for comp + typedef std::multiset<MoveOnly, some_comp2<MoveOnly>, some_alloc2<MoveOnly>> C; + C c1, c2; + static_assert( noexcept(swap(c1, c2)), ""); + } + + { // NOT always equal allocator, nothrow swap for comp + typedef std::multiset<MoveOnly, some_comp2<MoveOnly>, some_alloc3<MoveOnly>> C; + C c1, c2; + static_assert( noexcept(swap(c1, c2)), ""); + } +#endif + +#endif +} diff --git a/test/std/containers/associative/multiset/scary.pass.cpp b/test/std/containers/associative/multiset/scary.pass.cpp new file mode 100644 index 0000000000000..f5ee32714e860 --- /dev/null +++ b/test/std/containers/associative/multiset/scary.pass.cpp @@ -0,0 +1,24 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set class multiset + +// Extension: SCARY/N2913 iterator compatibility between set and multiset + +#include <set> + +int main() +{ + typedef std::set<int> M1; + typedef std::multiset<int> M2; + M2::iterator i; + M1::iterator j = i; +} diff --git a/test/std/containers/associative/multiset/size.pass.cpp b/test/std/containers/associative/multiset/size.pass.cpp new file mode 100644 index 0000000000000..68099b566dfd4 --- /dev/null +++ b/test/std/containers/associative/multiset/size.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// size_type size() const; + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<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); + } +#endif +} diff --git a/test/std/containers/associative/multiset/types.pass.cpp b/test/std/containers/associative/multiset/types.pass.cpp new file mode 100644 index 0000000000000..e1e3ad9100c3c --- /dev/null +++ b/test/std/containers/associative/multiset/types.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::multiset<int> C; + static_assert((std::is_same<C::key_type, int>::value), ""); + static_assert((std::is_same<C::value_type, int>::value), ""); + static_assert((std::is_same<C::key_compare, std::less<int> >::value), ""); + static_assert((std::is_same<C::value_compare, std::less<int> >::value), ""); + static_assert((std::is_same<C::allocator_type, std::allocator<int> >::value), ""); + static_assert((std::is_same<C::reference, int&>::value), ""); + static_assert((std::is_same<C::const_reference, const int&>::value), ""); + static_assert((std::is_same<C::pointer, int*>::value), ""); + static_assert((std::is_same<C::const_pointer, const int*>::value), ""); + static_assert((std::is_same<C::size_type, std::size_t>::value), ""); + static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), ""); + } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> C; + static_assert((std::is_same<C::key_type, int>::value), ""); + static_assert((std::is_same<C::value_type, int>::value), ""); + static_assert((std::is_same<C::key_compare, std::less<int> >::value), ""); + static_assert((std::is_same<C::value_compare, std::less<int> >::value), ""); + static_assert((std::is_same<C::allocator_type, min_allocator<int>>::value), ""); + static_assert((std::is_same<C::reference, int&>::value), ""); + static_assert((std::is_same<C::const_reference, const int&>::value), ""); + static_assert((std::is_same<C::pointer, min_pointer<int>>::value), ""); + static_assert((std::is_same<C::const_pointer, min_pointer<const int>>::value), ""); +// min_allocator doesn't have a size_type, so one gets synthesized + static_assert((std::is_same<C::size_type, std::make_unsigned<C::difference_type>::type>::value), ""); + static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), ""); + } +#endif +} diff --git a/test/std/containers/associative/multiset/upper_bound.pass.cpp b/test/std/containers/associative/multiset/upper_bound.pass.cpp new file mode 100644 index 0000000000000..7ad3d6ced3d62 --- /dev/null +++ b/test/std/containers/associative/multiset/upper_bound.pass.cpp @@ -0,0 +1,222 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class multiset + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; + +#include <set> +#include <cassert> + +#include "min_allocator.h" +#include "private_constructor.hpp" + +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)); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::multiset<int, std::less<int>, min_allocator<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)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::multiset<V, std::less<>> M; + + typedef M::iterator R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 9)); + } + + { + typedef PrivateConstructor V; + typedef std::multiset<V, std::less<>> M; + + typedef M::iterator R; + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 9 )); + + R r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 9)); + } +#endif +} diff --git a/test/std/containers/associative/set/clear.pass.cpp b/test/std/containers/associative/set/clear.pass.cpp new file mode 100644 index 0000000000000..4439ad3b1e4ea --- /dev/null +++ b/test/std/containers/associative/set/clear.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// void clear(); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::set<int, std::less<int>, min_allocator<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); + } +#endif +} diff --git a/test/std/containers/associative/set/count.pass.cpp b/test/std/containers/associative/set/count.pass.cpp new file mode 100644 index 0000000000000..32fe0b8bcee9c --- /dev/null +++ b/test/std/containers/associative/set/count.pass.cpp @@ -0,0 +1,168 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// size_type count(const key_type& k) const; + +#include <set> +#include <cassert> + +#include "min_allocator.h" +#include "private_constructor.hpp" + +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); + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::set<int, std::less<int>, min_allocator<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); + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::set<int, std::less<>> M; + typedef M::size_type R; + V ar[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.count(5); + assert(r == 1); + r = m.count(6); + assert(r == 1); + r = m.count(7); + assert(r == 1); + r = m.count(8); + assert(r == 1); + r = m.count(9); + assert(r == 1); + r = m.count(10); + assert(r == 1); + r = m.count(11); + assert(r == 1); + r = m.count(12); + assert(r == 1); + r = m.count(4); + assert(r == 0); + } + { + typedef PrivateConstructor V; + typedef std::set<V, std::less<>> M; + typedef M::size_type R; + + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 6 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 8 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 10 )); + m.insert ( V::make ( 11 )); + m.insert ( V::make ( 12 )); + + R r = m.count(5); + assert(r == 1); + r = m.count(6); + assert(r == 1); + r = m.count(7); + assert(r == 1); + r = m.count(8); + assert(r == 1); + r = m.count(9); + assert(r == 1); + r = m.count(10); + assert(r == 1); + r = m.count(11); + assert(r == 1); + r = m.count(12); + assert(r == 1); + r = m.count(4); + assert(r == 0); + } +#endif + +} diff --git a/test/std/containers/associative/set/emplace.pass.cpp b/test/std/containers/associative/set/emplace.pass.cpp new file mode 100644 index 0000000000000..5ebab4d24b92d --- /dev/null +++ b/test/std/containers/associative/set/emplace.pass.cpp @@ -0,0 +1,90 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// template <class... Args> +// pair<iterator, bool> emplace(Args&&... args); + +#include <set> +#include <cassert> + +#include "../../Emplaceable.h" +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } +#if __cplusplus >= 201103L + { + typedef std::set<int, std::less<int>, min_allocator<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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/set/emplace_hint.pass.cpp b/test/std/containers/associative/set/emplace_hint.pass.cpp new file mode 100644 index 0000000000000..5fdeb4ffef3aa --- /dev/null +++ b/test/std/containers/associative/set/emplace_hint.pass.cpp @@ -0,0 +1,83 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// template <class... Args> +// iterator emplace_hint(const_iterator position, Args&&... args); + +#include <set> +#include <cassert> + +#include "../../Emplaceable.h" +#include "DefaultOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } +#if __cplusplus >= 201103L + { + typedef std::set<int, std::less<int>, min_allocator<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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/set/empty.pass.cpp b/test/std/containers/associative/set/empty.pass.cpp new file mode 100644 index 0000000000000..eb1080263f4fe --- /dev/null +++ b/test/std/containers/associative/set/empty.pass.cpp @@ -0,0 +1,43 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// bool empty() const; + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +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()); + } +#if __cplusplus >= 201103L + { + typedef std::set<int, std::less<int>, min_allocator<int>> M; + M m; + assert(m.empty()); + m.insert(M::value_type(1)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); + } +#endif +} diff --git a/test/std/containers/associative/set/equal_range.pass.cpp b/test/std/containers/associative/set/equal_range.pass.cpp new file mode 100644 index 0000000000000..8a180ef492482 --- /dev/null +++ b/test/std/containers/associative/set/equal_range.pass.cpp @@ -0,0 +1,370 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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> + +#include "min_allocator.h" +#include "private_constructor.hpp" + +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)); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::set<int, std::less<int>, min_allocator<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)); + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::set<V, std::less<>> 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 PrivateConstructor V; + typedef std::set<V, std::less<>> M; + typedef std::pair<M::iterator, M::iterator> R; + + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 11 )); + m.insert ( V::make ( 13 )); + m.insert ( V::make ( 15 )); + m.insert ( V::make ( 17 )); + m.insert ( V::make ( 19 )); + + R r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(11); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(13); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(15); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(17); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(19); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 8)); + r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(12); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(14); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(16); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(18); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(20); + assert(r.first == next(m.begin(), 8)); + assert(r.second == next(m.begin(), 8)); + } +#endif +} diff --git a/test/std/containers/associative/set/erase_iter.pass.cpp b/test/std/containers/associative/set/erase_iter.pass.cpp new file mode 100644 index 0000000000000..36828be86f284 --- /dev/null +++ b/test/std/containers/associative/set/erase_iter.pass.cpp @@ -0,0 +1,203 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// iterator erase(const_iterator position); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +struct TemplateConstructor +{ + template<typename T> + TemplateConstructor (const T&) {} +}; + +bool operator<(const TemplateConstructor&, const TemplateConstructor&) { return false; } + +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()); + } +#if __cplusplus >= 201103L + { + typedef std::set<int, std::less<int>, min_allocator<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()); + } +#endif +#if __cplusplus >= 201402L + { + // This is LWG #2059 + typedef TemplateConstructor T; + typedef std::set<T> C; + typedef C::iterator I; + + C c; + T a{0}; + I it = c.find(a); + if (it != c.end()) + c.erase(it); + } +#endif +} diff --git a/test/std/containers/associative/set/erase_iter_iter.pass.cpp b/test/std/containers/associative/set/erase_iter_iter.pass.cpp new file mode 100644 index 0000000000000..4799503166550 --- /dev/null +++ b/test/std/containers/associative/set/erase_iter_iter.pass.cpp @@ -0,0 +1,141 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// iterator erase(const_iterator first, const_iterator last); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +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()); + } +#if __cplusplus >= 201103L + { + typedef std::set<int, std::less<int>, min_allocator<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()); + } +#endif +} diff --git a/test/std/containers/associative/set/erase_key.pass.cpp b/test/std/containers/associative/set/erase_key.pass.cpp new file mode 100644 index 0000000000000..9d92bd70d7001 --- /dev/null +++ b/test/std/containers/associative/set/erase_key.pass.cpp @@ -0,0 +1,203 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// size_type erase(const key_type& k); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::set<int, std::less<int>, min_allocator<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); + } +#endif +} diff --git a/test/std/containers/associative/set/find.pass.cpp b/test/std/containers/associative/set/find.pass.cpp new file mode 100644 index 0000000000000..d08d2fb1e2450 --- /dev/null +++ b/test/std/containers/associative/set/find.pass.cpp @@ -0,0 +1,240 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// iterator find(const key_type& k); +// const_iterator find(const key_type& k) const; + +#include <set> +#include <cassert> + +#include "min_allocator.h" +#include "private_constructor.hpp" + +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)); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::set<int, std::less<int>, min_allocator<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)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::set<V, std::less<>> M; + typedef M::iterator R; + + V ar[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + + { + typedef PrivateConstructor V; + typedef std::set<V, std::less<>> M; + typedef M::iterator R; + + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 6 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 8 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 10 )); + m.insert ( V::make ( 11 )); + m.insert ( V::make ( 12 )); + + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } +#endif +} diff --git a/test/std/containers/associative/set/insert_cv.pass.cpp b/test/std/containers/associative/set/insert_cv.pass.cpp new file mode 100644 index 0000000000000..18d5c2e033953 --- /dev/null +++ b/test/std/containers/associative/set/insert_cv.pass.cpp @@ -0,0 +1,81 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// pair<iterator, bool> insert(const value_type& v); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::set<int, std::less<int>, min_allocator<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); + } +#endif +} diff --git a/test/std/containers/associative/set/insert_initializer_list.pass.cpp b/test/std/containers/associative/set/insert_initializer_list.pass.cpp new file mode 100644 index 0000000000000..fc6d612b2ebed --- /dev/null +++ b/test/std/containers/associative/set/insert_initializer_list.pass.cpp @@ -0,0 +1,61 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// void insert(initializer_list<value_type> il); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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)); + } +#if __cplusplus >= 201103L + { + typedef std::set<int, std::less<int>, min_allocator<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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/associative/set/insert_iter_cv.pass.cpp b/test/std/containers/associative/set/insert_iter_cv.pass.cpp new file mode 100644 index 0000000000000..718e720559f46 --- /dev/null +++ b/test/std/containers/associative/set/insert_iter_cv.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// iterator insert(const_iterator position, const value_type& v); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::set<int, std::less<int>, min_allocator<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); + } +#endif +} diff --git a/test/std/containers/associative/set/insert_iter_iter.pass.cpp b/test/std/containers/associative/set/insert_iter_iter.pass.cpp new file mode 100644 index 0000000000000..ff729a0e7b9b0 --- /dev/null +++ b/test/std/containers/associative/set/insert_iter_iter.pass.cpp @@ -0,0 +1,73 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// template <class InputIterator> +// void insert(InputIterator first, InputIterator last); + +#include <set> +#include <cassert> + +#include "test_iterators.h" +#include "min_allocator.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); + } +#if __cplusplus >= 201103L + { + typedef std::set<int, std::less<int>, min_allocator<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); + } +#endif +} diff --git a/test/std/containers/associative/set/insert_iter_rv.pass.cpp b/test/std/containers/associative/set/insert_iter_rv.pass.cpp new file mode 100644 index 0000000000000..296ead84914d3 --- /dev/null +++ b/test/std/containers/associative/set/insert_iter_rv.pass.cpp @@ -0,0 +1,76 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// iterator insert(const_iterator position, value_type&& v); + +#include <set> +#include <cassert> + +#include "MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } +#if __cplusplus >= 201103L + { + typedef std::set<MoveOnly, std::less<MoveOnly>, min_allocator<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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/set/insert_rv.pass.cpp b/test/std/containers/associative/set/insert_rv.pass.cpp new file mode 100644 index 0000000000000..32cede1549569 --- /dev/null +++ b/test/std/containers/associative/set/insert_rv.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// pair<iterator, bool> insert(value_type&& v); + +#include <set> +#include <cassert> + +#include "MoveOnly.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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); + } +#if __cplusplus >= 201103L + { + typedef std::set<MoveOnly, std::less<MoveOnly>, min_allocator<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 +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/set/iterator.pass.cpp b/test/std/containers/associative/set/iterator.pass.cpp new file mode 100644 index 0000000000000..ecd950f03a009 --- /dev/null +++ b/test/std/containers/associative/set/iterator.pass.cpp @@ -0,0 +1,211 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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> + +#include "min_allocator.h" + +int main() +{ + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3, + 4, + 4, + 4, + 5, + 5, + 5, + 6, + 6, + 6, + 7, + 7, + 7, + 8, + 8, + 8 + }; + std::set<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; + 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>::const_iterator i; + i = m.begin(); + for (int j = 1; j <= m.size(); ++j, ++i) + assert(*i == j); + } +#if __cplusplus >= 201103L + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3, + 4, + 4, + 4, + 5, + 5, + 5, + 6, + 6, + 6, + 7, + 7, + 7, + 8, + 8, + 8 + }; + std::set<int, std::less<int>, min_allocator<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, std::less<int>, min_allocator<int>>::iterator i; + i = m.begin(); + std::set<int, std::less<int>, min_allocator<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, std::less<int>, min_allocator<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, std::less<int>, min_allocator<int>>::const_iterator i; + i = m.begin(); + for (int j = 1; j <= m.size(); ++j, ++i) + assert(*i == j); + } +#endif +#if _LIBCPP_STD_VER > 11 + { // N3644 testing + typedef std::set<int> C; + C::iterator ii1{}, ii2{}; + C::iterator ii4 = ii1; + C::const_iterator cii{}; + assert ( ii1 == ii2 ); + assert ( ii1 == ii4 ); + + assert (!(ii1 != ii2 )); + + assert ( (ii1 == cii )); + assert ( (cii == ii1 )); + assert (!(ii1 != cii )); + assert (!(cii != ii1 )); + } +#endif +} diff --git a/test/std/containers/associative/set/lower_bound.pass.cpp b/test/std/containers/associative/set/lower_bound.pass.cpp new file mode 100644 index 0000000000000..df202f31a4c30 --- /dev/null +++ b/test/std/containers/associative/set/lower_bound.pass.cpp @@ -0,0 +1,337 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// iterator lower_bound(const key_type& k); +// const_iterator lower_bound(const key_type& k) const; + +#include <set> +#include <cassert> + +#include "min_allocator.h" +#include "private_constructor.hpp" + +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)); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::set<int, std::less<int>, min_allocator<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)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::set<V, std::less<>> M; + typedef M::iterator R; + + V ar[] = + { + 5, + 7, + 9, + 11, + 13, + 15, + 17, + 19 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } + + { + typedef PrivateConstructor V; + typedef std::set<V, std::less<>> M; + typedef M::iterator R; + + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 11 )); + m.insert ( V::make ( 13 )); + m.insert ( V::make ( 15 )); + m.insert ( V::make ( 17 )); + m.insert ( V::make ( 19 )); + + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } +#endif + +} diff --git a/test/std/containers/associative/set/max_size.pass.cpp b/test/std/containers/associative/set/max_size.pass.cpp new file mode 100644 index 0000000000000..cde4397c71788 --- /dev/null +++ b/test/std/containers/associative/set/max_size.pass.cpp @@ -0,0 +1,35 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// size_type max_size() const; + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::set<int> M; + M m; + assert(m.max_size() != 0); + } +#if __cplusplus >= 201103L + { + typedef std::set<int, std::less<int>, min_allocator<int>> M; + M m; + assert(m.max_size() != 0); + } +#endif +} diff --git a/test/std/containers/associative/set/set.cons/alloc.pass.cpp b/test/std/containers/associative/set/set.cons/alloc.pass.cpp new file mode 100644 index 0000000000000..67433ff88a01c --- /dev/null +++ b/test/std/containers/associative/set/set.cons/alloc.pass.cpp @@ -0,0 +1,29 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp b/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp new file mode 100644 index 0000000000000..892ae5a0a799b --- /dev/null +++ b/test/std/containers/associative/set/set.cons/assign_initializer_list.pass.cpp @@ -0,0 +1,57 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set& operator=(initializer_list<value_type> il); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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)); + } +#if __cplusplus >= 201103L + { + typedef std::set<int, std::less<int>, min_allocator<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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/associative/set/set.cons/compare.pass.cpp b/test/std/containers/associative/set/set.cons/compare.pass.cpp new file mode 100644 index 0000000000000..af94c70671b80 --- /dev/null +++ b/test/std/containers/associative/set/set.cons/compare.pass.cpp @@ -0,0 +1,28 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/test/std/containers/associative/set/set.cons/compare_alloc.pass.cpp b/test/std/containers/associative/set/set.cons/compare_alloc.pass.cpp new file mode 100644 index 0000000000000..22b3328d4d792 --- /dev/null +++ b/test/std/containers/associative/set/set.cons/compare_alloc.pass.cpp @@ -0,0 +1,31 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/test/std/containers/associative/set/set.cons/copy.pass.cpp b/test/std/containers/associative/set/set.cons/copy.pass.cpp new file mode 100644 index 0000000000000..a0e34e48de434 --- /dev/null +++ b/test/std/containers/associative/set/set.cons/copy.pass.cpp @@ -0,0 +1,94 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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 // _LIBCPP_HAS_NO_ADVANCED_SFINAE +} diff --git a/test/std/containers/associative/set/set.cons/copy_alloc.pass.cpp b/test/std/containers/associative/set/set.cons/copy_alloc.pass.cpp new file mode 100644 index 0000000000000..1ad03dc1404de --- /dev/null +++ b/test/std/containers/associative/set/set.cons/copy_alloc.pass.cpp @@ -0,0 +1,56 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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/test/std/containers/associative/set/set.cons/copy_assign.pass.cpp b/test/std/containers/associative/set/set.cons/copy_assign.pass.cpp new file mode 100644 index 0000000000000..7f0f0447625fc --- /dev/null +++ b/test/std/containers/associative/set/set.cons/copy_assign.pass.cpp @@ -0,0 +1,109 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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; + const V ar[] = + { + 1, + 2, + 3 + }; + std::set<int> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + std::set<int> *p = &m; + m = *p; + + assert(m.size() == 3); + assert(std::equal(m.begin(), m.end(), ar)); + } + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare<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/test/std/containers/associative/set/set.cons/default.pass.cpp b/test/std/containers/associative/set/set.cons/default.pass.cpp new file mode 100644 index 0000000000000..746a2d1730716 --- /dev/null +++ b/test/std/containers/associative/set/set.cons/default.pass.cpp @@ -0,0 +1,40 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set(); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + std::set<int> m; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#if __cplusplus >= 201103L + { + std::set<int, std::less<int>, min_allocator<int>> m; + assert(m.empty()); + assert(m.begin() == m.end()); + } + { + std::set<int> m = {}; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#endif +} diff --git a/test/std/containers/associative/set/set.cons/default_noexcept.pass.cpp b/test/std/containers/associative/set/set.cons/default_noexcept.pass.cpp new file mode 100644 index 0000000000000..2156169acbc45 --- /dev/null +++ b/test/std/containers/associative/set/set.cons/default_noexcept.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// set() +// noexcept( +// is_nothrow_default_constructible<allocator_type>::value && +// is_nothrow_default_constructible<key_compare>::value && +// is_nothrow_copy_constructible<key_compare>::value); + +// This tests a conforming extension + +#include <set> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + some_comp(); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::set<MoveOnly> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::set<MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::set<MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } + { + typedef std::set<MoveOnly, some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_default_constructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/associative/set/set.cons/dtor_noexcept.pass.cpp b/test/std/containers/associative/set/set.cons/dtor_noexcept.pass.cpp new file mode 100644 index 0000000000000..b554d828d4864 --- /dev/null +++ b/test/std/containers/associative/set/set.cons/dtor_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// ~set() // implied noexcept; + +#include <set> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +#if __has_feature(cxx_noexcept) + +template <class T> +struct some_comp +{ + typedef T value_type; + ~some_comp() noexcept(false); +}; + +#endif + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::set<MoveOnly> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::set<MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::set<MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_destructible<C>::value, ""); + } + { + typedef std::set<MoveOnly, some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_destructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/associative/set/set.cons/initializer_list.pass.cpp b/test/std/containers/associative/set/set.cons/initializer_list.pass.cpp new file mode 100644 index 0000000000000..2ad538e143f8f --- /dev/null +++ b/test/std/containers/associative/set/set.cons/initializer_list.pass.cpp @@ -0,0 +1,55 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set(initializer_list<value_type> il, const key_compare& comp = key_compare()); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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)); + } +#if __cplusplus >= 201103L + { + typedef std::set<int, std::less<int>, min_allocator<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 +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/associative/set/set.cons/initializer_list_compare.pass.cpp b/test/std/containers/associative/set/set.cons/initializer_list_compare.pass.cpp new file mode 100644 index 0000000000000..a0afa02cf749b --- /dev/null +++ b/test/std/containers/associative/set/set.cons/initializer_list_compare.pass.cpp @@ -0,0 +1,38 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + 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 // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/associative/set/set.cons/initializer_list_compare_alloc.pass.cpp b/test/std/containers/associative/set/set.cons/initializer_list_compare_alloc.pass.cpp new file mode 100644 index 0000000000000..821820a1e0cee --- /dev/null +++ b/test/std/containers/associative/set/set.cons/initializer_list_compare_alloc.pass.cpp @@ -0,0 +1,63 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set(initializer_list<value_type> il, const key_compare& comp, const allocator_type& a); +// set(initializer_list<value_type> il, const allocator_type& a); + +#include <set> +#include <cassert> +#include "../../../test_compare.h" +#include "test_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { + 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)); + } +#if _LIBCPP_STD_VER > 11 + { + 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}, A(4)); + assert(m.size() == 6); + assert(distance(m.begin(), m.end()) == 6); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + assert(m.get_allocator() == A(4)); + } +#endif +#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +} diff --git a/test/std/containers/associative/set/set.cons/iter_iter.pass.cpp b/test/std/containers/associative/set/set.cons/iter_iter.pass.cpp new file mode 100644 index 0000000000000..7ca7fe14d6c40 --- /dev/null +++ b/test/std/containers/associative/set/set.cons/iter_iter.pass.cpp @@ -0,0 +1,71 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// template <class InputIterator> +// set(InputIterator first, InputIterator last); + +#include <set> +#include <cassert> + +#include "test_iterators.h" +#include "min_allocator.h" + +int main() +{ + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + std::set<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); + } +#if __cplusplus >= 201103L + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + std::set<V, std::less<int>, min_allocator<int>> 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); + } +#endif +} diff --git a/test/std/containers/associative/set/set.cons/iter_iter_alloc.pass.cpp b/test/std/containers/associative/set/set.cons/iter_iter_alloc.pass.cpp new file mode 100644 index 0000000000000..5ccb6e5cbcd75 --- /dev/null +++ b/test/std/containers/associative/set/set.cons/iter_iter_alloc.pass.cpp @@ -0,0 +1,84 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// template <class InputIterator> +// set(InputIterator first, InputIterator last, +// const value_compare& comp, const allocator_type& a); +// +// template <class InputIterator> +// set(InputIterator first, InputIterator last, +// const allocator_type& a); + +#include <set> +#include <cassert> + +#include "test_iterators.h" +#include "../../../test_compare.h" +#include "test_allocator.h" + +int main() +{ + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare<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); +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_allocator<V> A; + typedef test_compare<std::less<int> > C; + A a(7); + std::set<V, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), a); + + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == 1); + assert(*next(m.begin()) == 2); + assert(*next(m.begin(), 2) == 3); + assert(m.get_allocator() == a); + } +#endif +} diff --git a/test/std/containers/associative/set/set.cons/iter_iter_comp.pass.cpp b/test/std/containers/associative/set/set.cons/iter_iter_comp.pass.cpp new file mode 100644 index 0000000000000..18bc0839003b9 --- /dev/null +++ b/test/std/containers/associative/set/set.cons/iter_iter_comp.pass.cpp @@ -0,0 +1,47 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// template <class InputIterator> +// set(InputIterator first, InputIterator last, const value_compare& comp); + +#include <set> +#include <cassert> + +#include "test_iterators.h" +#include "../../../test_compare.h" + +int main() +{ + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare<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/test/std/containers/associative/set/set.cons/move.pass.cpp b/test/std/containers/associative/set/set.cons/move.pass.cpp new file mode 100644 index 0000000000000..4026ec70c3e1c --- /dev/null +++ b/test/std/containers/associative/set/set.cons/move.pass.cpp @@ -0,0 +1,107 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set(set&& s); + +#include <set> +#include <cassert> + +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef int V; + typedef test_compare<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); + } +#if __cplusplus >= 201103L + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::set<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::set<int, C, A> m = std::move(mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == 1); + assert(*next(m.begin()) == 2); + assert(*next(m.begin(), 2) == 3); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/set/set.cons/move_alloc.pass.cpp b/test/std/containers/associative/set/set.cons/move_alloc.pass.cpp new file mode 100644 index 0000000000000..799f0e402d63b --- /dev/null +++ b/test/std/containers/associative/set/set.cons/move_alloc.pass.cpp @@ -0,0 +1,188 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set(set&& s, const allocator_type& a); + +#include <set> +#include <cassert> + +#include "MoveOnly.h" +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "Counter.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + 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()); + } + { + typedef Counter<int> V; + typedef std::less<V> C; + typedef test_allocator<V> A; + typedef std::set<V, C, A> M; + typedef V* I; + Counter_base::gConstructed = 0; + { + V a1[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + const size_t num = sizeof(a1)/sizeof(a1[0]); + assert(Counter_base::gConstructed == num); + + M m1(I(a1), I(a1+num), C(), A()); + assert(Counter_base::gConstructed == 3+num); + + M m2(m1); + assert(m2 == m1); + assert(Counter_base::gConstructed == 6+num); + + M m3(std::move(m1), A()); + assert(m3 == m2); + assert(m1.empty()); + assert(Counter_base::gConstructed == 6+num); + + { + M m4(std::move(m2), A(5)); + assert(Counter_base::gConstructed == 6+num); + assert(m4 == m3); + assert(m2.empty()); + } + assert(Counter_base::gConstructed == 3+num); + } + assert(Counter_base::gConstructed == 0); + } + +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/set/set.cons/move_assign.pass.cpp b/test/std/containers/associative/set/set.cons/move_assign.pass.cpp new file mode 100644 index 0000000000000..ed0e77ae17966 --- /dev/null +++ b/test/std/containers/associative/set/set.cons/move_assign.pass.cpp @@ -0,0 +1,186 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// set& operator=(set&& s); + +#include <set> +#include <cassert> + +#include "MoveOnly.h" +#include "../../../test_compare.h" +#include "test_allocator.h" +#include "min_allocator.h" + +int main() +{ +#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { + typedef MoveOnly V; + typedef test_compare<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()); + } +#if __cplusplus >= 201103L + { + typedef MoveOnly V; + typedef test_compare<std::less<MoveOnly> > C; + typedef min_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()); + V a2[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A()); + M m3(C(3), A()); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A()); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif +#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +} diff --git a/test/std/containers/associative/set/set.cons/move_assign_noexcept.pass.cpp b/test/std/containers/associative/set/set.cons/move_assign_noexcept.pass.cpp new file mode 100644 index 0000000000000..3999c55e9e7c0 --- /dev/null +++ b/test/std/containers/associative/set/set.cons/move_assign_noexcept.pass.cpp @@ -0,0 +1,53 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// set& operator=(set&& c) +// noexcept( +// allocator_type::propagate_on_container_move_assignment::value && +// is_nothrow_move_assignable<allocator_type>::value && +// is_nothrow_move_assignable<key_compare>::value); + +// This tests a conforming extension + +#include <set> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + some_comp& operator=(const some_comp&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::set<MoveOnly> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::set<MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::set<MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_assignable<C>::value, ""); + } + { + typedef std::set<MoveOnly, some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_move_assignable<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/associative/set/set.cons/move_noexcept.pass.cpp b/test/std/containers/associative/set/set.cons/move_noexcept.pass.cpp new file mode 100644 index 0000000000000..5ccfed4675c54 --- /dev/null +++ b/test/std/containers/associative/set/set.cons/move_noexcept.pass.cpp @@ -0,0 +1,51 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// set(set&&) +// noexcept(is_nothrow_move_constructible<allocator_type>::value && +// is_nothrow_move_constructible<key_compare>::value); + +// This tests a conforming extension + +#include <set> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + some_comp(const some_comp&); +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::set<MoveOnly> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::set<MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::set<MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + static_assert(std::is_nothrow_move_constructible<C>::value, ""); + } + { + typedef std::set<MoveOnly, some_comp<MoveOnly>> C; + static_assert(!std::is_nothrow_move_constructible<C>::value, ""); + } +#endif +} diff --git a/test/std/containers/associative/set/set.special/member_swap.pass.cpp b/test/std/containers/associative/set/set.special/member_swap.pass.cpp new file mode 100644 index 0000000000000..b5129f880afdc --- /dev/null +++ b/test/std/containers/associative/set/set.special/member_swap.pass.cpp @@ -0,0 +1,177 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// void swap(set& m); + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +int main() +{ + { + typedef int V; + typedef std::set<int> M; + { + M m1; + M m2; + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1; + 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 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2; + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::set<int, std::less<int>, min_allocator<int>> M; + { + M m1; + M m2; + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1; + 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 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2; + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#endif +} diff --git a/test/std/containers/associative/set/set.special/non_member_swap.pass.cpp b/test/std/containers/associative/set/set.special/non_member_swap.pass.cpp new file mode 100644 index 0000000000000..0ac14464c70f3 --- /dev/null +++ b/test/std/containers/associative/set/set.special/non_member_swap.pass.cpp @@ -0,0 +1,165 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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; + { + M m1; + M m2; + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1; + 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 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2; + 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/test/std/containers/associative/set/set.special/swap_noexcept.pass.cpp b/test/std/containers/associative/set/set.special/swap_noexcept.pass.cpp new file mode 100644 index 0000000000000..3ec6976127545 --- /dev/null +++ b/test/std/containers/associative/set/set.special/swap_noexcept.pass.cpp @@ -0,0 +1,148 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// void swap(set& c) +// noexcept(!allocator_type::propagate_on_container_swap::value || +// __is_nothrow_swappable<allocator_type>::value); +// +// In C++17, the standard says that swap shall have: +// noexcept(allocator_traits<Allocator>::is_always_equal::value && +// noexcept(swap(declval<Compare&>(), declval<Compare&>()))); + +// This tests a conforming extension + +#include <set> +#include <cassert> + +#include "MoveOnly.h" +#include "test_allocator.h" + +template <class T> +struct some_comp +{ + typedef T value_type; + + some_comp() {} + some_comp(const some_comp&) {} + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +template <class T> +struct some_comp2 +{ + typedef T value_type; + + some_comp2() {} + some_comp2(const some_comp2&) {} + void deallocate(void*, unsigned) {} + typedef std::true_type propagate_on_container_swap; +}; + +#if TEST_STD_VER >= 14 +template <typename T> +void swap(some_comp2<T>&, some_comp2<T>&) noexcept {} +#endif + +template <class T> +struct some_alloc +{ + typedef T value_type; + + some_alloc() {} + some_alloc(const some_alloc&); + void deallocate(void*, unsigned) {} + + typedef std::true_type propagate_on_container_swap; +}; + +template <class T> +struct some_alloc2 +{ + typedef T value_type; + + some_alloc2() {} + some_alloc2(const some_alloc2&); + void deallocate(void*, unsigned) {} + + typedef std::false_type propagate_on_container_swap; + typedef std::true_type is_always_equal; +}; + +template <class T> +struct some_alloc3 +{ + typedef T value_type; + + some_alloc3() {} + some_alloc3(const some_alloc3&); + void deallocate(void*, unsigned) {} + + typedef std::false_type propagate_on_container_swap; + typedef std::false_type is_always_equal; +}; + +int main() +{ +#if __has_feature(cxx_noexcept) + { + typedef std::set<MoveOnly> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::set<MoveOnly, std::less<MoveOnly>, test_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::set<MoveOnly, std::less<MoveOnly>, other_allocator<MoveOnly>> C; + C c1, c2; + static_assert(noexcept(swap(c1, c2)), ""); + } + { + typedef std::set<MoveOnly, some_comp<MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + +#if TEST_STD_VER >= 14 + { // POCS allocator, throwable swap for comp + typedef std::set<MoveOnly, some_comp <MoveOnly>, some_alloc <MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { // always equal allocator, throwable swap for comp + typedef std::set<MoveOnly, some_comp <MoveOnly>, some_alloc2<MoveOnly>> C; + C c1, c2; + static_assert(!noexcept(swap(c1, c2)), ""); + } + { // POCS allocator, nothrow swap for comp + typedef std::set<MoveOnly, some_comp2<MoveOnly>, some_alloc <MoveOnly>> C; + C c1, c2; + static_assert( noexcept(swap(c1, c2)), ""); + } + { // always equal allocator, nothrow swap for comp + typedef std::set<MoveOnly, some_comp2<MoveOnly>, some_alloc2<MoveOnly>> C; + C c1, c2; + static_assert( noexcept(swap(c1, c2)), ""); + } + + { // NOT always equal allocator, nothrow swap for comp + typedef std::set<MoveOnly, some_comp2<MoveOnly>, some_alloc3<MoveOnly>> C; + C c1, c2; + static_assert( noexcept(swap(c1, c2)), ""); + } +#endif + +#endif +} diff --git a/test/std/containers/associative/set/size.pass.cpp b/test/std/containers/associative/set/size.pass.cpp new file mode 100644 index 0000000000000..e786547355081 --- /dev/null +++ b/test/std/containers/associative/set/size.pass.cpp @@ -0,0 +1,59 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// size_type size() const; + +#include <set> +#include <cassert> + +#include "min_allocator.h" + +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); + } +#if __cplusplus >= 201103L + { + typedef std::set<int, std::less<int>, min_allocator<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); + } +#endif +} diff --git a/test/std/containers/associative/set/types.pass.cpp b/test/std/containers/associative/set/types.pass.cpp new file mode 100644 index 0000000000000..3362c42aee429 --- /dev/null +++ b/test/std/containers/associative/set/types.pass.cpp @@ -0,0 +1,70 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <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> + +#include "min_allocator.h" + +int main() +{ + { + typedef std::set<int> C; + static_assert((std::is_same<C::key_type, int>::value), ""); + static_assert((std::is_same<C::value_type, int>::value), ""); + static_assert((std::is_same<C::key_compare, std::less<int> >::value), ""); + static_assert((std::is_same<C::value_compare, std::less<int> >::value), ""); + static_assert((std::is_same<C::allocator_type, std::allocator<int> >::value), ""); + static_assert((std::is_same<C::reference, int&>::value), ""); + static_assert((std::is_same<C::const_reference, const int&>::value), ""); + static_assert((std::is_same<C::pointer, int*>::value), ""); + static_assert((std::is_same<C::const_pointer, const int*>::value), ""); + static_assert((std::is_same<C::size_type, std::size_t>::value), ""); + static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), ""); + } +#if __cplusplus >= 201103L + { + typedef std::set<int, std::less<int>, min_allocator<int>> C; + static_assert((std::is_same<C::key_type, int>::value), ""); + static_assert((std::is_same<C::value_type, int>::value), ""); + static_assert((std::is_same<C::key_compare, std::less<int> >::value), ""); + static_assert((std::is_same<C::value_compare, std::less<int> >::value), ""); + static_assert((std::is_same<C::allocator_type, min_allocator<int> >::value), ""); + static_assert((std::is_same<C::reference, int&>::value), ""); + static_assert((std::is_same<C::const_reference, const int&>::value), ""); + static_assert((std::is_same<C::pointer, min_pointer<int>>::value), ""); + static_assert((std::is_same<C::const_pointer, min_pointer<const int>>::value), ""); +// min_allocator doesn't have a size_type, so one gets synthesized + static_assert((std::is_same<C::size_type, std::make_unsigned<C::difference_type>::type>::value), ""); + static_assert((std::is_same<C::difference_type, std::ptrdiff_t>::value), ""); + } +#endif +} diff --git a/test/std/containers/associative/set/upper_bound.pass.cpp b/test/std/containers/associative/set/upper_bound.pass.cpp new file mode 100644 index 0000000000000..10a28f064698f --- /dev/null +++ b/test/std/containers/associative/set/upper_bound.pass.cpp @@ -0,0 +1,336 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +// class set + +// iterator upper_bound(const key_type& k); +// const_iterator upper_bound(const key_type& k) const; + +#include <set> +#include <cassert> + +#include "min_allocator.h" +#include "private_constructor.hpp" + +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)); + } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::set<int, std::less<int>, min_allocator<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)); + } + } +#endif +#if _LIBCPP_STD_VER > 11 + { + typedef int V; + typedef std::set<V, std::less<>> M; + typedef M::iterator R; + + V ar[] = + { + 5, + 7, + 9, + 11, + 13, + 15, + 17, + 19 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } + + { + typedef PrivateConstructor V; + typedef std::set<V, std::less<>> M; + typedef M::iterator R; + + M m; + m.insert ( V::make ( 5 )); + m.insert ( V::make ( 7 )); + m.insert ( V::make ( 9 )); + m.insert ( V::make ( 11 )); + m.insert ( V::make ( 13 )); + m.insert ( V::make ( 15 )); + m.insert ( V::make ( 17 )); + m.insert ( V::make ( 19 )); + + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } +#endif +} diff --git a/test/std/containers/associative/set/version.pass.cpp b/test/std/containers/associative/set/version.pass.cpp new file mode 100644 index 0000000000000..c3c4d926e5c33 --- /dev/null +++ b/test/std/containers/associative/set/version.pass.cpp @@ -0,0 +1,20 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <set> + +#include <set> + +#ifndef _LIBCPP_VERSION +#error _LIBCPP_VERSION not defined +#endif + +int main() +{ +} diff --git a/test/std/containers/associative/tree_balance_after_insert.pass.cpp b/test/std/containers/associative/tree_balance_after_insert.pass.cpp new file mode 100644 index 0000000000000..b0a3e74cab0af --- /dev/null +++ b/test/std/containers/associative/tree_balance_after_insert.pass.cpp @@ -0,0 +1,1616 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Not a portable test + +// Precondition: __root->__is_black_ == true +// template <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/test/std/containers/associative/tree_left_rotate.pass.cpp b/test/std/containers/associative/tree_left_rotate.pass.cpp new file mode 100644 index 0000000000000..774cbc6879856 --- /dev/null +++ b/test/std/containers/associative/tree_left_rotate.pass.cpp @@ -0,0 +1,98 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Not a portable test + +// Precondition: __x->__right_ != nullptr +// template <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/test/std/containers/associative/tree_remove.pass.cpp b/test/std/containers/associative/tree_remove.pass.cpp new file mode 100644 index 0000000000000..fb14bd929e913 --- /dev/null +++ b/test/std/containers/associative/tree_remove.pass.cpp @@ -0,0 +1,1648 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Not a portable test + +// Returns __tree_next(__z) +// template <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/test/std/containers/associative/tree_right_rotate.pass.cpp b/test/std/containers/associative/tree_right_rotate.pass.cpp new file mode 100644 index 0000000000000..06ec7b8894525 --- /dev/null +++ b/test/std/containers/associative/tree_right_rotate.pass.cpp @@ -0,0 +1,98 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// Not a portable test + +// Precondition: __x->__left_ != nullptr +// template <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(); +} |