diff --git a/src/blackmisc/collection.h b/src/blackmisc/collection.h index c235c2e28..d842b2038 100644 --- a/src/blackmisc/collection.h +++ b/src/blackmisc/collection.h @@ -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 + void insert(const CRange &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 + void push_back(const CRange &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 + 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 + 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 + CCollection difference(const C &other) const { CCollection result; std::set_difference(begin(), end(), other.begin(), other.end(), std::inserter(result, result.begin())); diff --git a/src/blackmisc/sequence.h b/src/blackmisc/sequence.h index 1a0609e54..2414ce5e1 100644 --- a/src/blackmisc/sequence.h +++ b/src/blackmisc/sequence.h @@ -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 + void push_back(const CRange &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 + void insert(const CRange &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 + CSequence join(const CRange &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.