Commit b7a56965 authored by Quentin Khan's avatar Quentin Khan

Fix variadic_vector ranged insert

The ranged insert would not take a range of tuples but two tuple of
iterators defining a range for each sub-vector. It is now possible to
use both.

The assign overload for initializer_list, which worked aroung this bug,
is changed to reflect the fix.
parent e49fbac4
......@@ -795,6 +795,7 @@ public:
template<typename TupleIterator>
void assign(TupleIterator first_it, TupleIterator last_it) {
clear();
this->reserve(last_it - first_it);
insert(begin(), first_it, last_it);
}
......@@ -808,9 +809,7 @@ public:
void assign(std::initializer_list<value_type> ilist) {
this->clear();
this->reserve(ilist.size());
for(auto&& i : ilist) {
insert(end(), i);
}
this->insert(this->begin(), std::begin(ilist), std::end(ilist));
}
/** \brief Deletes all elements from the vector */
......@@ -1021,13 +1020,10 @@ public:
*
* \warning Behaviour is undefined if the range belongs to the container
*/
template<class TupleIterator>
template<class TupleIterator,
typename std::enable_if<is_tuple_get_like<TupleIterator>::value, char>::type = 0
>
iterator insert(const_iterator pos, TupleIterator first, TupleIterator last) {
static_assert(is_tuple_get_like<TupleIterator>::value,
"TupleIterator is not convertible to a tuple of iterators");
static_assert(std::tuple_size<TupleIterator>::value == sizeof...(Types),
"TupleIterator has wrong size...");
size_type pos_idx = pos - this->begin();
size_type count = last - first;
......@@ -1049,6 +1045,31 @@ public:
}
/** \brief Insert elements from a range
*
* \tparam ValueIterator Iterator type convertible to a tuple of elements
* that are convertible to the elements of #value_type.
*
* \param pos Position before which to insert values
* \param first Begining of range to copy
* \param last End of range to copy
*
* \return An iterator pointing to the first element inserted
*
* \warning Behaviour is undefined if the range belongs to the container
*/
template<class ValueIterator,
typename std::enable_if<! is_tuple_get_like<ValueIterator>::value, char>::type = 0
>
iterator insert(const_iterator pos, ValueIterator first, ValueIterator last) {
auto ret_offset = pos - this->cbegin();
while(first != last) {
insert(pos, *first);
++pos;
++first;
}
return this->begin() + ret_offset;
}
/** Erase an element */
iterator erase(const_iterator pos) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment