Class vector_multiset

Synopsis

#include <include/EASTL/vector_multiset.h>

template <typename Key, typename Compare = eastl::less<Key>, typename Allocator = EASTLAllocatorType, 
		  typename RandomAccessContainer = eastl::vector<Key, Allocator> >
class vector_multiset : public RandomAccessContainer

Description

vector_multiset

Implements a multiset via a random access container such as a vector. This container is also known as a sorted_vector. We choose to call it vector_multiset, as that is a more consistent universally applicable name for it in this library.

Note that with vector_set, vector_multiset, vector_map, vector_multimap that the modification of the container potentially invalidates all existing iterators into the container, unlike what happens with conventional sets and maps.

To consider: std::multiset has the limitation that values in the set cannot be modified, with the idea that modifying them would change their sort order. We have the opportunity to make it so that values can be modified via changing iterators to be non-const, with the downside being that the container can get screwed up if the user screws up. Alternatively, we can do what std STL does and require the user to make their stored classes use 'mutable' as needed. See the C++ standard defect report #103 (DR 103) for a discussion of this.

Note that the erase functions return iterator and not void. This allows for more efficient use of the container and is consistent with the C++ language defect report #130 (DR 130)

Mentioned in

Inheritance

Ancestors: vector

Methods

vector_multiset overloadvector_multiset
count
emplaceInherited from base class:
emplace_back
emplace_back_unsorted
emplace_hint
equal_range overload
equal_range_small overloadequal_range_small This is a special version of equal_range which is optimized for the case of there being few or no duplicated keys in the tree.
equal_range_small overload/ VC++ fails to compile this when defined here, saying the function isn't a memgber of vector_multimap
erase overload
find overload
find_as overload
insert overload
key_comp overload
lower_bound overload
operator= overload
push_back overloadFunctions which are disallowed due to being unsafe.
push_back_uninitialized
push_back_unsortedNOTE(rparolin): It is undefined behaviour if user code fails to ensure the container invariants are respected by performing an explicit call to 'sort' before any other operations on the container are performed that do not clear the elements.
swap
upper_bound overload
value_comp overload

Source

Lines 89-255 in include/EASTL/vector_multiset.h.

template <typename Key, typename Compare = eastl::less<Key>, typename Allocator = EASTLAllocatorType, 
          typename RandomAccessContainer = eastl::vector<Key, Allocator> >
class vector_multiset : public RandomAccessContainer
{
public:
    typedef RandomAccessContainer                                           base_type;
    typedef vector_multiset<Key, Compare, Allocator, RandomAccessContainer> this_type;
    typedef Allocator                                                       allocator_type;
    typedef Key                                                             key_type;
    typedef Key                                                             value_type;
    typedef Compare                                                         key_compare;
    typedef Compare                                                         value_compare;
    typedef value_type*                                                     pointer;
    typedef const value_type*                                               const_pointer;
    typedef value_type&                                                     reference;
    typedef const value_type&                                               const_reference;
    typedef typename base_type::size_type                                   size_type;
    typedef typename base_type::difference_type                             difference_type;
    typedef typename base_type::iterator                                    iterator;         // **Currently typedefing from iterator instead of const_iterator due to const issues **: Note that we typedef from const_iterator. This is by design, as sets are sorted and values cannot be modified. To consider: allow values to be modified and thus risk changing their sort values.
    typedef typename base_type::const_iterator                              const_iterator;
    typedef typename base_type::reverse_iterator                            reverse_iterator; // See notes directly above regarding const_iterator.
    typedef typename base_type::const_reverse_iterator                      const_reverse_iterator;
    using base_type::begin;
    using base_type::end;
    using base_type::get_allocator;
protected:
    value_compare mCompare; // To consider: Declare this instead as: 'key_compare mKeyCompare'
public:
    // We have an empty ctor and a ctor that takes an allocator instead of one for both
    // because this way our RandomAccessContainer wouldn't be required to have an constructor
    // that takes allocator_type. 
    vector_multiset();
    explicit vector_multiset(const allocator_type& allocator);
    explicit vector_multiset(const key_compare& comp, const allocator_type& allocator = EASTL_VECTOR_MULTISET_DEFAULT_ALLOCATOR);
    vector_multiset(const this_type& x);
    vector_multiset(this_type&& x);
    vector_multiset(this_type&& x, const allocator_type& allocator);
    vector_multiset(std::initializer_list<value_type> ilist, const key_compare& compare = key_compare(), const allocator_type& allocator = EASTL_VECTOR_MULTISET_DEFAULT_ALLOCATOR);
    template <typename InputIterator>
    vector_multiset(InputIterator first, InputIterator last); // allocator arg removed because VC7.1 fails on the default arg. To do: Make a second version of this function without a default arg.
    template <typename InputIterator>
    vector_multiset(InputIterator first, InputIterator last, const key_compare& compare); // allocator arg removed because VC7.1 fails on the default arg. To do: Make a second version of this function without a default arg.
    this_type& operator=(const this_type& x);
    this_type& operator=(std::initializer_list<value_type> ilist);
    this_type& operator=(this_type&& x);
    void swap(this_type& x);
    const key_compare& key_comp() const;
    key_compare&       key_comp();
    const value_compare& value_comp() const;
    value_compare&       value_comp();
    // Inherited from base class:
    //
    //     allocator_type& get_allocator();
    //     void            set_allocator(const allocator_type& allocator);
    //
    //     iterator       begin();
    //     const_iterator begin() const;
    //     const_iterator cbegin() const;
    //
    //     iterator       end();
    //     const_iterator end() const;
    //     const_iterator cend() const;
    //
    //     reverse_iterator       rbegin();
    //     const_reverse_iterator rbegin() const;
    //     const_reverse_iterator crbegin() const;
    //
    //     reverse_iterator       rend();
    //     const_reverse_iterator rend() const;
    //     const_reverse_iterator crend() const;
    //
    //     size_type size() const;
    //     bool      empty() const;
    //     void      clear();
    template <class... Args>
    iterator emplace(Args&&... args);
    template <class... Args> 
    iterator emplace_hint(const_iterator position, Args&&... args);
    iterator insert(const value_type& value);   // The signature of this function was change in EASTL v2.05.00 from (the mistaken) pair<iterator, bool> to (the correct) iterator.
    iterator insert(const_iterator position, const value_type& value);
    iterator insert(const_iterator position, value_type&& value);
    void     insert(std::initializer_list<value_type> ilist);
    template <typename P>
    iterator insert(P&& otherValue);
    template <typename InputIterator>
    void insert(InputIterator first, InputIterator last);
    iterator         erase(const_iterator position);
    iterator         erase(const_iterator first, const_iterator last);
    size_type        erase(const key_type& k);
    reverse_iterator erase(const_reverse_iterator position);
    reverse_iterator erase(const_reverse_iterator first, const_reverse_iterator last);
    iterator       find(const key_type& k);
    const_iterator find(const key_type& k) const;
    template <typename U, typename BinaryPredicate>
    iterator       find_as(const U& u, BinaryPredicate predicate);
    template <typename U, typename BinaryPredicate>
    const_iterator find_as(const U& u, BinaryPredicate predicate) const;
    size_type count(const key_type& k) const;
    iterator       lower_bound(const key_type& k);
    const_iterator lower_bound(const key_type& k) const;
    iterator       upper_bound(const key_type& k);
    const_iterator upper_bound(const key_type& k) const;
    eastl::pair<iterator, iterator>             equal_range(const key_type& k);
    eastl::pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
    /// equal_range_small
    /// This is a special version of equal_range which is optimized for the 
    /// case of there being few or no duplicated keys in the tree.
    eastl::pair<iterator, iterator>             equal_range_small(const key_type& k)
    {
        // Defined inline because VC7.1 is broken for when it's defined outside.
        const iterator itLower(lower_bound(k));
        iterator       itUpper(itLower);
        while((itUpper != end()) && !mCompare(k, *itUpper))
            ++itUpper;
        return eastl::pair<iterator, iterator>(itLower, itUpper);
    }
    eastl::pair<const_iterator, const_iterator> equal_range_small(const key_type& k) const;
    // Functions which are disallowed due to being unsafe. 
    void      push_back(const value_type& value) = delete;
    reference push_back()                        = delete;
    void*     push_back_uninitialized()          = delete;
    template <class... Args>
    reference emplace_back(Args&&...)            = delete;
    // NOTE(rparolin): It is undefined behaviour if user code fails to ensure the container
    // invariants are respected by performing an explicit call to 'sort' before any other
    // operations on the container are performed that do not clear the elements.
    //
    // 'push_back_unsorted' and 'emplace_back_unsorted' do not satisfy container invariants
    // for being sorted. We provide these overloads explicitly labelled as '_unsorted' as an
    // optimization opportunity when batch inserting elements so users can defer the cost of
    // sorting the container once when all elements are contained. This was done to clarify
    // the intent of code by leaving a trace that a manual call to sort is required.
    // 
    template <typename... Args> decltype(auto) push_back_unsorted(Args&&... args)    
        { return base_type::push_back(eastl::forward<Args>(args)...); }
    template <typename... Args> decltype(auto) emplace_back_unsorted(Args&&... args) 
        { return base_type::emplace_back(eastl::forward<Args>(args)...); }
}; // vector_multiset





Add Discussion as Guest

Log in