refs #290 using a CRange of iterator adaptors to return from the secondary predicate-based methods of the containers without copying elements

This commit is contained in:
Mathew Sutcliffe
2014-06-28 22:38:26 +01:00
parent 101c5a4f98
commit 98a6854f8c
2 changed files with 42 additions and 4 deletions

View File

@@ -201,6 +201,13 @@ namespace BlackMisc
*/
void insert(CCollection &&other) { std::move(other.begin(), other.end(), std::inserter(*this, begin())); }
/*!
* \brief Appends all elements from a range at the end of this collection.
* \pre This collection must be initialized.
*/
template <typename I>
void insert(const CRange<I> &range) { std::copy(range.begin(), range.end(), std::back_inserter(*this)); }
/*!
* \brief Synonym for insert.
* \return An iterator to the position where value was inserted.
@@ -228,9 +235,17 @@ namespace BlackMisc
void push_back(CCollection &&other) { insert(std::move(other)); }
/*!
* \brief Returns a collection which is the union of this collection and another.
* \brief Synonym for insert.
* \pre This collection must be initialized.
*/
CCollection makeUnion(const CCollection &other) const
template <typename I>
void push_back(const CRange<I> &range) { std::copy(range.begin(), range.end(), std::back_inserter(*this)); }
/*!
* \brief Returns a collection which is the union of this collection and another container.
*/
template <class C>
CCollection makeUnion(const C &other) const
{
CCollection result;
std::set_union(begin(), end(), other.begin(), other.end(), std::inserter(result, result.begin()));
@@ -240,7 +255,8 @@ namespace BlackMisc
/*!
* \brief Returns a collection which is the intersection of this collection and another.
*/
CCollection intersection(const CCollection &other) const
template <class C>
CCollection intersection(const C &other) const
{
CCollection result;
std::set_intersection(begin(), end(), other.begin(), other.end(), std::inserter(result, result.begin()));
@@ -250,7 +266,8 @@ namespace BlackMisc
/*!
* \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
template <class C>
CCollection difference(const C &other) const
{
CCollection result;
std::set_difference(begin(), end(), other.begin(), other.end(), std::inserter(result, result.begin()));

View File

@@ -239,6 +239,13 @@ namespace BlackMisc
*/
void push_back(CSequence &&other) { std::move(other.begin(), other.end(), std::back_inserter(*this)); }
/*!
* \brief Appends all elements from a range at the end of this sequence.
* \pre This sequence must be initialized.
*/
template <typename I>
void push_back(const CRange<I> &range) { std::copy(range.begin(), range.end(), std::back_inserter(*this)); }
/*!
* \brief Synonym for push_back.
* \pre The sequence must be initialized.
@@ -263,12 +270,26 @@ namespace BlackMisc
*/
void insert(CSequence &&other) { push_back(std::move(other)); }
/*!
* \brief Synonym for push_back.
* \pre This sequence must be initialized.
*/
template <typename I>
void insert(const CRange<I> &range) { std::copy(range.begin(), range.end(), std::back_inserter(*this)); }
/*!
* \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 Concatenates a sequence and a range and returns the result.
* \pre This sequence must be initialized.
*/
template <typename I>
CSequence join(const CRange<I> &range) const { CSequence copy(*this); copy.push_back(range); return copy; }
/*!
* \brief Removes an element at the end of the sequence.
* \pre The sequence must contain at least one element.