diff options
Diffstat (limited to 'libcxx/test')
5 files changed, 160 insertions, 4 deletions
diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp index 42b41fd7b86..fabafd332f4 100644 --- a/libcxx/test/std/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp +++ b/libcxx/test/std/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp @@ -52,7 +52,7 @@ int main() assert(r->first == 3); assert(r->second == 3); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { typedef std::map<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M; typedef std::pair<int, MoveOnly> P; @@ -83,5 +83,35 @@ int main() assert(r->second == 3); } #endif +#if TEST_STD_VER > 14 + { + typedef std::map<int, MoveOnly> M; + typedef M::iterator R; + M m; + R r = m.insert(m.end(), {2, MoveOnly(2)}); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2); + + r = m.insert(m.end(), {1, MoveOnly(1)}); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1); + + r = m.insert(m.end(), {3, MoveOnly(3)}); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3); + + r = m.insert(m.end(), {3, MoveOnly(3)}); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3); + } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#endif } diff --git a/libcxx/test/std/containers/associative/map/map.modifiers/insert_rv.pass.cpp b/libcxx/test/std/containers/associative/map/map.modifiers/insert_rv.pass.cpp index a9d3277e6d9..813e425e568 100644 --- a/libcxx/test/std/containers/associative/map/map.modifiers/insert_rv.pass.cpp +++ b/libcxx/test/std/containers/associative/map/map.modifiers/insert_rv.pass.cpp @@ -11,6 +11,7 @@ // class map +// pair<iterator, bool> insert( value_type&& v); // C++17 and later // template <class P> // pair<iterator, bool> insert(P&& p); @@ -55,7 +56,7 @@ int main() assert(r.first->first == 3); assert(r.first->second == 3); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { typedef std::map<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M; typedef std::pair<M::iterator, bool> R; @@ -89,5 +90,39 @@ int main() assert(r.first->second == 3); } #endif +#if TEST_STD_VER > 14 + { + typedef std::map<int, MoveOnly> M; + typedef std::pair<M::iterator, bool> R; + M m; + R r = m.insert({2, MoveOnly(2)}); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(r.first->first == 2); + assert(r.first->second == 2); + + r = m.insert({1, MoveOnly(1)}); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(r.first->first == 1); + assert(r.first->second == 1); + + r = m.insert({3, MoveOnly(3)}); + assert(r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(r.first->first == 3); + assert(r.first->second == 3); + + r = m.insert({3, MoveOnly(3)}); + assert(!r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(r.first->first == 3); + assert(r.first->second == 3); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_rv.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_rv.pass.cpp index b44f46429ec..de5aea614cb 100644 --- a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_rv.pass.cpp +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_iter_rv.pass.cpp @@ -52,7 +52,7 @@ int main() assert(r->first == 3); assert(r->second == 2); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { typedef std::multimap<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M; typedef std::pair<int, MoveOnly> P; @@ -83,5 +83,36 @@ int main() assert(r->second == 2); } #endif +#if TEST_STD_VER > 14 + { + typedef std::multimap<int, MoveOnly> M; + typedef std::pair<int, MoveOnly> P; + typedef M::iterator R; + M m; + R r = m.insert(m.cend(), {2, MoveOnly(2)}); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2); + + r = m.insert(m.cend(), {1, MoveOnly(1)}); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1); + + r = m.insert(m.cend(), {3, MoveOnly(3)}); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3); + + r = m.insert(m.cend(), {3, MoveOnly(2)}); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(r->first == 3); + assert(r->second == 2); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_rv.pass.cpp b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_rv.pass.cpp index b1c043586d6..86fc6cef043 100644 --- a/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_rv.pass.cpp +++ b/libcxx/test/std/containers/associative/multimap/multimap.modifiers/insert_rv.pass.cpp @@ -51,7 +51,7 @@ int main() assert(r->first == 3); assert(r->second == 3); } -#if __cplusplus >= 201103L +#if TEST_STD_VER >= 11 { typedef std::multimap<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M; typedef M::iterator R; @@ -81,5 +81,35 @@ int main() assert(r->second == 3); } #endif +#if TEST_STD_VER > 14 + { + typedef std::multimap<int, MoveOnly> M; + typedef M::iterator R; + M m; + R r = m.insert({2, MoveOnly(2)}); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2); + + r = m.insert({1, MoveOnly(1)}); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1); + + r = m.insert({3, MoveOnly(3)}); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3); + + r = m.insert({3, MoveOnly(3)}); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(r->first == 3); + assert(r->second == 3); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/support/MoveOnly.h b/libcxx/test/support/MoveOnly.h index e4d9f649560..b9653516cfd 100644 --- a/libcxx/test/support/MoveOnly.h +++ b/libcxx/test/support/MoveOnly.h @@ -17,6 +17,7 @@ class MoveOnly { + friend class MoveOnly2; MoveOnly(const MoveOnly&); MoveOnly& operator=(const MoveOnly&); @@ -34,6 +35,29 @@ public: bool operator< (const MoveOnly& x) const {return data_ < x.data_;} }; +class MoveOnly2 +{ + MoveOnly2(const MoveOnly&); + MoveOnly2& operator=(const MoveOnly2&); + + int data_; +public: + MoveOnly2(int data = 1) : data_(data) {} + MoveOnly2(MoveOnly2&& x) + : data_(x.data_) {x.data_ = 0;} + MoveOnly2& operator=(MoveOnly2&& x) + {data_ = x.data_; x.data_ = 0; return *this;} + MoveOnly2(MoveOnly&& x) + : data_(x.data_) {x.data_ = 0;} + MoveOnly2& operator=(MoveOnly&& x) + {data_ = x.data_; x.data_ = 0; return *this;} + + int get() const {return data_;} + + bool operator==(const MoveOnly2& x) const {return data_ == x.data_;} + bool operator< (const MoveOnly2& x) const {return data_ < x.data_;} +}; + namespace std { template <> @@ -43,6 +67,12 @@ struct hash<MoveOnly> std::size_t operator()(const MoveOnly& x) const {return x.get();} }; +template <> +struct hash<MoveOnly2> + : public std::unary_function<MoveOnly, std::size_t> +{ + std::size_t operator()(const MoveOnly2& x) const {return x.get();} +}; } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |