48template <
class T,
class Compare = std::less<T>>
58 using iterator =
typename std::vector<T>::iterator;
61 typename std::vector<T>::reverse_iterator;
63 typename std::vector<T>::const_reverse_iterator;
80 for (
const auto& value : list)
insert(value);
95 return vector_.insert(it, std::forward<V>(value));
109 template <
typename V>
113 return vector_.insert(it, std::forward<V>(value));
123 template <
typename... Args>
125 return insert(T(std::forward<Args>(args)...));
137 template <
typename... Args>
139 return insert(T(std::forward<Args>(args)...), insert_lower);
154 const T&
at(
size_t i)
const {
155 if (i >=
vector_.size())
throw std::out_of_range(
"Index out of range");
167 const T&
at(
int i)
const {
168 if (i < 0) i =
static_cast<int>(
vector_.size()) + i;
169 if (i < 0 || i >=
static_cast<int>(
vector_.size()))
throw std::out_of_range(
"Index out of range");
201 if (it ==
vector_.end())
return false;
213 if (i >=
vector_.size())
return false;
227 if (i < 0) i =
static_cast<int>(
vector_.size()) - i;
228 if (i < 0 || i >=
static_cast<int>(
vector_.size()))
return false;
293 [[nodiscard]]
size_t count(
const T& value)
const {
294 auto it =
find(value);
295 if (it ==
vector_.end())
return 0;
307 [[nodiscard]]
bool contains(
const T& value)
const {
return find(value) != end(); }
357 [[nodiscard]]
inline bool is_equal(
const T& lhs,
const T& rhs)
const {
367 std::copy(it.cbegin(), std::prev(it.cend()), std::ostream_iterator<T>(os,
", "));
368 return os << *(it.crbegin());
371extern template class SortedVector<Bound>;
372extern template class SortedVector<int>;
373extern template class SortedVector<double>;
Vector that maintains its elements sorted.
std::vector< T > vector_
Underlying vector to store the sorted list.
SortedVector()=default
Construct a new SortedVector object.
const T & at(size_t i) const
Access element at index i with bounds checking.
const T & operator[](size_t i) const
Direct access to the underlying vector.
typename std::vector< T >::reverse_iterator reverse_iterator
Type of the reverse iterator to the sorted list.
bool erase_value(const T &value)
Remove an element with the provided value from the sorted list.
const T & const_reference
Type of the const reference to an element in the sorted list.
const T & at(int i) const
Access element at index i with bounds checking.
const_iterator find(const T &value) const
Find the index of an element with the provided value in the sorted list.
Compare compare_
Comparison function to maintain the sorted order.
iterator insert(V &&value, bool insert_lower)
Insert an element with the provided value into the sorted list.
bool contains(const T &value) const
Check if the element with the provided value is contained in the vector.
SortedVector(size_t size)
Construct a new SortedVector object with the giver size.
bool erase(size_t i)
Remove the element at index i from the sorted list.
bool erase(const const_iterator &it)
Remove the element at position it from the sorted list.
const_iterator lesser_end(const T &value) const
Find the last element in the vector with a value lesser than value and return an iterator to the posi...
void clear()
Clear the sorted list, removing all elements.
size_t size() const
Get read-only access to the size of the vector.
const T * const_pointer
Type of the const pointer to an element in the sorted list.
const T & front() const
Reference to the first element in the sorted list.
T * pointer
Type of the pointer to an element in the sorted list.
const_iterator upper_bound(const T &value) const
Find the last position in which an element with the provided value could be inserted without changing...
bool is_equal(const T &lhs, const T &rhs) const
Use the compare_ function to check if two elements are equal.
std::ptrdiff_t difference_type
Type of the difference between two iterators.
const_iterator greater_begin(const T &value) const
Find the first element in the vector with a value greater than value and return an iterator to its po...
typename std::vector< T >::const_reverse_iterator const_reverse_iterator
Type of the const reverse iterator to the sorted list.
SortedVector(std::initializer_list< T > list)
Construct a new SortedVector object using an initializer list.
iterator insert(V &&value)
Insert an element with the provided value into the sorted list.
bool empty() const
Check whether the vector is emtpy.
bool erase(int i)
Remove the element at index i from the sorted list.
size_t count(const T &value) const
Count the number of occurrences of an element with the provided value in the sorted list.
iterator emplace(bool insert_lower, Args &&... args)
Emplace a new element into the sorted list.
iterator emplace(Args &&... args)
Emplace a new element into the sorted list.
typename std::vector< T >::const_iterator const_iterator
Type of the const iterator to the sorted list.
typename std::vector< T >::iterator iterator
Type of the iterator to the sorted list.
T & reference
Type of the reference to an element in the sorted list.
size_t size_type
Type of the size of the sorted list.
const T & back() const
Reference to the last element in the sorted list.
const_iterator lower_bound(const T &value) const
Find the first position in which an element with the provided value could be inserted without changin...
T value_type
Type of the elements in the sorted list.
Global namespace for the dlinear library.