diff options
Diffstat (limited to 'test/std/containers/associative/set')
47 files changed, 5101 insertions, 0 deletions
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 000000000000..4439ad3b1e4e --- /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 000000000000..32fe0b8bcee9 --- /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 000000000000..5ebab4d24b92 --- /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 000000000000..5fdeb4ffef3a --- /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 000000000000..eb1080263f4f --- /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 000000000000..8a180ef49248 --- /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 000000000000..36828be86f28 --- /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 000000000000..479950316655 --- /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 000000000000..9d92bd70d700 --- /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 000000000000..d08d2fb1e245 --- /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 000000000000..18d5c2e03395 --- /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 000000000000..fc6d612b2ebe --- /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 000000000000..718e720559f4 --- /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 000000000000..ff729a0e7b9b --- /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 000000000000..296ead84914d --- /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 000000000000..32cede154956 --- /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 000000000000..ecd950f03a00 --- /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 000000000000..df202f31a4c3 --- /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 000000000000..cde4397c7178 --- /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 000000000000..67433ff88a01 --- /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 000000000000..892ae5a0a799 --- /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 000000000000..af94c70671b8 --- /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 000000000000..22b3328d4d79 --- /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 000000000000..a0e34e48de43 --- /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 000000000000..1ad03dc1404d --- /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 000000000000..7f0f0447625f --- /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 000000000000..746a2d173071 --- /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 000000000000..2156169acbc4 --- /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 000000000000..b554d828d486 --- /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 000000000000..2ad538e143f8 --- /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 000000000000..a0afa02cf749 --- /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 000000000000..821820a1e0ce --- /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 000000000000..7ca7fe14d6c4 --- /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 000000000000..5ccb6e5cbcd7 --- /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 000000000000..18bc0839003b --- /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 000000000000..4026ec70c3e1 --- /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 000000000000..799f0e402d63 --- /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 000000000000..ed0e77ae1796 --- /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 000000000000..3999c55e9e7c --- /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 000000000000..5ccfed4675c5 --- /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 000000000000..b5129f880afd --- /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 000000000000..0ac14464c70f --- /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 000000000000..3ec697612754 --- /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 000000000000..e78654735508 --- /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 000000000000..3362c42aee42 --- /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 000000000000..10a28f064698 --- /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 000000000000..c3c4d926e5c3 --- /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() +{ +} |