Not in the C ++ standard library, no. You either have set / priority_queue for ordering, or vector / deque for random access.
But you have nothing to stop writing your own wrapper around vector , which simply forcibly arranges. This is not much code. Some sample functions:
template <typename T, typename COMP = std::less<T>> class sorted_vec { std::vector<T> vec_; public: // random access using iterator = typename std::vector<T>::iterator; T& operator[](size_t idx) { return vec_[idx]; } iterator begin() { return vec_.begin(); } iterator end() { return vec_.end(); } // insertion void push(const T& val) { vec_.insert(std::lower_bound(vec_.begin(), vec_.end(), COMP{}), val); } };
Barry source share