diff options
147 files changed, 7022 insertions, 279 deletions
diff --git a/libcxx/include/__tree b/libcxx/include/__tree index cd6d7efaae8..9ffc38d2287 100644 --- a/libcxx/include/__tree +++ b/libcxx/include/__tree @@ -644,7 +644,8 @@ public: _LIBCPP_INLINE_VISIBILITY __tree_iterator() _NOEXCEPT {} _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __ptr_->__value_;} - _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return &__ptr_->__value_;} + _LIBCPP_INLINE_VISIBILITY pointer operator->() const + {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);} _LIBCPP_INLINE_VISIBILITY __tree_iterator& operator++() @@ -686,7 +687,7 @@ class _LIBCPP_TYPE_VIS __tree_const_iterator { typedef _ConstNodePtr __node_pointer; typedef typename pointer_traits<__node_pointer>::element_type __node; - typedef const typename __node::base __node_base; + typedef typename __node::base __node_base; typedef typename pointer_traits<__node_pointer>::template #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES rebind<__node_base> @@ -729,7 +730,8 @@ public: : __ptr_(__p.__ptr_) {} _LIBCPP_INLINE_VISIBILITY reference operator*() const {return __ptr_->__value_;} - _LIBCPP_INLINE_VISIBILITY pointer operator->() const {return &__ptr_->__value_;} + _LIBCPP_INLINE_VISIBILITY pointer operator->() const + {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);} _LIBCPP_INLINE_VISIBILITY __tree_const_iterator& operator++() @@ -779,8 +781,10 @@ public: typedef typename __alloc_traits::size_type size_type; typedef typename __alloc_traits::difference_type difference_type; - typedef __tree_node<value_type, typename __alloc_traits::void_pointer> __node; - typedef __tree_node_base<typename __alloc_traits::void_pointer> __node_base; + typedef typename __alloc_traits::void_pointer __void_pointer; + + typedef __tree_node<value_type, __void_pointer> __node; + typedef __tree_node_base<__void_pointer> __node_base; typedef typename __alloc_traits::template #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES rebind_alloc<__node> @@ -790,9 +794,9 @@ public: __node_allocator; typedef allocator_traits<__node_allocator> __node_traits; typedef typename __node_traits::pointer __node_pointer; - typedef typename __node_traits::const_pointer __node_const_pointer; + typedef typename __node_traits::pointer __node_const_pointer; typedef typename __node_base::pointer __node_base_pointer; - typedef typename __node_base::const_pointer __node_base_const_pointer; + typedef typename __node_base::pointer __node_base_const_pointer; private: typedef typename __node_base::base __end_node_t; typedef typename pointer_traits<__node_pointer>::template @@ -804,9 +808,9 @@ private: __end_node_ptr; typedef typename pointer_traits<__node_pointer>::template #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind<const __end_node_t> + rebind<__end_node_t> #else - rebind<const __end_node_t>::other + rebind<__end_node_t>::other #endif __end_node_const_ptr; @@ -828,7 +832,7 @@ public: { return static_cast<__node_const_pointer> ( - pointer_traits<__end_node_const_ptr>::pointer_to(__pair1_.first()) + pointer_traits<__end_node_const_ptr>::pointer_to(const_cast<__end_node_t&>(__pair1_.first())) ); } _LIBCPP_INLINE_VISIBILITY @@ -865,7 +869,7 @@ public: {return static_cast<__node_const_pointer>(__end_node()->__left_);} typedef __tree_iterator<value_type, __node_pointer, difference_type> iterator; - typedef __tree_const_iterator<value_type, __node_const_pointer, difference_type> const_iterator; + typedef __tree_const_iterator<value_type, __node_pointer, difference_type> const_iterator; explicit __tree(const value_compare& __comp) _NOEXCEPT_( @@ -1102,6 +1106,9 @@ private: __node_pointer __detach(); static __node_pointer __detach(__node_pointer); + + template <class, class, class, class> friend class _LIBCPP_TYPE_VIS map; + template <class, class, class, class> friend class _LIBCPP_TYPE_VIS multimap; }; template <class _Tp, class _Compare, class _Allocator> @@ -1161,7 +1168,7 @@ __tree<_Tp, _Compare, _Allocator>::__detach(__node_pointer __cache) { if (__cache->__parent_ == nullptr) return nullptr; - if (__tree_is_left_child(__cache)) + if (__tree_is_left_child(static_cast<__node_base_pointer>(__cache))) { __cache->__parent_->__left_ = nullptr; __cache = static_cast<__node_pointer>(__cache->__parent_); @@ -1294,7 +1301,7 @@ __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t) __begin_node() = __end_node(); else { - __end_node()->__left_->__parent_ = __end_node(); + __end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__end_node()); __t.__begin_node() = __t.__end_node(); __t.__end_node()->__left_ = nullptr; __t.size() = 0; @@ -1314,7 +1321,7 @@ __tree<_Tp, _Compare, _Allocator>::__tree(__tree&& __t, const allocator_type& __ { __begin_node() = __t.__begin_node(); __end_node()->__left_ = __t.__end_node()->__left_; - __end_node()->__left_->__parent_ = __end_node(); + __end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__end_node()); size() = __t.size(); __t.__begin_node() = __t.__end_node(); __t.__end_node()->__left_ = nullptr; @@ -1342,7 +1349,7 @@ __tree<_Tp, _Compare, _Allocator>::__move_assign(__tree& __t, true_type) __begin_node() = __end_node(); else { - __end_node()->__left_->__parent_ = __end_node(); + __end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__end_node()); __t.__begin_node() = __t.__end_node(); __t.__end_node()->__left_ = nullptr; __t.size() = 0; @@ -1447,11 +1454,11 @@ __tree<_Tp, _Compare, _Allocator>::swap(__tree& __t) if (size() == 0) __begin_node() = __end_node(); else - __end_node()->__left_->__parent_ = __end_node(); + __end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__end_node()); if (__t.size() == 0) __t.__begin_node() = __t.__end_node(); else - __t.__end_node()->__left_->__parent_ = __t.__end_node(); + __t.__end_node()->__left_->__parent_ = static_cast<__node_base_pointer>(__t.__end_node()); } template <class _Tp, class _Compare, class _Allocator> @@ -1483,7 +1490,7 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf_low(typename __node_base::pointer __nd = static_cast<__node_pointer>(__nd->__right_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent->__right_; } } @@ -1493,13 +1500,13 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf_low(typename __node_base::pointer __nd = static_cast<__node_pointer>(__nd->__left_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent->__left_; } } } } - __parent = __end_node(); + __parent = static_cast<__node_base_pointer>(__end_node()); return __parent->__left_; } @@ -1522,7 +1529,7 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf_high(typename __node_base::pointe __nd = static_cast<__node_pointer>(__nd->__left_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent->__left_; } } @@ -1532,13 +1539,13 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf_high(typename __node_base::pointe __nd = static_cast<__node_pointer>(__nd->__right_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent->__right_; } } } } - __parent = __end_node(); + __parent = static_cast<__node_base_pointer>(__end_node()); return __parent->__left_; } @@ -1563,12 +1570,12 @@ __tree<_Tp, _Compare, _Allocator>::__find_leaf(const_iterator __hint, // *prev(__hint) <= __v <= *__hint if (__hint.__ptr_->__left_ == nullptr) { - __parent = const_cast<__node_pointer&>(__hint.__ptr_); + __parent = static_cast<__node_base_pointer>(__hint.__ptr_); return __parent->__left_; } else { - __parent = const_cast<__node_pointer&>(__prior.__ptr_); + __parent = static_cast<__node_base_pointer>(__prior.__ptr_); return __parent->__right_; } } @@ -1600,7 +1607,7 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(typename __node_base::pointer& _ __nd = static_cast<__node_pointer>(__nd->__left_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent->__left_; } } @@ -1610,18 +1617,18 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(typename __node_base::pointer& _ __nd = static_cast<__node_pointer>(__nd->__right_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent->__right_; } } else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent; } } } - __parent = __end_node(); + __parent = static_cast<__node_base_pointer>(__end_node()); return __parent->__left_; } @@ -1648,12 +1655,12 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(const_iterator __hint, // *prev(__hint) < __v < *__hint if (__hint.__ptr_->__left_ == nullptr) { - __parent = const_cast<__node_pointer&>(__hint.__ptr_); + __parent = static_cast<__node_base_pointer>(__hint.__ptr_); return __parent->__left_; } else { - __parent = const_cast<__node_pointer&>(__prior.__ptr_); + __parent = static_cast<__node_base_pointer>(__prior.__ptr_); return __parent->__right_; } } @@ -1669,12 +1676,12 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(const_iterator __hint, // *__hint < __v < *_VSTD::next(__hint) if (__hint.__ptr_->__right_ == nullptr) { - __parent = const_cast<__node_pointer&>(__hint.__ptr_); + __parent = static_cast<__node_base_pointer>(__hint.__ptr_); return __parent->__right_; } else { - __parent = const_cast<__node_pointer&>(__next.__ptr_); + __parent = static_cast<__node_base_pointer>(__next.__ptr_); return __parent->__left_; } } @@ -1682,7 +1689,7 @@ __tree<_Tp, _Compare, _Allocator>::__find_equal(const_iterator __hint, return __find_equal(__parent, __v); } // else __v == *__hint - __parent = const_cast<__node_pointer&>(__hint.__ptr_); + __parent = static_cast<__node_base_pointer>(__hint.__ptr_); return __parent; } @@ -1729,7 +1736,7 @@ __tree<_Tp, _Compare, _Allocator>::__emplace_unique(_Args&&... __args) bool __inserted = false; if (__child == nullptr) { - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); __inserted = true; } @@ -1747,7 +1754,7 @@ __tree<_Tp, _Compare, _Allocator>::__emplace_hint_unique(const_iterator __p, _Ar __node_pointer __r = static_cast<__node_pointer>(__child); if (__child == nullptr) { - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); } return iterator(__r); @@ -1761,7 +1768,7 @@ __tree<_Tp, _Compare, _Allocator>::__emplace_multi(_Args&&... __args) __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); __node_base_pointer __parent; __node_base_pointer& __child = __find_leaf_high(__parent, __h->__value_); - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(static_cast<__node_pointer>(__h.release())); } @@ -1774,7 +1781,7 @@ __tree<_Tp, _Compare, _Allocator>::__emplace_hint_multi(const_iterator __p, __node_holder __h = __construct_node(_VSTD::forward<_Args>(__args)...); __node_base_pointer __parent; __node_base_pointer& __child = __find_leaf(__p, __parent, __h->__value_); - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(static_cast<__node_pointer>(__h.release())); } @@ -1812,7 +1819,7 @@ __tree<_Tp, _Compare, _Allocator>::__insert_multi(_Vp&& __v) __node_holder __h = __construct_node(_VSTD::forward<_Vp>(__v)); __node_base_pointer __parent; __node_base_pointer& __child = __find_leaf_high(__parent, __h->__value_); - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(__h.release()); } @@ -1824,7 +1831,7 @@ __tree<_Tp, _Compare, _Allocator>::__insert_multi(const_iterator __p, _Vp&& __v) __node_holder __h = __construct_node(_VSTD::forward<_Vp>(__v)); __node_base_pointer __parent; __node_base_pointer& __child = __find_leaf(__p, __parent, __h->__value_); - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(__h.release()); } @@ -1854,7 +1861,7 @@ __tree<_Tp, _Compare, _Allocator>::__insert_unique(const value_type& __v) if (__child == nullptr) { __node_holder __h = __construct_node(__v); - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); __inserted = true; } @@ -1871,7 +1878,7 @@ __tree<_Tp, _Compare, _Allocator>::__insert_unique(const_iterator __p, const val if (__child == nullptr) { __node_holder __h = __construct_node(__v); - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); } return iterator(__r); @@ -1884,7 +1891,7 @@ __tree<_Tp, _Compare, _Allocator>::__insert_multi(const value_type& __v) __node_base_pointer __parent; __node_base_pointer& __child = __find_leaf_high(__parent, __v); __node_holder __h = __construct_node(__v); - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(__h.release()); } @@ -1895,7 +1902,7 @@ __tree<_Tp, _Compare, _Allocator>::__insert_multi(const_iterator __p, const valu __node_base_pointer __parent; __node_base_pointer& __child = __find_leaf(__p, __parent, __v); __node_holder __h = __construct_node(__v); - __insert_node_at(__parent, __child, __h.get()); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); return iterator(__h.release()); } @@ -1909,7 +1916,7 @@ __tree<_Tp, _Compare, _Allocator>::__node_insert_unique(__node_pointer __nd) bool __inserted = false; if (__child == nullptr) { - __insert_node_at(__parent, __child, __nd); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); __r = __nd; __inserted = true; } @@ -1926,7 +1933,7 @@ __tree<_Tp, _Compare, _Allocator>::__node_insert_unique(const_iterator __p, __node_pointer __r = static_cast<__node_pointer>(__child); if (__child == nullptr) { - __insert_node_at(__parent, __child, __nd); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); __r = __nd; } return iterator(__r); @@ -1938,7 +1945,7 @@ __tree<_Tp, _Compare, _Allocator>::__node_insert_multi(__node_pointer __nd) { __node_base_pointer __parent; __node_base_pointer& __child = __find_leaf_high(__parent, __nd->__value_); - __insert_node_at(__parent, __child, __nd); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); return iterator(__nd); } @@ -1949,7 +1956,7 @@ __tree<_Tp, _Compare, _Allocator>::__node_insert_multi(const_iterator __p, { __node_base_pointer __parent; __node_base_pointer& __child = __find_leaf(__p, __parent, __nd->__value_); - __insert_node_at(__parent, __child, __nd); + __insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__nd)); return iterator(__nd); } @@ -1957,7 +1964,7 @@ template <class _Tp, class _Compare, class _Allocator> typename __tree<_Tp, _Compare, _Allocator>::iterator __tree<_Tp, _Compare, _Allocator>::erase(const_iterator __p) { - __node_pointer __np = const_cast<__node_pointer>(__p.__ptr_); + __node_pointer __np = __p.__ptr_; iterator __r(__np); ++__r; if (__begin_node() == __np) @@ -1977,7 +1984,7 @@ __tree<_Tp, _Compare, _Allocator>::erase(const_iterator __f, const_iterator __l) { while (__f != __l) __f = erase(__f); - return iterator(const_cast<__node_pointer>(__l.__ptr_)); + return iterator(__l.__ptr_); } template <class _Tp, class _Compare, class _Allocator> @@ -2264,7 +2271,7 @@ template <class _Tp, class _Compare, class _Allocator> typename __tree<_Tp, _Compare, _Allocator>::__node_holder __tree<_Tp, _Compare, _Allocator>::remove(const_iterator __p) _NOEXCEPT { - __node_pointer __np = const_cast<__node_pointer>(__p.__ptr_); + __node_pointer __np = __p.__ptr_; if (__begin_node() == __np) { if (__np->__right_ != nullptr) diff --git a/libcxx/include/map b/libcxx/include/map index abc07a35d0e..df174daaae3 100644 --- a/libcxx/include/map +++ b/libcxx/include/map @@ -489,8 +489,8 @@ class __map_node_destructor public: typedef typename __alloc_traits::pointer pointer; private: - typedef typename value_type::first_type first_type; - typedef typename value_type::second_type second_type; + typedef typename value_type::value_type::first_type first_type; + typedef typename value_type::value_type::second_type second_type; allocator_type& __na_; @@ -522,9 +522,9 @@ public: void operator()(pointer __p) _NOEXCEPT { if (__second_constructed) - __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.second)); + __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.second)); if (__first_constructed) - __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.first)); + __alloc_traits::destroy(__na_, _VSTD::addressof(__p->__value_.__cc.first)); if (__p) __alloc_traits::deallocate(__na_, __p, 1); } @@ -542,8 +542,8 @@ class _LIBCPP_TYPE_VIS __map_iterator _TreeIterator __i_; typedef typename _TreeIterator::__pointer_traits __pointer_traits; - typedef const typename _TreeIterator::value_type::first_type __key_type; - typedef typename _TreeIterator::value_type::second_type __mapped_type; + typedef const typename _TreeIterator::value_type::value_type::first_type __key_type; + typedef typename _TreeIterator::value_type::value_type::second_type __mapped_type; public: typedef bidirectional_iterator_tag iterator_category; typedef pair<__key_type, __mapped_type> value_type; @@ -564,9 +564,9 @@ public: __map_iterator(_TreeIterator __i) _NOEXCEPT : __i_(__i) {} _LIBCPP_INLINE_VISIBILITY - reference operator*() const {return *operator->();} + reference operator*() const {return __i_->__cc;} _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return (pointer)__i_.operator->();} + pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);} _LIBCPP_INLINE_VISIBILITY __map_iterator& operator++() {++__i_; return *this;} @@ -607,8 +607,8 @@ class _LIBCPP_TYPE_VIS __map_const_iterator _TreeIterator __i_; typedef typename _TreeIterator::__pointer_traits __pointer_traits; - typedef const typename _TreeIterator::value_type::first_type __key_type; - typedef typename _TreeIterator::value_type::second_type __mapped_type; + typedef const typename _TreeIterator::value_type::value_type::first_type __key_type; + typedef typename _TreeIterator::value_type::value_type::second_type __mapped_type; public: typedef bidirectional_iterator_tag iterator_category; typedef pair<__key_type, __mapped_type> value_type; @@ -634,9 +634,9 @@ public: : __i_(__i.__i_) {} _LIBCPP_INLINE_VISIBILITY - reference operator*() const {return *operator->();} + reference operator*() const {return __i_->__cc;} _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return (pointer)__i_.operator->();} + pointer operator->() const {return pointer_traits<pointer>::pointer_to(__i_->__cc);} _LIBCPP_INLINE_VISIBILITY __map_const_iterator& operator++() {++__i_; return *this;} @@ -679,6 +679,7 @@ public: typedef _Key key_type; typedef _Tp mapped_type; typedef pair<const key_type, mapped_type> value_type; + typedef pair<key_type, mapped_type> __nc_value_type; typedef _Compare key_compare; typedef _Allocator allocator_type; typedef value_type& reference; @@ -699,7 +700,54 @@ public: }; private: - typedef pair<key_type, mapped_type> __value_type; + +#if __cplusplus >= 201103L + union __value_type + { + typedef typename map::value_type value_type; + typedef typename map::__nc_value_type __nc_value_type; + value_type __cc; + __nc_value_type __nc; + + template <class ..._Args> + __value_type(_Args&& ...__args) + : __cc(std::forward<_Args>(__args)...) {} + + __value_type(const __value_type& __v) + : __cc(std::move(__v.__cc)) {} + + __value_type(__value_type&& __v) + : __nc(std::move(__v.__nc)) {} + + __value_type& operator=(const __value_type& __v) + {__nc = __v.__cc; return *this;} + + __value_type& operator=(__value_type&& __v) + {__nc = std::move(__v.__nc); return *this;} + + ~__value_type() {__cc.~value_type();} + + operator const value_type& () const {return __cc;} + }; +#else + struct __value_type + { + typedef typename map::value_type value_type; + value_type __cc; + + __value_type() {} + + template <class _A0> + __value_type(const _A0& __a0) + : __cc(__a0) {} + + template <class _A0, class _A1> + __value_type(const _A0& __a0, const _A1& __a1) + : __cc(__a0, __a1) {} + + operator const value_type& () const {return __cc;} + }; +#endif typedef __map_value_compare<key_type, mapped_type, key_compare> __vc; typedef typename allocator_traits<allocator_type>::template #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES @@ -764,7 +812,14 @@ public: _LIBCPP_INLINE_VISIBILITY map& operator=(const map& __m) { +#if __cplusplus >= 201103L __tree_ = __m.__tree_; +#else + __tree_.clear(); + __tree_.value_comp() = __m.__tree_.value_comp(); + __tree_.__copy_assign_alloc(__m.__tree_); + insert(__m.begin(), __m.end()); +#endif return *this; } @@ -1009,9 +1064,6 @@ private: __node_base_pointer& __find_equal_key(__node_base_pointer& __parent, const key_type& __k); - __node_base_pointer& - __find_equal_key(const_iterator __hint, - __node_base_pointer& __parent, const key_type& __k); __node_base_const_pointer __find_equal_key(__node_base_const_pointer& __parent, const key_type& __k) const; }; @@ -1030,97 +1082,37 @@ map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_pointer& __pa { while (true) { - if (__tree_.value_comp().key_comp()(__k, __nd->__value_.first)) + if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first)) { if (__nd->__left_ != nullptr) __nd = static_cast<__node_pointer>(__nd->__left_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent->__left_; } } - else if (__tree_.value_comp().key_comp()(__nd->__value_.first, __k)) + else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k)) { if (__nd->__right_ != nullptr) __nd = static_cast<__node_pointer>(__nd->__right_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent->__right_; } } else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent; } } } - __parent = __tree_.__end_node(); + __parent = static_cast<__node_base_pointer>(__tree_.__end_node()); return __parent->__left_; } -// Find place to insert if __k doesn't exist -// First check prior to __hint. -// Next check after __hint. -// Next do O(log N) search. -// Set __parent to parent of null leaf -// Return reference to null leaf -// If __k exists, set parent to node of __k and return reference to node of __k -template <class _Key, class _Tp, class _Compare, class _Allocator> -typename map<_Key, _Tp, _Compare, _Allocator>::__node_base_pointer& -map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(const_iterator __hint, - __node_base_pointer& __parent, - const key_type& __k) -{ - if (__hint == end() || __tree_.value_comp().key_comp()(__k, __hint->first)) // check before - { - // __k < *__hint - const_iterator __prior = __hint; - if (__prior == begin() || __tree_.value_comp().key_comp()((--__prior)->first, __k)) - { - // *prev(__hint) < __k < *__hint - if (__hint.__ptr_->__left_ == nullptr) - { - __parent = const_cast<__node_pointer&>(__hint.__ptr_); - return __parent->__left_; - } - else - { - __parent = const_cast<__node_pointer&>(__prior.__ptr_); - return __parent->__right_; - } - } - // __k <= *prev(__hint) - return __find_equal_key(__parent, __k); - } - else if (__tree_.value_comp().key_comp()(__hint->first, __k)) // check after - { - // *__hint < __k - const_iterator __next = _VSTD::next(__hint); - if (__next == end() || __tree_.value_comp().key_comp()(__k, __next->first)) - { - // *__hint < __k < *next(__hint) - if (__hint.__ptr_->__right_ == nullptr) - { - __parent = const_cast<__node_pointer&>(__hint.__ptr_); - return __parent->__right_; - } - else - { - __parent = const_cast<__node_pointer&>(__next.__ptr_); - return __parent->__left_; - } - } - // *next(__hint) <= __k - return __find_equal_key(__parent, __k); - } - // else __k == *__hint - __parent = const_cast<__node_pointer&>(__hint.__ptr_); - return __parent; -} - // Find __k // Set __parent to parent of null leaf and // return reference to null leaf iv __k does not exist. @@ -1135,34 +1127,34 @@ map<_Key, _Tp, _Compare, _Allocator>::__find_equal_key(__node_base_const_pointer { while (true) { - if (__tree_.value_comp().key_comp()(__k, __nd->__value_.first)) + if (__tree_.value_comp().key_comp()(__k, __nd->__value_.__cc.first)) { if (__nd->__left_ != nullptr) __nd = static_cast<__node_pointer>(__nd->__left_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return const_cast<const __node_base_const_pointer&>(__parent->__left_); } } - else if (__tree_.value_comp().key_comp()(__nd->__value_.first, __k)) + else if (__tree_.value_comp().key_comp()(__nd->__value_.__cc.first, __k)) { if (__nd->__right_ != nullptr) __nd = static_cast<__node_pointer>(__nd->__right_); else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return const_cast<const __node_base_const_pointer&>(__parent->__right_); } } else { - __parent = __nd; + __parent = static_cast<__node_base_pointer>(__nd); return __parent; } } } - __parent = __tree_.__end_node(); + __parent = static_cast<__node_base_pointer>(__tree_.__end_node()); return const_cast<const __node_base_const_pointer&>(__parent->__left_); } @@ -1187,9 +1179,9 @@ map<_Key, _Tp, _Compare, _Allocator>::__construct_node() { __node_allocator& __na = __tree_.__node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first)); __h.get_deleter().__first_constructed = true; - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); __h.get_deleter().__second_constructed = true; return __h; } @@ -1222,9 +1214,9 @@ map<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0) { __node_allocator& __na = __tree_.__node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), _VSTD::forward<_A0>(__a0)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::forward<_A0>(__a0)); __h.get_deleter().__first_constructed = true; - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); __h.get_deleter().__second_constructed = true; return __h; } @@ -1256,9 +1248,9 @@ map<_Key, _Tp, _Compare, _Allocator>::__construct_node(const key_type& __k) { __node_allocator& __na = __tree_.__node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), __k); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), __k); __h.get_deleter().__first_constructed = true; - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); __h.get_deleter().__second_constructed = true; return _VSTD::move(__h); } @@ -1275,10 +1267,10 @@ map<_Key, _Tp, _Compare, _Allocator>::operator[](const key_type& __k) if (__child == nullptr) { __node_holder __h = __construct_node(__k); - __tree_.__insert_node_at(__parent, __child, __h.get()); + __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); } - return __r->__value_.second; + return __r->__value_.__cc.second; } #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -1293,10 +1285,10 @@ map<_Key, _Tp, _Compare, _Allocator>::operator[](key_type&& __k) if (__child == nullptr) { __node_holder __h = __construct_node(_VSTD::move(__k)); - __tree_.__insert_node_at(__parent, __child, __h.get()); + __tree_.__insert_node_at(__parent, __child, static_cast<__node_base_pointer>(__h.get())); __r = __h.release(); } - return __r->__value_.second; + return __r->__value_.__cc.second; } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES @@ -1311,7 +1303,7 @@ map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) if (__child == nullptr) throw out_of_range("map::at: key not found"); #endif // _LIBCPP_NO_EXCEPTIONS - return static_cast<__node_pointer>(__child)->__value_.second; + return static_cast<__node_pointer>(__child)->__value_.__cc.second; } template <class _Key, class _Tp, class _Compare, class _Allocator> @@ -1324,7 +1316,7 @@ map<_Key, _Tp, _Compare, _Allocator>::at(const key_type& __k) const if (__child == nullptr) throw out_of_range("map::at: key not found"); #endif // _LIBCPP_NO_EXCEPTIONS - return static_cast<__node_const_pointer>(__child)->__value_.second; + return static_cast<__node_const_pointer>(__child)->__value_.__cc.second; } #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS) @@ -1429,6 +1421,7 @@ public: typedef _Key key_type; typedef _Tp mapped_type; typedef pair<const key_type, mapped_type> value_type; + typedef pair<key_type, mapped_type> __nc_value_type; typedef _Compare key_compare; typedef _Allocator allocator_type; typedef value_type& reference; @@ -1450,7 +1443,53 @@ public: }; private: - typedef pair<key_type, mapped_type> __value_type; +#if __cplusplus >= 201103L + union __value_type + { + typedef typename multimap::value_type value_type; + typedef typename multimap::__nc_value_type __nc_value_type; + value_type __cc; + __nc_value_type __nc; + + template <class ..._Args> + __value_type(_Args&& ...__args) + : __cc(std::forward<_Args>(__args)...) {} + + __value_type(const __value_type& __v) + : __cc(std::move(__v.__cc)) {} + + __value_type(__value_type&& __v) + : __nc(std::move(__v.__nc)) {} + + __value_type& operator=(const __value_type& __v) + {__nc = __v.__cc; return *this;} + + __value_type& operator=(__value_type&& __v) + {__nc = std::move(__v.__nc); return *this;} + + ~__value_type() {__cc.~value_type();} + + operator const value_type& () const {return __cc;} + }; +#else + struct __value_type + { + typedef typename multimap::value_type value_type; + value_type __cc; + + __value_type() {} + + template <class _A0> + __value_type(const _A0& __a0) + : __cc(__a0) {} + + template <class _A0, class _A1> + __value_type(const _A0& __a0, const _A1& __a1) + : __cc(__a0, __a1) {} + + operator const value_type& () const {return __cc;} + }; +#endif typedef __map_value_compare<key_type, mapped_type, key_compare> __vc; typedef typename allocator_traits<allocator_type>::template #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES @@ -1516,7 +1555,14 @@ public: _LIBCPP_INLINE_VISIBILITY multimap& operator=(const multimap& __m) { +#if __cplusplus >= 201103L __tree_ = __m.__tree_; +#else + __tree_.clear(); + __tree_.value_comp() = __m.__tree_.value_comp(); + __tree_.__copy_assign_alloc(__m.__tree_); + insert(__m.begin(), __m.end()); +#endif return *this; } @@ -1766,9 +1812,9 @@ multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node() { __node_allocator& __na = __tree_.__node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first)); __h.get_deleter().__first_constructed = true; - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); __h.get_deleter().__second_constructed = true; return __h; } @@ -1801,9 +1847,9 @@ multimap<_Key, _Tp, _Compare, _Allocator>::__construct_node(_A0&& __a0) { __node_allocator& __na = __tree_.__node_alloc(); __node_holder __h(__node_traits::allocate(__na, 1), _Dp(__na)); - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.first), _VSTD::forward<_A0>(__a0)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.first), _VSTD::forward<_A0>(__a0)); __h.get_deleter().__first_constructed = true; - __node_traits::construct(__na, _VSTD::addressof(__h->__value_.second)); + __node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second)); __h.get_deleter().__second_constructed = true; return __h; } diff --git a/libcxx/test/containers/associative/map/map.access/at.pass.cpp b/libcxx/test/containers/associative/map/map.access/at.pass.cpp index 09f70b0f88d..6c001a34428 100644 --- a/libcxx/test/containers/associative/map/map.access/at.pass.cpp +++ b/libcxx/test/containers/associative/map/map.access/at.pass.cpp @@ -17,6 +17,8 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { { @@ -83,4 +85,70 @@ int main() assert(m.at(8) == 8.5); assert(m.size() == 7); } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1.5), + V(2, 2.5), + V(3, 3.5), + V(4, 4.5), + V(5, 5.5), + V(7, 7.5), + V(8, 8.5), + }; + std::map<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 7); + assert(m.at(1) == 1.5); + m.at(1) = -1.5; + assert(m.at(1) == -1.5); + assert(m.at(2) == 2.5); + assert(m.at(3) == 3.5); + assert(m.at(4) == 4.5); + assert(m.at(5) == 5.5); + try + { + m.at(6); + assert(false); + } + catch (std::out_of_range&) + { + } + assert(m.at(7) == 7.5); + assert(m.at(8) == 8.5); + assert(m.size() == 7); + } + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1.5), + V(2, 2.5), + V(3, 3.5), + V(4, 4.5), + V(5, 5.5), + V(7, 7.5), + V(8, 8.5), + }; + const std::map<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 7); + assert(m.at(1) == 1.5); + assert(m.at(2) == 2.5); + assert(m.at(3) == 3.5); + assert(m.at(4) == 4.5); + assert(m.at(5) == 5.5); + try + { + m.at(6); + assert(false); + } + catch (std::out_of_range&) + { + } + assert(m.at(7) == 7.5); + assert(m.at(8) == 8.5); + assert(m.size() == 7); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.access/empty.pass.cpp b/libcxx/test/containers/associative/map/map.access/empty.pass.cpp index b654117f7a7..2e542ac8c32 100644 --- a/libcxx/test/containers/associative/map/map.access/empty.pass.cpp +++ b/libcxx/test/containers/associative/map/map.access/empty.pass.cpp @@ -16,8 +16,11 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { + { typedef std::map<int, double> M; M m; assert(m.empty()); @@ -25,4 +28,16 @@ int main() assert(!m.empty()); m.clear(); assert(m.empty()); + } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + M m; + assert(m.empty()); + m.insert(M::value_type(1, 1.5)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.access/index_key.pass.cpp b/libcxx/test/containers/associative/map/map.access/index_key.pass.cpp index fb82bbedf81..7579088784c 100644 --- a/libcxx/test/containers/associative/map/map.access/index_key.pass.cpp +++ b/libcxx/test/containers/associative/map/map.access/index_key.pass.cpp @@ -16,8 +16,11 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { + { typedef std::pair<const int, double> V; V ar[] = { @@ -41,4 +44,33 @@ int main() m[6] = 6.5; assert(m[6] == 6.5); assert(m.size() == 8); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1.5), + V(2, 2.5), + V(3, 3.5), + V(4, 4.5), + V(5, 5.5), + V(7, 7.5), + V(8, 8.5), + }; + std::map<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 7); + assert(m[1] == 1.5); + assert(m.size() == 7); + const int i = 1; + m[i] = -1.5; + assert(m[1] == -1.5); + assert(m.size() == 7); + assert(m[6] == 0); + assert(m.size() == 8); + m[6] = 6.5; + assert(m[6] == 6.5); + assert(m.size() == 8); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.access/index_rv_key.pass.cpp b/libcxx/test/containers/associative/map/map.access/index_rv_key.pass.cpp index 4efe88c80d7..4c15f088fae 100644 --- a/libcxx/test/containers/associative/map/map.access/index_rv_key.pass.cpp +++ b/libcxx/test/containers/associative/map/map.access/index_rv_key.pass.cpp @@ -17,10 +17,12 @@ #include <cassert> #include "../../../MoveOnly.h" +#include "../../../min_allocator.h" int main() { #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES + { typedef std::pair<MoveOnly, double> V; std::map<MoveOnly, double> m; assert(m.size() == 0); @@ -34,5 +36,23 @@ int main() m[6] = 6.5; assert(m[6] == 6.5); assert(m.size() == 2); + } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::pair<MoveOnly, double> V; + std::map<MoveOnly, double, std::less<MoveOnly>, min_allocator<V>> m; + assert(m.size() == 0); + assert(m[1] == 0.0); + assert(m.size() == 1); + m[1] = -1.5; + assert(m[1] == -1.5); + assert(m.size() == 1); + assert(m[6] == 0); + assert(m.size() == 2); + m[6] = 6.5; + assert(m[6] == 6.5); + assert(m.size() == 2); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.access/iterator.pass.cpp b/libcxx/test/containers/associative/map/map.access/iterator.pass.cpp index d8b2e1a58d5..048c074c296 100644 --- a/libcxx/test/containers/associative/map/map.access/iterator.pass.cpp +++ b/libcxx/test/containers/associative/map/map.access/iterator.pass.cpp @@ -29,6 +29,8 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { { @@ -117,4 +119,92 @@ int main() assert(i->second == 1); } } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + V(4, 1), + V(4, 1.5), + V(4, 2), + V(5, 1), + V(5, 1.5), + V(5, 2), + V(6, 1), + V(6, 1.5), + V(6, 2), + V(7, 1), + V(7, 1.5), + V(7, 2), + V(8, 1), + V(8, 1.5), + V(8, 2) + }; + std::map<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + std::map<int, double, std::less<int>, min_allocator<V>>::iterator i; + i = m.begin(); + std::map<int, double, std::less<int>, min_allocator<V>>::const_iterator k = i; + assert(i == k); + for (int j = 1; j <= m.size(); ++j, ++i) + { + assert(i->first == j); + assert(i->second == 1); + i->second = 2.5; + assert(i->second == 2.5); + } + } + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + V(4, 1), + V(4, 1.5), + V(4, 2), + V(5, 1), + V(5, 1.5), + V(5, 2), + V(6, 1), + V(6, 1.5), + V(6, 2), + V(7, 1), + V(7, 1.5), + V(7, 2), + V(8, 1), + V(8, 1.5), + V(8, 2) + }; + const std::map<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.cbegin(), m.cend()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + assert(std::distance(m.crbegin(), m.crend()) == m.size()); + std::map<int, double, std::less<int>, min_allocator<V>>::const_iterator i; + i = m.begin(); + for (int j = 1; j <= m.size(); ++j, ++i) + { + assert(i->first == j); + assert(i->second == 1); + } + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.access/max_size.pass.cpp b/libcxx/test/containers/associative/map/map.access/max_size.pass.cpp index e63587d4b43..6f86d0e9de8 100644 --- a/libcxx/test/containers/associative/map/map.access/max_size.pass.cpp +++ b/libcxx/test/containers/associative/map/map.access/max_size.pass.cpp @@ -16,9 +16,20 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { + { typedef std::map<int, double> M; M m; assert(m.max_size() != 0); + } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + M m; + assert(m.max_size() != 0); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.access/size.pass.cpp b/libcxx/test/containers/associative/map/map.access/size.pass.cpp index ab4d7c63c33..ab4b05baa5a 100644 --- a/libcxx/test/containers/associative/map/map.access/size.pass.cpp +++ b/libcxx/test/containers/associative/map/map.access/size.pass.cpp @@ -16,8 +16,11 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { + { typedef std::map<int, double> M; M m; assert(m.size() == 0); @@ -33,4 +36,24 @@ int main() assert(m.size() == 1); m.erase(m.begin()); assert(m.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + M m; + assert(m.size() == 0); + m.insert(M::value_type(2, 1.5)); + assert(m.size() == 1); + m.insert(M::value_type(1, 1.5)); + assert(m.size() == 2); + m.insert(M::value_type(3, 1.5)); + assert(m.size() == 3); + m.erase(m.begin()); + assert(m.size() == 2); + m.erase(m.begin()); + assert(m.size() == 1); + m.erase(m.begin()); + assert(m.size() == 0); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.cons/alloc.pass.cpp b/libcxx/test/containers/associative/map/map.cons/alloc.pass.cpp index 1a77f60564c..95d71da664a 100644 --- a/libcxx/test/containers/associative/map/map.cons/alloc.pass.cpp +++ b/libcxx/test/containers/associative/map/map.cons/alloc.pass.cpp @@ -17,13 +17,26 @@ #include <cassert> #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { + { typedef std::less<int> C; typedef test_allocator<std::pair<const int, double> > A; std::map<int, double, C, A> m(A(5)); assert(m.empty()); assert(m.begin() == m.end()); assert(m.get_allocator() == A(5)); + } +#if __cplusplus >= 201103L + { + typedef std::less<int> C; + typedef min_allocator<std::pair<const int, double> > A; + std::map<int, double, C, A> m(A{}); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.get_allocator() == A()); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.cons/assign_initializer_list.pass.cpp b/libcxx/test/containers/associative/map/map.cons/assign_initializer_list.pass.cpp index 2fdf5b294af..a583f0d597f 100644 --- a/libcxx/test/containers/associative/map/map.cons/assign_initializer_list.pass.cpp +++ b/libcxx/test/containers/associative/map/map.cons/assign_initializer_list.pass.cpp @@ -16,9 +16,12 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { typedef std::pair<const int, double> V; std::map<int, double> m = { @@ -41,5 +44,32 @@ int main() assert(*m.begin() == V(1, 1)); assert(*next(m.begin()) == V(2, 1)); assert(*next(m.begin(), 2) == V(3, 1)); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + std::map<int, double, std::less<int>, min_allocator<V>> m = + { + {20, 1}, + }; + m = + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }; + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#endif #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS } diff --git a/libcxx/test/containers/associative/map/map.cons/compare.pass.cpp b/libcxx/test/containers/associative/map/map.cons/compare.pass.cpp index 5648ff0fb66..2c4bb1a8cbc 100644 --- a/libcxx/test/containers/associative/map/map.cons/compare.pass.cpp +++ b/libcxx/test/containers/associative/map/map.cons/compare.pass.cpp @@ -17,12 +17,24 @@ #include <cassert> #include "../../../test_compare.h" +#include "../../../min_allocator.h" int main() { + { typedef test_compare<std::less<int> > C; std::map<int, double, C> m(C(3)); assert(m.empty()); assert(m.begin() == m.end()); assert(m.key_comp() == C(3)); + } +#if __cplusplus >= 201103L + { + typedef test_compare<std::less<int> > C; + std::map<int, double, C, min_allocator<std::pair<const int, double>>> m(C(3)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(3)); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.cons/compare_alloc.pass.cpp b/libcxx/test/containers/associative/map/map.cons/compare_alloc.pass.cpp index 26efa0dabc8..670acffc458 100644 --- a/libcxx/test/containers/associative/map/map.cons/compare_alloc.pass.cpp +++ b/libcxx/test/containers/associative/map/map.cons/compare_alloc.pass.cpp @@ -18,9 +18,11 @@ #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { + { typedef test_compare<std::less<int> > C; typedef test_allocator<std::pair<const int, double> > A; std::map<int, double, C, A> m(C(4), A(5)); @@ -28,4 +30,16 @@ int main() assert(m.begin() == m.end()); assert(m.key_comp() == C(4)); assert(m.get_allocator() == A(5)); + } +#if __cplusplus >= 201103L + { + typedef test_compare<std::less<int> > C; + typedef min_allocator<std::pair<const int, double> > A; + std::map<int, double, C, A> m(C(4), A()); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(4)); + assert(m.get_allocator() == A()); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.cons/copy.pass.cpp b/libcxx/test/containers/associative/map/map.cons/copy.pass.cpp index 01c0d89d5e4..ce20d69d7c9 100644 --- a/libcxx/test/containers/associative/map/map.cons/copy.pass.cpp +++ b/libcxx/test/containers/associative/map/map.cons/copy.pass.cpp @@ -18,6 +18,7 @@ #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { @@ -91,4 +92,40 @@ int main() assert(*next(mo.begin(), 2) == V(3, 1)); } #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::map<int, double, C, A> m = mo; + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == V(1, 1)); + assert(*next(mo.begin()) == V(2, 1)); + assert(*next(mo.begin(), 2) == V(3, 1)); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.cons/copy_alloc.pass.cpp b/libcxx/test/containers/associative/map/map.cons/copy_alloc.pass.cpp index 27b1c9710cc..849240408ab 100644 --- a/libcxx/test/containers/associative/map/map.cons/copy_alloc.pass.cpp +++ b/libcxx/test/containers/associative/map/map.cons/copy_alloc.pass.cpp @@ -18,9 +18,11 @@ #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { + { typedef std::pair<const int, double> V; V ar[] = { @@ -53,4 +55,41 @@ int main() assert(*mo.begin() == V(1, 1)); assert(*next(mo.begin()) == V(2, 1)); assert(*next(mo.begin(), 2) == V(3, 1)); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::map<int, double, C, A> m(mo, A()); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == V(1, 1)); + assert(*next(mo.begin()) == V(2, 1)); + assert(*next(mo.begin(), 2) == V(3, 1)); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.cons/copy_assign.pass.cpp b/libcxx/test/containers/associative/map/map.cons/copy_assign.pass.cpp index 7422ec99a90..fefb35ce712 100644 --- a/libcxx/test/containers/associative/map/map.cons/copy_assign.pass.cpp +++ b/libcxx/test/containers/associative/map/map.cons/copy_assign.pass.cpp @@ -18,6 +18,7 @@ #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { @@ -91,4 +92,76 @@ int main() assert(*next(mo.begin()) == V(2, 1)); assert(*next(mo.begin(), 2) == V(3, 1)); } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2) + }; + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A()); + m = mo; + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == V(1, 1)); + assert(*next(mo.begin()) == V(2, 1)); + assert(*next(mo.begin(), 2) == V(3, 1)); + } + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2) + }; + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A()); + m = mo; + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 3); + assert(distance(mo.begin(), mo.end()) == 3); + assert(*mo.begin() == V(1, 1)); + assert(*next(mo.begin()) == V(2, 1)); + assert(*next(mo.begin(), 2) == V(3, 1)); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.cons/default.pass.cpp b/libcxx/test/containers/associative/map/map.cons/default.pass.cpp index 8b5397c3def..49fc223ffad 100644 --- a/libcxx/test/containers/associative/map/map.cons/default.pass.cpp +++ b/libcxx/test/containers/associative/map/map.cons/default.pass.cpp @@ -16,9 +16,20 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { + { std::map<int, double> m; assert(m.empty()); assert(m.begin() == m.end()); + } +#if __cplusplus >= 201103L + { + std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> m; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.cons/default_recursive.pass.cpp b/libcxx/test/containers/associative/map/map.cons/default_recursive.pass.cpp index 452746c87bb..8b393d3c91c 100644 --- a/libcxx/test/containers/associative/map/map.cons/default_recursive.pass.cpp +++ b/libcxx/test/containers/associative/map/map.cons/default_recursive.pass.cpp @@ -19,7 +19,7 @@ struct X { - std::multimap<int, X> m; + std::map<int, X> m; }; #endif diff --git a/libcxx/test/containers/associative/map/map.cons/initializer_list.pass.cpp b/libcxx/test/containers/associative/map/map.cons/initializer_list.pass.cpp index 4acf2dcab51..63820beea13 100644 --- a/libcxx/test/containers/associative/map/map.cons/initializer_list.pass.cpp +++ b/libcxx/test/containers/associative/map/map.cons/initializer_list.pass.cpp @@ -16,9 +16,12 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { typedef std::pair<const int, double> V; std::map<int, double> m = { @@ -37,5 +40,28 @@ int main() assert(*m.begin() == V(1, 1)); assert(*next(m.begin()) == V(2, 1)); assert(*next(m.begin(), 2) == V(3, 1)); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + std::map<int, double, std::less<int>, min_allocator<V>> m = + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }; + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#endif #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS } diff --git a/libcxx/test/containers/associative/map/map.cons/initializer_list_compare.pass.cpp b/libcxx/test/containers/associative/map/map.cons/initializer_list_compare.pass.cpp index 723a03f49d9..0c3bd23a635 100644 --- a/libcxx/test/containers/associative/map/map.cons/initializer_list_compare.pass.cpp +++ b/libcxx/test/containers/associative/map/map.cons/initializer_list_compare.pass.cpp @@ -16,10 +16,12 @@ #include <map> #include <cassert> #include "../../../test_compare.h" +#include "../../../min_allocator.h" int main() { #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { typedef std::pair<const int, double> V; typedef test_compare<std::less<int> > C; std::map<int, double, C> m({ @@ -39,5 +41,29 @@ int main() assert(*next(m.begin()) == V(2, 1)); assert(*next(m.begin(), 2) == V(3, 1)); assert(m.key_comp() == C(3)); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + typedef test_compare<std::less<int> > C; + std::map<int, double, C, min_allocator<std::pair<const int, double>>> m({ + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }, C(3)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + assert(m.key_comp() == C(3)); + } +#endif #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS } diff --git a/libcxx/test/containers/associative/map/map.cons/initializer_list_compare_alloc.pass.cpp b/libcxx/test/containers/associative/map/map.cons/initializer_list_compare_alloc.pass.cpp index f6300de20b9..14e0eb3d4f7 100644 --- a/libcxx/test/containers/associative/map/map.cons/initializer_list_compare_alloc.pass.cpp +++ b/libcxx/test/containers/associative/map/map.cons/initializer_list_compare_alloc.pass.cpp @@ -17,10 +17,12 @@ #include <cassert> #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { typedef std::pair<const int, double> V; typedef test_compare<std::less<int> > C; typedef test_allocator<std::pair<const int, double> > A; @@ -42,5 +44,31 @@ int main() assert(*next(m.begin(), 2) == V(3, 1)); assert(m.key_comp() == C(3)); assert(m.get_allocator() == A(6)); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + typedef test_compare<std::less<int> > C; + typedef min_allocator<std::pair<const int, double> > A; + std::map<int, double, C, A> m({ + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }, C(3), A()); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + assert(m.key_comp() == C(3)); + assert(m.get_allocator() == A()); + } +#endif #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS } diff --git a/libcxx/test/containers/associative/map/map.cons/iter_iter.pass.cpp b/libcxx/test/containers/associative/map/map.cons/iter_iter.pass.cpp index 00d3d8a2766..d981ccff889 100644 --- a/libcxx/test/containers/associative/map/map.cons/iter_iter.pass.cpp +++ b/libcxx/test/containers/associative/map/map.cons/iter_iter.pass.cpp @@ -17,8 +17,11 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { + { typedef std::pair<const int, double> V; V ar[] = { @@ -38,4 +41,28 @@ int main() assert(*m.begin() == V(1, 1)); assert(*next(m.begin()) == V(2, 1)); assert(*next(m.begin(), 2) == V(3, 1)); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.cons/iter_iter_comp.pass.cpp b/libcxx/test/containers/associative/map/map.cons/iter_iter_comp.pass.cpp index 6f851931ce9..0481de24ccd 100644 --- a/libcxx/test/containers/associative/map/map.cons/iter_iter_comp.pass.cpp +++ b/libcxx/test/containers/associative/map/map.cons/iter_iter_comp.pass.cpp @@ -18,9 +18,11 @@ #include <cassert> #include "../../../test_compare.h" +#include "../../../min_allocator.h" int main() { + { typedef std::pair<const int, double> V; V ar[] = { @@ -42,4 +44,30 @@ int main() assert(*m.begin() == V(1, 1)); assert(*next(m.begin()) == V(2, 1)); assert(*next(m.begin(), 2) == V(3, 1)); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare<std::less<int> > C; + std::map<int, double, C, min_allocator<std::pair<const int, double>>> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5)); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.cons/iter_iter_comp_alloc.pass.cpp b/libcxx/test/containers/associative/map/map.cons/iter_iter_comp_alloc.pass.cpp index abee6d9f0b0..8fabdcc087d 100644 --- a/libcxx/test/containers/associative/map/map.cons/iter_iter_comp_alloc.pass.cpp +++ b/libcxx/test/containers/associative/map/map.cons/iter_iter_comp_alloc.pass.cpp @@ -20,9 +20,11 @@ #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { + { typedef std::pair<const int, double> V; V ar[] = { @@ -46,4 +48,32 @@ int main() assert(*m.begin() == V(1, 1)); assert(*next(m.begin()) == V(2, 1)); assert(*next(m.begin(), 2) == V(3, 1)); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::map<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.cons/move.pass.cpp b/libcxx/test/containers/associative/map/map.cons/move.pass.cpp index b86dd6e382c..323a26548e9 100644 --- a/libcxx/test/containers/associative/map/map.cons/move.pass.cpp +++ b/libcxx/test/containers/associative/map/map.cons/move.pass.cpp @@ -18,6 +18,7 @@ #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { @@ -68,5 +69,52 @@ int main() assert(mo.size() == 0); assert(distance(mo.begin(), mo.end()) == 0); } +#if __cplusplus >= 201103L + { + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::map<int, double, C, A> mo(C(5), A()); + std::map<int, double, C, A> m = std::move(mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 0); + assert(distance(m.begin(), m.end()) == 0); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } + { + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::map<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::map<int, double, C, A> m = std::move(mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/containers/associative/map/map.cons/move_alloc.pass.cpp b/libcxx/test/containers/associative/map/map.cons/move_alloc.pass.cpp index c9675dbd645..2bb2c061258 100644 --- a/libcxx/test/containers/associative/map/map.cons/move_alloc.pass.cpp +++ b/libcxx/test/containers/associative/map/map.cons/move_alloc.pass.cpp @@ -19,6 +19,7 @@ #include "../../../MoveOnly.h" #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { @@ -140,5 +141,46 @@ int main() assert(m3.key_comp() == C(5)); assert(m1.empty()); } +#if __cplusplus >= 201103L + { + typedef std::pair<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef min_allocator<VC> A; + typedef std::map<MoveOnly, MoveOnly, C, A> M; + typedef std::move_iterator<V*> I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A()); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A()); + M m3(std::move(m1), A()); + assert(m3 == m2); + assert(m3.get_allocator() == A()); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/containers/associative/map/map.cons/move_assign.pass.cpp b/libcxx/test/containers/associative/map/map.cons/move_assign.pass.cpp index e8b9a88d97e..2e6ede7bec7 100644 --- a/libcxx/test/containers/associative/map/map.cons/move_assign.pass.cpp +++ b/libcxx/test/containers/associative/map/map.cons/move_assign.pass.cpp @@ -19,6 +19,7 @@ #include "../../../MoveOnly.h" #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { @@ -143,5 +144,47 @@ int main() assert(m3.key_comp() == C(5)); assert(m1.empty()); } +#if __cplusplus >= 201103L + { + typedef std::pair<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef min_allocator<VC> A; + typedef std::map<MoveOnly, MoveOnly, C, A> M; + typedef std::move_iterator<V*> I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A()); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A()); + M m3(C(3), A()); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A()); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/containers/associative/map/map.modifiers/clear.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/clear.pass.cpp index a181e632e88..77f50badfef 100644 --- a/libcxx/test/containers/associative/map/map.modifiers/clear.pass.cpp +++ b/libcxx/test/containers/associative/map/map.modifiers/clear.pass.cpp @@ -16,6 +16,8 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { { @@ -37,4 +39,25 @@ int main() m.clear(); assert(m.size() == 0); } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + typedef std::pair<int, double> P; + P ar[] = + { + P(1, 1.5), + P(2, 2.5), + P(3, 3.5), + P(4, 4.5), + P(5, 5.5), + P(6, 6.5), + P(7, 7.5), + P(8, 8.5), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + m.clear(); + assert(m.size() == 0); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.modifiers/emplace.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/emplace.pass.cpp index 4eb7e9f832a..3ade69db72e 100644 --- a/libcxx/test/containers/associative/map/map.modifiers/emplace.pass.cpp +++ b/libcxx/test/containers/associative/map/map.modifiers/emplace.pass.cpp @@ -20,6 +20,7 @@ #include "../../../Emplaceable.h" #include "../../../DefaultOnly.h" +#include "../../../min_allocator.h" int main() { @@ -88,5 +89,71 @@ int main() assert(m.begin()->first == 2); assert(m.begin()->second == 3.5); } +#if __cplusplus >= 201103L + { + typedef std::map<int, DefaultOnly, std::less<int>, min_allocator<std::pair<const int, DefaultOnly>>> M; + typedef std::pair<M::iterator, bool> R; + M m; + assert(DefaultOnly::count == 0); + R r = m.emplace(); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 0); + assert(m.begin()->second == DefaultOnly()); + assert(DefaultOnly::count == 1); + r = m.emplace(1); + assert(r.second); + assert(r.first == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace(1); + assert(!r.second); + assert(r.first == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + } + assert(DefaultOnly::count == 0); + { + typedef std::map<int, Emplaceable, std::less<int>, min_allocator<std::pair<const int, Emplaceable>>> M; + typedef std::pair<M::iterator, bool> R; + M m; + R r = m.emplace(2); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(!r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + } + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + typedef std::pair<M::iterator, bool> R; + M m; + R r = m.emplace(M::value_type(2, 3.5)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 3.5); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/containers/associative/map/map.modifiers/emplace_hint.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/emplace_hint.pass.cpp index 2bc225e28a7..e1eb586d487 100644 --- a/libcxx/test/containers/associative/map/map.modifiers/emplace_hint.pass.cpp +++ b/libcxx/test/containers/associative/map/map.modifiers/emplace_hint.pass.cpp @@ -19,6 +19,7 @@ #include "../../../Emplaceable.h" #include "../../../DefaultOnly.h" +#include "../../../min_allocator.h" int main() { @@ -82,5 +83,66 @@ int main() assert(m.begin()->first == 2); assert(m.begin()->second == 3.5); } +#if __cplusplus >= 201103L + { + typedef std::map<int, DefaultOnly, std::less<int>, min_allocator<std::pair<const int, DefaultOnly>>> M; + typedef M::iterator R; + M m; + assert(DefaultOnly::count == 0); + R r = m.emplace_hint(m.end()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 0); + assert(m.begin()->second == DefaultOnly()); + assert(DefaultOnly::count == 1); + r = m.emplace_hint(m.end(), 1); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace_hint(m.end(), 1); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + } + assert(DefaultOnly::count == 0); + { + typedef std::map<int, Emplaceable, std::less<int>, min_allocator<std::pair<const int, Emplaceable>>> M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.end(), 2); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace_hint(m.end(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + } + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.end(), M::value_type(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 3.5); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/containers/associative/map/map.modifiers/erase_iter.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/erase_iter.pass.cpp index caf16472e29..086096b7c8b 100644 --- a/libcxx/test/containers/associative/map/map.modifiers/erase_iter.pass.cpp +++ b/libcxx/test/containers/associative/map/map.modifiers/erase_iter.pass.cpp @@ -16,6 +16,8 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { { @@ -124,4 +126,112 @@ int main() assert(i == m.begin()); assert(i == m.end()); } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + typedef std::pair<int, double> P; + typedef M::iterator I; + P ar[] = + { + P(1, 1.5), + P(2, 2.5), + P(3, 3.5), + P(4, 4.5), + P(5, 5.5), + P(6, 6.5), + P(7, 7.5), + P(8, 8.5), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(next(m.cbegin(), 3)); + assert(m.size() == 7); + assert(i == next(m.begin(), 3)); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1.5); + assert(next(m.begin())->first == 2); + assert(next(m.begin())->second == 2.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 3.5); + assert(next(m.begin(), 3)->first == 5); + assert(next(m.begin(), 3)->second == 5.5); + assert(next(m.begin(), 4)->first == 6); + assert(next(m.begin(), 4)->second == 6.5); + assert(next(m.begin(), 5)->first == 7); + assert(next(m.begin(), 5)->second == 7.5); + assert(next(m.begin(), 6)->first == 8); + assert(next(m.begin(), 6)->second == 8.5); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 6); + assert(i == m.begin()); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 3); + assert(next(m.begin())->second == 3.5); + assert(next(m.begin(), 2)->first == 5); + assert(next(m.begin(), 2)->second == 5.5); + assert(next(m.begin(), 3)->first == 6); + assert(next(m.begin(), 3)->second == 6.5); + assert(next(m.begin(), 4)->first == 7); + assert(next(m.begin(), 4)->second == 7.5); + assert(next(m.begin(), 5)->first == 8); + assert(next(m.begin(), 5)->second == 8.5); + + i = m.erase(next(m.cbegin(), 5)); + assert(m.size() == 5); + assert(i == m.end()); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 3); + assert(next(m.begin())->second == 3.5); + assert(next(m.begin(), 2)->first == 5); + assert(next(m.begin(), 2)->second == 5.5); + assert(next(m.begin(), 3)->first == 6); + assert(next(m.begin(), 3)->second == 6.5); + assert(next(m.begin(), 4)->first == 7); + assert(next(m.begin(), 4)->second == 7.5); + + i = m.erase(next(m.cbegin(), 1)); + assert(m.size() == 4); + assert(i == next(m.begin())); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 5); + assert(next(m.begin())->second == 5.5); + assert(next(m.begin(), 2)->first == 6); + assert(next(m.begin(), 2)->second == 6.5); + assert(next(m.begin(), 3)->first == 7); + assert(next(m.begin(), 3)->second == 7.5); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 3); + assert(i == next(m.begin(), 2)); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 5); + assert(next(m.begin())->second == 5.5); + assert(next(m.begin(), 2)->first == 7); + assert(next(m.begin(), 2)->second == 7.5); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 2); + assert(i == next(m.begin(), 2)); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 5); + assert(next(m.begin())->second == 5.5); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 1); + assert(i == next(m.begin(), 0)); + assert(m.begin()->first == 5); + assert(m.begin()->second == 5.5); + + i = m.erase(m.cbegin()); + assert(m.size() == 0); + assert(i == m.begin()); + assert(i == m.end()); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.modifiers/erase_iter_iter.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/erase_iter_iter.pass.cpp index b595d8a0736..6589ace8ff1 100644 --- a/libcxx/test/containers/associative/map/map.modifiers/erase_iter_iter.pass.cpp +++ b/libcxx/test/containers/associative/map/map.modifiers/erase_iter_iter.pass.cpp @@ -16,6 +16,8 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { { @@ -84,4 +86,72 @@ int main() assert(i == m.begin()); assert(i == m.end()); } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + typedef std::pair<int, double> P; + typedef M::iterator I; + P ar[] = + { + P(1, 1.5), + P(2, 2.5), + P(3, 3.5), + P(4, 4.5), + P(5, 5.5), + P(6, 6.5), + P(7, 7.5), + P(8, 8.5), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(m.cbegin(), m.cbegin()); + assert(m.size() == 8); + assert(i == m.begin()); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1.5); + assert(next(m.begin())->first == 2); + assert(next(m.begin())->second == 2.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 3.5); + assert(next(m.begin(), 3)->first == 4); + assert(next(m.begin(), 3)->second == 4.5); + assert(next(m.begin(), 4)->first == 5); + assert(next(m.begin(), 4)->second == 5.5); + assert(next(m.begin(), 5)->first == 6); + assert(next(m.begin(), 5)->second == 6.5); + assert(next(m.begin(), 6)->first == 7); + assert(next(m.begin(), 6)->second == 7.5); + assert(next(m.begin(), 7)->first == 8); + assert(next(m.begin(), 7)->second == 8.5); + + i = m.erase(m.cbegin(), next(m.cbegin(), 2)); + assert(m.size() == 6); + assert(i == m.begin()); + assert(next(m.begin(), 0)->first == 3); + assert(next(m.begin(), 0)->second == 3.5); + assert(next(m.begin(), 1)->first == 4); + assert(next(m.begin(), 1)->second == 4.5); + assert(next(m.begin(), 2)->first == 5); + assert(next(m.begin(), 2)->second == 5.5); + assert(next(m.begin(), 3)->first == 6); + assert(next(m.begin(), 3)->second == 6.5); + assert(next(m.begin(), 4)->first == 7); + assert(next(m.begin(), 4)->second == 7.5); + assert(next(m.begin(), 5)->first == 8); + assert(next(m.begin(), 5)->second == 8.5); + + i = m.erase(next(m.cbegin(), 2), next(m.cbegin(), 6)); + assert(m.size() == 2); + assert(i == next(m.begin(), 2)); + assert(next(m.begin(), 0)->first == 3); + assert(next(m.begin(), 0)->second == 3.5); + assert(next(m.begin(), 1)->first == 4); + assert(next(m.begin(), 1)->second == 4.5); + + i = m.erase(m.cbegin(), m.cend()); + assert(m.size() == 0); + assert(i == m.begin()); + assert(i == m.end()); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.modifiers/erase_key.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/erase_key.pass.cpp index e78a00ff74e..4a93173a704 100644 --- a/libcxx/test/containers/associative/map/map.modifiers/erase_key.pass.cpp +++ b/libcxx/test/containers/associative/map/map.modifiers/erase_key.pass.cpp @@ -16,6 +16,8 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { { @@ -143,4 +145,131 @@ int main() assert(m.size() == 0); assert(s == 1); } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + typedef std::pair<int, double> P; + typedef M::size_type R; + P ar[] = + { + P(1, 1.5), + P(2, 2.5), + P(3, 3.5), + P(4, 4.5), + P(5, 5.5), + P(6, 6.5), + P(7, 7.5), + P(8, 8.5), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + R s = m.erase(9); + assert(s == 0); + assert(m.size() == 8); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1.5); + assert(next(m.begin())->first == 2); + assert(next(m.begin())->second == 2.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 3.5); + assert(next(m.begin(), 3)->first == 4); + assert(next(m.begin(), 3)->second == 4.5); + assert(next(m.begin(), 4)->first == 5); + assert(next(m.begin(), 4)->second == 5.5); + assert(next(m.begin(), 5)->first == 6); + assert(next(m.begin(), 5)->second == 6.5); + assert(next(m.begin(), 6)->first == 7); + assert(next(m.begin(), 6)->second == 7.5); + assert(next(m.begin(), 7)->first == 8); + assert(next(m.begin(), 7)->second == 8.5); + + s = m.erase(4); + assert(m.size() == 7); + assert(s == 1); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1.5); + assert(next(m.begin())->first == 2); + assert(next(m.begin())->second == 2.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 3.5); + assert(next(m.begin(), 3)->first == 5); + assert(next(m.begin(), 3)->second == 5.5); + assert(next(m.begin(), 4)->first == 6); + assert(next(m.begin(), 4)->second == 6.5); + assert(next(m.begin(), 5)->first == 7); + assert(next(m.begin(), 5)->second == 7.5); + assert(next(m.begin(), 6)->first == 8); + assert(next(m.begin(), 6)->second == 8.5); + + s = m.erase(1); + assert(m.size() == 6); + assert(s == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 3); + assert(next(m.begin())->second == 3.5); + assert(next(m.begin(), 2)->first == 5); + assert(next(m.begin(), 2)->second == 5.5); + assert(next(m.begin(), 3)->first == 6); + assert(next(m.begin(), 3)->second == 6.5); + assert(next(m.begin(), 4)->first == 7); + assert(next(m.begin(), 4)->second == 7.5); + assert(next(m.begin(), 5)->first == 8); + assert(next(m.begin(), 5)->second == 8.5); + + s = m.erase(8); + assert(m.size() == 5); + assert(s == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 3); + assert(next(m.begin())->second == 3.5); + assert(next(m.begin(), 2)->first == 5); + assert(next(m.begin(), 2)->second == 5.5); + assert(next(m.begin(), 3)->first == 6); + assert(next(m.begin(), 3)->second == 6.5); + assert(next(m.begin(), 4)->first == 7); + assert(next(m.begin(), 4)->second == 7.5); + + s = m.erase(3); + assert(m.size() == 4); + assert(s == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 5); + assert(next(m.begin())->second == 5.5); + assert(next(m.begin(), 2)->first == 6); + assert(next(m.begin(), 2)->second == 6.5); + assert(next(m.begin(), 3)->first == 7); + assert(next(m.begin(), 3)->second == 7.5); + + s = m.erase(6); + assert(m.size() == 3); + assert(s == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 5); + assert(next(m.begin())->second == 5.5); + assert(next(m.begin(), 2)->first == 7); + assert(next(m.begin(), 2)->second == 7.5); + + s = m.erase(7); + assert(m.size() == 2); + assert(s == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 2.5); + assert(next(m.begin())->first == 5); + assert(next(m.begin())->second == 5.5); + + s = m.erase(2); + assert(m.size() == 1); + assert(s == 1); + assert(m.begin()->first == 5); + assert(m.begin()->second == 5.5); + + s = m.erase(5); + assert(m.size() == 0); + assert(s == 1); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.modifiers/insert_cv.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/insert_cv.pass.cpp index f405c4c3765..24d3f84ea30 100644 --- a/libcxx/test/containers/associative/map/map.modifiers/insert_cv.pass.cpp +++ b/libcxx/test/containers/associative/map/map.modifiers/insert_cv.pass.cpp @@ -16,6 +16,8 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { { @@ -50,4 +52,38 @@ int main() assert(r.first->first == 3); assert(r.first->second == 3.5); } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + typedef std::pair<M::iterator, bool> R; + M m; + R r = m.insert(M::value_type(2, 2.5)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(r.first->first == 2); + assert(r.first->second == 2.5); + + r = m.insert(M::value_type(1, 1.5)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(r.first->first == 1); + assert(r.first->second == 1.5); + + r = m.insert(M::value_type(3, 3.5)); + assert(r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(r.first->first == 3); + assert(r.first->second == 3.5); + + r = m.insert(M::value_type(3, 3.5)); + assert(!r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(r.first->first == 3); + assert(r.first->second == 3.5); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.modifiers/insert_initializer_list.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/insert_initializer_list.pass.cpp index 66714d53eb5..bc7e760fad0 100644 --- a/libcxx/test/containers/associative/map/map.modifiers/insert_initializer_list.pass.cpp +++ b/libcxx/test/containers/associative/map/map.modifiers/insert_initializer_list.pass.cpp @@ -16,9 +16,12 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { typedef std::pair<const int, double> V; std::map<int, double> m = { @@ -39,5 +42,30 @@ int main() assert(*m.begin() == V(1, 1)); assert(*next(m.begin()) == V(2, 1)); assert(*next(m.begin(), 2) == V(3, 1)); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + std::map<int, double, std::less<int>, min_allocator<V>> m = + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }; + m.insert({ + {2, 1}, + {2, 1.5}, + {2, 2}, + }); + assert(m.size() == 3); + assert(distance(m.begin(), m.end()) == 3); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(2, 1)); + assert(*next(m.begin(), 2) == V(3, 1)); + } +#endif #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS } diff --git a/libcxx/test/containers/associative/map/map.modifiers/insert_iter_cv.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/insert_iter_cv.pass.cpp index 105b4564dcd..43ca35a099f 100644 --- a/libcxx/test/containers/associative/map/map.modifiers/insert_iter_cv.pass.cpp +++ b/libcxx/test/containers/associative/map/map.modifiers/insert_iter_cv.pass.cpp @@ -16,6 +16,8 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { { @@ -46,4 +48,34 @@ int main() assert(r->first == 3); assert(r->second == 3.5); } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + typedef M::iterator R; + M m; + R r = m.insert(m.end(), M::value_type(2, 2.5)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2.5); + + r = m.insert(m.end(), M::value_type(1, 1.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1.5); + + r = m.insert(m.end(), M::value_type(3, 3.5)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3.5); + + r = m.insert(m.end(), M::value_type(3, 3.5)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3.5); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.modifiers/insert_iter_iter.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/insert_iter_iter.pass.cpp index 307e3e42f39..d1acdf2b826 100644 --- a/libcxx/test/containers/associative/map/map.modifiers/insert_iter_iter.pass.cpp +++ b/libcxx/test/containers/associative/map/map.modifiers/insert_iter_iter.pass.cpp @@ -18,6 +18,7 @@ #include <cassert> #include "test_iterators.h" +#include "../../../min_allocator.h" int main() { @@ -46,4 +47,31 @@ int main() assert(next(m.begin(), 2)->first == 3); assert(next(m.begin(), 2)->second == 1); } +#if __cplusplus >= 201103L + { + typedef std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + typedef std::pair<int, double> P; + P ar[] = + { + P(1, 1), + P(1, 1.5), + P(1, 2), + P(2, 1), + P(2, 1.5), + P(2, 2), + P(3, 1), + P(3, 1.5), + P(3, 2), + }; + M m; + m.insert(input_iterator<P*>(ar), input_iterator<P*>(ar + sizeof(ar)/sizeof(ar[0]))); + assert(m.size() == 3); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1); + assert(next(m.begin())->first == 2); + assert(next(m.begin())->second == 1); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 1); + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp index 620c0159033..e84a82b609a 100644 --- a/libcxx/test/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp +++ b/libcxx/test/containers/associative/map/map.modifiers/insert_iter_rv.pass.cpp @@ -18,6 +18,7 @@ #include <cassert> #include "../../../MoveOnly.h" +#include "../../../min_allocator.h" int main() { @@ -51,5 +52,36 @@ int main() assert(r->first == 3); assert(r->second == 3); } +#if __cplusplus >= 201103L + { + typedef std::map<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M; + typedef std::pair<int, MoveOnly> P; + typedef M::iterator R; + M m; + R r = m.insert(m.end(), P(2, 2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2); + + r = m.insert(m.end(), P(1, 1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1); + + r = m.insert(m.end(), P(3, 3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3); + + r = m.insert(m.end(), P(3, 3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/containers/associative/map/map.modifiers/insert_rv.pass.cpp b/libcxx/test/containers/associative/map/map.modifiers/insert_rv.pass.cpp index b95202b32f8..c5724c42980 100644 --- a/libcxx/test/containers/associative/map/map.modifiers/insert_rv.pass.cpp +++ b/libcxx/test/containers/associative/map/map.modifiers/insert_rv.pass.cpp @@ -18,6 +18,7 @@ #include <cassert> #include "../../../MoveOnly.h" +#include "../../../min_allocator.h" int main() { @@ -54,5 +55,39 @@ int main() assert(r.first->first == 3); assert(r.first->second == 3); } +#if __cplusplus >= 201103L + { + typedef std::map<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M; + typedef std::pair<M::iterator, bool> R; + M m; + R r = m.insert(M::value_type(2, 2)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 1); + assert(r.first->first == 2); + assert(r.first->second == 2); + + r = m.insert(M::value_type(1, 1)); + assert(r.second); + assert(r.first == m.begin()); + assert(m.size() == 2); + assert(r.first->first == 1); + assert(r.first->second == 1); + + r = m.insert(M::value_type(3, 3)); + assert(r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(r.first->first == 3); + assert(r.first->second == 3); + + r = m.insert(M::value_type(3, 3)); + assert(!r.second); + assert(r.first == prev(m.end())); + assert(m.size() == 3); + assert(r.first->first == 3); + assert(r.first->second == 3); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/containers/associative/map/map.ops/count.pass.cpp b/libcxx/test/containers/associative/map/map.ops/count.pass.cpp index 427feff970b..70eadac3f8f 100644 --- a/libcxx/test/containers/associative/map/map.ops/count.pass.cpp +++ b/libcxx/test/containers/associative/map/map.ops/count.pass.cpp @@ -16,8 +16,11 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { + { typedef std::pair<const int, double> V; typedef std::map<int, double> M; { @@ -53,4 +56,44 @@ int main() r = m.count(4); assert(r == 0); } + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + typedef std::map<int, double, std::less<int>, min_allocator<V>> M; + { + typedef M::size_type R; + V ar[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.count(5); + assert(r == 1); + r = m.count(6); + assert(r == 1); + r = m.count(7); + assert(r == 1); + r = m.count(8); + assert(r == 1); + r = m.count(9); + assert(r == 1); + r = m.count(10); + assert(r == 1); + r = m.count(11); + assert(r == 1); + r = m.count(12); + assert(r == 1); + r = m.count(4); + assert(r == 0); + } + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.ops/equal_range.pass.cpp b/libcxx/test/containers/associative/map/map.ops/equal_range.pass.cpp index 057ef6a4458..dc0d09760a9 100644 --- a/libcxx/test/containers/associative/map/map.ops/equal_range.pass.cpp +++ b/libcxx/test/containers/associative/map/map.ops/equal_range.pass.cpp @@ -17,8 +17,11 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { + { typedef std::pair<const int, double> V; typedef std::map<int, double> M; { @@ -153,4 +156,143 @@ int main() assert(r.first == next(m.begin(), 8)); assert(r.second == next(m.begin(), 8)); } + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + typedef std::map<int, double, std::less<int>, min_allocator<V>> M; + { + typedef std::pair<M::iterator, M::iterator> R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(11); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(13); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(15); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(17); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(19); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 8)); + r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(12); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(14); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(16); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(18); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(20); + assert(r.first == next(m.begin(), 8)); + assert(r.second == next(m.begin(), 8)); + } + { + typedef std::pair<M::const_iterator, M::const_iterator> R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(11); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(13); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(15); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(17); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(19); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 8)); + r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 1)); + assert(r.second == next(m.begin(), 1)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 2)); + assert(r.second == next(m.begin(), 2)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(12); + assert(r.first == next(m.begin(), 4)); + assert(r.second == next(m.begin(), 4)); + r = m.equal_range(14); + assert(r.first == next(m.begin(), 5)); + assert(r.second == next(m.begin(), 5)); + r = m.equal_range(16); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(18); + assert(r.first == next(m.begin(), 7)); + assert(r.second == next(m.begin(), 7)); + r = m.equal_range(20); + assert(r.first == next(m.begin(), 8)); + assert(r.second == next(m.begin(), 8)); + } + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.ops/find.pass.cpp b/libcxx/test/containers/associative/map/map.ops/find.pass.cpp index afebf129474..a368dc5e7aa 100644 --- a/libcxx/test/containers/associative/map/map.ops/find.pass.cpp +++ b/libcxx/test/containers/associative/map/map.ops/find.pass.cpp @@ -17,8 +17,11 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { + { typedef std::pair<const int, double> V; typedef std::map<int, double> M; { @@ -87,4 +90,77 @@ int main() r = m.find(4); assert(r == next(m.begin(), 8)); } + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + typedef std::map<int, double, std::less<int>, min_allocator<V>> M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.ops/lower_bound.pass.cpp b/libcxx/test/containers/associative/map/map.ops/lower_bound.pass.cpp index f2f03cf37fe..a1b8e5b3c2e 100644 --- a/libcxx/test/containers/associative/map/map.ops/lower_bound.pass.cpp +++ b/libcxx/test/containers/associative/map/map.ops/lower_bound.pass.cpp @@ -17,8 +17,11 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { + { typedef std::pair<const int, double> V; typedef std::map<int, double> M; { @@ -119,4 +122,109 @@ int main() r = m.lower_bound(20); assert(r == next(m.begin(), 8)); } + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + typedef std::map<int, double, std::less<int>, min_allocator<V>> M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(7); + assert(r == next(m.begin())); + r = m.lower_bound(9); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(13); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(15); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(17); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(19); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 1)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 2)); + r = m.lower_bound(10); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(12); + assert(r == next(m.begin(), 4)); + r = m.lower_bound(14); + assert(r == next(m.begin(), 5)); + r = m.lower_bound(16); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(18); + assert(r == next(m.begin(), 7)); + r = m.lower_bound(20); + assert(r == next(m.begin(), 8)); + } + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.ops/upper_bound.pass.cpp b/libcxx/test/containers/associative/map/map.ops/upper_bound.pass.cpp index 0d97e70ee4a..eee08aee31b 100644 --- a/libcxx/test/containers/associative/map/map.ops/upper_bound.pass.cpp +++ b/libcxx/test/containers/associative/map/map.ops/upper_bound.pass.cpp @@ -17,8 +17,11 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { + { typedef std::pair<const int, double> V; typedef std::map<int, double> M; { @@ -119,4 +122,109 @@ int main() r = m.upper_bound(20); assert(r == next(m.begin(), 8)); } + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + typedef std::map<int, double, std::less<int>, min_allocator<V>> M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 5), + V(7, 6), + V(9, 7), + V(11, 8), + V(13, 9), + V(15, 10), + V(17, 11), + V(19, 12) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(5); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(13); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(15); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(17); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(19); + assert(r == next(m.begin(), 8)); + r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 1)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 2)); + r = m.upper_bound(10); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(12); + assert(r == next(m.begin(), 4)); + r = m.upper_bound(14); + assert(r == next(m.begin(), 5)); + r = m.upper_bound(16); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(18); + assert(r == next(m.begin(), 7)); + r = m.upper_bound(20); + assert(r == next(m.begin(), 8)); + } + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.special/member_swap.pass.cpp b/libcxx/test/containers/associative/map/map.special/member_swap.pass.cpp index 84513450e50..af5922526a0 100644 --- a/libcxx/test/containers/associative/map/map.special/member_swap.pass.cpp +++ b/libcxx/test/containers/associative/map/map.special/member_swap.pass.cpp @@ -16,8 +16,11 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { + { typedef std::pair<const int, double> V; typedef std::map<int, double> M; { @@ -104,4 +107,95 @@ int main() assert(m1 == m2_save); assert(m2 == m1_save); } + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + typedef std::map<int, double, std::less<int>, min_allocator<V>> M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#endif } diff --git a/libcxx/test/containers/associative/map/map.special/non_member_swap.pass.cpp b/libcxx/test/containers/associative/map/map.special/non_member_swap.pass.cpp index ef67892a7a7..e474a4661bb 100644 --- a/libcxx/test/containers/associative/map/map.special/non_member_swap.pass.cpp +++ b/libcxx/test/containers/associative/map/map.special/non_member_swap.pass.cpp @@ -19,9 +19,11 @@ #include <cassert> #include "../../../test_allocator.h" #include "../../../test_compare.h" +#include "../../../min_allocator.h" int main() { + { typedef std::pair<const int, double> V; typedef std::map<int, double> M; { @@ -176,4 +178,129 @@ int main() assert(m2.key_comp() == C(1)); assert(m2.get_allocator() == A(1)); } + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + typedef std::map<int, double, std::less<int>, min_allocator<V>> M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + typedef min_allocator<V> A; + typedef test_compare<std::less<int> > C; + typedef std::map<int, double, C, A> M; + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A()); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A()); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + assert(m1.key_comp() == C(2)); + assert(m1.get_allocator() == A()); + assert(m2.key_comp() == C(1)); + assert(m2.get_allocator() == A()); + } + } +#endif } diff --git a/libcxx/test/containers/associative/map/types.pass.cpp b/libcxx/test/containers/associative/map/types.pass.cpp index 313b7bdbbac..aca81dfb964 100644 --- a/libcxx/test/containers/associative/map/types.pass.cpp +++ b/libcxx/test/containers/associative/map/types.pass.cpp @@ -32,8 +32,11 @@ #include <map> #include <type_traits> +#include "../../min_allocator.h" + int main() { + { static_assert((std::is_same<std::map<int, double>::key_type, int>::value), ""); static_assert((std::is_same<std::map<int, double>::mapped_type, double>::value), ""); static_assert((std::is_same<std::map<int, double>::value_type, std::pair<const int, double> >::value), ""); @@ -45,4 +48,20 @@ int main() static_assert((std::is_same<std::map<int, double>::const_pointer, const std::pair<const int, double>*>::value), ""); static_assert((std::is_same<std::map<int, double>::size_type, std::size_t>::value), ""); static_assert((std::is_same<std::map<int, double>::difference_type, std::ptrdiff_t>::value), ""); + } +#if __cplusplus >= 201103L + { + static_assert((std::is_same<std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::key_type, int>::value), ""); + static_assert((std::is_same<std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::mapped_type, double>::value), ""); + static_assert((std::is_same<std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::value_type, std::pair<const int, double> >::value), ""); + static_assert((std::is_same<std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::key_compare, std::less<int> >::value), ""); + static_assert((std::is_same<std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::allocator_type, min_allocator<std::pair<const int, double> > >::value), ""); + static_assert((std::is_same<std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::reference, std::pair<const int, double>&>::value), ""); + static_assert((std::is_same<std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::const_reference, const std::pair<const int, double>&>::value), ""); + static_assert((std::is_same<std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::pointer, min_pointer<std::pair<const int, double>>>::value), ""); + static_assert((std::is_same<std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::const_pointer, min_pointer<const std::pair<const int, double>>>::value), ""); + static_assert((std::is_same<std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::size_type, std::size_t>::value), ""); + static_assert((std::is_same<std::map<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::difference_type, std::ptrdiff_t>::value), ""); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/empty.pass.cpp b/libcxx/test/containers/associative/multimap/empty.pass.cpp index c54920e03bd..cafdb7344c8 100644 --- a/libcxx/test/containers/associative/multimap/empty.pass.cpp +++ b/libcxx/test/containers/associative/multimap/empty.pass.cpp @@ -16,8 +16,11 @@ #include <map> #include <cassert> +#include "../../min_allocator.h" + int main() { + { typedef std::multimap<int, double> M; M m; assert(m.empty()); @@ -25,4 +28,16 @@ int main() assert(!m.empty()); m.clear(); assert(m.empty()); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + M m; + assert(m.empty()); + m.insert(M::value_type(1, 1.5)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/iterator.pass.cpp b/libcxx/test/containers/associative/multimap/iterator.pass.cpp index dfb2fdf5cd8..283b32dc912 100644 --- a/libcxx/test/containers/associative/multimap/iterator.pass.cpp +++ b/libcxx/test/containers/associative/multimap/iterator.pass.cpp @@ -29,6 +29,8 @@ #include <map> #include <cassert> +#include "../../min_allocator.h" + int main() { { @@ -119,4 +121,94 @@ int main() assert(i->second == d); } } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + V(4, 1), + V(4, 1.5), + V(4, 2), + V(5, 1), + V(5, 1.5), + V(5, 2), + V(6, 1), + V(6, 1.5), + V(6, 2), + V(7, 1), + V(7, 1.5), + V(7, 2), + V(8, 1), + V(8, 1.5), + V(8, 2) + }; + std::multimap<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + std::multimap<int, double, std::less<int>, min_allocator<V>>::iterator i; + i = m.begin(); + std::multimap<int, double, std::less<int>, min_allocator<V>>::const_iterator k = i; + assert(i == k); + for (int j = 1; j <= 8; ++j) + for (double d = 1; d <= 2; d += .5, ++i) + { + assert(i->first == j); + assert(i->second == d); + i->second = 2.5; + assert(i->second == 2.5); + } + } + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + V(4, 1), + V(4, 1.5), + V(4, 2), + V(5, 1), + V(5, 1.5), + V(5, 2), + V(6, 1), + V(6, 1.5), + V(6, 2), + V(7, 1), + V(7, 1.5), + V(7, 2), + V(8, 1), + V(8, 1.5), + V(8, 2) + }; + const std::multimap<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.cbegin(), m.cend()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + assert(std::distance(m.crbegin(), m.crend()) == m.size()); + std::multimap<int, double, std::less<int>, min_allocator<V>>::const_iterator i; + i = m.begin(); + for (int j = 1; j <= 8; ++j) + for (double d = 1; d <= 2; d += .5, ++i) + { + assert(i->first == j); + assert(i->second == d); + } + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/max_size.pass.cpp b/libcxx/test/containers/associative/multimap/max_size.pass.cpp index 2fcd56916ad..7bcb12a2e80 100644 --- a/libcxx/test/containers/associative/multimap/max_size.pass.cpp +++ b/libcxx/test/containers/associative/multimap/max_size.pass.cpp @@ -16,9 +16,20 @@ #include <map> #include <cassert> +#include "../../min_allocator.h" + int main() { + { typedef std::multimap<int, double> M; M m; assert(m.max_size() != 0); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + M m; + assert(m.max_size() != 0); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/alloc.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/alloc.pass.cpp index 3087c2e4408..aa3b6e2e6d2 100644 --- a/libcxx/test/containers/associative/multimap/multimap.cons/alloc.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.cons/alloc.pass.cpp @@ -17,13 +17,26 @@ #include <cassert> #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { + { typedef std::less<int> C; typedef test_allocator<std::pair<const int, double> > A; std::multimap<int, double, C, A> m(A(5)); assert(m.empty()); assert(m.begin() == m.end()); assert(m.get_allocator() == A(5)); + } +#if __cplusplus >= 201103L + { + typedef std::less<int> C; + typedef min_allocator<std::pair<const int, double> > A; + std::multimap<int, double, C, A> m(A{}); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.get_allocator() == A()); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/assign_initializer_list.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/assign_initializer_list.pass.cpp index 73e8f24ff48..8c658d4f61a 100644 --- a/libcxx/test/containers/associative/multimap/multimap.cons/assign_initializer_list.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.cons/assign_initializer_list.pass.cpp @@ -16,9 +16,12 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { typedef std::multimap<int, double> C; typedef C::value_type V; C m = {{20, 1}}; @@ -46,5 +49,37 @@ int main() assert(*++i == V(3, 1)); assert(*++i == V(3, 1.5)); assert(*++i == V(3, 2)); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> C; + typedef C::value_type V; + C m = {{20, 1}}; + m = + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }; + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + C::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(1, 2)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(2, 2)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 1.5)); + assert(*++i == V(3, 2)); + } +#endif #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS } diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/compare.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/compare.pass.cpp index 594db420db5..99265ef72f8 100644 --- a/libcxx/test/containers/associative/multimap/multimap.cons/compare.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.cons/compare.pass.cpp @@ -17,12 +17,24 @@ #include <cassert> #include "../../../test_compare.h" +#include "../../../min_allocator.h" int main() { + { typedef test_compare<std::less<int> > C; std::multimap<int, double, C> m(C(3)); assert(m.empty()); assert(m.begin() == m.end()); assert(m.key_comp() == C(3)); + } +#if __cplusplus >= 201103L + { + typedef test_compare<std::less<int> > C; + std::multimap<int, double, C, min_allocator<std::pair<const int, double>>> m(C(3)); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(3)); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/compare_alloc.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/compare_alloc.pass.cpp index 93546838b75..864a5429974 100644 --- a/libcxx/test/containers/associative/multimap/multimap.cons/compare_alloc.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.cons/compare_alloc.pass.cpp @@ -18,9 +18,11 @@ #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { + { typedef test_compare<std::less<int> > C; typedef test_allocator<std::pair<const int, double> > A; std::multimap<int, double, C, A> m(C(4), A(5)); @@ -28,4 +30,16 @@ int main() assert(m.begin() == m.end()); assert(m.key_comp() == C(4)); assert(m.get_allocator() == A(5)); + } +#if __cplusplus >= 201103L + { + typedef test_compare<std::less<int> > C; + typedef min_allocator<std::pair<const int, double> > A; + std::multimap<int, double, C, A> m(C(4), A()); + assert(m.empty()); + assert(m.begin() == m.end()); + assert(m.key_comp() == C(4)); + assert(m.get_allocator() == A()); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/copy.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/copy.pass.cpp index b995b6eb8c1..65a1e921a47 100644 --- a/libcxx/test/containers/associative/multimap/multimap.cons/copy.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.cons/copy.pass.cpp @@ -18,6 +18,7 @@ #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { @@ -73,4 +74,31 @@ int main() assert(mo.key_comp() == C(5)); } #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::multimap<int, double, C, A> m = mo; + assert(m == mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/copy_alloc.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/copy_alloc.pass.cpp index bbbc397533d..a9cba17de93 100644 --- a/libcxx/test/containers/associative/multimap/multimap.cons/copy_alloc.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.cons/copy_alloc.pass.cpp @@ -18,9 +18,11 @@ #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { + { typedef std::pair<const int, double> V; V ar[] = { @@ -44,4 +46,32 @@ int main() assert(mo.get_allocator() == A(7)); assert(mo.key_comp() == C(5)); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::multimap<int, double, C, A> m(mo, A()); + assert(m == mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/copy_assign.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/copy_assign.pass.cpp index 9b698035124..533338c9683 100644 --- a/libcxx/test/containers/associative/multimap/multimap.cons/copy_assign.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.cons/copy_assign.pass.cpp @@ -18,6 +18,7 @@ #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { @@ -73,4 +74,32 @@ int main() assert(mo.get_allocator() == A(2)); assert(mo.key_comp() == C(5)); } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::multimap<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0])/2, C(3), A()); + m = mo; + assert(m == mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/default.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/default.pass.cpp index d2e3f60483b..ca8225f3738 100644 --- a/libcxx/test/containers/associative/multimap/multimap.cons/default.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.cons/default.pass.cpp @@ -16,9 +16,20 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { + { std::multimap<int, double> m; assert(m.empty()); assert(m.begin() == m.end()); + } +#if __cplusplus >= 201103L + { + std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> m; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list.pass.cpp index 7683506f663..139052c5730 100644 --- a/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list.pass.cpp @@ -16,9 +16,12 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { typedef std::multimap<int, double> C; typedef C::value_type V; C m = @@ -45,5 +48,36 @@ int main() assert(*++i == V(3, 1)); assert(*++i == V(3, 1.5)); assert(*++i == V(3, 2)); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> C; + typedef C::value_type V; + C m = + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }; + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + C::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(1, 2)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(2, 2)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 1.5)); + assert(*++i == V(3, 2)); + } +#endif #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS } diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list_compare.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list_compare.pass.cpp index 6d7f546ea41..f2545c0cbc1 100644 --- a/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list_compare.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list_compare.pass.cpp @@ -16,10 +16,12 @@ #include <map> #include <cassert> #include "../../../test_compare.h" +#include "../../../min_allocator.h" int main() { #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { typedef test_compare<std::less<int> > Cmp; typedef std::multimap<int, double, Cmp> C; typedef C::value_type V; @@ -50,5 +52,40 @@ int main() assert(*++i == V(3, 1.5)); assert(*++i == V(3, 2)); assert(m.key_comp() == Cmp(4)); + } +#if __cplusplus >= 201103L + { + typedef test_compare<std::less<int> > Cmp; + typedef std::multimap<int, double, Cmp, min_allocator<std::pair<const int, double>>> C; + typedef C::value_type V; + C m( + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }, + Cmp(4) + ); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + C::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(1, 2)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(2, 2)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 1.5)); + assert(*++i == V(3, 2)); + assert(m.key_comp() == Cmp(4)); + } +#endif #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS } diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list_compare_alloc.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list_compare_alloc.pass.cpp index 47b48f1ef80..3f4073be082 100644 --- a/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list_compare_alloc.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.cons/initializer_list_compare_alloc.pass.cpp @@ -17,10 +17,12 @@ #include <cassert> #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { typedef test_compare<std::less<int> > Cmp; typedef test_allocator<std::pair<const int, double> > A; typedef std::multimap<int, double, Cmp, A> C; @@ -53,5 +55,42 @@ int main() assert(*++i == V(3, 2)); assert(m.key_comp() == Cmp(4)); assert(m.get_allocator() == A(5)); + } #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#if __cplusplus >= 201103L + { + typedef test_compare<std::less<int> > Cmp; + typedef min_allocator<std::pair<const int, double> > A; + typedef std::multimap<int, double, Cmp, A> C; + typedef C::value_type V; + C m( + { + {1, 1}, + {1, 1.5}, + {1, 2}, + {2, 1}, + {2, 1.5}, + {2, 2}, + {3, 1}, + {3, 1.5}, + {3, 2} + }, + Cmp(4), A() + ); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + C::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(1, 2)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(2, 2)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 1.5)); + assert(*++i == V(3, 2)); + assert(m.key_comp() == Cmp(4)); + assert(m.get_allocator() == A()); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter.pass.cpp index 00556ebcbf0..3095cb56f33 100644 --- a/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter.pass.cpp @@ -17,8 +17,11 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { + { typedef std::pair<const int, double> V; V ar[] = { @@ -44,4 +47,34 @@ int main() assert(*next(m.begin(), 6) == V(3, 1)); assert(*next(m.begin(), 7) == V(3, 1.5)); assert(*next(m.begin(), 8) == V(3, 2)); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + std::multimap<int, double, std::less<int>, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(1, 1.5)); + assert(*next(m.begin(), 2) == V(1, 2)); + assert(*next(m.begin(), 3) == V(2, 1)); + assert(*next(m.begin(), 4) == V(2, 1.5)); + assert(*next(m.begin(), 5) == V(2, 2)); + assert(*next(m.begin(), 6) == V(3, 1)); + assert(*next(m.begin(), 7) == V(3, 1.5)); + assert(*next(m.begin(), 8) == V(3, 2)); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter_comp.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter_comp.pass.cpp index 57f879615f6..267edc21061 100644 --- a/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter_comp.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter_comp.pass.cpp @@ -19,9 +19,11 @@ #include <cassert> #include "../../../test_compare.h" +#include "../../../min_allocator.h" int main() { + { typedef std::pair<const int, double> V; V ar[] = { @@ -49,4 +51,36 @@ int main() assert(*next(m.begin(), 6) == V(3, 1)); assert(*next(m.begin(), 7) == V(3, 1.5)); assert(*next(m.begin(), 8) == V(3, 2)); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare<std::less<int> > C; + std::multimap<int, double, C, min_allocator<V>> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5)); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(1, 1.5)); + assert(*next(m.begin(), 2) == V(1, 2)); + assert(*next(m.begin(), 3) == V(2, 1)); + assert(*next(m.begin(), 4) == V(2, 1.5)); + assert(*next(m.begin(), 5) == V(2, 2)); + assert(*next(m.begin(), 6) == V(3, 1)); + assert(*next(m.begin(), 7) == V(3, 1.5)); + assert(*next(m.begin(), 8) == V(3, 2)); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter_comp_alloc.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter_comp_alloc.pass.cpp index c7b0d97a5aa..883f64c8e93 100644 --- a/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter_comp_alloc.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.cons/iter_iter_comp_alloc.pass.cpp @@ -20,9 +20,11 @@ #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { + { typedef std::pair<const int, double> V; V ar[] = { @@ -52,4 +54,38 @@ int main() assert(*next(m.begin(), 6) == V(3, 1)); assert(*next(m.begin(), 7) == V(3, 1.5)); assert(*next(m.begin(), 8) == V(3, 2)); + } +#if __cplusplus >= 201103L + { + typedef std::pair<const int, double> V; + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::multimap<int, double, C, A> m(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(1, 1.5)); + assert(*next(m.begin(), 2) == V(1, 2)); + assert(*next(m.begin(), 3) == V(2, 1)); + assert(*next(m.begin(), 4) == V(2, 1.5)); + assert(*next(m.begin(), 5) == V(2, 2)); + assert(*next(m.begin(), 6) == V(3, 1)); + assert(*next(m.begin(), 7) == V(3, 1.5)); + assert(*next(m.begin(), 8) == V(3, 2)); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/move.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/move.pass.cpp index 815fc55676c..d6e835ca477 100644 --- a/libcxx/test/containers/associative/multimap/multimap.cons/move.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.cons/move.pass.cpp @@ -18,6 +18,7 @@ #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { @@ -74,5 +75,58 @@ int main() assert(mo.size() == 0); assert(distance(mo.begin(), mo.end()) == 0); } +#if __cplusplus >= 201103L + { + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::multimap<int, double, C, A> mo(C(5), A()); + std::multimap<int, double, C, A> m = std::move(mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 0); + assert(distance(m.begin(), m.end()) == 0); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } + { + V ar[] = + { + V(1, 1), + V(1, 1.5), + V(1, 2), + V(2, 1), + V(2, 1.5), + V(2, 2), + V(3, 1), + V(3, 1.5), + V(3, 2), + }; + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::multimap<int, double, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::multimap<int, double, C, A> m = std::move(mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*m.begin() == V(1, 1)); + assert(*next(m.begin()) == V(1, 1.5)); + assert(*next(m.begin(), 2) == V(1, 2)); + assert(*next(m.begin(), 3) == V(2, 1)); + assert(*next(m.begin(), 4) == V(2, 1.5)); + assert(*next(m.begin(), 5) == V(2, 2)); + assert(*next(m.begin(), 6) == V(3, 1)); + assert(*next(m.begin(), 7) == V(3, 1.5)); + assert(*next(m.begin(), 8) == V(3, 2)); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/move_alloc.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/move_alloc.pass.cpp index ed5eb24abcb..c807b4ff558 100644 --- a/libcxx/test/containers/associative/multimap/multimap.cons/move_alloc.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.cons/move_alloc.pass.cpp @@ -19,6 +19,7 @@ #include "../../../MoveOnly.h" #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { @@ -140,5 +141,46 @@ int main() assert(m3.key_comp() == C(5)); assert(m1.empty()); } +#if __cplusplus >= 201103L + { + typedef std::pair<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef min_allocator<VC> A; + typedef std::multimap<MoveOnly, MoveOnly, C, A> M; + typedef std::move_iterator<V*> I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A()); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A()); + M m3(std::move(m1), A()); + assert(m3 == m2); + assert(m3.get_allocator() == A()); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/containers/associative/multimap/multimap.cons/move_assign.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.cons/move_assign.pass.cpp index 4a1e2e95fcd..0aa7c185784 100644 --- a/libcxx/test/containers/associative/multimap/multimap.cons/move_assign.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.cons/move_assign.pass.cpp @@ -19,6 +19,7 @@ #include "../../../MoveOnly.h" #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { @@ -143,5 +144,47 @@ int main() assert(m3.key_comp() == C(5)); assert(m1.empty()); } +#if __cplusplus >= 201103L + { + typedef std::pair<MoveOnly, MoveOnly> V; + typedef std::pair<const MoveOnly, MoveOnly> VC; + typedef test_compare<std::less<MoveOnly> > C; + typedef min_allocator<VC> A; + typedef std::multimap<MoveOnly, MoveOnly, C, A> M; + typedef std::move_iterator<V*> I; + V a1[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A()); + V a2[] = + { + V(1, 1), + V(1, 2), + V(1, 3), + V(2, 1), + V(2, 2), + V(2, 3), + V(3, 1), + V(3, 2), + V(3, 3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A()); + M m3(C(3), A()); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A()); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/clear.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/clear.pass.cpp index e10b06a0c26..4864ec1141b 100644 --- a/libcxx/test/containers/associative/multimap/multimap.modifiers/clear.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/clear.pass.cpp @@ -16,6 +16,8 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { { @@ -37,4 +39,25 @@ int main() m.clear(); assert(m.size() == 0); } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + typedef std::pair<int, double> P; + P ar[] = + { + P(1, 1.5), + P(2, 2.5), + P(3, 3.5), + P(4, 4.5), + P(5, 5.5), + P(6, 6.5), + P(7, 7.5), + P(8, 8.5), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + m.clear(); + assert(m.size() == 0); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/emplace.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/emplace.pass.cpp index 22406d8fb52..c91909e7224 100644 --- a/libcxx/test/containers/associative/multimap/multimap.modifiers/emplace.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/emplace.pass.cpp @@ -19,6 +19,7 @@ #include "../../../Emplaceable.h" #include "../../../DefaultOnly.h" +#include "../../../min_allocator.h" int main() { @@ -80,5 +81,64 @@ int main() assert(m.begin()->first == 2); assert(m.begin()->second == 3.5); } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, DefaultOnly, std::less<int>, min_allocator<std::pair<const int, DefaultOnly>>> M; + typedef M::iterator R; + M m; + assert(DefaultOnly::count == 0); + R r = m.emplace(); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 0); + assert(m.begin()->second == DefaultOnly()); + assert(DefaultOnly::count == 1); + r = m.emplace(1); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace(1); + assert(r == next(m.begin(), 2)); + assert(m.size() == 3); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == DefaultOnly()); + assert(DefaultOnly::count == 3); + } + assert(DefaultOnly::count == 0); + { + typedef std::multimap<int, Emplaceable, std::less<int>, min_allocator<std::pair<const int, Emplaceable>>> M; + typedef M::iterator R; + M m; + R r = m.emplace(2); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace(std::piecewise_construct, std::forward_as_tuple(1), + std::forward_as_tuple(3, 3.5)); + assert(r == next(m.begin())); + assert(m.size() == 3); + assert(r->first == 1); + assert(r->second == Emplaceable(3, 3.5)); + } + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + typedef M::iterator R; + M m; + R r = m.emplace(M::value_type(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 3.5); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/emplace_hint.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/emplace_hint.pass.cpp index 4c3e468d594..8dc3195b711 100644 --- a/libcxx/test/containers/associative/multimap/multimap.modifiers/emplace_hint.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/emplace_hint.pass.cpp @@ -19,6 +19,7 @@ #include "../../../Emplaceable.h" #include "../../../DefaultOnly.h" +#include "../../../min_allocator.h" int main() { @@ -82,5 +83,66 @@ int main() assert(m.begin()->first == 2); assert(m.begin()->second == 3.5); } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, DefaultOnly, std::less<int>, min_allocator<std::pair<const int, DefaultOnly>>> M; + typedef M::iterator R; + M m; + assert(DefaultOnly::count == 0); + R r = m.emplace_hint(m.cend()); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 0); + assert(m.begin()->second == DefaultOnly()); + assert(DefaultOnly::count == 1); + r = m.emplace_hint(m.cend(), 1); + assert(r == next(m.begin())); + assert(m.size() == 2); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == DefaultOnly()); + assert(DefaultOnly::count == 2); + r = m.emplace_hint(m.cend(), 1); + assert(r == next(m.begin(), 2)); + assert(m.size() == 3); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == DefaultOnly()); + assert(DefaultOnly::count == 3); + } + assert(DefaultOnly::count == 0); + { + typedef std::multimap<int, Emplaceable, std::less<int>, min_allocator<std::pair<const int, Emplaceable>>> M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.cend(), 2); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == Emplaceable()); + r = m.emplace_hint(m.cbegin(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(m.begin()->first == 1); + assert(m.begin()->second == Emplaceable(2, 3.5)); + r = m.emplace_hint(m.cbegin(), std::piecewise_construct, + std::forward_as_tuple(1), + std::forward_as_tuple(3, 3.5)); + assert(r == m.begin()); + assert(m.size() == 3); + assert(r->first == 1); + assert(r->second == Emplaceable(3, 3.5)); + } + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.cend(), M::value_type(2, 3.5)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(m.begin()->first == 2); + assert(m.begin()->second == 3.5); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_iter.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_iter.pass.cpp index 794d31176aa..d2979b1eecc 100644 --- a/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_iter.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_iter.pass.cpp @@ -16,6 +16,8 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { { @@ -145,4 +147,133 @@ int main() assert(i == m.begin()); assert(i == m.end()); } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + typedef std::pair<int, double> P; + typedef M::iterator I; + P ar[] = + { + P(1, 1), + P(1, 1.5), + P(1, 2), + P(2, 1), + P(2, 1.5), + P(2, 2), + P(3, 1), + P(3, 1.5), + P(3, 2), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 9); + I i = m.erase(next(m.cbegin(), 3)); + assert(m.size() == 8); + assert(i == next(m.begin(), 3)); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == 1.5); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == 2); + assert(next(m.begin(), 3)->first == 2); + assert(next(m.begin(), 3)->second == 1.5); + assert(next(m.begin(), 4)->first == 2); + assert(next(m.begin(), 4)->second == 2); + assert(next(m.begin(), 5)->first == 3); + assert(next(m.begin(), 5)->second == 1); + assert(next(m.begin(), 6)->first == 3); + assert(next(m.begin(), 6)->second == 1.5); + assert(next(m.begin(), 7)->first == 3); + assert(next(m.begin(), 7)->second == 2); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 7); + assert(i == m.begin()); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1.5); + assert(next(m.begin(), 1)->first == 1); + assert(next(m.begin(), 1)->second == 2); + assert(next(m.begin(), 2)->first == 2); + assert(next(m.begin(), 2)->second == 1.5); + assert(next(m.begin(), 3)->first == 2); + assert(next(m.begin(), 3)->second == 2); + assert(next(m.begin(), 4)->first == 3); + assert(next(m.begin(), 4)->second == 1); + assert(next(m.begin(), 5)->first == 3); + assert(next(m.begin(), 5)->second == 1.5); + assert(next(m.begin(), 6)->first == 3); + assert(next(m.begin(), 6)->second == 2); + + i = m.erase(next(m.cbegin(), 5)); + assert(m.size() == 6); + assert(i == prev(m.end())); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1.5); + assert(next(m.begin(), 1)->first == 1); + assert(next(m.begin(), 1)->second == 2); + assert(next(m.begin(), 2)->first == 2); + assert(next(m.begin(), 2)->second == 1.5); + assert(next(m.begin(), 3)->first == 2); + assert(next(m.begin(), 3)->second == 2); + assert(next(m.begin(), 4)->first == 3); + assert(next(m.begin(), 4)->second == 1); + assert(next(m.begin(), 5)->first == 3); + assert(next(m.begin(), 5)->second == 2); + + i = m.erase(next(m.cbegin(), 1)); + assert(m.size() == 5); + assert(i == next(m.begin())); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1.5); + assert(next(m.begin(), 1)->first == 2); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 2); + assert(next(m.begin(), 2)->second == 2); + assert(next(m.begin(), 3)->first == 3); + assert(next(m.begin(), 3)->second == 1); + assert(next(m.begin(), 4)->first == 3); + assert(next(m.begin(), 4)->second == 2); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 4); + assert(i == next(m.begin(), 2)); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1.5); + assert(next(m.begin(), 1)->first == 2); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 1); + assert(next(m.begin(), 3)->first == 3); + assert(next(m.begin(), 3)->second == 2); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 3); + assert(i == next(m.begin(), 2)); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1.5); + assert(next(m.begin(), 1)->first == 2); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 2); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 2); + assert(i == next(m.begin(), 0)); + assert(next(m.begin(), 0)->first == 2); + assert(next(m.begin(), 0)->second == 1.5); + assert(next(m.begin(), 1)->first == 3); + assert(next(m.begin(), 1)->second == 2); + + i = m.erase(next(m.cbegin(), 1)); + assert(m.size() == 1); + assert(i == m.end()); + assert(next(m.begin(), 0)->first == 2); + assert(next(m.begin(), 0)->second == 1.5); + + i = m.erase(m.cbegin()); + assert(m.size() == 0); + assert(i == m.begin()); + assert(i == m.end()); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_iter_iter.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_iter_iter.pass.cpp index 954c56db509..be1ab6f8d23 100644 --- a/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_iter_iter.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_iter_iter.pass.cpp @@ -16,6 +16,8 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { { @@ -84,4 +86,72 @@ int main() assert(i == m.begin()); assert(i == m.end()); } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + typedef std::pair<int, double> P; + typedef M::iterator I; + P ar[] = + { + P(1, 1.5), + P(2, 2.5), + P(3, 3.5), + P(4, 4.5), + P(5, 5.5), + P(6, 6.5), + P(7, 7.5), + P(8, 8.5), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(m.cbegin(), m.cbegin()); + assert(m.size() == 8); + assert(i == m.begin()); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1.5); + assert(next(m.begin())->first == 2); + assert(next(m.begin())->second == 2.5); + assert(next(m.begin(), 2)->first == 3); + assert(next(m.begin(), 2)->second == 3.5); + assert(next(m.begin(), 3)->first == 4); + assert(next(m.begin(), 3)->second == 4.5); + assert(next(m.begin(), 4)->first == 5); + assert(next(m.begin(), 4)->second == 5.5); + assert(next(m.begin(), 5)->first == 6); + assert(next(m.begin(), 5)->second == 6.5); + assert(next(m.begin(), 6)->first == 7); + assert(next(m.begin(), 6)->second == 7.5); + assert(next(m.begin(), 7)->first == 8); + assert(next(m.begin(), 7)->second == 8.5); + + i = m.erase(m.cbegin(), next(m.cbegin(), 2)); + assert(m.size() == 6); + assert(i == m.begin()); + assert(next(m.begin(), 0)->first == 3); + assert(next(m.begin(), 0)->second == 3.5); + assert(next(m.begin(), 1)->first == 4); + assert(next(m.begin(), 1)->second == 4.5); + assert(next(m.begin(), 2)->first == 5); + assert(next(m.begin(), 2)->second == 5.5); + assert(next(m.begin(), 3)->first == 6); + assert(next(m.begin(), 3)->second == 6.5); + assert(next(m.begin(), 4)->first == 7); + assert(next(m.begin(), 4)->second == 7.5); + assert(next(m.begin(), 5)->first == 8); + assert(next(m.begin(), 5)->second == 8.5); + + i = m.erase(next(m.cbegin(), 2), next(m.cbegin(), 6)); + assert(m.size() == 2); + assert(i == next(m.begin(), 2)); + assert(next(m.begin(), 0)->first == 3); + assert(next(m.begin(), 0)->second == 3.5); + assert(next(m.begin(), 1)->first == 4); + assert(next(m.begin(), 1)->second == 4.5); + + i = m.erase(m.cbegin(), m.cend()); + assert(m.size() == 0); + assert(i == m.begin()); + assert(i == m.end()); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_key.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_key.pass.cpp index cdf5b9db023..c5dd6fbdcc7 100644 --- a/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_key.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/erase_key.pass.cpp @@ -16,6 +16,8 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { { @@ -81,4 +83,69 @@ int main() assert(m.size() == 0); assert(i == 3); } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + typedef std::pair<int, double> P; + typedef M::size_type I; + P ar[] = + { + P(1, 1), + P(1, 1.5), + P(1, 2), + P(2, 1), + P(2, 1.5), + P(2, 2), + P(3, 1), + P(3, 1.5), + P(3, 2), + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 9); + I i = m.erase(2); + assert(m.size() == 6); + assert(i == 3); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1); + assert(next(m.begin(), 1)->first == 1); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == 2); + assert(next(m.begin(), 3)->first == 3); + assert(next(m.begin(), 3)->second == 1); + assert(next(m.begin(), 4)->first == 3); + assert(next(m.begin(), 4)->second == 1.5); + assert(next(m.begin(), 5)->first == 3); + assert(next(m.begin(), 5)->second == 2); + + i = m.erase(2); + assert(m.size() == 6); + assert(i == 0); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1); + assert(next(m.begin(), 1)->first == 1); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == 2); + assert(next(m.begin(), 3)->first == 3); + assert(next(m.begin(), 3)->second == 1); + assert(next(m.begin(), 4)->first == 3); + assert(next(m.begin(), 4)->second == 1.5); + assert(next(m.begin(), 5)->first == 3); + assert(next(m.begin(), 5)->second == 2); + + i = m.erase(3); + assert(m.size() == 3); + assert(next(m.begin(), 0)->first == 1); + assert(next(m.begin(), 0)->second == 1); + assert(next(m.begin(), 1)->first == 1); + assert(next(m.begin(), 1)->second == 1.5); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == 2); + + i = m.erase(1); + assert(m.size() == 0); + assert(i == 3); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_cv.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_cv.pass.cpp index 4ad2704be0a..c23d821e0bb 100644 --- a/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_cv.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_cv.pass.cpp @@ -16,6 +16,8 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { { @@ -46,4 +48,34 @@ int main() assert(r->first == 3); assert(r->second == 3.5); } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + typedef M::iterator R; + M m; + R r = m.insert(M::value_type(2, 2.5)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2.5); + + r = m.insert(M::value_type(1, 1.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1.5); + + r = m.insert(M::value_type(3, 3.5)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3.5); + + r = m.insert(M::value_type(3, 3.5)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(r->first == 3); + assert(r->second == 3.5); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_initializer_list.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_initializer_list.pass.cpp index 26a9cb8cfd9..8fc080d013f 100644 --- a/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_initializer_list.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_initializer_list.pass.cpp @@ -16,9 +16,12 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { typedef std::multimap<int, double> C; typedef C::value_type V; C m = @@ -49,5 +52,40 @@ int main() assert(*++i == V(3, 1)); assert(*++i == V(3, 2)); assert(*++i == V(3, 1.5)); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> C; + typedef C::value_type V; + C m = + { + {1, 1}, + {1, 2}, + {2, 1}, + {2, 2}, + {3, 1}, + {3, 2} + }; + m.insert( + { + {1, 1.5}, + {2, 1.5}, + {3, 1.5}, + } + ); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + C::const_iterator i = m.cbegin(); + assert(*i == V(1, 1)); + assert(*++i == V(1, 2)); + assert(*++i == V(1, 1.5)); + assert(*++i == V(2, 1)); + assert(*++i == V(2, 2)); + assert(*++i == V(2, 1.5)); + assert(*++i == V(3, 1)); + assert(*++i == V(3, 2)); + assert(*++i == V(3, 1.5)); + } +#endif #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS } diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_cv.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_cv.pass.cpp index ebe49012cd0..0c8e9168731 100644 --- a/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_cv.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_cv.pass.cpp @@ -16,6 +16,8 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { { @@ -46,4 +48,34 @@ int main() assert(r->first == 3); assert(r->second == 4.5); } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + typedef M::iterator R; + M m; + R r = m.insert(m.end(), M::value_type(2, 2.5)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2.5); + + r = m.insert(m.end(), M::value_type(1, 1.5)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1.5); + + r = m.insert(m.end(), M::value_type(3, 3.5)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3.5); + + r = m.insert(prev(m.end()), M::value_type(3, 4.5)); + assert(r == prev(m.end(), 2)); + assert(m.size() == 4); + assert(r->first == 3); + assert(r->second == 4.5); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_iter.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_iter.pass.cpp index fcd4cee8f9b..6e3d2f26bc3 100644 --- a/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_iter.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_iter.pass.cpp @@ -18,6 +18,7 @@ #include <cassert> #include "test_iterators.h" +#include "../../../min_allocator.h" int main() { @@ -58,4 +59,43 @@ int main() assert(next(m.begin(), 8)->first == 3); assert(next(m.begin(), 8)->second == 2); } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + typedef std::pair<int, double> P; + P ar[] = + { + P(1, 1), + P(1, 1.5), + P(1, 2), + P(2, 1), + P(2, 1.5), + P(2, 2), + P(3, 1), + P(3, 1.5), + P(3, 2), + }; + M m; + m.insert(input_iterator<P*>(ar), input_iterator<P*>(ar + sizeof(ar)/sizeof(ar[0]))); + assert(m.size() == 9); + assert(m.begin()->first == 1); + assert(m.begin()->second == 1); + assert(next(m.begin())->first == 1); + assert(next(m.begin())->second == 1.5); + assert(next(m.begin(), 2)->first == 1); + assert(next(m.begin(), 2)->second == 2); + assert(next(m.begin(), 3)->first == 2); + assert(next(m.begin(), 3)->second == 1); + assert(next(m.begin(), 4)->first == 2); + assert(next(m.begin(), 4)->second == 1.5); + assert(next(m.begin(), 5)->first == 2); + assert(next(m.begin(), 5)->second == 2); + assert(next(m.begin(), 6)->first == 3); + assert(next(m.begin(), 6)->second == 1); + assert(next(m.begin(), 7)->first == 3); + assert(next(m.begin(), 7)->second == 1.5); + assert(next(m.begin(), 8)->first == 3); + assert(next(m.begin(), 8)->second == 2); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_rv.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_rv.pass.cpp index 15993cbfd31..efc99e1e762 100644 --- a/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_rv.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_iter_rv.pass.cpp @@ -18,6 +18,7 @@ #include <cassert> #include "../../../MoveOnly.h" +#include "../../../min_allocator.h" int main() { @@ -51,5 +52,36 @@ int main() assert(r->first == 3); assert(r->second == 2); } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M; + typedef std::pair<int, MoveOnly> P; + typedef M::iterator R; + M m; + R r = m.insert(m.cend(), P(2, 2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2); + + r = m.insert(m.cend(), P(1, 1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1); + + r = m.insert(m.cend(), P(3, 3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3); + + r = m.insert(m.cend(), P(3, 2)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(r->first == 3); + assert(r->second == 2); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_rv.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_rv.pass.cpp index 285881cac71..1678c9de89e 100644 --- a/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_rv.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.modifiers/insert_rv.pass.cpp @@ -18,6 +18,7 @@ #include <cassert> #include "../../../MoveOnly.h" +#include "../../../min_allocator.h" int main() { @@ -50,5 +51,35 @@ int main() assert(r->first == 3); assert(r->second == 3); } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, MoveOnly, std::less<int>, min_allocator<std::pair<const int, MoveOnly>>> M; + typedef M::iterator R; + M m; + R r = m.insert(M::value_type(2, 2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(r->first == 2); + assert(r->second == 2); + + r = m.insert(M::value_type(1, 1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(r->first == 1); + assert(r->second == 1); + + r = m.insert(M::value_type(3, 3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(r->first == 3); + assert(r->second == 3); + + r = m.insert(M::value_type(3, 3)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(r->first == 3); + assert(r->second == 3); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/containers/associative/multimap/multimap.ops/count.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.ops/count.pass.cpp index e707cd70066..b0e4c58873c 100644 --- a/libcxx/test/containers/associative/multimap/multimap.ops/count.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.ops/count.pass.cpp @@ -16,9 +16,12 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { typedef std::pair<const int, double> V; + { typedef std::multimap<int, double> M; { typedef M::size_type R; @@ -50,4 +53,40 @@ int main() r = m.count(10); assert(r == 0); } + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + { + typedef M::size_type R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.count(4); + assert(r == 0); + r = m.count(5); + assert(r == 3); + r = m.count(6); + assert(r == 0); + r = m.count(7); + assert(r == 3); + r = m.count(8); + assert(r == 0); + r = m.count(9); + assert(r == 3); + r = m.count(10); + assert(r == 0); + } + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.ops/equal_range.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.ops/equal_range.pass.cpp index 73f392cad10..030d4681ded 100644 --- a/libcxx/test/containers/associative/multimap/multimap.ops/equal_range.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.ops/equal_range.pass.cpp @@ -17,9 +17,12 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { typedef std::pair<const int, double> V; + { typedef std::multimap<int, double> M; { typedef std::pair<M::iterator, M::iterator> R; @@ -95,4 +98,84 @@ int main() assert(r.first == m.end()); assert(r.second == m.end()); } + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + { + typedef std::pair<M::iterator, M::iterator> R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(4); + assert(r.first == m.begin()); + assert(r.second == m.begin()); + r = m.equal_range(5); + assert(r.first == m.begin()); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(10); + assert(r.first == m.end()); + assert(r.second == m.end()); + } + { + typedef std::pair<M::const_iterator, M::const_iterator> R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(4); + assert(r.first == m.begin()); + assert(r.second == m.begin()); + r = m.equal_range(5); + assert(r.first == m.begin()); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(10); + assert(r.first == m.end()); + assert(r.second == m.end()); + } + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.ops/find.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.ops/find.pass.cpp index fe7e34f5fb2..aa22d3971fd 100644 --- a/libcxx/test/containers/associative/multimap/multimap.ops/find.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.ops/find.pass.cpp @@ -17,9 +17,12 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { typedef std::pair<const int, double> V; + { typedef std::multimap<int, double> M; { typedef M::iterator R; @@ -77,4 +80,66 @@ int main() r = m.find(10); assert(r == m.end()); } + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == m.end()); + r = m.find(7); + assert(r == next(m.begin(), 3)); + r = m.find(8); + assert(r == m.end()); + r = m.find(9); + assert(r == next(m.begin(), 6)); + r = m.find(10); + assert(r == m.end()); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == m.end()); + r = m.find(7); + assert(r == next(m.begin(), 3)); + r = m.find(8); + assert(r == m.end()); + r = m.find(9); + assert(r == next(m.begin(), 6)); + r = m.find(10); + assert(r == m.end()); + } + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.ops/lower_bound.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.ops/lower_bound.pass.cpp index fe682f18297..508b077b2ee 100644 --- a/libcxx/test/containers/associative/multimap/multimap.ops/lower_bound.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.ops/lower_bound.pass.cpp @@ -17,9 +17,12 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { typedef std::pair<const int, double> V; + { typedef std::multimap<int, double> M; { typedef M::iterator R; @@ -81,4 +84,70 @@ int main() r = m.lower_bound(10); assert(r == m.end()); } + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(4); + assert(r == m.begin()); + r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(10); + assert(r == m.end()); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(4); + assert(r == m.begin()); + r = m.lower_bound(5); + assert(r == m.begin()); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(10); + assert(r == m.end()); + } + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.ops/upper_bound.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.ops/upper_bound.pass.cpp index 3d6bd88a9f2..6f40c20d997 100644 --- a/libcxx/test/containers/associative/multimap/multimap.ops/upper_bound.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.ops/upper_bound.pass.cpp @@ -17,9 +17,12 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { typedef std::pair<const int, double> V; + { typedef std::multimap<int, double> M; { typedef M::iterator R; @@ -81,4 +84,70 @@ int main() r = m.upper_bound(10); assert(r == m.end()); } + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + { + typedef M::iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(4); + assert(r == m.begin()); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(10); + assert(r == m.end()); + } + { + typedef M::const_iterator R; + V ar[] = + { + V(5, 1), + V(5, 2), + V(5, 3), + V(7, 1), + V(7, 2), + V(7, 3), + V(9, 1), + V(9, 2), + V(9, 3) + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(4); + assert(r == m.begin()); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(10); + assert(r == m.end()); + } + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.special/member_swap.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.special/member_swap.pass.cpp index 05d1260319c..1e1ab2335ab 100644 --- a/libcxx/test/containers/associative/multimap/multimap.special/member_swap.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.special/member_swap.pass.cpp @@ -16,9 +16,12 @@ #include <map> #include <cassert> +#include "../../../min_allocator.h" + int main() { typedef std::pair<const int, double> V; + { typedef std::multimap<int, double> M; { V ar1[] = @@ -104,4 +107,94 @@ int main() assert(m1 == m2_save); assert(m2 == m1_save); } + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/multimap.special/non_member_swap.pass.cpp b/libcxx/test/containers/associative/multimap/multimap.special/non_member_swap.pass.cpp index 390340f1799..6f5b92fe1fe 100644 --- a/libcxx/test/containers/associative/multimap/multimap.special/non_member_swap.pass.cpp +++ b/libcxx/test/containers/associative/multimap/multimap.special/non_member_swap.pass.cpp @@ -19,10 +19,12 @@ #include <cassert> #include "../../../test_allocator.h" #include "../../../test_compare.h" +#include "../../../min_allocator.h" int main() { typedef std::pair<const int, double> V; + { typedef std::multimap<int, double> M; { V ar1[] = @@ -176,4 +178,128 @@ int main() assert(m2.key_comp() == C(1)); assert(m2.get_allocator() == A(1)); } + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + typedef min_allocator<V> A; + typedef test_compare<std::less<int> > C; + typedef std::multimap<int, double, C, A> M; + V ar1[] = + { + V(1, 1), + V(2, 2), + V(3, 3), + V(4, 4) + }; + V ar2[] = + { + V(5, 5), + V(6, 6), + V(7, 7), + V(8, 8), + V(9, 9), + V(10, 10), + V(11, 11), + V(12, 12) + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]), C(1), A()); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]), C(2), A()); + M m1_save = m1; + M m2_save = m2; + swap(m1, m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + assert(m1.key_comp() == C(2)); + assert(m1.get_allocator() == A()); + assert(m2.key_comp() == C(1)); + assert(m2.get_allocator() == A()); + } + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/size.pass.cpp b/libcxx/test/containers/associative/multimap/size.pass.cpp index eb7b1c914ae..794c34a2846 100644 --- a/libcxx/test/containers/associative/multimap/size.pass.cpp +++ b/libcxx/test/containers/associative/multimap/size.pass.cpp @@ -16,8 +16,11 @@ #include <map> #include <cassert> +#include "../../min_allocator.h" + int main() { + { typedef std::multimap<int, double> M; M m; assert(m.size() == 0); @@ -33,4 +36,24 @@ int main() assert(m.size() == 1); m.erase(m.begin()); assert(m.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>> M; + M m; + assert(m.size() == 0); + m.insert(M::value_type(2, 1.5)); + assert(m.size() == 1); + m.insert(M::value_type(1, 1.5)); + assert(m.size() == 2); + m.insert(M::value_type(3, 1.5)); + assert(m.size() == 3); + m.erase(m.begin()); + assert(m.size() == 2); + m.erase(m.begin()); + assert(m.size() == 1); + m.erase(m.begin()); + assert(m.size() == 0); + } +#endif } diff --git a/libcxx/test/containers/associative/multimap/types.pass.cpp b/libcxx/test/containers/associative/multimap/types.pass.cpp index 4bb72422747..2fe8fe0eabf 100644 --- a/libcxx/test/containers/associative/multimap/types.pass.cpp +++ b/libcxx/test/containers/associative/multimap/types.pass.cpp @@ -32,8 +32,11 @@ #include <map> #include <type_traits> +#include "../../min_allocator.h" + int main() { + { static_assert((std::is_same<std::multimap<int, double>::key_type, int>::value), ""); static_assert((std::is_same<std::multimap<int, double>::mapped_type, double>::value), ""); static_assert((std::is_same<std::multimap<int, double>::value_type, std::pair<const int, double> >::value), ""); @@ -45,4 +48,20 @@ int main() static_assert((std::is_same<std::multimap<int, double>::const_pointer, const std::pair<const int, double>*>::value), ""); static_assert((std::is_same<std::multimap<int, double>::size_type, std::size_t>::value), ""); static_assert((std::is_same<std::multimap<int, double>::difference_type, std::ptrdiff_t>::value), ""); + } +#if __cplusplus >= 201103L + { + static_assert((std::is_same<std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::key_type, int>::value), ""); + static_assert((std::is_same<std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::mapped_type, double>::value), ""); + static_assert((std::is_same<std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::value_type, std::pair<const int, double> >::value), ""); + static_assert((std::is_same<std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::key_compare, std::less<int> >::value), ""); + static_assert((std::is_same<std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::allocator_type, min_allocator<std::pair<const int, double> > >::value), ""); + static_assert((std::is_same<std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::reference, std::pair<const int, double>&>::value), ""); + static_assert((std::is_same<std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::const_reference, const std::pair<const int, double>&>::value), ""); + static_assert((std::is_same<std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::pointer, min_pointer<std::pair<const int, double>>>::value), ""); + static_assert((std::is_same<std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::const_pointer, min_pointer<const std::pair<const int, double>>>::value), ""); + static_assert((std::is_same<std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::size_type, std::size_t>::value), ""); + static_assert((std::is_same<std::multimap<int, double, std::less<int>, min_allocator<std::pair<const int, double>>>::difference_type, std::ptrdiff_t>::value), ""); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/clear.pass.cpp b/libcxx/test/containers/associative/multiset/clear.pass.cpp index f91b74f03e0..f325a701abe 100644 --- a/libcxx/test/containers/associative/multiset/clear.pass.cpp +++ b/libcxx/test/containers/associative/multiset/clear.pass.cpp @@ -16,6 +16,8 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { { @@ -37,4 +39,25 @@ int main() m.clear(); assert(m.size() == 0); } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + typedef int V; + V ar[] = + { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + m.clear(); + assert(m.size() == 0); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/count.pass.cpp b/libcxx/test/containers/associative/multiset/count.pass.cpp index 726c80594ca..cba64301a33 100644 --- a/libcxx/test/containers/associative/multiset/count.pass.cpp +++ b/libcxx/test/containers/associative/multiset/count.pass.cpp @@ -16,8 +16,11 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { + { typedef int V; typedef std::multiset<int> M; { @@ -50,4 +53,41 @@ int main() r = m.count(10); assert(r == 0); } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + { + typedef M::size_type R; + V ar[] = + { + 5, + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.count(4); + assert(r == 0); + r = m.count(5); + assert(r == 4); + r = m.count(6); + assert(r == 0); + r = m.count(7); + assert(r == 3); + r = m.count(8); + assert(r == 0); + r = m.count(9); + assert(r == 2); + r = m.count(10); + assert(r == 0); + } + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/emplace.pass.cpp b/libcxx/test/containers/associative/multiset/emplace.pass.cpp index 55f11fce207..08ac42b1d13 100644 --- a/libcxx/test/containers/associative/multiset/emplace.pass.cpp +++ b/libcxx/test/containers/associative/multiset/emplace.pass.cpp @@ -19,6 +19,7 @@ #include "../../Emplaceable.h" #include "../../DefaultOnly.h" +#include "../../min_allocator.h" int main() { @@ -67,5 +68,16 @@ int main() assert(m.size() == 1); assert(*r == 2); } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + typedef M::iterator R; + M m; + R r = m.emplace(M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/containers/associative/multiset/emplace_hint.pass.cpp b/libcxx/test/containers/associative/multiset/emplace_hint.pass.cpp index 9e4befa7119..1510c010477 100644 --- a/libcxx/test/containers/associative/multiset/emplace_hint.pass.cpp +++ b/libcxx/test/containers/associative/multiset/emplace_hint.pass.cpp @@ -19,6 +19,7 @@ #include "../../Emplaceable.h" #include "../../DefaultOnly.h" +#include "../../min_allocator.h" int main() { @@ -67,5 +68,16 @@ int main() assert(m.size() == 1); assert(*r == 2); } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + typedef M::iterator R; + M m; + R r = m.emplace_hint(m.cend(), M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + } +#endif #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES } diff --git a/libcxx/test/containers/associative/multiset/empty.pass.cpp b/libcxx/test/containers/associative/multiset/empty.pass.cpp index 8213fbb70c1..154180def46 100644 --- a/libcxx/test/containers/associative/multiset/empty.pass.cpp +++ b/libcxx/test/containers/associative/multiset/empty.pass.cpp @@ -16,8 +16,11 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { + { typedef std::multiset<int> M; M m; assert(m.empty()); @@ -25,4 +28,16 @@ int main() assert(!m.empty()); m.clear(); assert(m.empty()); + } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + M m; + assert(m.empty()); + m.insert(M::value_type(1)); + assert(!m.empty()); + m.clear(); + assert(m.empty()); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/equal_range.pass.cpp b/libcxx/test/containers/associative/multiset/equal_range.pass.cpp index 4d8cd98b9dd..fee94bc97cd 100644 --- a/libcxx/test/containers/associative/multiset/equal_range.pass.cpp +++ b/libcxx/test/containers/associative/multiset/equal_range.pass.cpp @@ -17,8 +17,11 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { + { typedef int V; typedef std::multiset<int> M; { @@ -95,4 +98,85 @@ int main() assert(r.first == next(m.begin(), 9)); assert(r.second == next(m.begin(), 9)); } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + { + typedef std::pair<M::iterator, M::iterator> R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 9)); + assert(r.second == next(m.begin(), 9)); + } + { + typedef std::pair<M::const_iterator, M::const_iterator> R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.equal_range(4); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 0)); + r = m.equal_range(5); + assert(r.first == next(m.begin(), 0)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(6); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 3)); + r = m.equal_range(7); + assert(r.first == next(m.begin(), 3)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(8); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 6)); + r = m.equal_range(9); + assert(r.first == next(m.begin(), 6)); + assert(r.second == next(m.begin(), 9)); + r = m.equal_range(10); + assert(r.first == next(m.begin(), 9)); + assert(r.second == next(m.begin(), 9)); + } + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/erase_iter.pass.cpp b/libcxx/test/containers/associative/multiset/erase_iter.pass.cpp index 207a720bdc2..3657f521cb1 100644 --- a/libcxx/test/containers/associative/multiset/erase_iter.pass.cpp +++ b/libcxx/test/containers/associative/multiset/erase_iter.pass.cpp @@ -16,6 +16,8 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { { @@ -96,4 +98,84 @@ int main() assert(i == m.begin()); assert(i == m.end()); } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + typedef int V; + typedef M::iterator I; + V ar[] = + { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(next(m.cbegin(), 3)); + assert(m.size() == 7); + assert(i == next(m.begin(), 3)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 5); + assert(*next(m.begin(), 4) == 6); + assert(*next(m.begin(), 5) == 7); + assert(*next(m.begin(), 6) == 8); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 6); + assert(i == m.begin()); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 5); + assert(*next(m.begin(), 3) == 6); + assert(*next(m.begin(), 4) == 7); + assert(*next(m.begin(), 5) == 8); + + i = m.erase(next(m.cbegin(), 5)); + assert(m.size() == 5); + assert(i == m.end()); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 5); + assert(*next(m.begin(), 3) == 6); + assert(*next(m.begin(), 4) == 7); + + i = m.erase(next(m.cbegin(), 1)); + assert(m.size() == 4); + assert(i == next(m.begin())); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + assert(*next(m.begin(), 2) == 6); + assert(*next(m.begin(), 3) == 7); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 3); + assert(i == next(m.begin(), 2)); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + assert(*next(m.begin(), 2) == 7); + + i = m.erase(next(m.cbegin(), 2)); + assert(m.size() == 2); + assert(i == next(m.begin(), 2)); + assert(*next(m.begin(), 0) == 2); + assert(*next(m.begin(), 1) == 5); + + i = m.erase(next(m.cbegin(), 0)); + assert(m.size() == 1); + assert(i == next(m.begin(), 0)); + assert(*next(m.begin(), 0) == 5); + + i = m.erase(m.cbegin()); + assert(m.size() == 0); + assert(i == m.begin()); + assert(i == m.end()); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/erase_iter_iter.pass.cpp b/libcxx/test/containers/associative/multiset/erase_iter_iter.pass.cpp index 091212815a1..de4c8783bf3 100644 --- a/libcxx/test/containers/associative/multiset/erase_iter_iter.pass.cpp +++ b/libcxx/test/containers/associative/multiset/erase_iter_iter.pass.cpp @@ -16,6 +16,8 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { { @@ -76,4 +78,64 @@ int main() assert(m.size() == 0); assert(i == m.end()); } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + typedef int V; + typedef M::iterator I; + V ar[] = + { + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 8); + I i = m.erase(next(m.cbegin(), 5), next(m.cbegin(), 5)); + assert(m.size() == 8); + assert(i == next(m.begin(), 5)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 4); + assert(*next(m.begin(), 4) == 5); + assert(*next(m.begin(), 5) == 6); + assert(*next(m.begin(), 6) == 7); + assert(*next(m.begin(), 7) == 8); + + i = m.erase(next(m.cbegin(), 3), next(m.cbegin(), 4)); + assert(m.size() == 7); + assert(i == next(m.begin(), 3)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 5); + assert(*next(m.begin(), 4) == 6); + assert(*next(m.begin(), 5) == 7); + assert(*next(m.begin(), 6) == 8); + + i = m.erase(next(m.cbegin(), 2), next(m.cbegin(), 5)); + assert(m.size() == 4); + assert(i == next(m.begin(), 2)); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 2); + assert(*next(m.begin(), 2) == 7); + assert(*next(m.begin(), 3) == 8); + + i = m.erase(next(m.cbegin(), 0), next(m.cbegin(), 2)); + assert(m.size() == 2); + assert(i == next(m.begin(), 0)); + assert(*next(m.begin(), 0) == 7); + assert(*next(m.begin(), 1) == 8); + + i = m.erase(m.cbegin(), m.cend()); + assert(m.size() == 0); + assert(i == m.end()); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/erase_key.pass.cpp b/libcxx/test/containers/associative/multiset/erase_key.pass.cpp index 20ba86df10a..170232904c4 100644 --- a/libcxx/test/containers/associative/multiset/erase_key.pass.cpp +++ b/libcxx/test/containers/associative/multiset/erase_key.pass.cpp @@ -16,6 +16,8 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { { @@ -70,4 +72,58 @@ int main() assert(m.size() == 0); assert(i == 3); } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + typedef int V; + typedef M::size_type I; + V ar[] = + { + 3, + 3, + 3, + 5, + 5, + 5, + 7, + 7, + 7 + }; + M m(ar, ar + sizeof(ar)/sizeof(ar[0])); + assert(m.size() == 9); + I i = m.erase(6); + assert(m.size() == 9); + assert(i == 0); + assert(*next(m.begin(), 0) == 3); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 5); + assert(*next(m.begin(), 4) == 5); + assert(*next(m.begin(), 5) == 5); + assert(*next(m.begin(), 6) == 7); + assert(*next(m.begin(), 7) == 7); + assert(*next(m.begin(), 8) == 7); + + i = m.erase(5); + assert(m.size() == 6); + assert(i == 3); + assert(*next(m.begin(), 0) == 3); + assert(*next(m.begin(), 1) == 3); + assert(*next(m.begin(), 2) == 3); + assert(*next(m.begin(), 3) == 7); + assert(*next(m.begin(), 4) == 7); + assert(*next(m.begin(), 5) == 7); + + i = m.erase(3); + assert(m.size() == 3); + assert(i == 3); + assert(*next(m.begin(), 0) == 7); + assert(*next(m.begin(), 1) == 7); + assert(*next(m.begin(), 2) == 7); + + i = m.erase(7); + assert(m.size() == 0); + assert(i == 3); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/find.pass.cpp b/libcxx/test/containers/associative/multiset/find.pass.cpp index f2af8f61741..53b1844e8ef 100644 --- a/libcxx/test/containers/associative/multiset/find.pass.cpp +++ b/libcxx/test/containers/associative/multiset/find.pass.cpp @@ -17,74 +17,150 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { - typedef int V; - typedef std::multiset<int> M; { - typedef M::iterator R; - V ar[] = + typedef int V; + typedef std::multiset<int> M; + { + typedef M::iterator R; + V ar[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } { - 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 M::const_iterator R; - V ar[] = + typedef int V; + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + { + typedef M::iterator R; + V ar[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.find(5); + assert(r == m.begin()); + r = m.find(6); + assert(r == next(m.begin())); + r = m.find(7); + assert(r == next(m.begin(), 2)); + r = m.find(8); + assert(r == next(m.begin(), 3)); + r = m.find(9); + assert(r == next(m.begin(), 4)); + r = m.find(10); + assert(r == next(m.begin(), 5)); + r = m.find(11); + assert(r == next(m.begin(), 6)); + r = m.find(12); + assert(r == next(m.begin(), 7)); + r = m.find(4); + assert(r == next(m.begin(), 8)); + } { - 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)); + 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 } diff --git a/libcxx/test/containers/associative/multiset/insert_cv.pass.cpp b/libcxx/test/containers/associative/multiset/insert_cv.pass.cpp index 2673ae74c15..57e1e98f500 100644 --- a/libcxx/test/containers/associative/multiset/insert_cv.pass.cpp +++ b/libcxx/test/containers/associative/multiset/insert_cv.pass.cpp @@ -16,6 +16,8 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { { @@ -42,4 +44,30 @@ int main() assert(m.size() == 4); assert(*r == 3); } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + typedef M::iterator R; + M m; + R r = m.insert(M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + + r = m.insert(M::value_type(1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(*r == 1); + + r = m.insert(M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + + r = m.insert(M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(*r == 3); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/insert_initializer_list.pass.cpp b/libcxx/test/containers/associative/multiset/insert_initializer_list.pass.cpp index 4f5691b09bf..c609d242ae2 100644 --- a/libcxx/test/containers/associative/multiset/insert_initializer_list.pass.cpp +++ b/libcxx/test/containers/associative/multiset/insert_initializer_list.pass.cpp @@ -16,9 +16,12 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { typedef std::multiset<int> C; typedef C::value_type V; C m = {10, 8}; @@ -34,5 +37,25 @@ int main() assert(*++i == V(6)); assert(*++i == V(8)); assert(*++i == V(10)); + } #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> C; + typedef C::value_type V; + C m = {10, 8}; + m.insert({1, 2, 3, 4, 5, 6}); + assert(m.size() == 8); + assert(distance(m.begin(), m.end()) == m.size()); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + assert(*++i == V(8)); + assert(*++i == V(10)); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/insert_iter_cv.pass.cpp b/libcxx/test/containers/associative/multiset/insert_iter_cv.pass.cpp index 6e4986292d1..fccc2b71960 100644 --- a/libcxx/test/containers/associative/multiset/insert_iter_cv.pass.cpp +++ b/libcxx/test/containers/associative/multiset/insert_iter_cv.pass.cpp @@ -16,6 +16,8 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { { @@ -42,4 +44,30 @@ int main() assert(m.size() == 4); assert(*r == 3); } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + typedef M::iterator R; + M m; + R r = m.insert(m.cend(), M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + + r = m.insert(m.cend(), M::value_type(1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(*r == 1); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(*r == 3); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/insert_iter_iter.pass.cpp b/libcxx/test/containers/associative/multiset/insert_iter_iter.pass.cpp index 231e0c57a6e..3cfa9dd16c4 100644 --- a/libcxx/test/containers/associative/multiset/insert_iter_iter.pass.cpp +++ b/libcxx/test/containers/associative/multiset/insert_iter_iter.pass.cpp @@ -18,6 +18,7 @@ #include <cassert> #include "test_iterators.h" +#include "../../min_allocator.h" int main() { @@ -50,4 +51,35 @@ int main() assert(*next(m.begin(), 7) == 3); assert(*next(m.begin(), 8) == 3); } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + M m; + m.insert(input_iterator<const V*>(ar), + input_iterator<const V*>(ar + sizeof(ar)/sizeof(ar[0]))); + assert(m.size() == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/insert_iter_rv.pass.cpp b/libcxx/test/containers/associative/multiset/insert_iter_rv.pass.cpp index 3700dd18888..f09d97de827 100644 --- a/libcxx/test/containers/associative/multiset/insert_iter_rv.pass.cpp +++ b/libcxx/test/containers/associative/multiset/insert_iter_rv.pass.cpp @@ -17,6 +17,7 @@ #include <cassert> #include "../../MoveOnly.h" +#include "../../min_allocator.h" int main() { @@ -46,4 +47,30 @@ int main() assert(*r == 3); } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::multiset<MoveOnly, std::less<MoveOnly>, min_allocator<MoveOnly>> M; + typedef M::iterator R; + M m; + R r = m.insert(m.cend(), M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + + r = m.insert(m.cend(), M::value_type(1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(*r == 1); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + + r = m.insert(m.cend(), M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(*r == 3); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/insert_rv.pass.cpp b/libcxx/test/containers/associative/multiset/insert_rv.pass.cpp index a65b67a9533..e9e773ccd73 100644 --- a/libcxx/test/containers/associative/multiset/insert_rv.pass.cpp +++ b/libcxx/test/containers/associative/multiset/insert_rv.pass.cpp @@ -17,6 +17,7 @@ #include <cassert> #include "../../MoveOnly.h" +#include "../../min_allocator.h" int main() { @@ -46,4 +47,30 @@ int main() assert(*r == 3); } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef std::multiset<MoveOnly, std::less<MoveOnly>, min_allocator<MoveOnly>> M; + typedef M::iterator R; + M m; + R r = m.insert(M::value_type(2)); + assert(r == m.begin()); + assert(m.size() == 1); + assert(*r == 2); + + r = m.insert(M::value_type(1)); + assert(r == m.begin()); + assert(m.size() == 2); + assert(*r == 1); + + r = m.insert(M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 3); + assert(*r == 3); + + r = m.insert(M::value_type(3)); + assert(r == prev(m.end())); + assert(m.size() == 4); + assert(*r == 3); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/iterator.pass.cpp b/libcxx/test/containers/associative/multiset/iterator.pass.cpp index 1b202191b3d..2a7b209e9c0 100644 --- a/libcxx/test/containers/associative/multiset/iterator.pass.cpp +++ b/libcxx/test/containers/associative/multiset/iterator.pass.cpp @@ -29,6 +29,8 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { { @@ -105,10 +107,92 @@ int main() assert(std::distance(m.cbegin(), m.cend()) == m.size()); assert(std::distance(m.rbegin(), m.rend()) == m.size()); assert(std::distance(m.crbegin(), m.crend()) == m.size()); - std::multiset<int, double>::const_iterator i; + std::multiset<int>::const_iterator i; + i = m.begin(); + for (int j = 1; j <= 8; ++j) + for (int k = 0; k < 3; ++k, ++i) + assert(*i == j); + } +#if __cplusplus >= 201103L + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3, + 4, + 4, + 4, + 5, + 5, + 5, + 6, + 6, + 6, + 7, + 7, + 7, + 8, + 8, + 8 + }; + std::multiset<int, std::less<int>, min_allocator<int>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + std::multiset<int, std::less<int>, min_allocator<int>>::iterator i; + i = m.begin(); + std::multiset<int, std::less<int>, min_allocator<int>>::const_iterator k = i; + assert(i == k); + for (int j = 1; j <= 8; ++j) + for (int k = 0; k < 3; ++k, ++i) + assert(*i == j); + } + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3, + 4, + 4, + 4, + 5, + 5, + 5, + 6, + 6, + 6, + 7, + 7, + 7, + 8, + 8, + 8 + }; + const std::multiset<int, std::less<int>, min_allocator<int>> m(ar, ar+sizeof(ar)/sizeof(ar[0])); + assert(std::distance(m.begin(), m.end()) == m.size()); + assert(std::distance(m.cbegin(), m.cend()) == m.size()); + assert(std::distance(m.rbegin(), m.rend()) == m.size()); + assert(std::distance(m.crbegin(), m.crend()) == m.size()); + std::multiset<int, std::less<int>, min_allocator<int>>::const_iterator i; i = m.begin(); for (int j = 1; j <= 8; ++j) for (int k = 0; k < 3; ++k, ++i) assert(*i == j); } +#endif } diff --git a/libcxx/test/containers/associative/multiset/lower_bound.pass.cpp b/libcxx/test/containers/associative/multiset/lower_bound.pass.cpp index 585c341cd23..537ccd3aff1 100644 --- a/libcxx/test/containers/associative/multiset/lower_bound.pass.cpp +++ b/libcxx/test/containers/associative/multiset/lower_bound.pass.cpp @@ -17,68 +17,138 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { - typedef int V; - typedef std::multiset<int> M; { - typedef M::iterator R; - V ar[] = + typedef int V; + typedef std::multiset<int> M; + { + typedef M::iterator R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(5); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 9)); + } { - 5, - 5, - 5, - 7, - 7, - 7, - 9, - 9, - 9 - }; - M m(ar, ar+sizeof(ar)/sizeof(ar[0])); - R r = m.lower_bound(4); - assert(r == next(m.begin(), 0)); - r = m.lower_bound(5); - assert(r == next(m.begin(), 0)); - r = m.lower_bound(6); - assert(r == next(m.begin(), 3)); - r = m.lower_bound(7); - assert(r == next(m.begin(), 3)); - r = m.lower_bound(8); - assert(r == next(m.begin(), 6)); - r = m.lower_bound(9); - assert(r == next(m.begin(), 6)); - r = m.lower_bound(11); - assert(r == next(m.begin(), 9)); + typedef M::const_iterator R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(5); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 9)); + } } +#if __cplusplus >= 201103L { - typedef M::const_iterator R; - V ar[] = + typedef int V; + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + { + typedef M::iterator R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(5); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 9)); + } { - 5, - 5, - 5, - 7, - 7, - 7, - 9, - 9, - 9 - }; - const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); - R r = m.lower_bound(4); - assert(r == next(m.begin(), 0)); - r = m.lower_bound(5); - assert(r == next(m.begin(), 0)); - r = m.lower_bound(6); - assert(r == next(m.begin(), 3)); - r = m.lower_bound(7); - assert(r == next(m.begin(), 3)); - r = m.lower_bound(8); - assert(r == next(m.begin(), 6)); - r = m.lower_bound(9); - assert(r == next(m.begin(), 6)); - r = m.lower_bound(11); - assert(r == next(m.begin(), 9)); + typedef M::const_iterator R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.lower_bound(4); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(5); + assert(r == next(m.begin(), 0)); + r = m.lower_bound(6); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(7); + assert(r == next(m.begin(), 3)); + r = m.lower_bound(8); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(9); + assert(r == next(m.begin(), 6)); + r = m.lower_bound(11); + assert(r == next(m.begin(), 9)); + } } +#endif } diff --git a/libcxx/test/containers/associative/multiset/max_size.pass.cpp b/libcxx/test/containers/associative/multiset/max_size.pass.cpp index cf3581ef5dc..a209d700ee6 100644 --- a/libcxx/test/containers/associative/multiset/max_size.pass.cpp +++ b/libcxx/test/containers/associative/multiset/max_size.pass.cpp @@ -16,9 +16,20 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { + { typedef std::multiset<int> M; M m; assert(m.max_size() != 0); + } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + M m; + assert(m.max_size() != 0); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/multiset.cons/assign_initializer_list.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/assign_initializer_list.pass.cpp index a6834afe0db..16ba28abfca 100644 --- a/libcxx/test/containers/associative/multiset/multiset.cons/assign_initializer_list.pass.cpp +++ b/libcxx/test/containers/associative/multiset/multiset.cons/assign_initializer_list.pass.cpp @@ -16,9 +16,12 @@ #include <set> #include <cassert> +#include "../../../min_allocator.h" + int main() { #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { typedef std::multiset<int> C; typedef C::value_type V; C m = {10, 8}; @@ -32,5 +35,23 @@ int main() assert(*++i == V(4)); assert(*++i == V(5)); assert(*++i == V(6)); + } #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> C; + typedef C::value_type V; + C m = {10, 8}; + m = {1, 2, 3, 4, 5, 6}; + assert(m.size() == 6); + assert(distance(m.begin(), m.end()) == 6); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/multiset.cons/default.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/default.pass.cpp index 72fd822f745..cf24bf771ce 100644 --- a/libcxx/test/containers/associative/multiset/multiset.cons/default.pass.cpp +++ b/libcxx/test/containers/associative/multiset/multiset.cons/default.pass.cpp @@ -16,9 +16,20 @@ #include <set> #include <cassert> +#include "../../../min_allocator.h" + int main() { + { std::multiset<int> m; assert(m.empty()); assert(m.begin() == m.end()); + } +#if __cplusplus >= 201103L + { + std::multiset<int, std::less<int>, min_allocator<int>> m; + assert(m.empty()); + assert(m.begin() == m.end()); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/multiset.cons/initializer_list.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/initializer_list.pass.cpp index 4ee2b4daa54..9e3186d9233 100644 --- a/libcxx/test/containers/associative/multiset/multiset.cons/initializer_list.pass.cpp +++ b/libcxx/test/containers/associative/multiset/multiset.cons/initializer_list.pass.cpp @@ -16,9 +16,12 @@ #include <set> #include <cassert> +#include "../../../min_allocator.h" + int main() { #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS + { typedef std::multiset<int> C; typedef C::value_type V; C m = {1, 2, 3, 4, 5, 6}; @@ -31,5 +34,22 @@ int main() assert(*++i == V(4)); assert(*++i == V(5)); assert(*++i == V(6)); + } #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> C; + typedef C::value_type V; + C m = {1, 2, 3, 4, 5, 6}; + assert(m.size() == 6); + assert(distance(m.begin(), m.end()) == 6); + C::const_iterator i = m.cbegin(); + assert(*i == V(1)); + assert(*++i == V(2)); + assert(*++i == V(3)); + assert(*++i == V(4)); + assert(*++i == V(5)); + assert(*++i == V(6)); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/multiset.cons/iter_iter.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/iter_iter.pass.cpp index d8a3c145370..3f0053996f3 100644 --- a/libcxx/test/containers/associative/multiset/multiset.cons/iter_iter.pass.cpp +++ b/libcxx/test/containers/associative/multiset/multiset.cons/iter_iter.pass.cpp @@ -18,9 +18,11 @@ #include <cassert> #include "test_iterators.h" +#include "../../../min_allocator.h" int main() { + { typedef int V; V ar[] = { @@ -47,4 +49,35 @@ int main() assert(*next(m.begin(), 6) == 3); assert(*next(m.begin(), 7) == 3); assert(*next(m.begin(), 8) == 3); + } +#if __cplusplus >= 201103L + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + std::multiset<V, std::less<V>, min_allocator<V>> m(input_iterator<const int*>(ar), + input_iterator<const int*>(ar+sizeof(ar)/sizeof(ar[0]))); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/multiset.cons/move.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/move.pass.cpp index dee53d98df6..97f593bb32b 100644 --- a/libcxx/test/containers/associative/multiset/multiset.cons/move.pass.cpp +++ b/libcxx/test/containers/associative/multiset/multiset.cons/move.pass.cpp @@ -18,6 +18,7 @@ #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { @@ -76,4 +77,43 @@ int main() assert(distance(mo.begin(), mo.end()) == 0); } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef int V; + V ar[] = + { + 1, + 1, + 1, + 2, + 2, + 2, + 3, + 3, + 3 + }; + typedef test_compare<std::less<int> > C; + typedef min_allocator<V> A; + std::multiset<int, C, A> mo(ar, ar+sizeof(ar)/sizeof(ar[0]), C(5), A()); + std::multiset<int, C, A> m = std::move(mo); + assert(m.get_allocator() == A()); + assert(m.key_comp() == C(5)); + assert(m.size() == 9); + assert(distance(m.begin(), m.end()) == 9); + assert(*next(m.begin(), 0) == 1); + assert(*next(m.begin(), 1) == 1); + assert(*next(m.begin(), 2) == 1); + assert(*next(m.begin(), 3) == 2); + assert(*next(m.begin(), 4) == 2); + assert(*next(m.begin(), 5) == 2); + assert(*next(m.begin(), 6) == 3); + assert(*next(m.begin(), 7) == 3); + assert(*next(m.begin(), 8) == 3); + + assert(mo.get_allocator() == A()); + assert(mo.key_comp() == C(5)); + assert(mo.size() == 0); + assert(distance(mo.begin(), mo.end()) == 0); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/multiset.cons/move_assign.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.cons/move_assign.pass.cpp index f17d29bb493..e02942ffeea 100644 --- a/libcxx/test/containers/associative/multiset/multiset.cons/move_assign.pass.cpp +++ b/libcxx/test/containers/associative/multiset/multiset.cons/move_assign.pass.cpp @@ -19,6 +19,7 @@ #include "../../../MoveOnly.h" #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { @@ -141,4 +142,45 @@ int main() assert(m1.empty()); } #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES +#if __cplusplus >= 201103L + { + typedef MoveOnly V; + typedef test_compare<std::less<MoveOnly> > C; + typedef min_allocator<V> A; + typedef std::multiset<MoveOnly, C, A> M; + typedef std::move_iterator<V*> I; + V a1[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m1(I(a1), I(a1+sizeof(a1)/sizeof(a1[0])), C(5), A()); + V a2[] = + { + V(1), + V(1), + V(1), + V(2), + V(2), + V(2), + V(3), + V(3), + V(3) + }; + M m2(I(a2), I(a2+sizeof(a2)/sizeof(a2[0])), C(5), A()); + M m3(C(3), A()); + m3 = std::move(m1); + assert(m3 == m2); + assert(m3.get_allocator() == A()); + assert(m3.key_comp() == C(5)); + assert(m1.empty()); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/multiset.special/member_swap.pass.cpp b/libcxx/test/containers/associative/multiset/multiset.special/member_swap.pass.cpp index db6ab15a5bc..8d5b1e822bc 100644 --- a/libcxx/test/containers/associative/multiset/multiset.special/member_swap.pass.cpp +++ b/libcxx/test/containers/associative/multiset/multiset.special/member_swap.pass.cpp @@ -16,8 +16,11 @@ #include <set> #include <cassert> +#include "../../../min_allocator.h" + int main() { + { typedef int V; typedef std::multiset<int> M; { @@ -104,4 +107,95 @@ int main() assert(m1 == m2_save); assert(m2 == m1_save); } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/size.pass.cpp b/libcxx/test/containers/associative/multiset/size.pass.cpp index f7b12388ce8..8129a9c3675 100644 --- a/libcxx/test/containers/associative/multiset/size.pass.cpp +++ b/libcxx/test/containers/associative/multiset/size.pass.cpp @@ -16,8 +16,11 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { + { typedef std::multiset<int> M; M m; assert(m.size() == 0); @@ -33,4 +36,24 @@ int main() assert(m.size() == 1); m.erase(m.begin()); assert(m.size() == 0); + } +#if __cplusplus >= 201103L + { + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + M m; + assert(m.size() == 0); + m.insert(M::value_type(2)); + assert(m.size() == 1); + m.insert(M::value_type(1)); + assert(m.size() == 2); + m.insert(M::value_type(2)); + assert(m.size() == 3); + m.erase(m.begin()); + assert(m.size() == 2); + m.erase(m.begin()); + assert(m.size() == 1); + m.erase(m.begin()); + assert(m.size() == 0); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/types.pass.cpp b/libcxx/test/containers/associative/multiset/types.pass.cpp index de5ee694fa4..e3331cddc6d 100644 --- a/libcxx/test/containers/associative/multiset/types.pass.cpp +++ b/libcxx/test/containers/associative/multiset/types.pass.cpp @@ -32,8 +32,11 @@ #include <set> #include <type_traits> +#include "../../min_allocator.h" + int main() { + { static_assert((std::is_same<std::multiset<int>::key_type, int>::value), ""); static_assert((std::is_same<std::multiset<int>::value_type, int>::value), ""); static_assert((std::is_same<std::multiset<int>::key_compare, std::less<int> >::value), ""); @@ -45,4 +48,20 @@ int main() static_assert((std::is_same<std::multiset<int>::const_pointer, const int*>::value), ""); static_assert((std::is_same<std::multiset<int>::size_type, std::size_t>::value), ""); static_assert((std::is_same<std::multiset<int>::difference_type, std::ptrdiff_t>::value), ""); + } +#if __cplusplus >= 201103L + { + static_assert((std::is_same<std::multiset<int, std::less<int>, min_allocator<int>>::key_type, int>::value), ""); + static_assert((std::is_same<std::multiset<int, std::less<int>, min_allocator<int>>::value_type, int>::value), ""); + static_assert((std::is_same<std::multiset<int, std::less<int>, min_allocator<int>>::key_compare, std::less<int> >::value), ""); + static_assert((std::is_same<std::multiset<int, std::less<int>, min_allocator<int>>::value_compare, std::less<int> >::value), ""); + static_assert((std::is_same<std::multiset<int, std::less<int>, min_allocator<int>>::allocator_type, min_allocator<int>>::value), ""); + static_assert((std::is_same<std::multiset<int, std::less<int>, min_allocator<int>>::reference, int&>::value), ""); + static_assert((std::is_same<std::multiset<int, std::less<int>, min_allocator<int>>::const_reference, const int&>::value), ""); + static_assert((std::is_same<std::multiset<int, std::less<int>, min_allocator<int>>::pointer, min_pointer<int>>::value), ""); + static_assert((std::is_same<std::multiset<int, std::less<int>, min_allocator<int>>::const_pointer, min_pointer<const int>>::value), ""); + static_assert((std::is_same<std::multiset<int, std::less<int>, min_allocator<int>>::size_type, std::size_t>::value), ""); + static_assert((std::is_same<std::multiset<int, std::less<int>, min_allocator<int>>::difference_type, std::ptrdiff_t>::value), ""); + } +#endif } diff --git a/libcxx/test/containers/associative/multiset/upper_bound.pass.cpp b/libcxx/test/containers/associative/multiset/upper_bound.pass.cpp index 592a3fcd82b..332254eef68 100644 --- a/libcxx/test/containers/associative/multiset/upper_bound.pass.cpp +++ b/libcxx/test/containers/associative/multiset/upper_bound.pass.cpp @@ -17,8 +17,11 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { + { typedef int V; typedef std::multiset<int> M; { @@ -81,4 +84,71 @@ int main() r = m.upper_bound(11); assert(r == next(m.begin(), 9)); } + } +#if __cplusplus >= 201103L + { + typedef int V; + typedef std::multiset<int, std::less<int>, min_allocator<int>> M; + { + typedef M::iterator R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 9)); + } + { + typedef M::const_iterator R; + V ar[] = + { + 5, + 5, + 5, + 7, + 7, + 7, + 9, + 9, + 9 + }; + const M m(ar, ar+sizeof(ar)/sizeof(ar[0])); + R r = m.upper_bound(4); + assert(r == next(m.begin(), 0)); + r = m.upper_bound(5); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(6); + assert(r == next(m.begin(), 3)); + r = m.upper_bound(7); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(8); + assert(r == next(m.begin(), 6)); + r = m.upper_bound(9); + assert(r == next(m.begin(), 9)); + r = m.upper_bound(11); + assert(r == next(m.begin(), 9)); + } + } +#endif } diff --git a/libcxx/test/containers/associative/set/clear.pass.cpp b/libcxx/test/containers/associative/set/clear.pass.cpp index aa632c7f1d9..c6e01023f65 100644 --- a/libcxx/test/containers/associative/set/clear.pass.cpp +++ b/libcxx/test/containers/associative/set/clear.pass.cpp @@ -16,6 +16,8 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { { @@ -37,4 +39,25 @@ int main() 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/libcxx/test/containers/associative/set/count.pass.cpp b/libcxx/test/containers/associative/set/count.pass.cpp index 4a678a198a7..7d7a31ad0db 100644 --- a/libcxx/test/containers/associative/set/count.pass.cpp +++ b/libcxx/test/containers/associative/set/count.pass.cpp @@ -16,11 +16,49 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { - typedef int V; - typedef std::set<int> M; { + 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[] = { @@ -53,4 +91,5 @@ int main() r = m.count(4); assert(r == 0); } +#endif } diff --git a/libcxx/test/containers/associative/set/emplace.pass.cpp b/libcxx/test/containers/associative/set/emplace.pass.cpp index e322ff1df6a..69fdbeeb6b2 100644 --- a/libcxx/test/containers/associative/set/emplace.pass.cpp +++ b/libcxx/test/containers/associative/set/emplace.pass.cpp @@ -19,6 +19,7 @@ #include "../../Emplaceable.h" #include "../../DefaultOnly.h" +#include "../../min_allocator.h" int main() { @@ -73,5 +74,17 @@ int main() 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/libcxx/test/containers/associative/set/emplace_hint.pass.cpp b/libcxx/test/containers/associative/set/emplace_hint.pass.cpp index be5d73dac93..8e7fbbc4033 100644 --- a/libcxx/test/containers/associative/set/emplace_hint.pass.cpp +++ b/libcxx/test/containers/associative/set/emplace_hint.pass.cpp @@ -19,6 +19,7 @@ #include "../../Emplaceable.h" #include "../../DefaultOnly.h" +#include "../../min_allocator.h" int main() { @@ -67,5 +68,16 @@ int main() 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/libcxx/test/containers/associative/set/empty.pass.cpp b/libcxx/test/containers/associative/set/empty.pass.cpp index 615bc61dd44..305ae39ff90 100644 --- a/libcxx/test/containers/associative/set/empty.pass.cpp +++ b/libcxx/test/containers/associative/set/empty.pass.cpp @@ -16,8 +16,11 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { + { typedef std::set<int> M; M m; assert(m.empty()); @@ -25,4 +28,16 @@ int main() 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/libcxx/test/containers/associative/set/equal_range.pass.cpp b/libcxx/test/containers/associative/set/equal_range.pass.cpp index 7b17a471371..95a933ef436 100644 --- a/libcxx/test/containers/associative/set/equal_range.pass.cpp +++ b/libcxx/test/containers/associative/set/equal_range.pass.cpp @@ -17,8 +17,11 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { + { typedef int V; typedef std::set<int> M; { @@ -153,4 +156,75 @@ int main() 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 } diff --git a/libcxx/test/containers/associative/set/erase_iter.pass.cpp b/libcxx/test/containers/associative/set/erase_iter.pass.cpp index 949e973961d..f05d4819e07 100644 --- a/libcxx/test/containers/associative/set/erase_iter.pass.cpp +++ b/libcxx/test/containers/associative/set/erase_iter.pass.cpp @@ -16,6 +16,8 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { { @@ -96,4 +98,84 @@ int main() 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 } diff --git a/libcxx/test/containers/associative/set/erase_iter_iter.pass.cpp b/libcxx/test/containers/associative/set/erase_iter_iter.pass.cpp index 283b8b57a2f..953d1be8bd4 100644 --- a/libcxx/test/containers/associative/set/erase_iter_iter.pass.cpp +++ b/libcxx/test/containers/associative/set/erase_iter_iter.pass.cpp @@ -16,6 +16,8 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { { @@ -76,4 +78,64 @@ int main() 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/libcxx/test/containers/associative/set/erase_key.pass.cpp b/libcxx/test/containers/associative/set/erase_key.pass.cpp index 61455b6c94c..12ee0af980e 100644 --- a/libcxx/test/containers/associative/set/erase_key.pass.cpp +++ b/libcxx/test/containers/associative/set/erase_key.pass.cpp @@ -16,6 +16,8 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { { @@ -107,4 +109,95 @@ int main() 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/libcxx/test/containers/associative/set/find.pass.cpp b/libcxx/test/containers/associative/set/find.pass.cpp index 96ab73b37b5..b661898a861 100644 --- a/libcxx/test/containers/associative/set/find.pass.cpp +++ b/libcxx/test/containers/associative/set/find.pass.cpp @@ -17,8 +17,11 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { + { typedef int V; typedef std::set<int> M; { @@ -87,4 +90,77 @@ int main() 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 } diff --git a/libcxx/test/containers/associative/set/insert_cv.pass.cpp b/libcxx/test/containers/associative/set/insert_cv.pass.cpp index 9cbb61618c1..eabd1a8722a 100644 --- a/libcxx/test/containers/associative/set/insert_cv.pass.cpp +++ b/libcxx/test/containers/associative/set/insert_cv.pass.cpp @@ -16,6 +16,8 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { { @@ -46,4 +48,34 @@ int main() 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/libcxx/test/containers/associative/set/insert_initializer_list.pass.cpp b/libcxx/test/containers/associative/set/insert_initializer_list.pass.cpp index e9245cd46b2..d75e8a8bcbd 100644 --- a/libcxx/test/containers/associative/set/insert_initializer_list.pass.cpp +++ b/libcxx/test/containers/associative/set/insert_initializer_list.pass.cpp @@ -16,9 +16,12 @@ #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}; @@ -34,5 +37,25 @@ int main() 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/libcxx/test/containers/associative/set/insert_iter_cv.pass.cpp b/libcxx/test/containers/associative/set/insert_iter_cv.pass.cpp index 78ce18337c9..d86d40e8909 100644 --- a/libcxx/test/containers/associative/set/insert_iter_cv.pass.cpp +++ b/libcxx/test/containers/associative/set/insert_iter_cv.pass.cpp @@ -16,6 +16,8 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { { @@ -42,4 +44,30 @@ int main() 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/libcxx/test/containers/associative/set/insert_iter_iter.pass.cpp b/libcxx/test/containers/associative/set/insert_iter_iter.pass.cpp index 3bc3a61544d..d99dbe365ac 100644 --- a/libcxx/test/containers/associative/set/insert_iter_iter.pass.cpp +++ b/libcxx/test/containers/associative/set/insert_iter_iter.pass.cpp @@ -18,6 +18,7 @@ #include <cassert> #include "test_iterators.h" +#include "../../min_allocator.h" int main() { @@ -44,4 +45,29 @@ int main() 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/libcxx/test/containers/associative/set/insert_iter_rv.pass.cpp b/libcxx/test/containers/associative/set/insert_iter_rv.pass.cpp index fdf9f05972c..cf2dcbf91bb 100644 --- a/libcxx/test/containers/associative/set/insert_iter_rv.pass.cpp +++ b/libcxx/test/containers/associative/set/insert_iter_rv.pass.cpp @@ -17,6 +17,7 @@ #include <cassert> #include "../../MoveOnly.h" +#include "../../min_allocator.h" int main() { @@ -45,5 +46,31 @@ int main() 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/libcxx/test/containers/associative/set/insert_rv.pass.cpp b/libcxx/test/containers/associative/set/insert_rv.pass.cpp index c7e868d7911..0b58af6cad0 100644 --- a/libcxx/test/containers/associative/set/insert_rv.pass.cpp +++ b/libcxx/test/containers/associative/set/insert_rv.pass.cpp @@ -17,6 +17,7 @@ #include <cassert> #include "../../MoveOnly.h" +#include "../../min_allocator.h" int main() { @@ -49,5 +50,35 @@ int main() 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/libcxx/test/containers/associative/set/iterator.pass.cpp b/libcxx/test/containers/associative/set/iterator.pass.cpp index eb401951aaa..b509aea0cb7 100644 --- a/libcxx/test/containers/associative/set/iterator.pass.cpp +++ b/libcxx/test/containers/associative/set/iterator.pass.cpp @@ -29,6 +29,8 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { { @@ -104,9 +106,89 @@ int main() assert(std::distance(m.cbegin(), m.cend()) == m.size()); assert(std::distance(m.rbegin(), m.rend()) == m.size()); assert(std::distance(m.crbegin(), m.crend()) == m.size()); - std::set<int, double>::const_iterator i; + 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 } diff --git a/libcxx/test/containers/associative/set/lower_bound.pass.cpp b/libcxx/test/containers/associative/set/lower_bound.pass.cpp index 8703c8a16b7..072a5879157 100644 --- a/libcxx/test/containers/associative/set/lower_bound.pass.cpp +++ b/libcxx/test/containers/associative/set/lower_bound.pass.cpp @@ -17,8 +17,11 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { + { typedef int V; typedef std::set<int> M; { @@ -119,4 +122,109 @@ int main() 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 } diff --git a/libcxx/test/containers/associative/set/max_size.pass.cpp b/libcxx/test/containers/associative/set/max_size.pass.cpp index 493c78514a8..b744b9eb16a 100644 --- a/libcxx/test/containers/associative/set/max_size.pass.cpp +++ b/libcxx/test/containers/associative/set/max_size.pass.cpp @@ -16,9 +16,20 @@ #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/libcxx/test/containers/associative/set/set.cons/assign_initializer_list.pass.cpp b/libcxx/test/containers/associative/set/set.cons/assign_initializer_list.pass.cpp index b37e0d4740e..26f38e94b19 100644 --- a/libcxx/test/containers/associative/set/set.cons/assign_initializer_list.pass.cpp +++ b/libcxx/test/containers/associative/set/set.cons/assign_initializer_list.pass.cpp @@ -16,9 +16,12 @@ #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}; @@ -32,5 +35,23 @@ int main() 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/libcxx/test/containers/associative/set/set.cons/default.pass.cpp b/libcxx/test/containers/associative/set/set.cons/default.pass.cpp index 955a0d37df4..300b4fc6873 100644 --- a/libcxx/test/containers/associative/set/set.cons/default.pass.cpp +++ b/libcxx/test/containers/associative/set/set.cons/default.pass.cpp @@ -16,9 +16,20 @@ #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()); + } +#endif } diff --git a/libcxx/test/containers/associative/set/set.cons/initializer_list.pass.cpp b/libcxx/test/containers/associative/set/set.cons/initializer_list.pass.cpp index badb107ab86..7d981a11a85 100644 --- a/libcxx/test/containers/associative/set/set.cons/initializer_list.pass.cpp +++ b/libcxx/test/containers/associative/set/set.cons/initializer_list.pass.cpp @@ -16,9 +16,12 @@ #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}; @@ -31,5 +34,22 @@ int main() 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/libcxx/test/containers/associative/set/set.cons/iter_iter.pass.cpp b/libcxx/test/containers/associative/set/set.cons/iter_iter.pass.cpp index ff068503e5b..3248257fe2a 100644 --- a/libcxx/test/containers/associative/set/set.cons/iter_iter.pass.cpp +++ b/libcxx/test/containers/associative/set/set.cons/iter_iter.pass.cpp @@ -18,9 +18,11 @@ #include <cassert> #include "test_iterators.h" +#include "../../../min_allocator.h" int main() { + { typedef int V; V ar[] = { @@ -41,4 +43,29 @@ int main() 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/libcxx/test/containers/associative/set/set.cons/move.pass.cpp b/libcxx/test/containers/associative/set/set.cons/move.pass.cpp index 350513ab995..2d1b37f4e07 100644 --- a/libcxx/test/containers/associative/set/set.cons/move.pass.cpp +++ b/libcxx/test/containers/associative/set/set.cons/move.pass.cpp @@ -18,6 +18,7 @@ #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { @@ -69,5 +70,38 @@ int main() 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/libcxx/test/containers/associative/set/set.cons/move_assign.pass.cpp b/libcxx/test/containers/associative/set/set.cons/move_assign.pass.cpp index 15bcb6d64e2..3e82e28d516 100644 --- a/libcxx/test/containers/associative/set/set.cons/move_assign.pass.cpp +++ b/libcxx/test/containers/associative/set/set.cons/move_assign.pass.cpp @@ -19,6 +19,7 @@ #include "../../../MoveOnly.h" #include "../../../test_compare.h" #include "../../../test_allocator.h" +#include "../../../min_allocator.h" int main() { @@ -140,5 +141,46 @@ int main() 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/libcxx/test/containers/associative/set/set.special/member_swap.pass.cpp b/libcxx/test/containers/associative/set/set.special/member_swap.pass.cpp index 0ac283729ed..aa38fe03577 100644 --- a/libcxx/test/containers/associative/set/set.special/member_swap.pass.cpp +++ b/libcxx/test/containers/associative/set/set.special/member_swap.pass.cpp @@ -16,8 +16,11 @@ #include <set> #include <cassert> +#include "../../../min_allocator.h" + int main() { + { typedef int V; typedef std::set<int> M; { @@ -104,4 +107,95 @@ int main() 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; + { + V ar1[] = + { + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + { + V ar1[] = + { + 1, + 2, + 3, + 4 + }; + V ar2[] = + { + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12 + }; + M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0])); + M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0])); + M m1_save = m1; + M m2_save = m2; + m1.swap(m2); + assert(m1 == m2_save); + assert(m2 == m1_save); + } + } +#endif } diff --git a/libcxx/test/containers/associative/set/size.pass.cpp b/libcxx/test/containers/associative/set/size.pass.cpp index e2083031191..e1b6b6ce7c8 100644 --- a/libcxx/test/containers/associative/set/size.pass.cpp +++ b/libcxx/test/containers/associative/set/size.pass.cpp @@ -16,8 +16,11 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { + { typedef std::set<int> M; M m; assert(m.size() == 0); @@ -33,4 +36,24 @@ int main() 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/libcxx/test/containers/associative/set/types.pass.cpp b/libcxx/test/containers/associative/set/types.pass.cpp index 5a6b2c3d4cd..04b9ead0381 100644 --- a/libcxx/test/containers/associative/set/types.pass.cpp +++ b/libcxx/test/containers/associative/set/types.pass.cpp @@ -32,8 +32,11 @@ #include <set> #include <type_traits> +#include "../../min_allocator.h" + int main() { + { static_assert((std::is_same<std::set<int>::key_type, int>::value), ""); static_assert((std::is_same<std::set<int>::value_type, int>::value), ""); static_assert((std::is_same<std::set<int>::key_compare, std::less<int> >::value), ""); @@ -45,4 +48,20 @@ int main() static_assert((std::is_same<std::set<int>::const_pointer, const int*>::value), ""); static_assert((std::is_same<std::set<int>::size_type, std::size_t>::value), ""); static_assert((std::is_same<std::set<int>::difference_type, std::ptrdiff_t>::value), ""); + } +#if __cplusplus >= 201103L + { + static_assert((std::is_same<std::set<int, std::less<int>, min_allocator<int>>::key_type, int>::value), ""); + static_assert((std::is_same<std::set<int, std::less<int>, min_allocator<int>>::value_type, int>::value), ""); + static_assert((std::is_same<std::set<int, std::less<int>, min_allocator<int>>::key_compare, std::less<int> >::value), ""); + static_assert((std::is_same<std::set<int, std::less<int>, min_allocator<int>>::value_compare, std::less<int> >::value), ""); + static_assert((std::is_same<std::set<int, std::less<int>, min_allocator<int>>::allocator_type, min_allocator<int> >::value), ""); + static_assert((std::is_same<std::set<int, std::less<int>, min_allocator<int>>::reference, int&>::value), ""); + static_assert((std::is_same<std::set<int, std::less<int>, min_allocator<int>>::const_reference, const int&>::value), ""); + static_assert((std::is_same<std::set<int, std::less<int>, min_allocator<int>>::pointer, min_pointer<int>>::value), ""); + static_assert((std::is_same<std::set<int, std::less<int>, min_allocator<int>>::const_pointer, min_pointer<const int>>::value), ""); + static_assert((std::is_same<std::set<int, std::less<int>, min_allocator<int>>::size_type, std::size_t>::value), ""); + static_assert((std::is_same<std::set<int, std::less<int>, min_allocator<int>>::difference_type, std::ptrdiff_t>::value), ""); + } +#endif } diff --git a/libcxx/test/containers/associative/set/upper_bound.pass.cpp b/libcxx/test/containers/associative/set/upper_bound.pass.cpp index 8f5713308c0..3d000d88e57 100644 --- a/libcxx/test/containers/associative/set/upper_bound.pass.cpp +++ b/libcxx/test/containers/associative/set/upper_bound.pass.cpp @@ -17,8 +17,11 @@ #include <set> #include <cassert> +#include "../../min_allocator.h" + int main() { + { typedef int V; typedef std::set<int> M; { @@ -119,4 +122,109 @@ int main() 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 } diff --git a/libcxx/test/containers/min_allocator.h b/libcxx/test/containers/min_allocator.h new file mode 100644 index 00000000000..7aa197758a5 --- /dev/null +++ b/libcxx/test/containers/min_allocator.h @@ -0,0 +1,268 @@ +#ifndef MIN_ALLOCATOR_H +#define MIN_ALLOCATOR_H + +#if __cplusplus >= 201103L + +#include <memory> + +template <class T> class min_pointer; +template <class T> class min_pointer<const T>; +template <> class min_pointer<void>; +template <> class min_pointer<const void>; +template <class T> class min_allocator; + +template <class T> +bool +operator==(min_pointer<T> x, min_pointer<T> y); + +template <> +class min_pointer<const void> +{ + const void* ptr_; +public: + min_pointer() noexcept = default; + min_pointer(std::nullptr_t) : ptr_(nullptr) {} + template <class T> + min_pointer(min_pointer<T> p) : ptr_(p.ptr_) {} + + explicit operator bool() const {return ptr_ != nullptr;} + + template <class U> friend bool operator==(min_pointer<U>, min_pointer<U>); + template <class U> friend class min_pointer; +}; + +template <> +class min_pointer<void> +{ + void* ptr_; +public: + min_pointer() noexcept = default; + min_pointer(std::nullptr_t) : ptr_(nullptr) {} + template <class T, + class = typename std::enable_if + < + !std::is_const<T>::value + >::type + > + min_pointer(min_pointer<T> p) : ptr_(p.ptr_) {} + + explicit operator bool() const {return ptr_ != nullptr;} + + template <class U> friend bool operator==(min_pointer<U>, min_pointer<U>); + template <class U> friend class min_pointer; +}; + +template <class T> +class min_pointer +{ + T* ptr_; + + explicit min_pointer(T* p) : ptr_(p) {} +public: + min_pointer() noexcept = default; + min_pointer(std::nullptr_t) : ptr_(nullptr) {} + explicit min_pointer(min_pointer<void> p) : ptr_(static_cast<T*>(p.ptr_)) {} + + explicit operator bool() const {return ptr_ != nullptr;} + + typedef std::ptrdiff_t difference_type; + typedef T& reference; + typedef T* pointer; + typedef T value_type; + typedef std::random_access_iterator_tag iterator_category; + + reference operator*() const {return *ptr_;} + pointer operator->() const {return ptr_;} + + min_pointer& operator++() {++ptr_; return *this;} + min_pointer operator++(int) {min_pointer tmp(*this); ++ptr_; return tmp;} + + min_pointer& operator--() {--ptr_; return *this;} + min_pointer operator--(int) {min_pointer tmp(*this); --ptr_; return tmp;} + + min_pointer& operator+=(difference_type n) {ptr_ += n; return *this;} + min_pointer& operator-=(difference_type n) {ptr_ -= n; return *this;} + + min_pointer operator+(difference_type n) const + { + min_pointer tmp(*this); + tmp += n; + return tmp; + } + + friend min_pointer operator+(difference_type n, min_pointer x) + { + return x + n; + } + + min_pointer operator-(difference_type n) const + { + min_pointer tmp(*this); + tmp -= n; + return tmp; + } + + friend difference_type operator-(min_pointer x, min_pointer y) + { + return x.ptr_ - y.ptr_; + } + + reference operator[](difference_type n) const {return ptr_[n];} + + friend bool operator< (min_pointer x, min_pointer y) {return x.ptr_ < y.ptr_;} + friend bool operator> (min_pointer x, min_pointer y) {return y < x;} + friend bool operator<=(min_pointer x, min_pointer y) {return !(y < x);} + friend bool operator>=(min_pointer x, min_pointer y) {return !(x < y);} + + static min_pointer pointer_to(T& t) {return min_pointer(std::addressof(t));} + + template <class U> friend bool operator==(min_pointer<U>, min_pointer<U>); + template <class U> friend class min_pointer; + template <class U> friend class min_allocator; +}; + +template <class T> +class min_pointer<const T> +{ + const T* ptr_; + + explicit min_pointer(const T* p) : ptr_(p) {} +public: + min_pointer() noexcept = default; + min_pointer(std::nullptr_t) : ptr_(nullptr) {} + min_pointer(min_pointer<T> p) : ptr_(p.ptr_) {} + explicit min_pointer(min_pointer<const void> p) : ptr_(static_cast<const T*>(p.ptr_)) {} + + explicit operator bool() const {return ptr_ != nullptr;} + + typedef std::ptrdiff_t difference_type; + typedef const T& reference; + typedef const T* pointer; + typedef const T value_type; + typedef std::random_access_iterator_tag iterator_category; + + reference operator*() const {return *ptr_;} + pointer operator->() const {return ptr_;} + + min_pointer& operator++() {++ptr_; return *this;} + min_pointer operator++(int) {min_pointer tmp(*this); ++ptr_; return tmp;} + + min_pointer& operator--() {--ptr_; return *this;} + min_pointer operator--(int) {min_pointer tmp(*this); --ptr_; return tmp;} + + min_pointer& operator+=(difference_type n) {ptr_ += n; return *this;} + min_pointer& operator-=(difference_type n) {ptr_ -= n; return *this;} + + min_pointer operator+(difference_type n) const + { + min_pointer tmp(*this); + tmp += n; + return tmp; + } + + friend min_pointer operator+(difference_type n, min_pointer x) + { + return x + n; + } + + min_pointer operator-(difference_type n) const + { + min_pointer tmp(*this); + tmp -= n; + return tmp; + } + + friend difference_type operator-(min_pointer x, min_pointer y) + { + return x.ptr_ - y.ptr_; + } + + reference operator[](difference_type n) const {return ptr_[n];} + + friend bool operator< (min_pointer x, min_pointer y) {return x.ptr_ < y.ptr_;} + friend bool operator> (min_pointer x, min_pointer y) {return y < x;} + friend bool operator<=(min_pointer x, min_pointer y) {return !(y < x);} + friend bool operator>=(min_pointer x, min_pointer y) {return !(x < y);} + + static min_pointer pointer_to(const T& t) {return min_pointer(std::addressof(t));} + + template <class U> friend bool operator==(min_pointer<U>, min_pointer<U>); + template <class U> friend class min_pointer; +}; + +template <class T> +inline +bool +operator==(min_pointer<T> x, min_pointer<T> y) +{ + return x.ptr_ == y.ptr_; +} + +template <class T> +inline +bool +operator!=(min_pointer<T> x, min_pointer<T> y) +{ + return !(x == y); +} + +template <class T> +inline +bool +operator==(min_pointer<T> x, std::nullptr_t) +{ + return !static_cast<bool>(x); +} + +template <class T> +inline +bool +operator==(std::nullptr_t, min_pointer<T> x) +{ + return !static_cast<bool>(x); +} + +template <class T> +inline +bool +operator!=(min_pointer<T> x, std::nullptr_t) +{ + return static_cast<bool>(x); +} + +template <class T> +inline +bool +operator!=(std::nullptr_t, min_pointer<T> x) +{ + return static_cast<bool>(x); +} + +template <class T> +class min_allocator +{ +public: + typedef T value_type; + typedef min_pointer<T> pointer; + + min_allocator() = default; + template <class U> + min_allocator(min_allocator<U>) {} + + pointer allocate(std::ptrdiff_t n) + { + return pointer(static_cast<T*>(::operator new(n*sizeof(T)))); + } + + void deallocate(pointer p, std::ptrdiff_t) + { + return ::operator delete(p.ptr_); + } + + friend bool operator==(min_allocator, min_allocator) {return true;} + friend bool operator!=(min_allocator x, min_allocator y) {return !(x == y);} +}; + +#endif // __cplusplus >= 201103L + +#endif // MIN_ALLOCATOR_H |