mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 13:36:48 +08:00
refs #230 methods to combine and bisect containers
This commit is contained in:
@@ -188,6 +188,19 @@ namespace BlackMisc
|
||||
*/
|
||||
iterator insert(T &&value) { Q_ASSERT(pimpl()); return pimpl()->insert(std::move(value)); }
|
||||
|
||||
/*!
|
||||
* \brief Inserts all elements from another collection into this collection.
|
||||
* \pre This collection must be initialized.
|
||||
*/
|
||||
void insert(const CCollection &other) { std::copy(other.begin(), other.end(), std::inserter(*this, begin())); }
|
||||
|
||||
/*!
|
||||
* \brief Inserts all elements from another collection into this collection.
|
||||
* This version moves elements instead of copying.
|
||||
* \pre This collection must be initialized.
|
||||
*/
|
||||
void insert(CCollection &&other) { std::move(other.begin(), other.end(), std::inserter(*this, begin())); }
|
||||
|
||||
/*!
|
||||
* \brief Synonym for insert.
|
||||
* \return An iterator to the position where value was inserted.
|
||||
@@ -202,6 +215,48 @@ namespace BlackMisc
|
||||
*/
|
||||
iterator push_back(T &&value) { return insert(std::move(value)); }
|
||||
|
||||
/*!
|
||||
* \brief Synonym for insert.
|
||||
* \pre This collection must be initialized.
|
||||
*/
|
||||
void push_back(const CCollection &other) { insert(other); }
|
||||
|
||||
/*!
|
||||
* \brief Synonym for insert.
|
||||
* \pre This collection must be initialized.
|
||||
*/
|
||||
void push_back(CCollection &&other) { insert(std::move(other)); }
|
||||
|
||||
/*!
|
||||
* \brief Returns a collection which is the union of this collection and another.
|
||||
*/
|
||||
CCollection makeUnion(const CCollection &other) const
|
||||
{
|
||||
CCollection result;
|
||||
std::set_union(begin(), end(), other.begin(), other.end(), std::inserter(result, result.begin()));
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a collection which is the intersection of this collection and another.
|
||||
*/
|
||||
CCollection intersection(const CCollection &other) const
|
||||
{
|
||||
CCollection result;
|
||||
std::set_intersection(begin(), end(), other.begin(), other.end(), std::inserter(result, result.begin()));
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Returns a collection which contains all the elements from this collection which are not in the other collection.
|
||||
*/
|
||||
CCollection difference(const CCollection &other) const
|
||||
{
|
||||
CCollection result;
|
||||
std::set_difference(begin(), end(), other.begin(), other.end(), std::inserter(result, result.begin()));
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Remove the element pointed to by the given iterator.
|
||||
* \return An iterator to the position of the next element after the one removed.
|
||||
@@ -237,6 +292,12 @@ namespace BlackMisc
|
||||
*/
|
||||
void remove(const T &object) { auto it = find(object); if (it != end()) { erase(it); } }
|
||||
|
||||
/*!
|
||||
* \brief Removes from this collection all of the elements of another collection.
|
||||
* \pre This sequence must be initialized.
|
||||
*/
|
||||
void remove(const CCollection &other) { *this = CCollection(*this).difference(other); }
|
||||
|
||||
/*!
|
||||
* \brief Test for equality.
|
||||
* \todo Improve inefficient implementation.
|
||||
|
||||
@@ -206,6 +206,19 @@ namespace BlackMisc
|
||||
*/
|
||||
void push_back(T &&value) { Q_ASSERT(pimpl()); pimpl()->push_back(std::move(value)); }
|
||||
|
||||
/*!
|
||||
* \brief Appends all elements from another sequence at the end of this sequence.
|
||||
* \pre This sequence must be initialized.
|
||||
*/
|
||||
void push_back(const CSequence &other) { std::copy(other.begin(), other.end(), std::back_inserter(*this)); }
|
||||
|
||||
/*!
|
||||
* \brief Appends all elements from another sequence at the end of this sequence.
|
||||
* This version moves elements instead of copying.
|
||||
* \pre This sequence must be initialized.
|
||||
*/
|
||||
void push_back(CSequence &&other) { std::move(other.begin(), other.end(), std::back_inserter(*this)); }
|
||||
|
||||
/*!
|
||||
* \brief Synonym for push_back.
|
||||
* \pre The sequence must be initialized.
|
||||
@@ -218,6 +231,24 @@ namespace BlackMisc
|
||||
*/
|
||||
void insert(T &&value) { push_back(std::move(value)); }
|
||||
|
||||
/*!
|
||||
* \brief Synonym for push_back.
|
||||
* \pre The sequence must be initialized.
|
||||
*/
|
||||
void insert(const CSequence &other) { push_back(other); }
|
||||
|
||||
/*!
|
||||
* \brief Synonym for push_back.
|
||||
* \pre The sequence must be initialized.
|
||||
*/
|
||||
void insert(CSequence &&other) { push_back(std::move(other)); }
|
||||
|
||||
/*!
|
||||
* \brief Concatenates two sequences and returns the result.
|
||||
* \pre This sequence must be initialized.
|
||||
*/
|
||||
CSequence join(const CSequence &other) const { CSequence copy(*this); copy.push_back(other); return copy; }
|
||||
|
||||
/*!
|
||||
* \brief Removes an element at the end of the sequence.
|
||||
* \pre The sequence must contain at least one element.
|
||||
|
||||
Reference in New Issue
Block a user