// like C++ 2011: erase with const_iterator (doesn't change sort order)
const_iterator erase(const_iterator const& position)
{ // C++98 has vector::erase(iterator), so call that return m_vector.erase(m_vector.begin() + (position - m_vector.begin()));
}
/** *makeerasereturntheremovedelement,otherwisethereisnousefulwayofextractingastd::unique_ptr *fromthis.
*/
Value erase_extract( size_t index )
{
Value val = std::move(m_vector[index]);
m_vector.erase(m_vector.begin() + index); return val;
}
/* Searches the container for an element with a value of x *andreturnsaniteratortoitiffound,otherwiseitreturnsan *iteratortosorted_vector::end(theelementpasttheendofthecontainer). * *Onlyreturnaconstiterator,sothatthevectorcannotbedirectlyupdated.
*/ template <typename Comparable> const_iterator find(const Comparable& x) const
{
std::pair<const_iterator, bool> const ret(Find_t()(m_vector.begin(), m_vector.end(), x)); return (ret.second) ? ret.first : m_vector.end();
}
void insert(const sorted_vector& rOther)
{ // optimization for the rather common case that we are overwriting this with the contents // of another sorted vector if ( empty() )
m_vector.insert(m_vector.begin(), rOther.m_vector.begin(), rOther.m_vector.end()); else
insert_internal( rOther.m_vector );
}
/* Clear() elements in the vector, and free them one by one. */ void DeleteAndDestroyAll()
{ for (const_iterator it = m_vector.begin(); it != m_vector.end(); ++it)
{ delete *it;
}
clear();
}
// fdo#58793: some existing code in Writer (SwpHintsArray) // routinely modifies the members of the vector in a way that // violates the sort order, and then re-sorts the array. // This is a kludge to enable that code to work. // If you are calling this function, you are Doing It Wrong! void Resort()
{
std::stable_sort(m_vector.begin(), m_vector.end(), Compare());
}
void insert_internal( const std::vector<Value>& rOther )
{ // Do a union in one pass rather than repeated insert() that could repeatedly // move large amounts of data.
vector_t tmp;
tmp.reserve( m_vector.size() + rOther.size());
std::set_union( m_vector.begin(), m_vector.end(),
rOther.begin(), rOther.end(),
std::back_inserter( tmp ), Compare());
m_vector.swap( tmp );
}
vector_t m_vector;
};
/** Implements an ordering function over a pointer, where the comparison uses the < operator on the pointed-to types. Veryusefulforthecaseswhereweputpointerstoobjectsinsideasorted_vector.
*/ struct less_ptr_to
{ template <class T1, class T2> booloperator()(const T1& lhs, const T2& rhs) const
{ return (*lhs) < (*rhs);
}
};
/** the elements are partially ordered by Compare, 2elementsareallowediftheyarenotthesameelement(pointerequal)
*/ template <class Compare> struct find_partialorder_ptrequals
{ template <typename Iterator, typename Comparable> autooperator()(Iterator first, Iterator last, Comparable const& v)
{ autoconst& [begin, end] = std::equal_range(first, last, v, Compare()); for (auto it = begin; it != end; ++it)
{ if (&*v == &**it)
{ return std::make_pair(it, true);
}
} return std::make_pair(begin, false);
}
};
template <class Ref, class Referenced>
concept is_reference_to = std::is_convertible_v<decltype(*std::declval<Ref>()), Referenced>;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.