diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json deleted file mode 100644 index 12e1e94e..00000000 --- a/.vs/VSWorkspaceState.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "ExpandedNodes": [ - "", - "\\arduino", - "\\include", - "\\include\\etl", - "\\include\\etl\\private", - "\\test" - ], - "SelectedNode": "\\test\\test_unordered_map.cpp", - "PreviewInSolutionExplorer": false -} \ No newline at end of file diff --git a/.vs/slnx.sqlite b/.vs/slnx.sqlite deleted file mode 100644 index 7a232630..00000000 Binary files a/.vs/slnx.sqlite and /dev/null differ diff --git a/include/etl/array.h b/include/etl/array.h index 9906b6ef..289e1d46 100644 --- a/include/etl/array.h +++ b/include/etl/array.h @@ -403,7 +403,7 @@ namespace etl //************************************************************************* iterator insert(const_iterator position, parameter_t value) { - iterator p = const_cast(position); + iterator p = to_iterator(position); etl::move_backward(p, end() - 1, end()); *p = value; @@ -432,7 +432,7 @@ namespace etl template iterator insert(const_iterator position, TIterator first, const TIterator last) { - iterator p = const_cast(position); + iterator p = to_iterator(position); iterator result(p); size_t source_size = etl::distance(first, last); @@ -468,7 +468,7 @@ namespace etl //************************************************************************* iterator erase(const_iterator position) { - iterator p = const_cast(position); + iterator p = to_iterator(position); etl::move(p + 1, end(), p); return p; @@ -493,7 +493,7 @@ namespace etl //************************************************************************* iterator erase(const_iterator first, const_iterator last) { - iterator p = const_cast(first); + iterator p = to_iterator(first); etl::move(last, cend(), p); return p; } @@ -515,7 +515,7 @@ namespace etl //************************************************************************* iterator erase(const_iterator position, parameter_t value) { - iterator p = const_cast(position); + iterator p = to_iterator(position); etl::move(p + 1, end(), p); back() = value; @@ -541,16 +541,26 @@ namespace etl //************************************************************************* iterator erase(const_iterator first, const_iterator last, parameter_t value) { - iterator p = const_cast(first); + iterator p = to_iterator(first); p = etl::move(last, cend(), p); etl::fill(p, end(), value); - return const_cast(first); + return to_iterator(first); } /// The array data. T _buffer[SIZE]; + + private: + + //************************************************************************* + /// Convert from const_iterator to iterator + //************************************************************************* + iterator to_iterator(const_iterator itr) const + { + return const_cast(itr); + } }; //************************************************************************* diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 7130606a..93fcd197 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -918,7 +918,7 @@ namespace etl iterator insert(const_iterator position, T value) { // Quick hack, as iterators are pointers. - iterator insert_position = const_cast(position); + iterator insert_position = to_iterator(position); if (current_size < CAPACITY) { @@ -967,15 +967,17 @@ namespace etl ///\param n The number of elements to add. ///\param value The value to insert. //********************************************************************* - void insert(const_iterator position, size_type n, T value) + iterator insert(const_iterator position, size_type n, T value) { + iterator position_ = to_iterator(position); + if (n == 0) { - return; + return position_; } // Quick hack, as iterators are pointers. - iterator insert_position = const_cast(position); + iterator insert_position = to_iterator(position); const size_type start = etl::distance(cbegin(), position); // No effect. @@ -988,7 +990,7 @@ namespace etl ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); #endif #endif - return; + return to_iterator(position);; } // Fills the string to the end? @@ -1040,6 +1042,8 @@ namespace etl } p_buffer[current_size] = 0; + + return position_; } //********************************************************************* @@ -1049,15 +1053,17 @@ namespace etl ///\param first The first element to add. ///\param last The last + 1 element to add. //********************************************************************* - template - void insert(iterator position, TIterator first, TIterator last) + template + iterator insert(const_iterator position, TIterator first, TIterator last) { + iterator position_ = to_iterator(position); + if (first == last) { - return; + return position_; } - const size_type start = etl::distance(begin(), position); + const size_type start = etl::distance(begin(), position_); const size_type n = etl::distance(first, last); // No effect. @@ -1070,7 +1076,7 @@ namespace etl ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); #endif #endif - return; + return position_; } // Fills the string to the end? @@ -1089,9 +1095,9 @@ namespace etl current_size = CAPACITY; - while (position != end()) + while (position_ != end()) { - *position++ = *first++; + *position_++ = *first++; } } else @@ -1121,15 +1127,17 @@ namespace etl current_size += shift_amount; } - etl::copy_backward(position, position + characters_to_shift, begin() + to_position + characters_to_shift); + etl::copy_backward(position_, position_ + characters_to_shift, begin() + to_position + characters_to_shift); while (first != last) { - *position++ = *first++; + *position_++ = *first++; } } p_buffer[current_size] = 0; + + return position_; } //********************************************************************* @@ -1260,6 +1268,21 @@ namespace etl return i_element; } + //********************************************************************* + /// Erases an element. + ///\param i_element Iterator to the element. + ///\return An iterator pointing to the element that followed the erased element. + //********************************************************************* + iterator erase(const_iterator i_element) + { + iterator i_element_(to_iterator(i_element)); + + etl::copy(i_element_ + 1, end(), i_element_); + p_buffer[--current_size] = 0; + + return i_element_; + } + //********************************************************************* /// Erases a range of elements. /// The range includes all the elements between first and last, including the @@ -1268,21 +1291,24 @@ namespace etl ///\param last Iterator to the last element. ///\return An iterator pointing to the element that followed the erased element. //********************************************************************* - iterator erase(iterator first, iterator last) + iterator erase(const_iterator first, const_iterator last) { - if (first == last) + iterator first_ = to_iterator(first); + iterator last_ = to_iterator(last); + + if (first_ == last_) { - return first; + return first_; } - etl::copy(last, end(), first); - size_type n_delete = etl::distance(first, last); + etl::copy(last_, end(), first_); + size_type n_delete = etl::distance(first_, last_); current_size -= n_delete; p_buffer[current_size] = 0; cleanup(); - return first; + return first_; } //********************************************************************* @@ -1576,8 +1602,8 @@ namespace etl ibasic_string& replace(const_iterator first, const_iterator last, const ibasic_string& str) { // Quick hack, as iterators are pointers. - iterator first_ = const_cast(first); - iterator last_ = const_cast(last); + iterator first_ = to_iterator(first); + iterator last_ = to_iterator(last); // Erase the bit we want to replace. erase(first_, last_); @@ -1656,8 +1682,8 @@ namespace etl ibasic_string& replace(const_iterator first, const_iterator last, const_pointer s) { // Quick hack, as iterators are pointers. - iterator first_ = const_cast(first); - iterator last_ = const_cast(last); + iterator first_ = to_iterator(first); + iterator last_ = to_iterator(last); // Erase the bit we want to replace. erase(first_, last_); @@ -1693,8 +1719,8 @@ namespace etl ibasic_string& replace(const_iterator first, const_iterator last, const_pointer s, size_type n) { // Quick hack, as iterators are pointers. - iterator first_ = const_cast(first); - iterator last_ = const_cast(last); + iterator first_ = to_iterator(first); + iterator last_ = to_iterator(last); // Erase the bit we want to replace. erase(first_, last_); @@ -1730,8 +1756,8 @@ namespace etl ibasic_string& replace(const_iterator first, const_iterator last, size_type n, value_type c) { // Quick hack, as iterators are pointers. - iterator first_ = const_cast(first); - iterator last_ = const_cast(last); + iterator first_ = to_iterator(first); + iterator last_ = to_iterator(last); // Erase the bit we want to replace. erase(first_, last_); @@ -1749,8 +1775,8 @@ namespace etl ibasic_string& replace(const_iterator first, const_iterator last, TIterator first_replace, TIterator last_replace) { // Quick hack, as iterators are pointers. - iterator first_ = const_cast(first); - iterator last_ = const_cast(last); + iterator first_ = to_iterator(first); + iterator last_ = to_iterator(last); // Erase the bit we want to replace. erase(first_, last_); @@ -2352,6 +2378,16 @@ namespace etl } #endif } + + protected: + + //************************************************************************* + /// Convert from const_iterator to iterator + //************************************************************************* + iterator to_iterator(const_iterator itr) const + { + return const_cast(itr); + } }; //*************************************************************************** @@ -2393,7 +2429,6 @@ namespace etl return (rhs.size() == etl::strlen(lhs)) && etl::equal(rhs.begin(), rhs.end(), lhs); } - //*************************************************************************** /// Not equal operator. ///\param lhs Reference to the first string. diff --git a/include/etl/circular_buffer.h b/include/etl/circular_buffer.h index 941951e5..db614ccd 100644 --- a/include/etl/circular_buffer.h +++ b/include/etl/circular_buffer.h @@ -1281,7 +1281,7 @@ namespace etl //************************************************************************* /// Template deduction guides. //************************************************************************* -#if ETL_CPP17_SUPPORTED +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST template circular_buffer(T, Ts...) ->circular_buffer && ...), T>, 1U + sizeof...(Ts)>; diff --git a/include/etl/delegate.h b/include/etl/delegate.h index 49faf477..b8062c45 100644 --- a/include/etl/delegate.h +++ b/include/etl/delegate.h @@ -111,10 +111,7 @@ namespace etl //************************************************************************* // Copy constructor. //************************************************************************* - ETL_CONSTEXPR14 delegate(const delegate& other) - : invocation(other.invocation) - { - } + ETL_CONSTEXPR14 delegate(const delegate& other) = default; //************************************************************************* // Construct from lambda or functor. diff --git a/include/etl/deque.h b/include/etl/deque.h index a7564afa..2886e9e8 100644 --- a/include/etl/deque.h +++ b/include/etl/deque.h @@ -241,18 +241,6 @@ namespace etl typedef const T* const_pointer; typedef typename etl::iterator_traits::difference_type difference_type; - protected: - - //************************************************************************* - /// Test for an iterator. - //************************************************************************* - template - struct is_iterator : public etl::integral_constant::value && !etl::is_floating_point::value> - { - }; - - public: - //************************************************************************* /// Iterator //************************************************************************* @@ -730,7 +718,7 @@ namespace etl /// Assigns a range to the deque. //************************************************************************* template - typename etl::enable_if::value, void>::type + typename etl::enable_if::value, void>::type assign(TIterator range_begin, TIterator range_end) { initialise(); @@ -962,7 +950,7 @@ namespace etl //************************************************************************* iterator insert(const_iterator insert_position, const value_type& value) { - iterator position(insert_position.index, *this, p_buffer); + iterator position(to_iterator(insert_position)); ETL_ASSERT(!full(), ETL_ERROR(deque_full)); @@ -1504,7 +1492,7 @@ namespace etl ///\param range_end The end of the range to insert. //************************************************************************* template - typename enable_if::value, iterator>::type + typename enable_if::value, iterator>::type insert(const_iterator insert_position, TIterator range_begin, TIterator range_end) { iterator position; @@ -1608,7 +1596,8 @@ namespace etl //************************************************************************* iterator erase(const_iterator erase_position) { - iterator position(erase_position.index, *this, p_buffer); + iterator position(to_iterator(erase_position)); + //iterator position(erase_position.index, *this, p_buffer); ETL_ASSERT(distance(position) <= difference_type(current_size), ETL_ERROR(deque_out_of_bounds)); @@ -1649,7 +1638,7 @@ namespace etl //************************************************************************* iterator erase(const_iterator range_begin, const_iterator range_end) { - iterator position(range_begin.index, *this, p_buffer); + iterator position(to_iterator(range_begin)); ETL_ASSERT((distance(range_begin) <= difference_type(current_size)) && (distance(range_end) <= difference_type(current_size)), ETL_ERROR(deque_out_of_bounds)); @@ -2265,6 +2254,14 @@ namespace etl } } + //************************************************************************* + /// Converts from const_iterator to iterator. + //************************************************************************* + iterator to_iterator(const_iterator itr) const + { + return iterator(itr.index, const_cast(*this), p_buffer); + } + // Disable copy construction. ideque(const ideque&); @@ -2453,15 +2450,15 @@ namespace etl //************************************************************************* /// Template deduction guides. //************************************************************************* -#if ETL_CPP17_SUPPORTED +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST template - deque(T...) -> deque::type, sizeof...(T)>; + deque(T...) -> deque, sizeof...(T)>; #endif //************************************************************************* /// Make //************************************************************************* -#if ETL_USING_INITIALIZER_LIST +#if ETL_CPP11_SUPPORTED && ETL_USING_INITIALIZER_LIST template constexpr auto make_deque(TValues&&... values) -> etl::deque { diff --git a/include/etl/flat_map.h b/include/etl/flat_map.h index 14f469ac..d96b7645 100644 --- a/include/etl/flat_map.h +++ b/include/etl/flat_map.h @@ -339,7 +339,7 @@ namespace etl ///\param position The position to insert at. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, const_reference value) + iterator insert(const_iterator position, const_reference value) { return insert(value).first; } @@ -351,7 +351,7 @@ namespace etl ///\param position The position to insert at. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, rvalue_reference value) + iterator insert(const_iterator position, rvalue_reference value) { return insert(etl::move(value)).first; } @@ -573,12 +573,24 @@ namespace etl /// Erases an element. ///\param i_element Iterator to the element. //********************************************************************* - void erase(iterator i_element) + iterator erase(iterator i_element) { i_element->~value_type(); storage.release(etl::addressof(*i_element)); - refmap_t::erase(i_element); ETL_DECREMENT_DEBUG_COUNT + return refmap_t::erase(i_element); + } + + //********************************************************************* + /// Erases an element. + ///\ param i_element Iterator to the element. + //********************************************************************* + iterator erase(const_iterator i_element) + { + i_element->~value_type(); + storage.release(etl::addressof(*i_element)); + ETL_DECREMENT_DEBUG_COUNT + return refmap_t::erase(i_element); } //********************************************************************* @@ -588,9 +600,9 @@ namespace etl ///\param first Iterator to the first element. ///\param last Iterator to the last element. //********************************************************************* - void erase(iterator first, iterator last) + iterator erase(const_iterator first, const_iterator last) { - iterator itr = first; + const_iterator itr = first; while (itr != last) { @@ -600,7 +612,7 @@ namespace etl ETL_DECREMENT_DEBUG_COUNT } - refmap_t::erase(first, last); + return refmap_t::erase(first, last); } //************************************************************************* diff --git a/include/etl/flat_multimap.h b/include/etl/flat_multimap.h index 17be8d52..9395dddc 100644 --- a/include/etl/flat_multimap.h +++ b/include/etl/flat_multimap.h @@ -300,7 +300,7 @@ namespace etl ///\param position The position to insert at. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, const value_type& value) + iterator insert(const_iterator position, const value_type& value) { return insert(value).first; } @@ -312,7 +312,7 @@ namespace etl ///\param position The position to insert at. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, rvalue_reference value) + iterator insert(const_iterator position, rvalue_reference value) { return insert(etl::move(value)).first; } @@ -478,12 +478,24 @@ namespace etl /// Erases an element. ///\param i_element Iterator to the element. //********************************************************************* - void erase(iterator i_element) + iterator erase(iterator i_element) { i_element->~value_type(); storage.release(etl::addressof(*i_element)); - refmap_t::erase(i_element); ETL_DECREMENT_DEBUG_COUNT + return refmap_t::erase(i_element); + } + + //********************************************************************* + /// Erases an element. + ///\param i_element Iterator to the element. + //********************************************************************* + iterator erase(const_iterator i_element) + { + i_element->~value_type(); + storage.release(etl::addressof(*i_element)); + ETL_DECREMENT_DEBUG_COUNT + return refmap_t::erase(i_element); } //********************************************************************* @@ -493,9 +505,9 @@ namespace etl ///\param first Iterator to the first element. ///\param last Iterator to the last element. //********************************************************************* - void erase(iterator first, iterator last) + iterator erase(const_iterator first, const_iterator last) { - iterator itr = first; + const_iterator itr = first; while (itr != last) { @@ -505,7 +517,7 @@ namespace etl ETL_DECREMENT_DEBUG_COUNT } - refmap_t::erase(first, last); + return refmap_t::erase(first, last); } //************************************************************************* diff --git a/include/etl/flat_multiset.h b/include/etl/flat_multiset.h index 956f3e3f..cbed6903 100644 --- a/include/etl/flat_multiset.h +++ b/include/etl/flat_multiset.h @@ -269,7 +269,7 @@ namespace etl ///\param position The position to insert at. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, const_reference value) + iterator insert(const_iterator position, const_reference value) { return insert(value).first; } @@ -281,7 +281,7 @@ namespace etl ///\param position The position to insert at. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, rvalue_reference value) + iterator insert(const_iterator position, rvalue_reference value) { return insert(etl::move(value)).first; } @@ -429,12 +429,24 @@ namespace etl /// Erases an element. ///\param i_element Iterator to the element. //********************************************************************* - void erase(iterator i_element) + iterator erase(iterator i_element) { etl::destroy_at(etl::addressof(*i_element)); storage.release(etl::addressof(*i_element)); - refset_t::erase(i_element); ETL_DECREMENT_DEBUG_COUNT + return refset_t::erase(i_element); + } + + //********************************************************************* + /// Erases an element. + ///\param i_element Iterator to the element. + //********************************************************************* + iterator erase(const_iterator i_element) + { + etl::destroy_at(etl::addressof(*i_element)); + storage.release(etl::addressof(*i_element)); + ETL_DECREMENT_DEBUG_COUNT + return refset_t::erase(i_element); } //********************************************************************* @@ -444,9 +456,9 @@ namespace etl ///\param first Iterator to the first element. ///\param last Iterator to the last element. //********************************************************************* - void erase(iterator first, iterator last) + iterator erase(const_iterator first, const_iterator last) { - iterator itr = first; + const_iterator itr = first; while (itr != last) { @@ -456,7 +468,7 @@ namespace etl ETL_DECREMENT_DEBUG_COUNT } - refset_t::erase(first, last); + return refset_t::erase(first, last); } //************************************************************************* diff --git a/include/etl/flat_set.h b/include/etl/flat_set.h index 32844f0a..b9d63cfd 100644 --- a/include/etl/flat_set.h +++ b/include/etl/flat_set.h @@ -277,7 +277,7 @@ namespace etl ///\param position The position to insert at. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, const_reference value) + iterator insert(const_iterator position, const_reference value) { return insert(value).first; } @@ -289,7 +289,7 @@ namespace etl ///\param position The position to insert at. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, rvalue_reference value) + iterator insert(const_iterator position, rvalue_reference value) { return insert(etl::move(value)).first; } @@ -513,12 +513,24 @@ namespace etl /// Erases an element. ///\param i_element Iterator to the element. //********************************************************************* - void erase(iterator i_element) + iterator erase(iterator i_element) { etl::destroy_at(etl::addressof(*i_element)); storage.release(etl::addressof(*i_element)); - refset_t::erase(i_element); ETL_DECREMENT_DEBUG_COUNT + return refset_t::erase(i_element); + } + + //********************************************************************* + /// Erases an element. + ///\param i_element Iterator to the element. + //********************************************************************* + iterator erase(const_iterator i_element) + { + etl::destroy_at(etl::addressof(*i_element)); + storage.release(etl::addressof(*i_element)); + ETL_DECREMENT_DEBUG_COUNT + return refset_t::erase(i_element); } //********************************************************************* @@ -528,9 +540,9 @@ namespace etl ///\param first Iterator to the first element. ///\param last Iterator to the last element. //********************************************************************* - void erase(iterator first, iterator last) + iterator erase(const_iterator first, const_iterator last) { - iterator itr = first; + const_iterator itr = first; while (itr != last) { @@ -540,7 +552,7 @@ namespace etl ETL_DECREMENT_DEBUG_COUNT } - refset_t::erase(first, last); + return refset_t::erase(first, last); } //************************************************************************* diff --git a/include/etl/forward_list.h b/include/etl/forward_list.h index 5d0ed1cb..6cfca525 100644 --- a/include/etl/forward_list.h +++ b/include/etl/forward_list.h @@ -647,7 +647,7 @@ namespace etl /// If ETL_THROW_EXCEPTIONS & ETL_DEBUG are defined throws forward_list_iterator if the iterators are reversed. //************************************************************************* template - void assign(TIterator first, TIterator last) + void assign(TIterator first, TIterator last, typename etl::enable_if::value, int>::type = 0) { #if defined(ETL_DEBUG) difference_type d = etl::distance(first, last); @@ -866,12 +866,12 @@ namespace etl //************************************************************************* /// Inserts a value to the forward_list after the specified position. //************************************************************************* - iterator insert_after(iterator position, const T& value) + iterator insert_after(const_iterator position, const T& value) { ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); data_node_t& data_node = allocate_data_node(value); - insert_node_after(*position.p_node, data_node); + insert_node_after(*to_iterator(position).p_node, data_node); return iterator(&data_node); } @@ -881,14 +881,14 @@ namespace etl /// Emplaces a value to the forward_list after the specified position. //************************************************************************* template - iterator emplace_after(iterator position, Args && ... args) + iterator emplace_after(const_iterator position, Args && ... args) { ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); data_node_t* p_data_node = create_data_node(); ::new (&(p_data_node->value)) T(etl::forward(args)...); ETL_INCREMENT_DEBUG_COUNT - insert_node_after(*position.p_node, *p_data_node); + insert_node_after(*to_iterator(position).p_node, *p_data_node); return iterator(p_data_node); } @@ -897,7 +897,7 @@ namespace etl /// Emplaces a value to the forward_list after the specified position. //************************************************************************* template - iterator emplace_after(iterator position, const T1& value1) + iterator emplace_after(const_iterator position, const T1& value1) { ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); @@ -913,7 +913,7 @@ namespace etl /// Emplaces a value to the forward_list after the specified position. //************************************************************************* template - iterator emplace_after(iterator position, const T1& value1, const T2& value2) + iterator emplace_after(const_iterator position, const T1& value1, const T2& value2) { ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); @@ -929,7 +929,7 @@ namespace etl /// Emplaces a value to the forward_list after the specified position. //************************************************************************* template - iterator emplace_after(iterator position, const T1& value1, const T2& value2, const T3& value3) + iterator emplace_after(const_iterator position, const T1& value1, const T2& value2, const T3& value3) { ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); @@ -945,7 +945,7 @@ namespace etl /// Emplaces a value to the forward_list after the specified position. //************************************************************************* template - iterator emplace_after(iterator position, const T1& value1, const T2& value2, const T3& value3, const T4& value4) + iterator emplace_after(const_iterator position, const T1& value1, const T2& value2, const T3& value3, const T4& value4) { ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); @@ -961,7 +961,7 @@ namespace etl //************************************************************************* /// Inserts 'n' copies of a value to the forward_list after the specified position. //************************************************************************* - void insert_after(iterator position, size_t n, const T& value) + iterator insert_after(const_iterator position, size_t n, const T& value) { ETL_ASSERT(!full(), ETL_ERROR(forward_list_full)); @@ -969,15 +969,22 @@ namespace etl { // Set up the next free node. data_node_t& data_node = allocate_data_node(value); - insert_node_after(*position.p_node, data_node); + insert_node_after(*to_iterator(position).p_node, data_node); } + + if (n > 0U) + { + ++position; + } + + return to_iterator(position); } //************************************************************************* /// Inserts a range of values to the forward_list after the specified position. //************************************************************************* template - void insert_after(iterator position, TIterator first, TIterator last) + iterator insert_after(const_iterator position, TIterator first, TIterator last, typename etl::enable_if::value, int>::type = 0) { #if defined(ETL_DEBUG) difference_type d = etl::distance(first, last); @@ -988,9 +995,11 @@ namespace etl { // Set up the next free node. data_node_t& data_node = allocate_data_node(*first++); - insert_node_after(*position.p_node, data_node); + insert_node_after(*to_iterator(position).p_node, data_node); ++position; } + + return to_iterator(position); } //************************************************************************* @@ -1012,16 +1021,35 @@ namespace etl return next; } + //************************************************************************* + /// Erases the value at the specified position. + //************************************************************************* + iterator erase_after(const_iterator position) + { + iterator next(position); + if (next != end()) + { + ++next; + if (next != end()) + { + ++next; + remove_node_after(*position.p_node); + } + } + + return next; + } + //************************************************************************* /// Erases a range of elements. //************************************************************************* - iterator erase_after(iterator first, iterator last) + iterator erase_after(const_iterator first, const_iterator last) { if (first != end() && (first != last)) { - node_t* p_first = first.p_node; - node_t* p_last = last.p_node; - node_t* p_next = p_first->next; + node_t* p_first = to_iterator(first).p_node; + node_t* p_last = to_iterator(last).p_node; + node_t* p_next = p_first->next; // Join the ends. join(p_first, p_last); @@ -1063,7 +1091,7 @@ namespace etl } node_t* p_from_before = const_cast(from_before.p_node); // We're not changing the value, just it's position. - node_t* p_to_before = const_cast(to_before.p_node); // We're not changing the value, just it's position. + node_t* p_to_before = const_cast(to_before.p_node); // We're not changing the value, just it's position. node_t* p_from = p_from_before->next; @@ -1592,6 +1620,16 @@ namespace etl { } #endif + + private: + + //************************************************************************* + /// Convert const_iterator to iterator. + //************************************************************************* + iterator to_iterator(const_iterator itr) const + { + return iterator(const_cast(itr.p_node)); + } }; //************************************************************************* @@ -1718,7 +1756,7 @@ namespace etl //************************************************************************* /// Template deduction guides. //************************************************************************* -#if ETL_CPP17_SUPPORTED +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST template forward_list(T...) ->forward_list, sizeof...(T)>; #endif @@ -1726,7 +1764,7 @@ namespace etl //************************************************************************* /// Make //************************************************************************* -#if ETL_USING_INITIALIZER_LIST +#if ETL_CPP11_SUPPORTED && ETL_USING_INITIALIZER_LIST template constexpr auto make_forward_list(T... t) -> etl::forward_list, sizeof...(T)> { diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index 4df6a814..10b3bc6a 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -2024,60 +2024,92 @@ namespace etl #endif #if ETL_CPP11_SUPPORTED - // primary template (used for zero types) - template - struct common_type {}; + //********************************************* + // common_type + // Based on the sample implementation detailed on + // https://en.cppreference.com/w/cpp/types/common_type + //********************************************* +#if ETL_CPP11_SUPPORTED + //*********************************** + // Primary template + template + struct common_type + { + }; - //////// one type - template - struct common_type : common_type {}; + //*********************************** + // One type + template + struct common_type : common_type + { + }; - namespace detail { - template + namespace private_common_type + { + template using void_t = void; - template - using conditional_result_t = decltype(false ? std::declval() : std::declval()); + template + using conditional_result_t = decltype(false ? declval() : declval()); - template - struct decay_conditional_result {}; - template + template + struct decay_conditional_result + { + }; + + template struct decay_conditional_result>> - : std::decay> {}; + : etl::decay> + { + }; - template - struct common_type_2_impl : decay_conditional_result {}; + template + struct common_type_2_impl : decay_conditional_result + { + }; - // C++11 implementation: - // template - // struct common_type_2_impl {}; - - template + template struct common_type_2_impl>> - : decay_conditional_result {}; + : decay_conditional_result + { + }; } - //////// two types - template + //*********************************** + // Two types + template struct common_type - : std::conditional::type>::value&& - std::is_same::type>::value, - detail::common_type_2_impl, - common_type::type, - typename std::decay::type>>::type{}; + : etl::conditional::type>::value&& etl::is_same::type>::value, + private_common_type::common_type_2_impl, + common_type::type, + typename etl::decay::type>>::type + { + }; - //////// 3+ types - namespace detail { - template - struct common_type_multi_impl {}; - template - struct common_type_multi_impl::type>, T1, T2, R...> - : common_type::type, R...> {}; + //*********************************** + // Three or more types + namespace private_common_type + { + template + struct common_type_multi_impl + { + }; + + template + struct common_type_multi_impl::type>, T1, T2, TRest...> + : common_type::type, TRest...> + { + }; } - template - struct common_type - : detail::common_type_multi_impl {}; + template + struct common_type + : private_common_type::common_type_multi_impl + { + }; + + template + using common_type_t = typename common_type::type; #endif } diff --git a/include/etl/indirect_vector.h b/include/etl/indirect_vector.h index 93f5867c..3e6339af 100644 --- a/include/etl/indirect_vector.h +++ b/include/etl/indirect_vector.h @@ -854,14 +854,14 @@ namespace etl ///\param position The position to insert before. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, const_reference value) + iterator insert(const_iterator position, const_reference value) { ETL_ASSERT(size() != capacity(), ETL_ERROR(vector_full)); T* p = storage.create(T(value)); position = iterator(lookup.insert(position.lookup_itr, p)); - return position; + return to_iterator(position); } #if ETL_CPP11_SUPPORTED @@ -871,14 +871,14 @@ namespace etl ///\param position The position to insert before. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, rvalue_reference value) + iterator insert(const_iterator position, rvalue_reference value) { ETL_ASSERT(size() != capacity(), ETL_ERROR(vector_full)); T* p = storage.create(T(etl::move(value))); position = iterator(lookup.insert(position.lookup_itr, p)); - return position; + return to_iterator(position); } #endif @@ -949,12 +949,14 @@ namespace etl ///\param n The number of elements to add. ///\param value The value to insert. //********************************************************************* - void insert(iterator position, size_t n, parameter_t value) + iterator insert(const_iterator position, size_t n, parameter_t value) { ETL_ASSERT((size() + n) <= capacity(), ETL_ERROR(vector_full)); + iterator position_ = to_iterator(position); + // Make space for the new lookup pointers. - typename etl::ivector::iterator lookup_itr = position.lookup_itr; + typename etl::ivector::iterator lookup_itr = position_.lookup_itr; lookup.insert(lookup_itr, n, ETL_NULLPTR); while (n-- != 0U) @@ -962,6 +964,8 @@ namespace etl T* p = storage.create(value); *lookup_itr++ = p; } + + return position_; } //********************************************************************* @@ -972,14 +976,14 @@ namespace etl ///\param last The last + 1 element to add. //********************************************************************* template - void insert(iterator position, TIterator first, TIterator last) + iterator insert(const_iterator position, TIterator first, TIterator last) { size_t count = size_t(etl::distance(first, last)); ETL_ASSERT((size() + count) <= capacity(), ETL_ERROR(vector_full)); // Make space for the new lookup pointers. - typename etl::ivector::iterator lookup_itr = position.lookup_itr; + typename etl::ivector::iterator lookup_itr = to_iterator(position).lookup_itr; lookup.insert(lookup_itr, count, ETL_NULLPTR); while (first != last) @@ -988,6 +992,8 @@ namespace etl *lookup_itr++ = p; ++first; } + + return to_iterator(position); } //********************************************************************* @@ -1002,6 +1008,18 @@ namespace etl return iterator(lookup.erase(i_element.lookup_itr)); } + //********************************************************************* + /// Erases an element. + ///\param i_element Iterator to the element. + ///\return An iterator pointing to the element that followed the erased element. + //********************************************************************* + iterator erase(const_iterator i_element) + { + storage.destroy(etl::addressof(*i_element)); + + return iterator(lookup.erase(i_element.lookup_itr)); + } + //********************************************************************* /// Erases a range of elements. /// The range includes all the elements between first and last, including the @@ -1010,9 +1028,9 @@ namespace etl ///\param last Iterator to the last element. ///\return An iterator pointing to the element that followed the erased element. //********************************************************************* - iterator erase(iterator first, iterator last) + iterator erase(const_iterator first, const_iterator last) { - iterator element = first; + iterator element = to_iterator(first); while (element != last) { @@ -1022,7 +1040,7 @@ namespace etl lookup.erase(first.lookup_itr, last.lookup_itr); - return last; + return to_iterator(last); } //************************************************************************* @@ -1186,6 +1204,16 @@ namespace etl { initialise(); } + + protected: + + //************************************************************************* + /// Convert from const_iterator to iterator. + //************************************************************************* + iterator to_iterator(const_iterator itr) const + { + return iterator(const_cast(itr.lookup_itr)); + } }; //*************************************************************************** @@ -1394,12 +1422,23 @@ namespace etl //************************************************************************* /// Template deduction guides. //************************************************************************* -#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST template indirect_vector(T, Ts...) ->indirect_vector && ...), T>, 1U + sizeof...(Ts)>; #endif + //************************************************************************* + /// Make + //************************************************************************* +#if ETL_CPP11_SUPPORTED && ETL_USING_INITIALIZER_LIST + template + constexpr auto make_indirect_vector(T... t) -> etl::indirect_vector, sizeof...(T)> + { + return { { etl::forward(t)... } }; + } +#endif + //*************************************************************************** /// A indirect_vector implementation that uses a fixed size buffer. /// The buffer is supplied on construction. diff --git a/include/etl/intrusive_list.h b/include/etl/intrusive_list.h index f667bb57..681c8e75 100644 --- a/include/etl/intrusive_list.h +++ b/include/etl/intrusive_list.h @@ -673,7 +673,7 @@ namespace etl //************************************************************************* /// Inserts a value to the intrusive_list before the specified position. //************************************************************************* - iterator insert(iterator position, value_type& value) + iterator insert(const_iterator position, value_type& value) { this->insert_link(position.p_value->link_type::etl_previous, value); return iterator(value); @@ -683,7 +683,7 @@ namespace etl /// Inserts a range of values to the intrusive_list after the specified position. //************************************************************************* template - void insert(iterator position, TIterator first, TIterator last) + void insert(const_iterator position, TIterator first, TIterator last) { while (first != last) { @@ -705,14 +705,30 @@ namespace etl return next; } + //************************************************************************* + /// Erases the value at the specified position. + //************************************************************************* + iterator erase(const_iterator position) + { + iterator next(position); + ++next; + + this->remove_link(*position.p_value); + + return next; + } + //************************************************************************* /// Erases a range of elements. /// Clears the links after erasing if AUTO or CHECKED. //************************************************************************* - iterator erase(iterator first, iterator last) + iterator erase(const_iterator first, const_iterator last) { - link_type* p_first = first.p_value; - link_type* p_last = last.p_value; + const link_type* cp_first = first.p_value; + const link_type* cp_last = last.p_value; + + link_type* p_first = const_cast(cp_first); + link_type* p_last = const_cast(cp_last); // Join the ends. etl::link(p_first->etl_previous, p_last); diff --git a/include/etl/list.h b/include/etl/list.h index 134c5381..60357cf6 100644 --- a/include/etl/list.h +++ b/include/etl/list.h @@ -797,7 +797,7 @@ namespace etl /// If ETL_THROW_EXCEPTIONS & ETL_DEBUG are defined throws list_iterator if the iterators are reversed. //************************************************************************* template - void assign(TIterator first, TIterator last) + void assign(TIterator first, TIterator last, typename etl::enable_if::value, int>::type = 0) { #if defined(ETL_DEBUG) difference_type d = etl::distance(first, last); @@ -822,7 +822,7 @@ namespace etl void assign(size_t n, const T& value) { #if defined(ETL_DEBUG) - ETL_ASSERT(n <= available(), ETL_ERROR(list_full)); + ETL_ASSERT(n <= MAX_SIZE, ETL_ERROR(list_full)); #endif initialise(); @@ -1073,12 +1073,12 @@ namespace etl //************************************************************************* /// Inserts a value to the list at the specified position. //************************************************************************* - iterator insert(iterator position, const_reference value) + iterator insert(const_iterator position, const_reference value) { ETL_ASSERT(!full(), ETL_ERROR(list_full)); data_node_t& data_node = allocate_data_node(value); - insert_node(*position.p_node, data_node); + insert_node(*to_iterator(position).p_node, data_node); return iterator(data_node); } @@ -1087,12 +1087,12 @@ namespace etl //************************************************************************* /// Inserts a value to the list at the specified position. //************************************************************************* - iterator insert(iterator position, rvalue_reference value) + iterator insert(const_iterator position, rvalue_reference value) { ETL_ASSERT(!full(), ETL_ERROR(list_full)); data_node_t& data_node = allocate_data_node(etl::move(value)); - insert_node(*position.p_node, data_node); + insert_node(*to_iterator(position).p_node, data_node); return iterator(data_node); } @@ -1103,7 +1103,7 @@ namespace etl //************************************************************************* #if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT template - iterator emplace(iterator position, Args && ... args) + iterator emplace(const_iterator position, Args && ... args) { ETL_ASSERT(!full(), ETL_ERROR(list_full)); ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); @@ -1111,13 +1111,13 @@ namespace etl data_node_t* p_data_node = create_data_node(); ::new (&(p_data_node->value)) T(etl::forward(args)...); ETL_INCREMENT_DEBUG_COUNT - insert_node(*position.p_node, *p_data_node); + insert_node(*to_iterator(position).p_node, *p_data_node); return iterator(*p_data_node); } #else template - iterator emplace(iterator position, const T1& value1) + iterator emplace(const_iterator position, const T1& value1) { ETL_ASSERT(!full(), ETL_ERROR(list_full)); ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); @@ -1131,7 +1131,7 @@ namespace etl } template - iterator emplace(iterator position, const T1& value1, const T2& value2) + iterator emplace(const_iterator position, const T1& value1, const T2& value2) { ETL_ASSERT(!full(), ETL_ERROR(list_full)); ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); @@ -1145,7 +1145,7 @@ namespace etl } template - iterator emplace(iterator position, const T1& value1, const T2& value2, const T3& value3) + iterator emplace(const_iterator position, const T1& value1, const T2& value2, const T3& value3) { ETL_ASSERT(!full(), ETL_ERROR(list_full)); ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); @@ -1159,7 +1159,7 @@ namespace etl } template - iterator emplace(iterator position, const T1& value1, const T2& value2, const T3& value3, const T4& value4) + iterator emplace(const_iterator position, const T1& value1, const T2& value2, const T3& value3, const T4& value4) { ETL_ASSERT(!full(), ETL_ERROR(list_full)); ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); @@ -1176,14 +1176,14 @@ namespace etl //************************************************************************* /// Inserts 'n' copies of a value to the list at the specified position. //************************************************************************* - void insert(iterator position, size_t n, const_reference value) + void insert(const_iterator position, size_t n, const_reference value) { for (size_t i = 0UL; i < n; ++i) { ETL_ASSERT(!full(), ETL_ERROR(list_full)); // Set up the next free node and insert. - insert_node(*position.p_node, allocate_data_node(value)); + insert_node(*to_iterator(position).p_node, allocate_data_node(value)); } } @@ -1191,34 +1191,39 @@ namespace etl /// Inserts a range of values to the list at the specified position. //************************************************************************* template - void insert(iterator position, TIterator first, TIterator last) + void insert(const_iterator position, TIterator first, TIterator last, typename etl::enable_if::value, int>::type = 0) { while (first != last) { ETL_ASSERT(!full(), ETL_ERROR(list_full)); // Set up the next free node and insert. - insert_node(*position.p_node, allocate_data_node(*first++)); + insert_node(*to_iterator(position).p_node, allocate_data_node(*first++)); } } //************************************************************************* /// Erases the value at the specified position. //************************************************************************* - iterator erase(iterator position) + iterator erase(const_iterator position) { - ++position; - remove_node(*position.p_node->previous); - return position; + iterator position_ = to_iterator(position); + + ++position_; + remove_node(*position_.p_node->previous); + return position_; } //************************************************************************* /// Erases a range of elements. //************************************************************************* - iterator erase(iterator first, iterator last) + iterator erase(const_iterator first, const_iterator last) { - node_t* p_first = first.p_node; - node_t* p_last = last.p_node; + iterator first_ = to_iterator(first); + iterator last_ = to_iterator(last); + + node_t* p_first = first_.p_node; + node_t* p_last = last_.p_node; node_t* p_next; // Join the ends. @@ -1227,12 +1232,12 @@ namespace etl // Erase the ones in between. while (p_first != p_last) { - p_next = p_first->next; // Remember the next node. + p_next = p_first->next; // Remember the next node. destroy_data_node(static_cast(*p_first)); // Destroy the current node. p_first = p_next; // Move to the next node. } - return last; + return last_; } //************************************************************************* @@ -2001,6 +2006,16 @@ namespace etl { } #endif + + private: + + //************************************************************************* + /// Convert from const_iterator to iterator. + //************************************************************************* + iterator to_iterator(const_iterator itr) const + { + return iterator(*(const_cast(itr.p_node))); + } }; //************************************************************************* @@ -2151,7 +2166,7 @@ namespace etl //************************************************************************* /// Template deduction guides. //************************************************************************* -#if ETL_CPP17_SUPPORTED +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST template list(T...) -> list, sizeof...(T)>; @@ -2160,7 +2175,7 @@ namespace etl //************************************************************************* /// Make //************************************************************************* -#if ETL_USING_INITIALIZER_LIST +#if ETL_CPP11_SUPPORTED && ETL_USING_INITIALIZER_LIST template constexpr auto make_list(T... t) -> etl::list, sizeof...(T)> { diff --git a/include/etl/map.h b/include/etl/map.h index 4398de9e..01a01ae5 100644 --- a/include/etl/map.h +++ b/include/etl/map.h @@ -991,15 +991,6 @@ namespace etl const_iterator(*this, find_upper_node(root_node, key))); } - //************************************************************************* - /// Erases the value at the specified position. - //************************************************************************* - void erase(iterator position) - { - // Remove the node by its key - erase((*position).first); - } - //************************************************************************* /// Erases the value at the specified position. //************************************************************************* @@ -1024,20 +1015,6 @@ namespace etl return remove_node(root_node, key) ? 1 : 0; } - //************************************************************************* - /// Erases a range of elements. - //************************************************************************* - iterator erase(iterator first, iterator last) - { - iterator next; - while (first != last) - { - next = erase(const_iterator(first++)); - } - - return next; - } - //************************************************************************* /// Erases a range of elements. //************************************************************************* @@ -1128,7 +1105,7 @@ namespace etl ///\param position The position that would precede the value to insert. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator, const_reference value) + iterator insert(const_iterator /*position*/, const_reference value) { // Default to no inserted node Node* inserted_node = ETL_NULLPTR; @@ -1152,55 +1129,7 @@ namespace etl ///\param position The position that would precede the value to insert. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator, rvalue_reference value) - { - // Default to no inserted node - Node* inserted_node = ETL_NULLPTR; - - ETL_ASSERT(!full(), ETL_ERROR(map_full)); - - // Get next available free node - Data_Node& node = allocate_data_node(etl::move(value)); - - // Obtain the inserted node (might be ETL_NULLPTR if node was a duplicate) - inserted_node = insert_node(root_node, node); - - // Insert node into tree and return iterator to new node location in tree - return iterator(*this, inserted_node); - } -#endif - - //********************************************************************* - /// Inserts a value to the map starting at the position recommended. - /// If asserts or exceptions are enabled, emits map_full if the map is already full. - ///\param position The position that would precede the value to insert. - ///\param value The value to insert. - //********************************************************************* - iterator insert(const_iterator, const_reference value) - { - // Default to no inserted node - Node* inserted_node = ETL_NULLPTR; - - ETL_ASSERT(!full(), ETL_ERROR(map_full)); - - // Get next available free node - Data_Node& node = allocate_data_node(value); - - // Obtain the inserted node (might be ETL_NULLPTR if node was a duplicate) - inserted_node = insert_node(root_node, node); - - // Insert node into tree and return iterator to new node location in tree - return iterator(*this, inserted_node); - } - -#if ETL_CPP11_SUPPORTED - //********************************************************************* - /// Inserts a value to the map starting at the position recommended. - /// If asserts or exceptions are enabled, emits map_full if the map is already full. - ///\param position The position that would precede the value to insert. - ///\param value The value to insert. - //********************************************************************* - iterator insert(const_iterator, rvalue_reference value) + iterator insert(const_iterator /*position*/, rvalue_reference value) { // Default to no inserted node Node* inserted_node = ETL_NULLPTR; diff --git a/include/etl/multimap.h b/include/etl/multimap.h index 5d049adb..6630bf43 100644 --- a/include/etl/multimap.h +++ b/include/etl/multimap.h @@ -1102,10 +1102,10 @@ namespace etl //************************************************************************* /// Erases the value at the specified position. //************************************************************************* - void erase(iterator position) + iterator erase(iterator position) { // Remove the node by its node specified in iterator position - (void)erase(const_iterator(position)); + return erase(const_iterator(position)); } //************************************************************************* @@ -1147,20 +1147,6 @@ namespace etl return d; } - //************************************************************************* - /// Erases a range of elements. - //************************************************************************* - iterator erase(iterator first, iterator last) - { - iterator next; - while (first != last) - { - next = erase(const_iterator(first++)); - } - - return next; - } - //************************************************************************* /// Erases a range of elements. //************************************************************************* @@ -1241,18 +1227,6 @@ namespace etl } #endif - //********************************************************************* - /// Inserts a value to the multimap starting at the position recommended. - /// If asserts or exceptions are enabled, emits map_full if the multimap is already full. - ///\param position The position that would precede the value to insert. - ///\param value The value to insert. - //********************************************************************* - iterator insert(iterator /*position*/, const_reference value) - { - // Ignore position provided and just do a normal insert - return insert(value); - } - //********************************************************************* /// Inserts a value to the multimap starting at the position recommended. /// If asserts or exceptions are enabled, emits map_full if the multimap is already full. @@ -1266,18 +1240,6 @@ namespace etl } #if ETL_CPP11_SUPPORTED - //********************************************************************* - /// Inserts a value to the multimap starting at the position recommended. - /// If asserts or exceptions are enabled, emits map_full if the multimap is already full. - ///\param position The position that would precede the value to insert. - ///\param value The value to insert. - //********************************************************************* - iterator insert(iterator /*position*/, rvalue_reference value) - { - // Ignore position provided and just do a normal insert - return insert(etl::move(value)); - } - //********************************************************************* /// Inserts a value to the multimap starting at the position recommended. /// If asserts or exceptions are enabled, emits map_full if the multimap is already full. diff --git a/include/etl/multiset.h b/include/etl/multiset.h index 15d84251..8aaa4582 100644 --- a/include/etl/multiset.h +++ b/include/etl/multiset.h @@ -1086,10 +1086,10 @@ namespace etl //************************************************************************* /// Erases the value at the specified position. //************************************************************************* - void erase(iterator position) + iterator erase(iterator position) { // Remove the node by its node specified in iterator position - (void)erase(const_iterator(position)); + return erase(const_iterator(position)); } //************************************************************************* @@ -1131,20 +1131,6 @@ namespace etl return d; } - //************************************************************************* - /// Erases a range of elements. - //************************************************************************* - iterator erase(iterator first, iterator last) - { - iterator next; - while (first != last) - { - next = erase(const_iterator(first++)); - } - - return next; - } - //************************************************************************* /// Erases a range of elements. //************************************************************************* @@ -1225,32 +1211,6 @@ namespace etl } #endif - //********************************************************************* - /// Inserts a value to the multiset starting at the position recommended. - /// If asserts or exceptions are enabled, emits set_full if the multiset is already full. - ///\param position The position that would precede the value to insert. - ///\param value The value to insert. - //********************************************************************* - iterator insert(iterator /*position*/, const_reference value) - { - // Ignore position provided and just do a normal insert - return insert(value); - } - -#if ETL_CPP11_SUPPORTED - //********************************************************************* - /// Inserts a value to the multiset starting at the position recommended. - /// If asserts or exceptions are enabled, emits set_full if the multiset is already full. - ///\param position The position that would precede the value to insert. - ///\param value The value to insert. - //********************************************************************* - iterator insert(iterator /*position*/, rvalue_reference value) - { - // Ignore position provided and just do a normal insert - return insert(etl::move(value)); - } -#endif - //********************************************************************* /// Inserts a value to the multiset starting at the position recommended. /// If asserts or exceptions are enabled, emits set_full if the multiset is already full. diff --git a/include/etl/platform.h b/include/etl/platform.h index a4736b46..1456b0f3 100644 --- a/include/etl/platform.h +++ b/include/etl/platform.h @@ -222,9 +222,6 @@ SOFTWARE. // Check for availability of certain builtins #include "profiles/determine_builtin_support.h" -// Check for availability of certain builtins -#include "profiles/determine_builtin_support.h" - // Sort out namespaces for STL/No STL options. #include "private/choose_namespace.h" diff --git a/include/etl/private/ivectorpointer.h b/include/etl/private/ivectorpointer.h index 3d319cbc..9e225f92 100644 --- a/include/etl/private/ivectorpointer.h +++ b/include/etl/private/ivectorpointer.h @@ -374,7 +374,7 @@ namespace etl ///\param position The position to insert before. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, parameter_t value) + iterator insert(const_iterator position, parameter_t value) { return iterator(base_t::insert(base_t::iterator(position), value)); } @@ -382,7 +382,7 @@ namespace etl //************************************************************************* /// Emplaces a value to the vector at the specified position. //************************************************************************* - iterator emplace(iterator position, parameter_t value) + iterator emplace(const_iterator position, parameter_t value) { return iterator(base_t::emplace(base_t::iterator(position), value)); } @@ -394,7 +394,7 @@ namespace etl ///\param n The number of elements to add. ///\param value The value to insert. //********************************************************************* - void insert(iterator position, size_t n, parameter_t value) + void insert(const_iterator position, size_t n, parameter_t value) { base_t::insert(base_t::iterator(position), n, value); } @@ -407,7 +407,7 @@ namespace etl ///\param last The last + 1 element to add. //********************************************************************* template - void insert(iterator position, TIterator first, TIterator last) + void insert(const_iterator position, TIterator first, TIterator last) { base_t::insert(base_t::iterator(position), first, last); } @@ -422,6 +422,16 @@ namespace etl return iterator(base_t::erase(base_t::iterator(i_element))); } + //********************************************************************* + /// Erases an element. + ///\param i_element Iterator to the element. + ///\return An iterator pointing to the element that followed the erased element. + //********************************************************************* + iterator erase(const_iterator i_element) + { + return iterator(base_t::erase(base_t::const_iterator(i_element))); + } + //********************************************************************* /// Erases a range of elements. /// The range includes all the elements between first and last, including the @@ -430,9 +440,9 @@ namespace etl ///\param last Iterator to the last element. ///\return An iterator pointing to the element that followed the erased element. //********************************************************************* - iterator erase(iterator first, iterator last) + iterator erase(const_iterator first, const_iterator last) { - return iterator(base_t::erase(base_t::iterator(first), base_t::iterator(last))); + return iterator(base_t::erase(base_t::const_iterator(first), base_t::const_iterator(last))); } //************************************************************************* @@ -795,7 +805,7 @@ namespace etl ///\param position The position to insert before. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, parameter_t value) + iterator insert(const_iterator position, parameter_t value) { return iterator(base_t::insert(base_t::iterator(position), const_cast(value))); } @@ -807,7 +817,7 @@ namespace etl ///\param n The number of elements to add. ///\param value The value to insert. //********************************************************************* - void insert(iterator position, size_t n, parameter_t value) + void insert(const_iterator position, size_t n, parameter_t value) { base_t::insert(base_t::iterator(position), n, const_cast(value)); } @@ -820,7 +830,7 @@ namespace etl ///\param last The last + 1 element to add. //********************************************************************* template - void insert(iterator position, TIterator first, TIterator last) + void insert(const_iterator position, TIterator first, TIterator last) { base_t::insert(base_t::iterator(position), first, last); } @@ -835,6 +845,16 @@ namespace etl return iterator(base_t::erase(base_t::iterator(i_element))); } + //********************************************************************* + /// Erases an element. + ///\param i_element Iterator to the element. + ///\return An iterator pointing to the element that followed the erased element. + //********************************************************************* + iterator erase(const_iterator i_element) + { + return iterator(base_t::erase(base_t::iterator(i_element))); + } + //********************************************************************* /// Erases a range of elements. /// The range includes all the elements between first and last, including the @@ -843,7 +863,7 @@ namespace etl ///\param last Iterator to the last element. ///\return An iterator pointing to the element that followed the erased element. //********************************************************************* - iterator erase(iterator first, iterator last) + iterator erase(const_iterator first, const_iterator last) { return iterator(base_t::erase(base_t::iterator(first), base_t::iterator(last))); } diff --git a/include/etl/private/pvoidvector.h b/include/etl/private/pvoidvector.h index 51247c23..0b4ae1e2 100644 --- a/include/etl/private/pvoidvector.h +++ b/include/etl/private/pvoidvector.h @@ -441,22 +441,24 @@ namespace etl ///\param position The position to insert before. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, value_type value) + iterator insert(const_iterator position, value_type value) { + iterator position_ = to_iterator(position); + ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); - if (position != end()) + if (position_ != end()) { ++p_end; - etl::copy_backward(position, end() - 1, end()); - *position = value; + etl::copy_backward(position_, end() - 1, end()); + *position_ = value; } else { *p_end++ = value; } - return position; + return position_; } @@ -464,22 +466,24 @@ namespace etl /// Emplaces a value to the vector at the specified position. /// If asserts or exceptions are enabled, emits vector_full if the vector is already full. //************************************************************************* - iterator emplace(iterator position, value_type value) + iterator emplace(const_iterator position, value_type value) { ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); - if (position != end()) + iterator position_ = to_iterator(position); + + if (position_ != end()) { ++p_end; - etl::copy_backward(position, end() - 1, end()); - *position = value; + etl::copy_backward(position_, end() - 1, end()); + *position_ = value; } else { *p_end++ = value; } - return position; + return position_; } //********************************************************************* @@ -489,12 +493,14 @@ namespace etl ///\param n The number of elements to add. ///\param value The value to insert. //********************************************************************* - void insert(iterator position, size_t n, value_type value) + void insert(const_iterator position, size_t n, value_type value) { ETL_ASSERT((size() + n) <= CAPACITY, ETL_ERROR(vector_full)); - etl::copy_backward(position, p_end, p_end + n); - etl::fill_n(position, n, value); + iterator position_ = to_iterator(position); + + etl::copy_backward(position_, p_end, p_end + n); + etl::fill_n(position_, n, value); p_end += n; } @@ -508,14 +514,16 @@ namespace etl ///\param last The last + 1 element to add. //********************************************************************* template - void insert(iterator position, TIterator first, TIterator last) + void insert(const_iterator position, TIterator first, TIterator last) { size_t count = etl::distance(first, last); + iterator position_ = to_iterator(position); + ETL_ASSERT((size() + count) <= CAPACITY, ETL_ERROR(vector_full)); - etl::copy_backward(position, p_end, p_end + count); - etl::copy(first, last, position); + etl::copy_backward(position_, p_end, p_end + count); + etl::copy(first, last, position_); p_end += count; } @@ -532,6 +540,21 @@ namespace etl return i_element; } + //********************************************************************* + /// Erases an element. + ///\param i_element Iterator to the element. + ///\return An iterator pointing to the element that followed the erased element. + //********************************************************************* + iterator erase(const_iterator i_element) + { + iterator i_element_ = to_iterator(i_element); + + etl::copy(i_element_ + 1, end(), i_element_); + --p_end; + + return i_element_; + } + //********************************************************************* /// Erases a range of elements. /// The range includes all the elements between first and last, including the @@ -540,15 +563,18 @@ namespace etl ///\param last Iterator to the last element. ///\return An iterator pointing to the element that followed the erased element. //********************************************************************* - iterator erase(iterator first, iterator last) + iterator erase(const_iterator first, const_iterator last) { - etl::copy(last, end(), first); + iterator first_ = to_iterator(first); + iterator last_ = to_iterator(last); + + etl::copy(last_, end(), first_); size_t n_delete = etl::distance(first, last); // Just adjust the count. p_end -= n_delete; - return first; + return first_; } //************************************************************************* @@ -656,6 +682,14 @@ namespace etl private: + //************************************************************************* + /// Convert from const_iterator to iterator + //************************************************************************* + iterator to_iterator(const_iterator itr) const + { + return const_cast(itr); + } + // Disable copy construction. pvoidvector(const pvoidvector&); }; diff --git a/include/etl/reference_flat_map.h b/include/etl/reference_flat_map.h index c3a1b45c..f5613953 100644 --- a/include/etl/reference_flat_map.h +++ b/include/etl/reference_flat_map.h @@ -544,7 +544,7 @@ namespace etl ///\param position The position to insert at. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, reference value) + iterator insert(const_iterator position, reference value) { return insert(value).first; } @@ -589,9 +589,18 @@ namespace etl /// Erases an element. ///\param i_element Iterator to the element. //********************************************************************* - void erase(iterator i_element) + iterator erase(iterator i_element) { - lookup.erase(i_element.ilookup); + return lookup.erase(i_element.ilookup); + } + + //********************************************************************* + /// Erases an element. + ///\param i_element Iterator to the element. + //********************************************************************* + iterator erase(const_iterator i_element) + { + return lookup.erase(i_element.ilookup); } //********************************************************************* @@ -601,9 +610,9 @@ namespace etl ///\param first Iterator to the first element. ///\param last Iterator to the last element. //********************************************************************* - void erase(iterator first, iterator last) + iterator erase(const_iterator first, const_iterator last) { - lookup.erase(first.ilookup, last.ilookup); + return lookup.erase(first.ilookup, last.ilookup); } //************************************************************************* diff --git a/include/etl/reference_flat_multimap.h b/include/etl/reference_flat_multimap.h index de67f5c6..f44560f5 100644 --- a/include/etl/reference_flat_multimap.h +++ b/include/etl/reference_flat_multimap.h @@ -461,7 +461,7 @@ namespace etl ///\param position The position to insert at. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, const value_type& value) + iterator insert(const_iterator position, const value_type& value) { return insert(value).first; } @@ -507,9 +507,18 @@ namespace etl /// Erases an element. ///\param i_element Iterator to the element. //********************************************************************* - void erase(iterator i_element) + iterator erase(iterator i_element) { - lookup.erase(i_element.ilookup); + return lookup.erase(i_element.ilookup); + } + + //********************************************************************* + /// Erases an element. + ///\param i_element Iterator to the element. + //********************************************************************* + iterator erase(const_iterator i_element) + { + return lookup.erase(i_element.ilookup); } //********************************************************************* @@ -519,9 +528,9 @@ namespace etl ///\param first Iterator to the first element. ///\param last Iterator to the last element. //********************************************************************* - void erase(iterator first, iterator last) + iterator erase(const_iterator first, const_iterator last) { - lookup.erase(first.ilookup, last.ilookup); + return lookup.erase(first.ilookup, last.ilookup); } //************************************************************************* diff --git a/include/etl/reference_flat_multiset.h b/include/etl/reference_flat_multiset.h index 1343c994..7959e579 100644 --- a/include/etl/reference_flat_multiset.h +++ b/include/etl/reference_flat_multiset.h @@ -470,7 +470,7 @@ namespace etl ///\param position The position to insert at. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, value_type& value) + iterator insert(const_iterator position, value_type& value) { return insert(value).first; } @@ -516,9 +516,18 @@ namespace etl /// Erases an element. ///\param i_element Iterator to the element. //********************************************************************* - void erase(iterator i_element) + iterator erase(iterator i_element) { - lookup.erase(i_element.ilookup); + return lookup.erase(i_element.ilookup); + } + + //********************************************************************* + /// Erases an element. + ///\param i_element Iterator to the element. + //********************************************************************* + iterator erase(const_iterator i_element) + { + return lookup.erase(i_element.ilookup); } //********************************************************************* @@ -528,9 +537,9 @@ namespace etl ///\param first Iterator to the first element. ///\param last Iterator to the last element. //********************************************************************* - void erase(iterator first, iterator last) + iterator erase(const_iterator first, const_iterator last) { - lookup.erase(first.ilookup, last.ilookup); + return lookup.erase(first.ilookup, last.ilookup); } //************************************************************************* diff --git a/include/etl/reference_flat_set.h b/include/etl/reference_flat_set.h index 08585415..68472cd6 100644 --- a/include/etl/reference_flat_set.h +++ b/include/etl/reference_flat_set.h @@ -453,7 +453,7 @@ namespace etl ///\param position The position to insert at. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, reference value) + iterator insert(const_iterator position, reference value) { return insert(value).first; } @@ -498,9 +498,18 @@ namespace etl /// Erases an element. ///\param i_element Iterator to the element. //********************************************************************* - void erase(iterator i_element) + iterator erase(iterator i_element) { - lookup.erase(i_element.ilookup); + return lookup.erase(i_element.ilookup); + } + + //********************************************************************* + /// Erases an element. + ///\param i_element Iterator to the element. + //********************************************************************* + iterator erase(const_iterator i_element) + { + return lookup.erase(i_element.ilookup); } //********************************************************************* @@ -510,9 +519,9 @@ namespace etl ///\param first Iterator to the first element. ///\param last Iterator to the last element. //********************************************************************* - void erase(iterator first, iterator last) + iterator erase(const_iterator first, const_iterator last) { - lookup.erase(first.ilookup, last.ilookup); + return lookup.erase(first.ilookup, last.ilookup); } //************************************************************************* diff --git a/include/etl/set.h b/include/etl/set.h index a06adff4..57235854 100644 --- a/include/etl/set.h +++ b/include/etl/set.h @@ -957,10 +957,10 @@ namespace etl //************************************************************************* /// Erases the value at the specified position. //************************************************************************* - void erase(iterator position) + iterator erase(iterator position) { - // Remove the node by its key - erase((*position)); + // Remove the node by its node specified in iterator position + return erase(const_iterator(position)); } //************************************************************************* @@ -987,20 +987,6 @@ namespace etl return remove_node(root_node, key_value) ? 1 : 0; } - //************************************************************************* - /// Erases a range of elements. - //************************************************************************* - iterator erase(iterator first, iterator last) - { - iterator next; - while (first != last) - { - next = erase(const_iterator(first++)); - } - - return next; - } - //************************************************************************* /// Erases a range of elements. //************************************************************************* @@ -1085,54 +1071,6 @@ namespace etl } #endif - //********************************************************************* - /// Inserts a value to the set starting at the position recommended. - /// If asserts or exceptions are enabled, emits set_full if the set is already full. - ///\param position The position that would precede the value to insert. - ///\param value The value to insert. - //********************************************************************* - iterator insert(iterator, const_reference value) - { - // Default to no inserted node - Node* inserted_node = ETL_NULLPTR; - - ETL_ASSERT(!full(), ETL_ERROR(set_full)); - - // Get next available free node - Data_Node& node = allocate_data_node(value); - - // Obtain the inserted node (might be ETL_NULLPTR if node was a duplicate) - inserted_node = insert_node(root_node, node); - - // Insert node into tree and return iterator to new node location in tree - return iterator(*this, inserted_node); - } - -#if ETL_CPP11_SUPPORTED - //********************************************************************* - /// Inserts a value to the set starting at the position recommended. - /// If asserts or exceptions are enabled, emits set_full if the set is already full. - ///\param position The position that would precede the value to insert. - ///\param value The value to insert. - //********************************************************************* - iterator insert(iterator, rvalue_reference value) - { - // Default to no inserted node - Node* inserted_node = ETL_NULLPTR; - - ETL_ASSERT(!full(), ETL_ERROR(set_full)); - - // Get next available free node - Data_Node& node = allocate_data_node(etl::move(value)); - - // Obtain the inserted node (might be ETL_NULLPTR if node was a duplicate) - inserted_node = insert_node(root_node, node); - - // Insert node into tree and return iterator to new node location in tree - return iterator(*this, inserted_node); - } -#endif - //********************************************************************* /// Inserts a value to the set starting at the position recommended. /// If asserts or exceptions are enabled, emits set_full if the set is already full. diff --git a/include/etl/vector.h b/include/etl/vector.h index e44b63bb..499092d9 100644 --- a/include/etl/vector.h +++ b/include/etl/vector.h @@ -383,7 +383,8 @@ namespace etl ///\param last The iterator to the last element + 1. //********************************************************************* template - void assign(TIterator first, TIterator last) + typename etl::enable_if::value, void>::type + assign(TIterator first, TIterator last) { ETL_STATIC_ASSERT((etl::is_same::type, typename etl::remove_cv::value_type>::type>::value), "Iterator type does not match container type"); @@ -550,22 +551,24 @@ namespace etl ///\param position The position to insert before. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, const_reference value) + iterator insert(const_iterator position, const_reference value) { ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); - if (position == end()) + iterator position_ = to_iterator(position); + + if (position_ == end()) { create_back(value); } else { create_back(back()); - etl::move_backward(position, p_end - 2, p_end - 1); - *position = value; + etl::move_backward(position_, p_end - 2, p_end - 1); + *position_ = value; } - return position; + return position_; } #if ETL_CPP11_SUPPORTED @@ -575,22 +578,24 @@ namespace etl ///\param position The position to insert before. ///\param value The value to insert. //********************************************************************* - iterator insert(iterator position, rvalue_reference value) + iterator insert(const_iterator position, rvalue_reference value) { ETL_ASSERT(size() != CAPACITY, ETL_ERROR(vector_full)); - if (position == end()) + iterator position_ = to_iterator(position); + + if (position_ == end()) { create_back(etl::move(value)); } else { create_back(etl::move(back())); - etl::move_backward(position, p_end - 2, p_end - 1); - *position = etl::move(value); + etl::move_backward(position_, p_end - 2, p_end - 1); + *position_ = etl::move(value); } - return position; + return position_; } #endif @@ -599,128 +604,138 @@ namespace etl //************************************************************************* #if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT template - iterator emplace(iterator position, Args && ... args) + iterator emplace(const_iterator position, Args && ... args) { ETL_ASSERT(!full(), ETL_ERROR(vector_full)); + iterator position_ = to_iterator(position); + void* p; - if (position == end()) + if (position_ == end()) { p = p_end++; ETL_INCREMENT_DEBUG_COUNT } else { - p = etl::addressof(*position); + p = etl::addressof(*position_); create_back(back()); - etl::move_backward(position, p_end - 2, p_end - 1); - (*position).~T(); + etl::move_backward(position_, p_end - 2, p_end - 1); + (*position_).~T(); } ::new (p) T(etl::forward(args)...); - return position; + return position_; } #else template - iterator emplace(iterator position, const T1& value1) + iterator emplace(const_iterator position, const T1& value1) { ETL_ASSERT(!full(), ETL_ERROR(vector_full)); + iterator position_ = to_iterator(position); + void* p; - if (position == end()) + if (position_ == end()) { p = p_end++; ETL_INCREMENT_DEBUG_COUNT } else { - p = etl::addressof(*position); + p = etl::addressof(*position_); create_back(back()); - etl::move_backward(position, p_end - 2, p_end - 1); - (*position).~T(); + etl::move_backward(position_, p_end - 2, p_end - 1); + (*position_).~T(); } ::new (p) T(value1); - return position; + return position_; } template - iterator emplace(iterator position, const T1& value1, const T2& value2) + iterator emplace(const_iterator position, const T1& value1, const T2& value2) { ETL_ASSERT(!full(), ETL_ERROR(vector_full)); + iterator position_ = to_iterator(position); + void* p; - if (position == end()) + if (position_ == end()) { p = p_end++; ETL_INCREMENT_DEBUG_COUNT } else { - p = etl::addressof(*position); + p = etl::addressof(*position_); create_back(back()); - etl::move_backward(position, p_end - 2, p_end - 1); - (*position).~T(); + etl::move_backward(position_, p_end - 2, p_end - 1); + (*position_).~T(); } ::new (p) T(value1, value2); - return position; + return position_; } template - iterator emplace(iterator position, const T1& value1, const T2& value2, const T3& value3) + iterator emplace(const_iterator position, const T1& value1, const T2& value2, const T3& value3) { ETL_ASSERT(!full(), ETL_ERROR(vector_full)); + iterator position_ = to_iterator(position); + void* p; - if (position == end()) + if (position_ == end()) { p = p_end++; ETL_INCREMENT_DEBUG_COUNT } else { - p = etl::addressof(*position); + p = etl::addressof(*position_); create_back(back()); - etl::move_backward(position, p_end - 2, p_end - 1); - (*position).~T(); + etl::move_backward(position_, p_end - 2, p_end - 1); + (*position_).~T(); } ::new (p) T(value1, value2, value3); - return position; + return position_; } template - iterator emplace(iterator position, const T1& value1, const T2& value2, const T3& value3, const T4& value4) + iterator emplace(const_iterator position, const T1& value1, const T2& value2, const T3& value3, const T4& value4) { ETL_ASSERT(!full(), ETL_ERROR(vector_full)); + iterator position_ = to_iterator(position); + void* p; - if (position == end()) + if (position_ == end()) { p = p_end++; ETL_INCREMENT_DEBUG_COUNT } else { - p = etl::addressof(*position); + p = etl::addressof(*position_); create_back(back()); - etl::move_backward(position, p_end - 2, p_end - 1); - (*position).~T(); + etl::move_backward(position_, p_end - 2, p_end - 1); + (*position_).~T(); } ::new (p) T(value1, value2, value3, value4); - return position; + return position_; } #endif @@ -731,12 +746,14 @@ namespace etl ///\param n The number of elements to add. ///\param value The value to insert. //********************************************************************* - void insert(iterator position, size_t n, parameter_t value) + void insert(const_iterator position, size_t n, parameter_t value) { ETL_ASSERT((size() + n) <= CAPACITY, ETL_ERROR(vector_full)); + iterator position_ = to_iterator(position); + size_t insert_n = n; - size_t insert_begin = etl::distance(begin(), position); + size_t insert_begin = etl::distance(begin(), position_); size_t insert_end = insert_begin + insert_n; // Copy old data. @@ -786,14 +803,14 @@ namespace etl ///\param last The last + 1 element to add. //********************************************************************* template - void insert(iterator position, TIterator first, TIterator last) + void insert(const_iterator position, TIterator first, TIterator last, typename etl::enable_if::value, int>::type = 0) { size_t count = etl::distance(first, last); ETL_ASSERT((size() + count) <= CAPACITY, ETL_ERROR(vector_full)); size_t insert_n = count; - size_t insert_begin = etl::distance(begin(), position); + size_t insert_begin = etl::distance(cbegin(), position); size_t insert_end = insert_begin + insert_n; // Move old data. @@ -847,6 +864,21 @@ namespace etl return i_element; } + //********************************************************************* + /// Erases an element. + ///\param i_element Iterator to the element. + ///\return An iterator pointing to the element that followed the erased element. + //********************************************************************* + iterator erase(const_iterator i_element) + { + iterator i_element_ = to_iterator(i_element); + + etl::move(i_element_ + 1, end(), i_element_); + destroy_back(); + + return i_element_; + } + //********************************************************************* /// Erases a range of elements. /// The range includes all the elements between first and last, including the @@ -855,24 +887,27 @@ namespace etl ///\param last Iterator to the last element. ///\return An iterator pointing to the element that followed the erased element. //********************************************************************* - iterator erase(iterator first, iterator last) + iterator erase(const_iterator first, const_iterator last) { + iterator first_ = to_iterator(first); + iterator last_ = to_iterator(last); + if (first == begin() && last == end()) { clear(); } else { - etl::move(last, end(), first); - size_t n_delete = etl::distance(first, last); + etl::move(last_, end(), first_); + size_t n_delete = etl::distance(first_, last_); // Destroy the elements left over at the end. etl::destroy(p_end - n_delete, p_end); ETL_SUBTRACT_DEBUG_COUNT(n_delete) - p_end -= n_delete; + p_end -= n_delete; } - return first; + return first_; } //************************************************************************* @@ -1030,7 +1065,7 @@ namespace etl //********************************************************************* /// Destroy an element at the back. //********************************************************************* - inline void destroy_back() + void destroy_back() { --p_end; @@ -1040,6 +1075,16 @@ namespace etl // Disable copy construction. ivector(const ivector&) ETL_DELETE; + + private: + + //************************************************************************* + /// Convert from const_iterator to iterator + //************************************************************************* + ETL_CONSTEXPR iterator to_iterator(const_iterator itr) const + { + return const_cast(itr); + } }; //*************************************************************************** @@ -1294,7 +1339,7 @@ namespace etl //************************************************************************* /// Template deduction guides. //************************************************************************* -#if ETL_CPP17_SUPPORTED +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST template vector(T...) -> vector, sizeof...(T)>; #endif @@ -1302,7 +1347,7 @@ namespace etl //************************************************************************* /// Make //************************************************************************* -#if ETL_USING_INITIALIZER_LIST +#if ETL_CPP11_SUPPORTED && ETL_USING_INITIALIZER_LIST template constexpr auto make_vector(T... t) -> etl::vector, sizeof...(T)> { @@ -1596,12 +1641,12 @@ namespace etl //************************************************************************* /// Template deduction guides. //************************************************************************* -#if ETL_CPP17_SUPPORTED +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST template vector(T*...) -> vector, sizeof...(T)>; #endif -#if ETL_CPP11_SUPPORTED +#if ETL_CPP11_SUPPORTED && ETL_USING_INITIALIZER_LIST template constexpr auto make_vector(T*... t) -> etl::vector, sizeof...(T)> { diff --git a/include/etl/version.h b/include/etl/version.h index 4efd7bdb..3821b26d 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,7 +38,7 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 20 -#define ETL_VERSION_MINOR 19 +#define ETL_VERSION_MINOR 20 #define ETL_VERSION_PATCH 0 #define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) "." ETL_STRINGIFY(ETL_VERSION_MINOR) "." ETL_STRINGIFY(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_STRINGIFY(ETL_VERSION_MAJOR) L"." ETL_STRINGIFY(ETL_VERSION_MINOR) L"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index 9729d2ac..270e34a4 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "ETL Embedded Template Library", - "version": "20.19.0", + "version": "20.20.0", "author s": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index 0e43a057..c3d3d74e 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library ETL -version=20.19.0 +version=20.20.0 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/meson.build b/meson.build index 9194bba9..9f708c8b 100644 --- a/meson.build +++ b/meson.build @@ -8,7 +8,7 @@ project('etl', 'cpp_std=c++17', 'build.cpp_std=c++17', ], meson_version: '>=0.54.0', - version: '20.19.0' + version: '20.20.0' ) compile_args = [] diff --git a/support/Release notes.txt b/support/Release notes.txt index f74589a2..0bcee639 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,15 @@ +=============================================================================== +20.20.0 +Updated container 'insert' and 'erase' to C++11 style const_iterator parameters. (#463) +Fixed container template function overload abiguity. (#466) +Harmonize copy ctor and assignment for etl::delegate. (#465) +Added constexpr support for etl::enum_type. (#462) +Added 'make' functions to construct containers. +Remove unnecessary casts that causes warnings. (#461) +Added non-const string pointer overload. (#449) +Changed != to < in etl::ipool to get rid of erroneous clang-tidy nullptr dereference warning. (#457) +Added ifdef guard for MSVC pragma (#455) + =============================================================================== 20.19.0 Updates to etl::delegate. Added more constexpr and set() functions. diff --git a/test/test_array.cpp b/test/test_array.cpp index f4641ecd..e3ed098d 100644 --- a/test/test_array.cpp +++ b/test/test_array.cpp @@ -62,7 +62,7 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } -#if !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -651,7 +651,7 @@ namespace } //************************************************************************* -#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST(test_array_template_deduction) { etl::array data{ char(0), short(1), int(2), long(3), 4, 5, 6, 7, 8, 9 }; diff --git a/test/test_array_view.cpp b/test/test_array_view.cpp index 4b909fc1..6af583df 100644 --- a/test/test_array_view.cpp +++ b/test/test_array_view.cpp @@ -284,7 +284,7 @@ namespace } //************************************************************************* -#if !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST(test_cpp17_deduced_constructor) { etl::array data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; diff --git a/test/test_circular_buffer.cpp b/test/test_circular_buffer.cpp index ca1d7bca..d44576d8 100644 --- a/test/test_circular_buffer.cpp +++ b/test/test_circular_buffer.cpp @@ -98,7 +98,7 @@ namespace } #endif -#if !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) && ETL_USING_STL +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -112,8 +112,10 @@ namespace bool isEqual = std::equal(data.begin(), data.end(), compare.begin()); CHECK(isEqual); } +#endif //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST(test_cpp17_deduced_constructor_excess) { Data data{ Ndc("0"), Ndc("1"), Ndc("2"), Ndc("3"), Ndc("4"), Ndc("5"), Ndc("6"), Ndc("7"), Ndc("8"), Ndc("9"), Ndc("10"), Ndc("11"), Ndc("12") }; diff --git a/test/test_circular_buffer_external_buffer.cpp b/test/test_circular_buffer_external_buffer.cpp index 748a3516..04aaa107 100644 --- a/test/test_circular_buffer_external_buffer.cpp +++ b/test/test_circular_buffer_external_buffer.cpp @@ -107,7 +107,7 @@ namespace } #endif -#if !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) && ETL_USING_STL +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -121,8 +121,10 @@ namespace bool isEqual = std::equal(data.begin(), data.end(), compare.begin()); CHECK(isEqual); } +#endif //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST(test_cpp17_deduced_constructor_excess) { Data data({ Ndc("0"), Ndc("1"), Ndc("2"), Ndc("3"), Ndc("4"), Ndc("5"), Ndc("6"), Ndc("7"), Ndc("8"), Ndc("9"), Ndc("10"), Ndc("11"), Ndc("12") }, buffer1.raw, SIZE); diff --git a/test/test_deque.cpp b/test/test_deque.cpp index 0f2cc3d2..d975a7f6 100644 --- a/test/test_deque.cpp +++ b/test/test_deque.cpp @@ -101,24 +101,6 @@ namespace CHECK_EQUAL(SIZE, data.max_size()); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) - //************************************************************************* - TEST(test_cpp17_deduced_constructor) - { - etl::deque data{ N0, N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, N11, N12, N13 }; - etl::deque check = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9, N10, N11, N12, N13 }; - - CHECK(!data.empty()); - CHECK(data.full()); - CHECK(data.begin() != data.end()); - CHECK_EQUAL(14U, data.size()); - CHECK_EQUAL(0U, data.available()); - CHECK_EQUAL(14U, data.capacity()); - CHECK_EQUAL(14U, data.max_size()); - CHECK(data == check); - } -#endif - //************************************************************************* TEST(test_constructor_fill) { @@ -874,7 +856,7 @@ namespace etl::deque valuesToInsert(insertCount, value); etl::deque data; - data.insert(data.begin(), valuesToInsert.begin(), valuesToInsert.end()); + data.insert(data.cbegin(), valuesToInsert.begin(), valuesToInsert.end()); CHECK_EQUAL(insertCount, std::distance(data.begin(), data.end())); CHECK(data.size() == insertCount); @@ -889,8 +871,8 @@ namespace Compare_Data compare_data(initial_data_under.begin(), initial_data_under.end()); DataNDC data(compare_data.begin(), compare_data.end()); - Compare_Data::iterator cposition = compare_data.insert(compare_data.begin(), N14); - DataNDC::iterator position = data.insert(data.begin(), N14); + Compare_Data::iterator cposition = compare_data.insert(compare_data.cbegin(), N14); + DataNDC::iterator position = data.insert(data.cbegin(), N14); CHECK_EQUAL(compare_data.size(), std::distance(data.begin(), data.end())); CHECK_EQUAL(compare_data.size(), data.size()); @@ -919,8 +901,8 @@ namespace Compare_Data compare_data(initial_data_under.begin(), initial_data_under.end()); DataNDC data(compare_data.begin(), compare_data.end()); - Compare_Data::iterator cposition = compare_data.insert(compare_data.end(), N14); - DataNDC::iterator position = data.insert(data.end(), N14); + Compare_Data::iterator cposition = compare_data.insert(compare_data.cend(), N14); + DataNDC::iterator position = data.insert(data.cend(), N14); CHECK_EQUAL(compare_data.size(), std::distance(data.begin(), data.end())); CHECK_EQUAL(compare_data.size(), data.size()); @@ -949,8 +931,8 @@ namespace Compare_Data compare_data(initial_data_under.begin(), initial_data_under.end()); DataNDC data(compare_data.begin(), compare_data.end()); - Compare_Data::iterator cposition = compare_data.insert(compare_data.begin() + 3, N14); - DataNDC::iterator position = data.insert(data.begin() + 3, N14); + Compare_Data::iterator cposition = compare_data.insert(compare_data.cbegin() + 3, N14); + DataNDC::iterator position = data.insert(data.cbegin() + 3, N14); CHECK_EQUAL(compare_data.size(), std::distance(data.begin(), data.end())); CHECK_EQUAL(compare_data.size(), data.size()); @@ -960,8 +942,8 @@ namespace compare_data.assign(initial_data_under.begin(), initial_data_under.end()); data.assign(compare_data.begin(), compare_data.end()); - cposition = compare_data.insert(compare_data.begin() + 4, N14); - position = data.insert(data.begin() + 4, N14); + cposition = compare_data.insert(compare_data.cbegin() + 4, N14); + position = data.insert(data.cbegin() + 4, N14); CHECK_EQUAL(compare_data.size(), std::distance(data.begin(), data.end())); CHECK_EQUAL(compare_data.size(), data.size()); @@ -1007,8 +989,8 @@ namespace Compare_Data compare_data(initial_data_small.begin(), initial_data_small.end()); DataNDC data(compare_data.begin(), compare_data.end()); - compare_data.insert(compare_data.begin() + offset, insert_size, N14); - data.insert(data.begin() + offset, insert_size, N14); + compare_data.insert(compare_data.cbegin() + offset, insert_size, N14); + data.insert(data.cbegin() + offset, insert_size, N14); CHECK_EQUAL(compare_data.size(), data.size()); CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin())); @@ -1023,9 +1005,9 @@ namespace size_t insert_size = SIZE - initial_data_under.size() + 1; - CHECK_THROW(data.insert(data.begin(), insert_size, N14), etl::deque_full); - CHECK_THROW(data.insert(data.end(), insert_size, N14), etl::deque_full); - CHECK_THROW(data.insert(data.begin() + 6, insert_size, N14), etl::deque_full); + CHECK_THROW(data.insert(data.cbegin(), insert_size, N14), etl::deque_full); + CHECK_THROW(data.insert(data.cend(), insert_size, N14), etl::deque_full); + CHECK_THROW(data.insert(data.cbegin() + 6, insert_size, N14), etl::deque_full); } //************************************************************************* @@ -1043,8 +1025,8 @@ namespace DataNDC data(blank_data.begin(), blank_data.end()); data.assign(compare_data.begin(), compare_data.end()); - compare_data.insert(compare_data.begin() + offset, range.begin(), range.end()); - data.insert(data.begin() + offset, range.begin(), range.end()); + compare_data.insert(compare_data.cbegin() + offset, range.begin(), range.end()); + data.insert(data.cbegin() + offset, range.begin(), range.end()); CHECK_EQUAL(compare_data.size(), std::distance(data.begin(), data.end())); CHECK_EQUAL(compare_data.size(), data.size()); @@ -1059,9 +1041,9 @@ namespace Compare_Data range = { N12, N13, N14, N15 }; DataNDC data(initial_data_under.begin(), initial_data_under.end()); - CHECK_THROW(data.insert(data.begin(), range.begin(), range.end()), etl::deque_full); - CHECK_THROW(data.insert(data.end(), range.begin(), range.end()), etl::deque_full); - CHECK_THROW(data.insert(data.begin() + 6, range.begin(), range.end()), etl::deque_full); + CHECK_THROW(data.insert(data.cbegin(), range.begin(), range.end()), etl::deque_full); + CHECK_THROW(data.insert(data.cend(), range.begin(), range.end()), etl::deque_full); + CHECK_THROW(data.insert(data.cbegin() + 6, range.begin(), range.end()), etl::deque_full); } //************************************************************************* @@ -1103,12 +1085,12 @@ namespace compare_data.push_back(N9); compare_data.push_back(N10); - DataNDC::iterator i_next = data.erase(data.begin()); - Compare_Data::iterator i_cnext = compare_data.erase(compare_data.begin()); + DataNDC::const_iterator i_next = data.erase(data.cbegin()); + Compare_Data::const_iterator i_cnext = compare_data.erase(compare_data.cbegin()); CHECK_EQUAL(DataNDC::difference_type(data.size()), std::distance(data.begin(), data.end())); CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin())); - CHECK_EQUAL(std::distance(compare_data.begin(), i_cnext), std::distance(data.begin(), i_next)); + CHECK_EQUAL(std::distance(compare_data.cbegin(), i_cnext), std::distance(data.cbegin(), i_next)); } //************************************************************************* @@ -1153,7 +1135,7 @@ namespace DataNDC::iterator i_erase = data.end() - 1; DataNDC::iterator i_next = data.erase(i_erase); - Compare_Data::iterator i_cerase = compare_data.end() - 1; + Compare_Data::const_iterator i_cerase = compare_data.cend() - 1U; Compare_Data::iterator i_cnext = compare_data.erase(i_cerase); CHECK_EQUAL(DataNDC::difference_type(compare_data.size()), std::distance(data.begin(), data.end())); @@ -1203,10 +1185,10 @@ namespace compare_data.push_back(N10); // Erase near beginning. - DataNDC::iterator i_erase = data.begin() + 2; + DataNDC::const_iterator i_erase = data.begin() + 2; DataNDC::iterator i_next = data.erase(i_erase); - Compare_Data::iterator i_cerase = compare_data.begin() + 2; + Compare_Data::const_iterator i_cerase = compare_data.begin() + 2; Compare_Data::iterator i_cnext = compare_data.erase(i_cerase); CHECK_EQUAL(DataNDC::difference_type(compare_data.size()), std::distance(data.begin(), data.end())); @@ -1303,8 +1285,8 @@ namespace compare_data.push_back(N9); compare_data.push_back(N10); - DataNDC::iterator i_next = data.erase(data.begin(), data.begin() + 3); - Compare_Data::iterator i_cnext = compare_data.erase(compare_data.begin(), compare_data.begin() + 3); + DataNDC::iterator i_next = data.erase(data.cbegin(), data.cbegin() + 3); + Compare_Data::iterator i_cnext = compare_data.erase(compare_data.cbegin(), compare_data.cbegin() + 3); CHECK_EQUAL(DataNDC::difference_type(compare_data.size()), std::distance(data.begin(), data.end())); CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin())); @@ -1352,8 +1334,8 @@ namespace compare_data.push_back(N9); compare_data.push_back(N10); - DataNDC::iterator i_next = data.erase(data.end() - 3, data.end()); - Compare_Data::iterator i_cnext = compare_data.erase(compare_data.end() - 3, compare_data.end()); + DataNDC::iterator i_next = data.erase(data.cend() - 3, data.cend()); + Compare_Data::iterator i_cnext = compare_data.erase(compare_data.cend() - 3, compare_data.cend()); CHECK_EQUAL(DataNDC::difference_type(compare_data.size()), std::distance(data.begin(), data.end())); CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin())); @@ -1401,8 +1383,8 @@ namespace compare_data.push_back(N9); compare_data.push_back(N10); - DataNDC::iterator i_next = data.erase(data.begin() + 1, data.begin() + 3); - Compare_Data::iterator i_cnext = compare_data.erase(compare_data.begin() + 1, compare_data.begin() + 3); + DataNDC::iterator i_next = data.erase(data.cbegin() + 1, data.cbegin() + 3); + Compare_Data::iterator i_cnext = compare_data.erase(compare_data.cbegin() + 1, compare_data.cbegin() + 3); CHECK_EQUAL(DataNDC::difference_type(compare_data.size()), std::distance(data.begin(), data.end())); CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin())); @@ -1444,8 +1426,8 @@ namespace compare_data.push_back(N9); compare_data.push_back(N10); - i_next = data.erase(data.begin() + 3, data.begin() + 5); - i_cnext = compare_data.erase(compare_data.begin() + 3, compare_data.begin() + 5); + i_next = data.erase(data.cbegin() + 3, data.cbegin() + 5); + i_cnext = compare_data.erase(compare_data.cbegin() + 3, compare_data.cbegin() + 5); CHECK_EQUAL(DataNDC::difference_type(compare_data.size()), std::distance(data.begin(), data.end())); CHECK(std::equal(compare_data.begin(), compare_data.end(), data.begin())); @@ -2010,7 +1992,7 @@ namespace } //************************************************************************* -#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST(test_deque_template_deduction) { etl::deque data{ char(0), short(1), int(2), long(3), 4, 5, 6, 7, 8, 9 }; @@ -2032,7 +2014,7 @@ namespace #endif //************************************************************************* -#if ETL_USING_INITIALIZER_LIST +#if ETL_CPP11_SUPPORTED && ETL_USING_INITIALIZER_LIST TEST(test_make_deque) { auto data = etl::make_deque(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); diff --git a/test/test_flat_map.cpp b/test/test_flat_map.cpp index ef32a3ad..927a30ac 100644 --- a/test/test_flat_map.cpp +++ b/test/test_flat_map.cpp @@ -53,14 +53,14 @@ namespace typedef ETL_OR_STD::pair ElementDC; typedef ETL_OR_STD::pair ElementNDC; - typedef ETL_OR_STD::pair ElementInt; + typedef ETL_OR_STD::pair ElementInt; typedef etl::flat_map DataDC; typedef etl::flat_map DataNDC; typedef etl::iflat_map IDataDC; typedef etl::iflat_map IDataNDC; - typedef etl::flat_map DataInt; + typedef etl::flat_map DataInt; typedef etl::flat_map DataM; typedef etl::iflat_map IDataM; @@ -316,7 +316,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -1003,23 +1003,81 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end()); - Compare_DataNDC::iterator i_compare = compare_data.begin(); - DataNDC::iterator i_data = data.begin(); + Compare_DataNDC::iterator i_compare_begin = compare_data.begin(); + DataNDC::iterator i_data_begin = data.begin(); + + Compare_DataNDC::iterator i_compare = i_compare_begin; + DataNDC::iterator i_data = i_data_begin; + + Compare_DataNDC::iterator i_compare_expected = i_compare_begin; + DataNDC::iterator i_data_expected = i_data_begin; std::advance(i_compare, 2); - std::advance(i_data, 2); + std::advance(i_data, 2); - compare_data.erase(i_compare); - data.erase(i_data); + std::advance(i_compare_expected, 3); + std::advance(i_data_expected, 3); - bool isEqual = Check_Equal(data.begin(), - data.end(), - compare_data.begin()); + ElementNDC compare_expected = *i_compare_expected; + ElementNDC data_expected = *i_data_expected; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare); + DataNDC::iterator i_data_result = data.erase(i_data); + + CHECK(compare_expected.first == i_compare_result->first); + CHECK(data_expected.first == i_data_result->first); + + CHECK(compare_expected.second == i_compare_result->second); + CHECK(data_expected.second == i_data_result->second); + + bool isEqual = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(isEqual); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) + { + Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); + DataNDC data(initial_data.begin(), initial_data.end()); + + Compare_DataNDC::iterator i_compare_begin = compare_data.begin(); + DataNDC::iterator i_data_begin = data.begin(); + + Compare_DataNDC::const_iterator i_compare = i_compare_begin; + DataNDC::const_iterator i_data = i_data_begin; + + Compare_DataNDC::iterator i_compare_expected = i_compare_begin; + DataNDC::iterator i_data_expected = i_data_begin; + + std::advance(i_compare, 2); + std::advance(i_data, 2); + + std::advance(i_compare_expected, 3); + std::advance(i_data_expected, 3); + + ElementNDC compare_expected = *i_compare_expected; + ElementNDC data_expected = *i_data_expected; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare); + DataNDC::iterator i_data_result = data.erase(i_data); + + CHECK(compare_expected.first == i_compare_result->first); + CHECK(data_expected.first == i_data_result->first); + + CHECK(compare_expected.second == i_compare_result->second); + CHECK(data_expected.second == i_data_result->second); + + bool isEqual = std::equal(data.begin(), + data.end(), + compare_data.begin()); CHECK(isEqual); } @@ -1030,24 +1088,33 @@ namespace Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end()); - Compare_DataNDC::iterator i_compare = compare_data.begin(); - DataNDC::iterator i_data = data.begin(); + Compare_DataNDC::const_iterator i_compare = compare_data.begin(); + DataNDC::const_iterator i_data = data.begin(); - Compare_DataNDC::iterator i_compare_end = compare_data.begin(); - DataNDC::iterator i_data_end = data.begin(); + Compare_DataNDC::const_iterator i_compare_end = compare_data.begin(); + DataNDC::const_iterator i_data_end = data.begin(); std::advance(i_compare, 2); - std::advance(i_data, 2); + std::advance(i_data, 2); std::advance(i_compare_end, 4); - std::advance(i_data_end, 4); + std::advance(i_data_end, 4); - compare_data.erase(i_compare, i_compare_end); - data.erase(i_data, i_data_end); + ElementNDC compare_expected = *i_compare_end; + ElementNDC data_expected = *i_data_end; - bool isEqual = Check_Equal(data.begin(), - data.end(), - compare_data.begin()); + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare, i_compare_end); + DataNDC::iterator i_data_result = data.erase(i_data, i_data_end); + + CHECK(compare_expected.first == i_compare_result->first); + CHECK(data_expected.first == i_data_result->first); + + CHECK(compare_expected.second == i_compare_result->second); + CHECK(data_expected.second == i_data_result->second); + + bool isEqual = std::equal(data.begin(), + data.end(), + compare_data.begin()); CHECK(isEqual); } @@ -1263,7 +1330,7 @@ namespace } //************************************************************************* -#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST(test_flat_map_template_deduction) { using Pair = ETL_OR_STD::pair; diff --git a/test/test_flat_multimap.cpp b/test/test_flat_multimap.cpp index 385297b0..557309d3 100644 --- a/test/test_flat_multimap.cpp +++ b/test/test_flat_multimap.cpp @@ -277,7 +277,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -753,23 +753,81 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end()); - Compare_DataNDC::iterator i_compare = compare_data.begin(); - DataNDC::iterator i_data = data.begin(); + Compare_DataNDC::iterator i_compare_begin = compare_data.begin(); + DataNDC::iterator i_data_begin = data.begin(); + + Compare_DataNDC::iterator i_compare = i_compare_begin; + DataNDC::iterator i_data = i_data_begin; + + Compare_DataNDC::iterator i_compare_expected = i_compare_begin; + DataNDC::iterator i_data_expected = i_data_begin; std::advance(i_compare, 2); - std::advance(i_data, 2); + std::advance(i_data, 2); - compare_data.erase(i_compare); - data.erase(i_data); + std::advance(i_compare_expected, 3); + std::advance(i_data_expected, 3); - bool isEqual = Check_Equal(data.begin(), - data.end(), - compare_data.begin()); + ElementNDC compare_expected = *i_compare_expected; + ElementNDC data_expected = *i_data_expected; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare); + DataNDC::iterator i_data_result = data.erase(i_data); + + CHECK(compare_expected.first == i_compare_result->first); + CHECK(data_expected.first == i_data_result->first); + + CHECK(compare_expected.second == i_compare_result->second); + CHECK(data_expected.second == i_data_result->second); + + bool isEqual = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(isEqual); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) + { + Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); + DataNDC data(initial_data.begin(), initial_data.end()); + + Compare_DataNDC::iterator i_compare_begin = compare_data.begin(); + DataNDC::iterator i_data_begin = data.begin(); + + Compare_DataNDC::const_iterator i_compare = i_compare_begin; + DataNDC::const_iterator i_data = i_data_begin; + + Compare_DataNDC::iterator i_compare_expected = i_compare_begin; + DataNDC::iterator i_data_expected = i_data_begin; + + std::advance(i_compare, 2); + std::advance(i_data, 2); + + std::advance(i_compare_expected, 3); + std::advance(i_data_expected, 3); + + ElementNDC compare_expected = *i_compare_expected; + ElementNDC data_expected = *i_data_expected; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare); + DataNDC::iterator i_data_result = data.erase(i_data); + + CHECK(compare_expected.first == i_compare_result->first); + CHECK(data_expected.first == i_data_result->first); + + CHECK(compare_expected.second == i_compare_result->second); + CHECK(data_expected.second == i_data_result->second); + + bool isEqual = std::equal(data.begin(), + data.end(), + compare_data.begin()); CHECK(isEqual); } @@ -780,24 +838,33 @@ namespace Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end()); - Compare_DataNDC::iterator i_compare = compare_data.begin(); - DataNDC::iterator i_data = data.begin(); + Compare_DataNDC::const_iterator i_compare = compare_data.begin(); + DataNDC::const_iterator i_data = data.begin(); - Compare_DataNDC::iterator i_compare_end = compare_data.begin(); - DataNDC::iterator i_data_end = data.begin(); + Compare_DataNDC::const_iterator i_compare_end = compare_data.begin(); + DataNDC::const_iterator i_data_end = data.begin(); std::advance(i_compare, 2); - std::advance(i_data, 2); + std::advance(i_data, 2); std::advance(i_compare_end, 4); - std::advance(i_data_end, 4); + std::advance(i_data_end, 4); - compare_data.erase(i_compare, i_compare_end); - data.erase(i_data, i_data_end); + ElementNDC compare_expected = *i_compare_end; + ElementNDC data_expected = *i_data_end; - bool isEqual = Check_Equal(data.begin(), - data.end(), - compare_data.begin()); + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare, i_compare_end); + DataNDC::iterator i_data_result = data.erase(i_data, i_data_end); + + CHECK(compare_expected.first == i_compare_result->first); + CHECK(data_expected.first == i_data_result->first); + + CHECK(compare_expected.second == i_compare_result->second); + CHECK(data_expected.second == i_data_result->second); + + bool isEqual = std::equal(data.begin(), + data.end(), + compare_data.begin()); CHECK(isEqual); } @@ -1065,7 +1132,7 @@ namespace } //************************************************************************* -#if ETL_USING_INITIALIZER_LIST +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST(test_flat_multimap_template_deduction) { using Pair = ETL_OR_STD::pair; diff --git a/test/test_flat_multiset.cpp b/test/test_flat_multiset.cpp index 3a4a9712..5df0bb12 100644 --- a/test/test_flat_multiset.cpp +++ b/test/test_flat_multiset.cpp @@ -245,7 +245,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -715,23 +715,75 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end()); - Compare_DataNDC::iterator i_compare = compare_data.begin(); - DataNDC::iterator i_data = data.begin(); + Compare_DataNDC::iterator i_compare_begin = compare_data.begin(); + DataNDC::iterator i_data_begin = data.begin(); + + Compare_DataNDC::iterator i_compare = i_compare_begin; + DataNDC::iterator i_data = i_data_begin; + + Compare_DataNDC::iterator i_compare_expected = i_compare_begin; + DataNDC::iterator i_data_expected = i_data_begin; std::advance(i_compare, 2); - std::advance(i_data, 2); + std::advance(i_data, 2); - compare_data.erase(i_compare); - data.erase(i_data); + std::advance(i_compare_expected, 3); + std::advance(i_data_expected, 3); + + NDC compare_expected = *i_compare_expected; + NDC data_expected = *i_data_expected; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare); + DataNDC::iterator i_data_result = data.erase(i_data); + + CHECK(compare_expected == *i_compare_result); + CHECK(data_expected == *i_data_result); bool isEqual = std::equal(data.begin(), - data.end(), - compare_data.begin()); + data.end(), + compare_data.begin()); + + CHECK(isEqual); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) + { + Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); + DataNDC data(initial_data.begin(), initial_data.end()); + + Compare_DataNDC::iterator i_compare_begin = compare_data.begin(); + DataNDC::iterator i_data_begin = data.begin(); + + Compare_DataNDC::const_iterator i_compare = i_compare_begin; + DataNDC::const_iterator i_data = i_data_begin; + + Compare_DataNDC::iterator i_compare_expected = i_compare_begin; + DataNDC::iterator i_data_expected = i_data_begin; + + std::advance(i_compare, 2); + std::advance(i_data, 2); + + std::advance(i_compare_expected, 3); + std::advance(i_data_expected, 3); + + NDC compare_expected = *i_compare_expected; + NDC data_expected = *i_data_expected; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare); + DataNDC::iterator i_data_result = data.erase(i_data); + + CHECK(compare_expected == *i_compare_result); + CHECK(data_expected == *i_data_result); + + bool isEqual = std::equal(data.begin(), + data.end(), + compare_data.begin()); CHECK(isEqual); } @@ -742,20 +794,26 @@ namespace Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end()); - Compare_DataNDC::iterator i_compare = compare_data.begin(); - DataNDC::iterator i_data = data.begin(); + Compare_DataNDC::const_iterator i_compare = compare_data.begin(); + DataNDC::const_iterator i_data = data.begin(); - Compare_DataNDC::iterator i_compare_end = compare_data.begin(); - DataNDC::iterator i_data_end = data.begin(); + Compare_DataNDC::const_iterator i_compare_end = compare_data.begin(); + DataNDC::const_iterator i_data_end = data.begin(); std::advance(i_compare, 2); - std::advance(i_data, 2); + std::advance(i_data, 2); std::advance(i_compare_end, 4); - std::advance(i_data_end, 4); + std::advance(i_data_end, 4); - compare_data.erase(i_compare, i_compare_end); - data.erase(i_data, i_data_end); + NDC compare_expected = *i_compare_end; + NDC data_expected = *i_data_end; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare, i_compare_end); + DataNDC::iterator i_data_result = data.erase(i_data, i_data_end); + + CHECK(compare_expected == *i_compare_result); + CHECK(data_expected == *i_data_result); bool isEqual = std::equal(data.begin(), data.end(), @@ -1022,7 +1080,7 @@ namespace } //************************************************************************* -#if ETL_USING_INITIALIZER_LIST +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST(test_flat_set_template_deduction) { using Pair = ETL_OR_STD::pair; diff --git a/test/test_flat_set.cpp b/test/test_flat_set.cpp index cd436cee..a1f9096c 100644 --- a/test/test_flat_set.cpp +++ b/test/test_flat_set.cpp @@ -258,7 +258,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -696,19 +696,71 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end()); - Compare_DataNDC::iterator i_compare = compare_data.begin(); - DataNDC::iterator i_data = data.begin(); + Compare_DataNDC::iterator i_compare_begin = compare_data.begin(); + DataNDC::iterator i_data_begin = data.begin(); + + Compare_DataNDC::iterator i_compare = i_compare_begin; + DataNDC::iterator i_data = i_data_begin; + + Compare_DataNDC::iterator i_compare_expected = i_compare_begin; + DataNDC::iterator i_data_expected = i_data_begin; std::advance(i_compare, 2); - std::advance(i_data, 2); + std::advance(i_data, 2); - compare_data.erase(i_compare); - data.erase(i_data); + std::advance(i_compare_expected, 3); + std::advance(i_data_expected, 3); + + NDC compare_expected = *i_compare_expected; + NDC data_expected = *i_data_expected; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare); + DataNDC::iterator i_data_result = data.erase(i_data); + + CHECK(compare_expected == *i_compare_result); + CHECK(data_expected == *i_data_result); + + bool isEqual = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(isEqual); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) + { + Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); + DataNDC data(initial_data.begin(), initial_data.end()); + + Compare_DataNDC::iterator i_compare_begin = compare_data.begin(); + DataNDC::iterator i_data_begin = data.begin(); + + Compare_DataNDC::const_iterator i_compare = i_compare_begin; + DataNDC::const_iterator i_data = i_data_begin; + + Compare_DataNDC::iterator i_compare_expected = i_compare_begin; + DataNDC::iterator i_data_expected = i_data_begin; + + std::advance(i_compare, 2); + std::advance(i_data, 2); + + std::advance(i_compare_expected, 3); + std::advance(i_data_expected, 3); + + NDC compare_expected = *i_compare_expected; + NDC data_expected = *i_data_expected; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare); + DataNDC::iterator i_data_result = data.erase(i_data); + + CHECK(compare_expected == *i_compare_result); + CHECK(data_expected == *i_data_result); bool isEqual = std::equal(data.begin(), data.end(), @@ -723,20 +775,26 @@ namespace Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end()); - Compare_DataNDC::iterator i_compare = compare_data.begin(); - DataNDC::iterator i_data = data.begin(); + Compare_DataNDC::const_iterator i_compare = compare_data.begin(); + DataNDC::const_iterator i_data = data.begin(); - Compare_DataNDC::iterator i_compare_end = compare_data.begin(); - DataNDC::iterator i_data_end = data.begin(); + Compare_DataNDC::const_iterator i_compare_end = compare_data.begin(); + DataNDC::const_iterator i_data_end = data.begin(); std::advance(i_compare, 2); - std::advance(i_data, 2); + std::advance(i_data, 2); std::advance(i_compare_end, 4); - std::advance(i_data_end, 4); + std::advance(i_data_end, 4); - compare_data.erase(i_compare, i_compare_end); - data.erase(i_data, i_data_end); + NDC compare_expected = *i_compare_end; + NDC data_expected = *i_data_end; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare, i_compare_end); + DataNDC::iterator i_data_result = data.erase(i_data, i_data_end); + + CHECK(compare_expected == *i_compare_result); + CHECK(data_expected == *i_data_result); bool isEqual = std::equal(data.begin(), data.end(), @@ -953,7 +1011,7 @@ namespace } //************************************************************************* -#if ETL_USING_INITIALIZER_LIST +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST(test_flat_set_template_deduction) { using Pair = ETL_OR_STD::pair; diff --git a/test/test_forward_list.cpp b/test/test_forward_list.cpp index 17340ea0..b8287b58 100644 --- a/test/test_forward_list.cpp +++ b/test/test_forward_list.cpp @@ -94,7 +94,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -1351,7 +1351,19 @@ namespace } //************************************************************************* -#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST + TEST(test_two_parameter_same_type_non_iterator) + { + // No compile error. + etl::forward_list fl(10, 1); + CHECK(fl.size() == 10); + fl.assign(5, 2); + CHECK(fl.size() == 5); + fl.insert_after(fl.before_begin(), 5, 3); + CHECK(fl.size() == fl.max_size()); + } + + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST(test_forward_list_template_deduction) { etl::forward_list data{ ItemNDC("A"), ItemNDC("B"), ItemNDC("C"), ItemNDC("D"), ItemNDC("E"), ItemNDC("F") }; diff --git a/test/test_indirect_vector.cpp b/test/test_indirect_vector.cpp index f994c82a..0c498527 100644 --- a/test/test_indirect_vector.cpp +++ b/test/test_indirect_vector.cpp @@ -136,7 +136,7 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -1105,15 +1105,15 @@ namespace CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end()); - compare_data.erase(compare_data.begin() + 2); + compare_data.erase(compare_data.cbegin() + 2); - data.erase(data.begin() + 2); + data.erase(data.cbegin() + 2); CHECK_EQUAL(compare_data.size(), data.size()); - bool is_equal = std::equal(data.begin(), - data.end(), - compare_data.begin()); + bool is_equal = std::equal(data.cbegin(), + data.cend(), + compare_data.cbegin()); CHECK(is_equal); } @@ -1124,15 +1124,15 @@ namespace CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end()); - compare_data.erase(compare_data.begin() + 2, compare_data.begin() + 4); + compare_data.erase(compare_data.cbegin() + 2, compare_data.cbegin() + 4); - data.erase(data.begin() + 2, data.begin() + 4); + data.erase(data.cbegin() + 2, data.cbegin() + 4); CHECK_EQUAL(compare_data.size(), data.size()); - bool is_equal = std::equal(data.begin(), - data.end(), - compare_data.begin()); + bool is_equal = std::equal(data.cbegin(), + data.cend(), + compare_data.cbegin()); CHECK(is_equal); } diff --git a/test/test_indirect_vector_external_buffer.cpp b/test/test_indirect_vector_external_buffer.cpp index a999bb10..e6ac0795 100644 --- a/test/test_indirect_vector_external_buffer.cpp +++ b/test/test_indirect_vector_external_buffer.cpp @@ -1189,15 +1189,15 @@ namespace CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end(), lookup, pool); - compare_data.erase(compare_data.begin() + 2); + compare_data.erase(compare_data.cbegin() + 2); - data.erase(data.begin() + 2); + data.erase(data.cbegin() + 2); CHECK_EQUAL(compare_data.size(), data.size()); - bool is_equal = std::equal(data.begin(), - data.end(), - compare_data.begin()); + bool is_equal = std::equal(data.cbegin(), + data.cend(), + compare_data.cbegin()); CHECK(is_equal); } @@ -1211,15 +1211,15 @@ namespace CompareDataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end(), lookup, pool); - compare_data.erase(compare_data.begin() + 2, compare_data.begin() + 4); + compare_data.erase(compare_data.cbegin() + 2, compare_data.cbegin() + 4); - data.erase(data.begin() + 2, data.begin() + 4); + data.erase(data.cbegin() + 2, data.cbegin() + 4); CHECK_EQUAL(compare_data.size(), data.size()); - bool is_equal = std::equal(data.begin(), - data.end(), - compare_data.begin()); + bool is_equal = std::equal(data.cbegin(), + data.cend(), + compare_data.cbegin()); CHECK(is_equal); } diff --git a/test/test_list.cpp b/test/test_list.cpp index d9e618eb..d7ad7b25 100644 --- a/test/test_list.cpp +++ b/test/test_list.cpp @@ -105,7 +105,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -919,7 +919,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { CompareData compare_data(sorted_data.begin(), sorted_data.end()); DataNDC data(sorted_data.begin(), sorted_data.end()); @@ -970,27 +970,81 @@ namespace CHECK(are_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) + { + CompareData compare_data(sorted_data.begin(), sorted_data.end()); + DataNDC data(sorted_data.begin(), sorted_data.end()); + + DataNDC::const_iterator i_data = data.begin(); + std::advance(i_data, 2); + + CompareData::const_iterator i_compare_data = compare_data.cbegin(); + std::advance(i_compare_data, 2); + + i_compare_data = compare_data.erase(i_compare_data); + i_data = data.erase(i_data); + + CHECK_EQUAL(compare_data.size(), data.size()); + + are_equal = std::equal(data.cbegin(), data.cend(), compare_data.cbegin()); + + CHECK(are_equal); + CHECK(*i_compare_data == *i_data); + + i_compare_data = compare_data.erase(compare_data.cbegin()); + i_data = data.erase(data.cbegin()); + + CHECK_EQUAL(compare_data.size(), data.size()); + + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(are_equal); + + are_equal = i_data == data.begin(); + CHECK(are_equal); + + // Move to the last value and erase. + i_compare_data = compare_data.begin(); + std::advance(i_compare_data, compare_data.size() - 1); + i_compare_data = compare_data.erase(i_compare_data); + + i_data = data.begin(); + std::advance(i_data, data.size() - 1); + i_data = data.erase(i_data); + + CHECK_EQUAL(compare_data.size(), data.size()); + + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(are_equal); + are_equal = i_data == data.end(); + CHECK(are_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { CompareData compare_data(sorted_data.begin(), sorted_data.end()); DataNDC data(sorted_data.begin(), sorted_data.end()); - DataNDC::iterator i_data_1 = data.begin(); + DataNDC::const_iterator i_data_1 = data.cbegin(); std::advance(i_data_1, 2); - DataNDC::iterator i_data_2 = data.begin(); + DataNDC::const_iterator i_data_2 = data.cbegin(); std::advance(i_data_2, 4); - CompareData::iterator i_compare_data_1 = compare_data.begin(); + CompareData::const_iterator i_compare_data_1 = compare_data.begin(); std::advance(i_compare_data_1, 2); - CompareData::iterator i_compare_data_2 = compare_data.begin(); + CompareData::const_iterator i_compare_data_2 = compare_data.begin(); std::advance(i_compare_data_2, 4); - compare_data.erase(i_compare_data_1, i_compare_data_2); + CompareData::iterator citr = compare_data.erase(i_compare_data_1, i_compare_data_2); + CHECK(citr == i_compare_data_2); - data.erase(i_data_1, i_data_2); + DataNDC::iterator ditr = data.erase(i_data_1, i_data_2); + CHECK(ditr == i_data_2); CHECK_EQUAL(compare_data.size(), data.size()); @@ -1003,8 +1057,8 @@ namespace { DataNDC data(sorted_data.begin(), sorted_data.end()); - data.erase(data.begin(), data.end()); - + DataNDC::iterator itr = data.erase(data.cbegin(), data.cend()); + CHECK(itr == data.cbegin()); CHECK(data.empty()); // Check that it is still in a valid state. @@ -2029,7 +2083,18 @@ namespace } //************************************************************************* -#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST + TEST(test_same_type_non_iterator) + { + etl::list l(10, 1); + CHECK(l.size() == 10); + l.assign(5, 2); + CHECK(l.size() == 5); + l.insert(l.begin(), 5, 3); + CHECK(l.size() == l.max_size()); + } + + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST(test_forward_list_template_deduction) { etl::list data{ ItemNDC("A"), ItemNDC("B"), ItemNDC("C"), ItemNDC("D"), ItemNDC("E"), ItemNDC("F") }; diff --git a/test/test_list_shared_pool.cpp b/test/test_list_shared_pool.cpp index 35598e27..edd7cbf8 100644 --- a/test/test_list_shared_pool.cpp +++ b/test/test_list_shared_pool.cpp @@ -590,9 +590,9 @@ namespace DataNDC data1(pool); DataNDC data2(pool); - data1.assign(SIZE / 2UL, VALUE); + data1.assign(SIZE, VALUE); - CHECK_THROW(data2.assign((SIZE / 2) + 1, VALUE), etl::list_full); + CHECK_THROW(data2.assign(SIZE + 1, VALUE), etl::list_full); } //************************************************************************* @@ -1126,7 +1126,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { Pool pool; CompareData compare_data(sorted_data.begin(), sorted_data.end()); @@ -1178,6 +1178,59 @@ namespace CHECK(are_equal); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) + { + Pool pool; + CompareData compare_data(sorted_data.begin(), sorted_data.end()); + DataNDC data(sorted_data.begin(), sorted_data.end(), pool); + + DataNDC::iterator i_data = data.begin(); + std::advance(i_data, 2); + + CompareData::iterator i_compare_data = compare_data.begin(); + std::advance(i_compare_data, 2); + + i_compare_data = compare_data.erase(i_compare_data); + i_data = data.erase(i_data); + + CHECK_EQUAL(compare_data.size(), data.size()); + + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(are_equal); + CHECK(*i_compare_data == *i_data); + + i_compare_data = compare_data.erase(compare_data.begin()); + i_data = data.erase(data.begin()); + + CHECK_EQUAL(compare_data.size(), data.size()); + + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(are_equal); + + are_equal = i_data == data.begin(); + CHECK(are_equal); + + // Move to the last value and erase. + i_compare_data = compare_data.begin(); + std::advance(i_compare_data, compare_data.size() - 1); + i_compare_data = compare_data.erase(i_compare_data); + + i_data = data.begin(); + std::advance(i_data, data.size() - 1); + i_data = data.erase(i_data); + + CHECK_EQUAL(compare_data.size(), data.size()); + + are_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(are_equal); + are_equal = i_data == data.end(); + CHECK(are_equal); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { @@ -1185,21 +1238,23 @@ namespace CompareData compare_data(sorted_data.begin(), sorted_data.end()); DataNDC data(sorted_data.begin(), sorted_data.end(), pool); - DataNDC::iterator i_data_1 = data.begin(); + DataNDC::const_iterator i_data_1 = data.cbegin(); std::advance(i_data_1, 2); - DataNDC::iterator i_data_2 = data.begin(); + DataNDC::const_iterator i_data_2 = data.cbegin(); std::advance(i_data_2, 4); - CompareData::iterator i_compare_data_1 = compare_data.begin(); + CompareData::const_iterator i_compare_data_1 = compare_data.cbegin(); std::advance(i_compare_data_1, 2); - CompareData::iterator i_compare_data_2 = compare_data.begin(); + CompareData::const_iterator i_compare_data_2 = compare_data.cbegin(); std::advance(i_compare_data_2, 4); - compare_data.erase(i_compare_data_1, i_compare_data_2); + CompareData::iterator citr = compare_data.erase(i_compare_data_1, i_compare_data_2); + CHECK(citr == i_compare_data_2); - data.erase(i_data_1, i_data_2); + DataNDC::iterator ditr = data.erase(i_data_1, i_data_2); + CHECK(ditr == i_data_2); CHECK_EQUAL(compare_data.size(), data.size()); @@ -1214,8 +1269,8 @@ namespace DataNDC data1(half_data.begin(), half_data.end(), pool); DataNDC data2(half_data.begin(), half_data.end(), pool); - data1.erase(data1.begin(), data1.end()); - + DataNDC::iterator itr = data1.erase(data1.cbegin(), data1.cend()); + CHECK(itr == data1.cbegin()); CHECK(data1.empty()); CHECK(!data2.empty()); diff --git a/test/test_map.cpp b/test/test_map.cpp index 8530dfab..981e42a1 100644 --- a/test/test_map.cpp +++ b/test/test_map.cpp @@ -193,7 +193,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -830,8 +830,10 @@ namespace std::advance(i_compare, 2); std::advance(i_data, 2); - compare_data.erase(i_compare); - data.erase(i_data); + Compare_Data::iterator i_compare1 = compare_data.erase(i_compare); + Data::iterator i_data1 = data.erase(i_data); + + CHECK(i_compare1->second == i_data1->second); bool isEqual = Check_Equal(data.begin(), data.end(), @@ -1281,7 +1283,7 @@ namespace } //************************************************************************* -#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST(test_map_template_deduction) { using Pair = std::pair; diff --git a/test/test_multimap.cpp b/test/test_multimap.cpp index a09720f4..84eaf299 100644 --- a/test/test_multimap.cpp +++ b/test/test_multimap.cpp @@ -195,7 +195,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -699,8 +699,10 @@ namespace Compare_Data::iterator i_compare = compare_data.begin(); Data::iterator i_data = data.begin(); - compare_data.erase(i_compare); - data.erase(i_data); + Compare_Data::iterator i_compare1 = compare_data.erase(i_compare); + Data::iterator i_data1 = data.erase(i_data); + + CHECK(i_compare1->second == i_data1->second); bool isEqual = Check_Equal(data.begin(), data.end(), @@ -1246,7 +1248,7 @@ namespace } //************************************************************************* -#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST(test_multimap_template_deduction) { using Pair = std::pair; diff --git a/test/test_multiset.cpp b/test/test_multiset.cpp index d0d7efb6..32c72b76 100644 --- a/test/test_multiset.cpp +++ b/test/test_multiset.cpp @@ -210,7 +210,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -713,8 +713,10 @@ namespace Compare_Data::iterator i_compare = compare_data.begin(); Data::iterator i_data = data.begin(); - compare_data.erase(i_compare); - data.erase(i_data); + Compare_Data::iterator i_compare1 = compare_data.erase(i_compare); + Data::iterator i_data1 = data.erase(i_data); + + CHECK_EQUAL(*i_compare1, *i_data1); bool isEqual = Check_Equal(data.begin(), data.end(), @@ -1252,7 +1254,7 @@ namespace } //************************************************************************* -#if ETL_USING_INITIALIZER_LIST +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST(test_multiset_template_deduction) { etl::multiset data{ std::string("A"), std::string("B"), std::string("C"), std::string("D"), std::string("E"), std::string("F") }; diff --git a/test/test_reference_flat_map.cpp b/test/test_reference_flat_map.cpp index be76bf43..58d5dfa3 100644 --- a/test/test_reference_flat_map.cpp +++ b/test/test_reference_flat_map.cpp @@ -534,19 +534,71 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end()); - Compare_DataNDC::iterator i_compare = compare_data.begin(); - DataNDC::iterator i_data = data.begin(); + Compare_DataNDC::iterator i_compare_begin = compare_data.begin(); + DataNDC::iterator i_data_begin = data.begin(); + + Compare_DataNDC::iterator i_compare = i_compare_begin; + DataNDC::iterator i_data = i_data_begin; + + Compare_DataNDC::iterator i_compare_expected = i_compare_begin; + DataNDC::iterator i_data_expected = i_data_begin; + + std::advance(i_compare, 2); + std::advance(i_data, 2); + + std::advance(i_compare_expected, 3); + std::advance(i_data_expected, 3); + + ElementNDC compare_expected = *i_compare_expected; + ElementNDC data_expected = *i_data_expected; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare); + DataNDC::iterator i_data_result = data.erase(i_data); + + CHECK(compare_expected == *i_compare_result); + CHECK(data_expected == *i_data_result); + + bool isEqual = Check_Equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(isEqual); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) + { + Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); + DataNDC data(initial_data.begin(), initial_data.end()); + + Compare_DataNDC::iterator i_compare_begin = compare_data.begin(); + DataNDC::iterator i_data_begin = data.begin(); + + Compare_DataNDC::const_iterator i_compare = i_compare_begin; + DataNDC::const_iterator i_data = i_data_begin; + + Compare_DataNDC::iterator i_compare_expected = i_compare_begin; + DataNDC::iterator i_data_expected = i_data_begin; std::advance(i_compare, 2); std::advance(i_data, 2); + + std::advance(i_compare_expected, 3); + std::advance(i_data_expected, 3); - compare_data.erase(i_compare); - data.erase(i_data); + ElementNDC compare_expected = *i_compare_expected; + ElementNDC data_expected = *i_data_expected; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare); + DataNDC::iterator i_data_result = data.erase(i_data); + + CHECK(compare_expected == *i_compare_result); + CHECK(data_expected == *i_data_result); bool isEqual = Check_Equal(data.begin(), data.end(), @@ -561,11 +613,11 @@ namespace Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end()); - Compare_DataNDC::iterator i_compare = compare_data.begin(); - DataNDC::iterator i_data = data.begin(); + Compare_DataNDC::const_iterator i_compare = compare_data.begin(); + DataNDC::const_iterator i_data = data.begin(); - Compare_DataNDC::iterator i_compare_end = compare_data.begin(); - DataNDC::iterator i_data_end = data.begin(); + Compare_DataNDC::const_iterator i_compare_end = compare_data.begin(); + DataNDC::const_iterator i_data_end = data.begin(); std::advance(i_compare, 2); std::advance(i_data, 2); @@ -573,8 +625,14 @@ namespace std::advance(i_compare_end, 4); std::advance(i_data_end, 4); - compare_data.erase(i_compare, i_compare_end); - data.erase(i_data, i_data_end); + ElementNDC compare_expected = *i_compare_end; + ElementNDC data_expected = *i_data_end; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare, i_compare_end); + DataNDC::iterator i_data_result = data.erase(i_data, i_data_end); + + CHECK(compare_expected == *i_compare_result); + CHECK(data_expected == *i_data_result); bool isEqual = Check_Equal(data.begin(), data.end(), diff --git a/test/test_reference_flat_multimap.cpp b/test/test_reference_flat_multimap.cpp index abe2c8d4..6ece0eab 100644 --- a/test/test_reference_flat_multimap.cpp +++ b/test/test_reference_flat_multimap.cpp @@ -360,19 +360,71 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end()); - Compare_DataNDC::iterator i_compare = compare_data.begin(); - DataNDC::iterator i_data = data.begin(); + Compare_DataNDC::iterator i_compare_begin = compare_data.begin(); + DataNDC::iterator i_data_begin = data.begin(); + + Compare_DataNDC::iterator i_compare = i_compare_begin; + DataNDC::iterator i_data = i_data_begin; + + Compare_DataNDC::iterator i_compare_expected = i_compare_begin; + DataNDC::iterator i_data_expected = i_data_begin; std::advance(i_compare, 2); - std::advance(i_data, 2); + std::advance(i_data, 2); - compare_data.erase(i_compare); - data.erase(i_data); + std::advance(i_compare_expected, 3); + std::advance(i_data_expected, 3); + + ElementNDC compare_expected = *i_compare_expected; + ElementNDC data_expected = *i_data_expected; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare); + DataNDC::iterator i_data_result = data.erase(i_data); + + CHECK(compare_expected == *i_compare_result); + CHECK(data_expected == *i_data_result); + + bool isEqual = Check_Equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(isEqual); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) + { + Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); + DataNDC data(initial_data.begin(), initial_data.end()); + + Compare_DataNDC::iterator i_compare_begin = compare_data.begin(); + DataNDC::iterator i_data_begin = data.begin(); + + Compare_DataNDC::const_iterator i_compare = i_compare_begin; + DataNDC::const_iterator i_data = i_data_begin; + + Compare_DataNDC::iterator i_compare_expected = i_compare_begin; + DataNDC::iterator i_data_expected = i_data_begin; + + std::advance(i_compare, 2); + std::advance(i_data, 2); + + std::advance(i_compare_expected, 3); + std::advance(i_data_expected, 3); + + ElementNDC compare_expected = *i_compare_expected; + ElementNDC data_expected = *i_data_expected; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare); + DataNDC::iterator i_data_result = data.erase(i_data); + + CHECK(compare_expected == *i_compare_result); + CHECK(data_expected == *i_data_result); bool isEqual = Check_Equal(data.begin(), data.end(), @@ -387,24 +439,30 @@ namespace Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end()); - Compare_DataNDC::iterator i_compare = compare_data.begin(); - DataNDC::iterator i_data = data.begin(); + Compare_DataNDC::const_iterator i_compare = compare_data.begin(); + DataNDC::const_iterator i_data = data.begin(); - Compare_DataNDC::iterator i_compare_end = compare_data.begin(); - DataNDC::iterator i_data_end = data.begin(); + Compare_DataNDC::const_iterator i_compare_end = compare_data.begin(); + DataNDC::const_iterator i_data_end = data.begin(); std::advance(i_compare, 2); - std::advance(i_data, 2); + std::advance(i_data, 2); std::advance(i_compare_end, 4); - std::advance(i_data_end, 4); + std::advance(i_data_end, 4); - compare_data.erase(i_compare, i_compare_end); - data.erase(i_data, i_data_end); + ElementNDC compare_expected = *i_compare_end; + ElementNDC data_expected = *i_data_end; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare, i_compare_end); + DataNDC::iterator i_data_result = data.erase(i_data, i_data_end); + + CHECK(compare_expected == *i_compare_result); + CHECK(data_expected == *i_data_result); bool isEqual = Check_Equal(data.begin(), - data.end(), - compare_data.begin()); + data.end(), + compare_data.begin()); CHECK(isEqual); } diff --git a/test/test_reference_flat_multiset.cpp b/test/test_reference_flat_multiset.cpp index ad881d68..4362fe6a 100644 --- a/test/test_reference_flat_multiset.cpp +++ b/test/test_reference_flat_multiset.cpp @@ -338,23 +338,75 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end()); - Compare_DataNDC::iterator i_compare = compare_data.begin(); - DataNDC::iterator i_data = data.begin(); + Compare_DataNDC::iterator i_compare_begin = compare_data.begin(); + DataNDC::iterator i_data_begin = data.begin(); + + Compare_DataNDC::iterator i_compare = i_compare_begin; + DataNDC::iterator i_data = i_data_begin; + + Compare_DataNDC::iterator i_compare_expected = i_compare_begin; + DataNDC::iterator i_data_expected = i_data_begin; std::advance(i_compare, 2); - std::advance(i_data, 2); + std::advance(i_data, 2); - compare_data.erase(i_compare); - data.erase(i_data); + std::advance(i_compare_expected, 3); + std::advance(i_data_expected, 3); + + NDC compare_expected = *i_compare_expected; + NDC data_expected = *i_data_expected; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare); + DataNDC::iterator i_data_result = data.erase(i_data); + + CHECK(compare_expected == *i_compare_result); + CHECK(data_expected == *i_data_result); bool isEqual = std::equal(data.begin(), - data.end(), - compare_data.begin()); + data.end(), + compare_data.begin()); + + CHECK(isEqual); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) + { + Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); + DataNDC data(initial_data.begin(), initial_data.end()); + + Compare_DataNDC::iterator i_compare_begin = compare_data.begin(); + DataNDC::iterator i_data_begin = data.begin(); + + Compare_DataNDC::const_iterator i_compare = i_compare_begin; + DataNDC::const_iterator i_data = i_data_begin; + + Compare_DataNDC::iterator i_compare_expected = i_compare_begin; + DataNDC::iterator i_data_expected = i_data_begin; + + std::advance(i_compare, 2); + std::advance(i_data, 2); + + std::advance(i_compare_expected, 3); + std::advance(i_data_expected, 3); + + NDC compare_expected = *i_compare_expected; + NDC data_expected = *i_data_expected; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare); + DataNDC::iterator i_data_result = data.erase(i_data); + + CHECK(compare_expected == *i_compare_result); + CHECK(data_expected == *i_data_result); + + bool isEqual = std::equal(data.begin(), + data.end(), + compare_data.begin()); CHECK(isEqual); } @@ -365,24 +417,30 @@ namespace Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end()); - Compare_DataNDC::iterator i_compare = compare_data.begin(); - DataNDC::iterator i_data = data.begin(); + Compare_DataNDC::const_iterator i_compare = compare_data.begin(); + DataNDC::const_iterator i_data = data.begin(); - Compare_DataNDC::iterator i_compare_end = compare_data.begin(); - DataNDC::iterator i_data_end = data.begin(); + Compare_DataNDC::const_iterator i_compare_end = compare_data.begin(); + DataNDC::const_iterator i_data_end = data.begin(); std::advance(i_compare, 2); - std::advance(i_data, 2); + std::advance(i_data, 2); std::advance(i_compare_end, 4); - std::advance(i_data_end, 4); + std::advance(i_data_end, 4); - compare_data.erase(i_compare, i_compare_end); - data.erase(i_data, i_data_end); + NDC compare_expected = *i_compare_end; + NDC data_expected = *i_data_end; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare, i_compare_end); + DataNDC::iterator i_data_result = data.erase(i_data, i_data_end); + + CHECK(compare_expected == *i_compare_result); + CHECK(data_expected == *i_data_result); bool isEqual = std::equal(data.begin(), - data.end(), - compare_data.begin()); + data.end(), + compare_data.begin()); CHECK(isEqual); } diff --git a/test/test_reference_flat_set.cpp b/test/test_reference_flat_set.cpp index 6f5ed491..2eb75bb1 100644 --- a/test/test_reference_flat_set.cpp +++ b/test/test_reference_flat_set.cpp @@ -362,19 +362,71 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end()); - Compare_DataNDC::iterator i_compare = compare_data.begin(); - DataNDC::iterator i_data = data.begin(); + Compare_DataNDC::iterator i_compare_begin = compare_data.begin(); + DataNDC::iterator i_data_begin = data.begin(); + + Compare_DataNDC::iterator i_compare = i_compare_begin; + DataNDC::iterator i_data = i_data_begin; + + Compare_DataNDC::iterator i_compare_expected = i_compare_begin; + DataNDC::iterator i_data_expected = i_data_begin; std::advance(i_compare, 2); - std::advance(i_data, 2); + std::advance(i_data, 2); - compare_data.erase(i_compare); - data.erase(i_data); + std::advance(i_compare_expected, 3); + std::advance(i_data_expected, 3); + + NDC compare_expected = *i_compare_expected; + NDC data_expected = *i_data_expected; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare); + DataNDC::iterator i_data_result = data.erase(i_data); + + CHECK(compare_expected == *i_compare_result); + CHECK(data_expected == *i_data_result); + + bool isEqual = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(isEqual); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) + { + Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); + DataNDC data(initial_data.begin(), initial_data.end()); + + Compare_DataNDC::iterator i_compare_begin = compare_data.begin(); + DataNDC::iterator i_data_begin = data.begin(); + + Compare_DataNDC::const_iterator i_compare = i_compare_begin; + DataNDC::const_iterator i_data = i_data_begin; + + Compare_DataNDC::iterator i_compare_expected = i_compare_begin; + DataNDC::iterator i_data_expected = i_data_begin; + + std::advance(i_compare, 2); + std::advance(i_data, 2); + + std::advance(i_compare_expected, 3); + std::advance(i_data_expected, 3); + + NDC compare_expected = *i_compare_expected; + NDC data_expected = *i_data_expected; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare); + DataNDC::iterator i_data_result = data.erase(i_data); + + CHECK(compare_expected == *i_compare_result); + CHECK(data_expected == *i_data_result); bool isEqual = std::equal(data.begin(), data.end(), @@ -389,20 +441,26 @@ namespace Compare_DataNDC compare_data(initial_data.begin(), initial_data.end()); DataNDC data(initial_data.begin(), initial_data.end()); - Compare_DataNDC::iterator i_compare = compare_data.begin(); - DataNDC::iterator i_data = data.begin(); + Compare_DataNDC::const_iterator i_compare = compare_data.begin(); + DataNDC::const_iterator i_data = data.begin(); - Compare_DataNDC::iterator i_compare_end = compare_data.begin(); - DataNDC::iterator i_data_end = data.begin(); + Compare_DataNDC::const_iterator i_compare_end = compare_data.begin(); + DataNDC::const_iterator i_data_end = data.begin(); std::advance(i_compare, 2); - std::advance(i_data, 2); + std::advance(i_data, 2); std::advance(i_compare_end, 4); - std::advance(i_data_end, 4); + std::advance(i_data_end, 4); - compare_data.erase(i_compare, i_compare_end); - data.erase(i_data, i_data_end); + NDC compare_expected = *i_compare_end; + NDC data_expected = *i_data_end; + + Compare_DataNDC::iterator i_compare_result = compare_data.erase(i_compare, i_compare_end); + DataNDC::iterator i_data_result = data.erase(i_data, i_data_end); + + CHECK(compare_expected == *i_compare_result); + CHECK(data_expected == *i_data_result); bool isEqual = std::equal(data.begin(), data.end(), diff --git a/test/test_set.cpp b/test/test_set.cpp index bd603d13..52f91050 100644 --- a/test/test_set.cpp +++ b/test/test_set.cpp @@ -226,7 +226,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -754,8 +754,10 @@ namespace std::advance(i_compare, 2); std::advance(i_data, 2); - compare_data.erase(i_compare); - data.erase(i_data); + Compare_Data::iterator i_compare1 = compare_data.erase(i_compare); + Data::iterator i_data1 = data.erase(i_data); + + CHECK_EQUAL(*i_compare1, *i_data1); bool isEqual = Check_Equal(data.begin(), data.end(), @@ -1199,7 +1201,7 @@ namespace } //************************************************************************* -#if ETL_USING_INITIALIZER_LIST +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST(test_set_template_deduction) { etl::set data{ std::string("A"), std::string("B"), std::string("C"), std::string("D"), std::string("E"), std::string("F") }; diff --git a/test/test_span.cpp b/test/test_span.cpp index a94b077d..286b9fc8 100644 --- a/test/test_span.cpp +++ b/test/test_span.cpp @@ -260,7 +260,7 @@ namespace CHECK(isEqual); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 6c5d3149..bc4eecdd 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -1251,9 +1251,9 @@ namespace const value_t INITIAL_VALUE = STR('A'); size_t offset = 2UL; - text.insert(text.begin() + offset, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, INITIAL_VALUE); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, INITIAL_VALUE); + compare_text.insert(compare_text.cbegin() + offset, INITIAL_VALUE); + compare_text.erase(compare_text.cend() - 1); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1263,9 +1263,9 @@ namespace CHECK(is_equal); offset = 0; - text.insert(text.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, STR('A')); + compare_text.insert(compare_text.cbegin() + offset, STR('A')); + compare_text.erase(compare_text.cend() - 1); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1275,9 +1275,9 @@ namespace CHECK(is_equal); offset = text.size(); - text.insert(text.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, STR('A')); + compare_text.insert(compare_text.cbegin() + offset, STR('A')); + compare_text.erase(compare_text.cend() - 1); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1323,11 +1323,11 @@ namespace const value_t INSERT_VALUE = STR('A'); size_t offset = 0UL; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1337,12 +1337,12 @@ namespace CHECK(is_equal); offset = 2; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1352,12 +1352,12 @@ namespace CHECK(is_equal); offset = 4; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1367,12 +1367,12 @@ namespace CHECK(is_equal); offset = text.size(); - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1392,10 +1392,10 @@ namespace Compare_Text compare_text; Text text; - text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); - compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); - text.insert(text.begin() + offset, insert_text.begin(), insert_text.end()); - compare_text.insert(compare_text.begin() + offset, insert_text.begin(), insert_text.end()); + text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); + compare_text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); + text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(!text.is_truncated()); @@ -1419,9 +1419,9 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1434,9 +1434,9 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1450,9 +1450,9 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1473,8 +1473,8 @@ namespace Compare_Text compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); - compare_text.insert(compare_text.begin() + offset, compare_text.begin() + 5, compare_text.begin() + 10); + text.insert(text.cbegin() + offset, text.cbegin() + 5, text.cbegin() + 10); + compare_text.insert(compare_text.cbegin() + offset, compare_text.cbegin() + 5, compare_text.cbegin() + 10); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1489,9 +1489,9 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - Compare_Text compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + Compare_Text compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + Text insert(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1510,9 +1510,9 @@ namespace { for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - Compare_Text compare_text(initial_text.begin(), initial_text.end()); - Text text(initial_text.begin(), initial_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + Compare_Text compare_text(initial_text.cbegin(), initial_text.cend()); + Text text(initial_text.cbegin(), initial_text.cend()); + Text insert(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1531,11 +1531,11 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - Compare_Text compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(longer_text.begin(), longer_text.end()); - insert.erase(insert.begin(), insert.end()); - insert.append(insert_text.begin(), insert_text.end()); + Compare_Text compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + Text insert(longer_text.cbegin(), longer_text.cend()); + insert.erase(insert.cbegin(), insert.cend()); + insert.append(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1552,9 +1552,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - Compare_Text compare_text(short_text.begin(), short_text.end()); - Text text(short_text.begin(), short_text.end()); - Text insert(insert_text.begin(), insert_text.end()); + Compare_Text compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + Text insert(insert_text.cbegin(), insert_text.cend()); text.insert(0, insert, 0, insert.size()); compare_text.insert(0, insert_text, 0, insert_text.size()); @@ -1566,8 +1566,8 @@ namespace CHECK(!text.is_truncated()); #endif - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + compare_text.assign(short_text.cbegin(), short_text.cend()); + text.assign(short_text.cbegin(), short_text.cend()); text.insert(2, insert, 2, insert.size() - 2); compare_text.insert(2, insert_text, 2, insert_text.size() - 2); @@ -1581,8 +1581,8 @@ namespace CHECK(!text.is_truncated()); #endif - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + compare_text.assign(short_text.cbegin(), short_text.cend()); + text.assign(short_text.cbegin(), short_text.cend()); text.insert(short_text.size(), insert, 0, insert.size()); compare_text.insert(short_text.size(), insert_text, 0, insert_text.size()); @@ -2704,13 +2704,31 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - compare_text.erase(compare_text.begin() + 2); - text.erase(text.begin() + 2); + Compare_Text::iterator citr = compare_text.erase(compare_text.begin() + 2); + Text::iterator ditr = text.erase(text.begin() + 2); + CHECK(*citr == *ditr); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + CHECK(!text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) + { + Compare_Text compare_text(initial_text.c_str()); + Text text(initial_text.c_str()); + + Compare_Text::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + Text::iterator ditr = text.erase(text.cbegin() + 2); + CHECK(*citr == *ditr); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2725,9 +2743,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); - - text.erase(text.begin() + 2, text.begin() + 4); + Compare_Text::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); + CHECK(*citr == *ditr); bool is_equal = Equal(compare_text, text); CHECK(is_equal); diff --git a/test/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index 9fb14110..1ca2b6f3 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -1443,16 +1443,15 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { Compare_Text compare_text(initial_text.begin(), initial_text.end()); - TextBuffer buffer; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); const value_t INITIAL_VALUE = STR('A'); - size_t offset = 2; - text.insert(text.begin() + offset, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, INITIAL_VALUE); - compare_text.erase(compare_text.end() - 1); + size_t offset = 2UL; + text.insert(text.cbegin() + offset, INITIAL_VALUE); + compare_text.insert(compare_text.cbegin() + offset, INITIAL_VALUE); + compare_text.erase(compare_text.cend() - 1); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1462,9 +1461,9 @@ namespace CHECK(is_equal); offset = 0; - text.insert(text.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, STR('A')); + compare_text.insert(compare_text.cbegin() + offset, STR('A')); + compare_text.erase(compare_text.cend() - 1); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1474,9 +1473,9 @@ namespace CHECK(is_equal); offset = text.size(); - text.insert(text.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, STR('A')); + compare_text.insert(compare_text.cbegin() + offset, STR('A')); + compare_text.erase(compare_text.cend() - 1); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1490,15 +1489,14 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { Compare_Text compare_text; - TextBuffer buffer; Text text(buffer.data(), buffer.size()); - const size_t INITIAL_SIZE = 5; - const size_t INSERT_SIZE = 3; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; + const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1518,19 +1516,18 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { Compare_Text compare_text; - TextBuffer buffer; Text text(buffer.data(), buffer.size()); - const size_t INSERT_SIZE = 4; - const value_t INSERT_VALUE = STR('A'); + const size_t INSERT_SIZE = 4UL; + const value_t INSERT_VALUE = STR('A'); - size_t offset = 0; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + size_t offset = 0UL; + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1540,12 +1537,12 @@ namespace CHECK(is_equal); offset = 2; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1555,12 +1552,12 @@ namespace CHECK(is_equal); offset = 4; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1570,12 +1567,12 @@ namespace CHECK(is_equal); offset = text.size(); - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1588,19 +1585,18 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { Compare_Text compare_text; - TextBuffer buffer; Text text(buffer.data(), buffer.size()); - text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); - compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); - text.insert(text.begin() + offset, insert_text.begin(), insert_text.end()); - compare_text.insert(compare_text.begin() + offset, insert_text.begin(), insert_text.end()); + text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); + compare_text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); + text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(!text.is_truncated()); @@ -1614,21 +1610,20 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { - const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const size_t INITIAL_SIZE = 5UL; + const value_t INITIAL_VALUE = STR('A'); Compare_Text compare_text; - TextBuffer buffer; Text text(buffer.data(), buffer.size()); - size_t offset = 0; + size_t offset = 0UL; compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1641,9 +1636,9 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1652,13 +1647,14 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + offset = 4; compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1674,15 +1670,15 @@ namespace { size_t length = SIZE_L / 2; - for (size_t offset = 10; offset < length; ++offset) + for (size_t offset = 10UL; offset < length; ++offset) { Compare_Text compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); - compare_text.insert(compare_text.begin() + offset, compare_text.begin() + 5, compare_text.begin() + 10); + text.insert(text.cbegin() + offset, text.cbegin() + 5, text.cbegin() + 10); + compare_text.insert(compare_text.cbegin() + offset, compare_text.cbegin() + 5, compare_text.cbegin() + 10); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1695,10 +1691,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - Compare_Text compare_text(short_text.begin(), short_text.end()); - + Compare_Text compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1720,10 +1715,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { - for (size_t offset = 0; offset <= initial_text.size(); ++offset) + for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - Compare_Text compare_text(initial_text.begin(), initial_text.end()); - + Compare_Text compare_text(initial_text.cbegin(), initial_text.cend()); + TextBuffer buffer; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1745,18 +1740,18 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - Compare_Text compare_text(short_text.begin(), short_text.end()); - + Compare_Text compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); TextBuffer buffer2; Text insert(longer_text.begin(), longer_text.end(), buffer2.data(), buffer2.size()); - - insert.erase(insert.begin(), insert.end()); - insert.append(insert_text.begin(), insert_text.end()); + + insert.erase(insert.cbegin(), insert.cend()); + insert.append(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1773,8 +1768,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - Compare_Text compare_text(short_text.begin(), short_text.end()); - + Compare_Text compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1791,8 +1786,8 @@ namespace CHECK(!text.is_truncated()); #endif - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + compare_text.assign(short_text.cbegin(), short_text.cend()); + text.assign(short_text.cbegin(), short_text.cend()); text.insert(2, insert, 2, insert.size() - 2); compare_text.insert(2, insert_text, 2, insert_text.size() - 2); @@ -1806,8 +1801,8 @@ namespace CHECK(!text.is_truncated()); #endif - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + compare_text.assign(short_text.cbegin(), short_text.cend()); + text.assign(short_text.cbegin(), short_text.cend()); text.insert(short_text.size(), insert, 0, insert.size()); compare_text.insert(short_text.size(), insert_text, 0, insert_text.size()); diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index e75a75ee..34b96484 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -2704,13 +2704,31 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - compare_text.erase(compare_text.begin() + 2); - text.erase(text.begin() + 2); + Compare_Text::iterator citr = compare_text.erase(compare_text.begin() + 2); + Text::iterator ditr = text.erase(text.begin() + 2); + CHECK(*citr == *ditr); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + CHECK(!text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) + { + Compare_Text compare_text(initial_text.c_str()); + Text text(initial_text.c_str()); + + Compare_Text::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + Text::iterator ditr = text.erase(text.cbegin() + 2); + CHECK(*citr == *ditr); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2725,9 +2743,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); - - text.erase(text.begin() + 2, text.begin() + 4); + Compare_Text::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); + CHECK(*citr == *ditr); bool is_equal = Equal(compare_text, text); CHECK(is_equal); diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index e7bd8b30..bbde373c 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -1443,16 +1443,15 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { Compare_Text compare_text(initial_text.begin(), initial_text.end()); - TextBuffer buffer; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); const value_t INITIAL_VALUE = STR('A'); - size_t offset = 2; - text.insert(text.begin() + offset, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, INITIAL_VALUE); - compare_text.erase(compare_text.end() - 1); + size_t offset = 2UL; + text.insert(text.cbegin() + offset, INITIAL_VALUE); + compare_text.insert(compare_text.cbegin() + offset, INITIAL_VALUE); + compare_text.erase(compare_text.cend() - 1); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1462,9 +1461,9 @@ namespace CHECK(is_equal); offset = 0; - text.insert(text.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, STR('A')); + compare_text.insert(compare_text.cbegin() + offset, STR('A')); + compare_text.erase(compare_text.cend() - 1); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1474,9 +1473,9 @@ namespace CHECK(is_equal); offset = text.size(); - text.insert(text.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, STR('A')); + compare_text.insert(compare_text.cbegin() + offset, STR('A')); + compare_text.erase(compare_text.cend() - 1); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1490,15 +1489,14 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { Compare_Text compare_text; - TextBuffer buffer; Text text(buffer.data(), buffer.size()); - const size_t INITIAL_SIZE = 5; - const size_t INSERT_SIZE = 3; + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1518,19 +1516,18 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { Compare_Text compare_text; - TextBuffer buffer; Text text(buffer.data(), buffer.size()); - const size_t INSERT_SIZE = 4; + const size_t INSERT_SIZE = 4UL; const value_t INSERT_VALUE = STR('A'); - size_t offset = 0; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + size_t offset = 0UL; + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1540,12 +1537,12 @@ namespace CHECK(is_equal); offset = 2; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1555,12 +1552,12 @@ namespace CHECK(is_equal); offset = 4; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1570,12 +1567,12 @@ namespace CHECK(is_equal); offset = text.size(); - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1588,19 +1585,18 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { Compare_Text compare_text; - TextBuffer buffer; Text text(buffer.data(), buffer.size()); - text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); - compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); - text.insert(text.begin() + offset, insert_text.begin(), insert_text.end()); - compare_text.insert(compare_text.begin() + offset, insert_text.begin(), insert_text.end()); + text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); + compare_text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); + text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(!text.is_truncated()); @@ -1614,21 +1610,20 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); Compare_Text compare_text; - TextBuffer buffer; Text text(buffer.data(), buffer.size()); - size_t offset = 0; + size_t offset = 0UL; compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1641,9 +1636,9 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1652,13 +1647,14 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + offset = 4; compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1674,15 +1670,15 @@ namespace { size_t length = SIZE_L / 2; - for (size_t offset = 10; offset < length; ++offset) + for (size_t offset = 10UL; offset < length; ++offset) { Compare_Text compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); - compare_text.insert(compare_text.begin() + offset, compare_text.begin() + 5, compare_text.begin() + 10); + text.insert(text.cbegin() + offset, text.cbegin() + 5, text.cbegin() + 10); + compare_text.insert(compare_text.cbegin() + offset, compare_text.cbegin() + 5, compare_text.cbegin() + 10); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1695,10 +1691,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - Compare_Text compare_text(short_text.begin(), short_text.end()); - + Compare_Text compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1720,9 +1715,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { - for (size_t offset = 0; offset <= initial_text.size(); ++offset) + for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - Compare_Text compare_text(initial_text.begin(), initial_text.end()); + Compare_Text compare_text(initial_text.cbegin(), initial_text.cend()); TextBuffer buffer; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1745,9 +1740,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - Compare_Text compare_text(short_text.begin(), short_text.end()); + Compare_Text compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1755,8 +1750,8 @@ namespace TextBuffer buffer2; Text insert(longer_text.begin(), longer_text.end(), buffer2.data(), buffer2.size()); - insert.erase(insert.begin(), insert.end()); - insert.append(insert_text.begin(), insert_text.end()); + insert.erase(insert.cbegin(), insert.cend()); + insert.append(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1773,7 +1768,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - Compare_Text compare_text(short_text.begin(), short_text.end()); + Compare_Text compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1791,8 +1786,8 @@ namespace CHECK(!text.is_truncated()); #endif - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + compare_text.assign(short_text.cbegin(), short_text.cend()); + text.assign(short_text.cbegin(), short_text.cend()); text.insert(2, insert, 2, insert.size() - 2); compare_text.insert(2, insert_text, 2, insert_text.size() - 2); @@ -1806,8 +1801,8 @@ namespace CHECK(!text.is_truncated()); #endif - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + compare_text.assign(short_text.cbegin(), short_text.cend()); + text.assign(short_text.cbegin(), short_text.cend()); text.insert(short_text.size(), insert, 0, insert.size()); compare_text.insert(short_text.size(), insert_text, 0, insert_text.size()); @@ -2973,15 +2968,33 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { Compare_Text compare_text(initial_text.c_str()); - TextBuffer buffer; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - compare_text.erase(compare_text.begin() + 2); - text.erase(text.begin() + 2); + Compare_Text::iterator citr = compare_text.erase(compare_text.begin() + 2); + Text::iterator ditr = text.erase(text.begin() + 2); + CHECK(*citr == *ditr); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + CHECK(!text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) + { + Compare_Text compare_text(initial_text.c_str()); + TextBuffer buffer; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + + Compare_Text::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + Text::iterator ditr = text.erase(text.cbegin() + 2); + CHECK(*citr == *ditr); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2994,13 +3007,12 @@ namespace TEST_FIXTURE(SetupFixture, test_erase_range) { Compare_Text compare_text(initial_text.c_str()); - TextBuffer buffer; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); - - text.erase(text.begin() + 2, text.begin() + 4); + Compare_Text::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); + CHECK(*citr == *ditr); bool is_equal = Equal(compare_text, text); CHECK(is_equal); diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index 71da400f..3058afdb 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -2704,13 +2704,31 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - compare_text.erase(compare_text.begin() + 2); - text.erase(text.begin() + 2); + Compare_Text::iterator citr = compare_text.erase(compare_text.begin() + 2); + Text::iterator ditr = text.erase(text.begin() + 2); + CHECK(*citr == *ditr); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + CHECK(!text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) + { + Compare_Text compare_text(initial_text.c_str()); + Text text(initial_text.c_str()); + + Compare_Text::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + Text::iterator ditr = text.erase(text.cbegin() + 2); + CHECK(*citr == *ditr); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2725,9 +2743,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); - - text.erase(text.begin() + 2, text.begin() + 4); + Compare_Text::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); + CHECK(*citr == *ditr); bool is_equal = Equal(compare_text, text); CHECK(is_equal); diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index 4c950f06..d0592438 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -1443,16 +1443,15 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { Compare_Text compare_text(initial_text.begin(), initial_text.end()); - TextBuffer buffer; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); const value_t INITIAL_VALUE = STR('A'); - size_t offset = 2; - text.insert(text.begin() + offset, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, INITIAL_VALUE); - compare_text.erase(compare_text.end() - 1); + size_t offset = 2UL; + text.insert(text.cbegin() + offset, INITIAL_VALUE); + compare_text.insert(compare_text.cbegin() + offset, INITIAL_VALUE); + compare_text.erase(compare_text.cend() - 1); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1462,9 +1461,9 @@ namespace CHECK(is_equal); offset = 0; - text.insert(text.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, STR('A')); + compare_text.insert(compare_text.cbegin() + offset, STR('A')); + compare_text.erase(compare_text.cend() - 1); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1474,9 +1473,9 @@ namespace CHECK(is_equal); offset = text.size(); - text.insert(text.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, STR('A')); + compare_text.insert(compare_text.cbegin() + offset, STR('A')); + compare_text.erase(compare_text.cend() - 1); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1490,15 +1489,14 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { Compare_Text compare_text; - TextBuffer buffer; Text text(buffer.data(), buffer.size()); - const size_t INITIAL_SIZE = 5; - const size_t INSERT_SIZE = 3; + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1518,19 +1516,18 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { Compare_Text compare_text; - TextBuffer buffer; Text text(buffer.data(), buffer.size()); - const size_t INSERT_SIZE = 4; + const size_t INSERT_SIZE = 4UL; const value_t INSERT_VALUE = STR('A'); - size_t offset = 0; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + size_t offset = 0UL; + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1540,12 +1537,12 @@ namespace CHECK(is_equal); offset = 2; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1555,12 +1552,12 @@ namespace CHECK(is_equal); offset = 4; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1570,12 +1567,12 @@ namespace CHECK(is_equal); offset = text.size(); - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1588,19 +1585,18 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { Compare_Text compare_text; - TextBuffer buffer; Text text(buffer.data(), buffer.size()); - text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); - compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); - text.insert(text.begin() + offset, insert_text.begin(), insert_text.end()); - compare_text.insert(compare_text.begin() + offset, insert_text.begin(), insert_text.end()); + text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); + compare_text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); + text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(!text.is_truncated()); @@ -1614,21 +1610,20 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); Compare_Text compare_text; - TextBuffer buffer; Text text(buffer.data(), buffer.size()); - size_t offset = 0; + size_t offset = 0UL; compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1641,9 +1636,9 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1652,13 +1647,14 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + offset = 4; compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1674,15 +1670,15 @@ namespace { size_t length = SIZE_L / 2; - for (size_t offset = 10; offset < length; ++offset) + for (size_t offset = 10UL; offset < length; ++offset) { Compare_Text compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); - compare_text.insert(compare_text.begin() + offset, compare_text.begin() + 5, compare_text.begin() + 10); + text.insert(text.cbegin() + offset, text.cbegin() + 5, text.cbegin() + 10); + compare_text.insert(compare_text.cbegin() + offset, compare_text.cbegin() + 5, compare_text.cbegin() + 10); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1695,10 +1691,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - Compare_Text compare_text(short_text.begin(), short_text.end()); - + Compare_Text compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1720,9 +1715,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { - for (size_t offset = 0; offset <= initial_text.size(); ++offset) + for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - Compare_Text compare_text(initial_text.begin(), initial_text.end()); + Compare_Text compare_text(initial_text.cbegin(), initial_text.cend()); TextBuffer buffer; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1745,9 +1740,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - Compare_Text compare_text(short_text.begin(), short_text.end()); + Compare_Text compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1755,8 +1750,8 @@ namespace TextBuffer buffer2; Text insert(longer_text.begin(), longer_text.end(), buffer2.data(), buffer2.size()); - insert.erase(insert.begin(), insert.end()); - insert.append(insert_text.begin(), insert_text.end()); + insert.erase(insert.cbegin(), insert.cend()); + insert.append(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1773,7 +1768,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - Compare_Text compare_text(short_text.begin(), short_text.end()); + Compare_Text compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1791,8 +1786,8 @@ namespace CHECK(!text.is_truncated()); #endif - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + compare_text.assign(short_text.cbegin(), short_text.cend()); + text.assign(short_text.cbegin(), short_text.cend()); text.insert(2, insert, 2, insert.size() - 2); compare_text.insert(2, insert_text, 2, insert_text.size() - 2); @@ -1806,8 +1801,8 @@ namespace CHECK(!text.is_truncated()); #endif - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + compare_text.assign(short_text.cbegin(), short_text.cend()); + text.assign(short_text.cbegin(), short_text.cend()); text.insert(short_text.size(), insert, 0, insert.size()); compare_text.insert(short_text.size(), insert_text, 0, insert_text.size()); @@ -2973,15 +2968,33 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { Compare_Text compare_text(initial_text.c_str()); - TextBuffer buffer; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - compare_text.erase(compare_text.begin() + 2); - text.erase(text.begin() + 2); + Compare_Text::iterator citr = compare_text.erase(compare_text.begin() + 2); + Text::iterator ditr = text.erase(text.begin() + 2); + CHECK(*citr == *ditr); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + CHECK(!text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) + { + Compare_Text compare_text(initial_text.c_str()); + TextBuffer buffer; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + + Compare_Text::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + Text::iterator ditr = text.erase(text.cbegin() + 2); + CHECK(*citr == *ditr); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2994,13 +3007,12 @@ namespace TEST_FIXTURE(SetupFixture, test_erase_range) { Compare_Text compare_text(initial_text.c_str()); - TextBuffer buffer; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); - - text.erase(text.begin() + 2, text.begin() + 4); + Compare_Text::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); + CHECK(*citr == *ditr); bool is_equal = Equal(compare_text, text); CHECK(is_equal); diff --git a/test/test_string_view.cpp b/test/test_string_view.cpp index 94bd6436..5b925d8c 100644 --- a/test/test_string_view.cpp +++ b/test/test_string_view.cpp @@ -169,6 +169,7 @@ namespace } //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) TEST(test_template_deduction) { etl::basic_string_view cview{ "Hello World" }; @@ -181,6 +182,7 @@ namespace CHECK(std::equal(u16view.begin(), u16view.end(), text.begin())); CHECK(std::equal(u32view.begin(), u32view.end(), text.begin())); } +#endif //************************************************************************* TEST(test_assign_from_string_view) diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index 7c2854b7..77af504c 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -2704,13 +2704,31 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - compare_text.erase(compare_text.begin() + 2); - text.erase(text.begin() + 2); + Compare_Text::iterator citr = compare_text.erase(compare_text.begin() + 2); + Text::iterator ditr = text.erase(text.begin() + 2); + CHECK(*citr == *ditr); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + CHECK(!text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) + { + Compare_Text compare_text(initial_text.c_str()); + Text text(initial_text.c_str()); + + Compare_Text::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + Text::iterator ditr = text.erase(text.cbegin() + 2); + CHECK(*citr == *ditr); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2725,9 +2743,9 @@ namespace Compare_Text compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); - - text.erase(text.begin() + 2, text.begin() + 4); + Compare_Text::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); + CHECK(*citr == *ditr); bool is_equal = Equal(compare_text, text); CHECK(is_equal); diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index 39be13b0..d8ebde05 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -1443,16 +1443,15 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { Compare_Text compare_text(initial_text.begin(), initial_text.end()); - TextBuffer buffer; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); const value_t INITIAL_VALUE = STR('A'); - size_t offset = 2; - text.insert(text.begin() + offset, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, INITIAL_VALUE); - compare_text.erase(compare_text.end() - 1); + size_t offset = 2UL; + text.insert(text.cbegin() + offset, INITIAL_VALUE); + compare_text.insert(compare_text.cbegin() + offset, INITIAL_VALUE); + compare_text.erase(compare_text.cend() - 1); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1462,9 +1461,9 @@ namespace CHECK(is_equal); offset = 0; - text.insert(text.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, STR('A')); + compare_text.insert(compare_text.cbegin() + offset, STR('A')); + compare_text.erase(compare_text.cend() - 1); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1474,9 +1473,9 @@ namespace CHECK(is_equal); offset = text.size(); - text.insert(text.begin() + offset, STR('A')); - compare_text.insert(compare_text.begin() + offset, STR('A')); - compare_text.erase(compare_text.end() - 1); + text.insert(text.cbegin() + offset, STR('A')); + compare_text.insert(compare_text.cbegin() + offset, STR('A')); + compare_text.erase(compare_text.cend() - 1); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1490,15 +1489,14 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { Compare_Text compare_text; - TextBuffer buffer; Text text(buffer.data(), buffer.size()); - const size_t INITIAL_SIZE = 5; - const size_t INSERT_SIZE = 3; + const size_t INITIAL_SIZE = 5UL; + const size_t INSERT_SIZE = 3UL; const value_t INITIAL_VALUE = STR('A'); - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1518,19 +1516,18 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { Compare_Text compare_text; - TextBuffer buffer; Text text(buffer.data(), buffer.size()); - const size_t INSERT_SIZE = 4; + const size_t INSERT_SIZE = 4UL; const value_t INSERT_VALUE = STR('A'); - size_t offset = 0; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + size_t offset = 0UL; + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1540,12 +1537,12 @@ namespace CHECK(is_equal); offset = 2; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1555,12 +1552,12 @@ namespace CHECK(is_equal); offset = 4; - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1570,12 +1567,12 @@ namespace CHECK(is_equal); offset = text.size(); - compare_text.assign(initial_text.begin(), initial_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - compare_text.insert(compare_text.begin() + offset, INSERT_SIZE, INSERT_VALUE); - compare_text.erase(compare_text.end() - INSERT_SIZE, compare_text.end()); - text.assign(initial_text.begin(), initial_text.end()); - text.insert(text.begin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.assign(initial_text.cbegin(), initial_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); + compare_text.erase(compare_text.cend() - INSERT_SIZE, compare_text.cend()); + text.assign(initial_text.cbegin(), initial_text.cend()); + text.insert(text.cbegin() + offset, INSERT_SIZE, INSERT_VALUE); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1588,19 +1585,18 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; - for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) + for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { Compare_Text compare_text; - TextBuffer buffer; Text text(buffer.data(), buffer.size()); - text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); - compare_text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); - text.insert(text.begin() + offset, insert_text.begin(), insert_text.end()); - compare_text.insert(compare_text.begin() + offset, insert_text.begin(), insert_text.end()); + text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); + compare_text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); + text.insert(text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); + compare_text.insert(compare_text.cbegin() + offset, insert_text.cbegin(), insert_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(!text.is_truncated()); @@ -1614,21 +1610,20 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_range_excess) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); Compare_Text compare_text; - TextBuffer buffer; Text text(buffer.data(), buffer.size()); - size_t offset = 0; + size_t offset = 0UL; compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1641,9 +1636,9 @@ namespace compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1652,13 +1647,14 @@ namespace is_equal = Equal(compare_text, text); CHECK(is_equal); + offset = 4; compare_text.assign(INITIAL_SIZE, INITIAL_VALUE); text.assign(INITIAL_SIZE, INITIAL_VALUE); - compare_text.insert(compare_text.begin() + offset, initial_text.begin(), initial_text.end()); + compare_text.insert(compare_text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); compare_text.resize(initial_text.size()); - text.insert(text.begin() + offset, initial_text.begin(), initial_text.end()); + text.insert(text.cbegin() + offset, initial_text.cbegin(), initial_text.cend()); #if ETL_STRING_TRUNCATION_CHECKS_ENABLED CHECK(text.is_truncated()); @@ -1674,15 +1670,15 @@ namespace { size_t length = SIZE_L / 2; - for (size_t offset = 10; offset < length; ++offset) + for (size_t offset = 10UL; offset < length; ++offset) { Compare_Text compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); - text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); - compare_text.insert(compare_text.begin() + offset, compare_text.begin() + 5, compare_text.begin() + 10); + text.insert(text.cbegin() + offset, text.cbegin() + 5, text.cbegin() + 10); + compare_text.insert(compare_text.cbegin() + offset, compare_text.cbegin() + 5, compare_text.cbegin() + 10); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1695,10 +1691,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - Compare_Text compare_text(short_text.begin(), short_text.end()); - + Compare_Text compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1720,9 +1715,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { - for (size_t offset = 0; offset <= initial_text.size(); ++offset) + for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - Compare_Text compare_text(initial_text.begin(), initial_text.end()); + Compare_Text compare_text(initial_text.cbegin(), initial_text.cend()); TextBuffer buffer; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1745,9 +1740,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_from_truncated) { - for (size_t offset = 0; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - Compare_Text compare_text(short_text.begin(), short_text.end()); + Compare_Text compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1755,8 +1750,8 @@ namespace TextBuffer buffer2; Text insert(longer_text.begin(), longer_text.end(), buffer2.data(), buffer2.size()); - insert.erase(insert.begin(), insert.end()); - insert.append(insert_text.begin(), insert_text.end()); + insert.erase(insert.cbegin(), insert.cend()); + insert.append(insert_text.cbegin(), insert_text.cend()); text.insert(offset, insert); compare_text.insert(offset, insert_text); @@ -1773,7 +1768,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - Compare_Text compare_text(short_text.begin(), short_text.end()); + Compare_Text compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1791,8 +1786,8 @@ namespace CHECK(!text.is_truncated()); #endif - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + compare_text.assign(short_text.cbegin(), short_text.cend()); + text.assign(short_text.cbegin(), short_text.cend()); text.insert(2, insert, 2, insert.size() - 2); compare_text.insert(2, insert_text, 2, insert_text.size() - 2); @@ -1806,8 +1801,8 @@ namespace CHECK(!text.is_truncated()); #endif - compare_text.assign(short_text.begin(), short_text.end()); - text.assign(short_text.begin(), short_text.end()); + compare_text.assign(short_text.cbegin(), short_text.cend()); + text.assign(short_text.cbegin(), short_text.cend()); text.insert(short_text.size(), insert, 0, insert.size()); compare_text.insert(short_text.size(), insert_text, 0, insert_text.size()); @@ -2973,15 +2968,33 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { Compare_Text compare_text(initial_text.c_str()); - TextBuffer buffer; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - compare_text.erase(compare_text.begin() + 2); - text.erase(text.begin() + 2); + Compare_Text::iterator citr = compare_text.erase(compare_text.begin() + 2); + Text::iterator ditr = text.erase(text.begin() + 2); + CHECK(*citr == *ditr); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + CHECK(!text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) + { + Compare_Text compare_text(initial_text.c_str()); + TextBuffer buffer; + Text text(initial_text.c_str(), buffer.data(), buffer.size()); + + Compare_Text::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + Text::iterator ditr = text.erase(text.cbegin() + 2); + CHECK(*citr == *ditr); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2994,13 +3007,12 @@ namespace TEST_FIXTURE(SetupFixture, test_erase_range) { Compare_Text compare_text(initial_text.c_str()); - TextBuffer buffer; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); - - text.erase(text.begin() + 2, text.begin() + 4); + Compare_Text::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); + CHECK(*citr == *ditr); bool is_equal = Equal(compare_text, text); CHECK(is_equal); diff --git a/test/test_unordered_map.cpp b/test/test_unordered_map.cpp index 45295360..9694ef89 100644 --- a/test/test_unordered_map.cpp +++ b/test/test_unordered_map.cpp @@ -244,7 +244,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -599,7 +599,23 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + DataNDC::iterator idata = data.find(K5); + DataNDC::iterator inext = idata; + ++inext; + + DataNDC::iterator iafter = data.erase(idata); + idata = data.find(K5); + + CHECK(idata == data.end()); + CHECK(inext == iafter); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) { DataNDC data(initial_data.begin(), initial_data.end()); @@ -607,7 +623,7 @@ namespace DataNDC::const_iterator inext = idata; ++inext; - DataNDC::const_iterator iafter = data.erase(idata); + DataNDC::iterator iafter = data.erase(idata); idata = data.find(K5); CHECK(idata == data.end()); @@ -619,10 +635,10 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - DataNDC::iterator idata = data.begin(); + DataNDC::const_iterator idata = data.begin(); std::advance(idata, 2); - DataNDC::iterator idata_end = data.begin(); + DataNDC::const_iterator idata_end = data.begin(); std::advance(idata_end, 5); data.erase(idata, idata_end); @@ -670,10 +686,10 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - DataNDC::iterator end = data.begin(); + DataNDC::const_iterator end = data.cbegin(); etl::advance(end, data.size() / 2); - auto itr = data.erase(data.begin(), end); + auto itr = data.erase(data.cbegin(), end); CHECK_EQUAL(initial_data.size() / 2, data.size()); CHECK(!data.full()); @@ -686,10 +702,10 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - DataNDC::iterator begin = data.begin(); + DataNDC::const_iterator begin = data.cbegin(); etl::advance(begin, data.size() / 2); - auto itr = data.erase(begin, data.end()); + auto itr = data.erase(begin, data.cend()); CHECK_EQUAL(initial_data.size() / 2, data.size()); CHECK(!data.full()); @@ -702,7 +718,7 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - auto itr = data.erase(data.begin(), data.end()); + auto itr = data.erase(data.cbegin(), data.cend()); CHECK_EQUAL(0U, data.size()); CHECK(!data.full()); diff --git a/test/test_unordered_multimap.cpp b/test/test_unordered_multimap.cpp index 2036f546..742cf50f 100644 --- a/test/test_unordered_multimap.cpp +++ b/test/test_unordered_multimap.cpp @@ -221,7 +221,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -510,7 +510,27 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + DataNDC::iterator idata = data.find(K5); + DataNDC::iterator inext = idata; + ++inext; + + DataNDC::iterator iafter = data.erase(idata); + idata = data.find(K5); + + CHECK(idata == data.end()); + CHECK(inext == iafter); + + // Test that erase really does erase from the pool. + CHECK(!data.full()); + CHECK(!data.empty()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) { DataNDC data(initial_data.begin(), initial_data.end()); @@ -518,10 +538,10 @@ namespace DataNDC::const_iterator inext = idata; ++inext; - DataNDC::const_iterator iafter = data.erase(idata); + DataNDC::iterator iafter = data.erase(idata); idata = data.find(K5); - CHECK(idata == data.end()); + CHECK(idata == data.cend()); CHECK(inext == iafter); // Test that erase really does erase from the pool. @@ -534,10 +554,10 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - DataNDC::iterator idata = data.begin(); + DataNDC::const_iterator idata = data.cbegin(); std::advance(idata, 2); - DataNDC::iterator idata_end = data.begin(); + DataNDC::const_iterator idata_end = data.cbegin(); std::advance(idata_end, 5); data.erase(idata, idata_end); @@ -585,10 +605,10 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - DataNDC::iterator end = data.begin(); + DataNDC::const_iterator end = data.cbegin(); etl::advance(end, data.size() / 2); - auto itr = data.erase(data.begin(), end); + auto itr = data.erase(data.cbegin(), end); CHECK_EQUAL(initial_data.size() / 2, data.size()); CHECK(!data.full()); @@ -601,10 +621,10 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - DataNDC::iterator begin = data.begin(); + DataNDC::const_iterator begin = data.cbegin(); etl::advance(begin, data.size() / 2); - auto itr = data.erase(begin, data.end()); + auto itr = data.erase(begin, data.cend()); CHECK_EQUAL(initial_data.size() / 2, data.size()); CHECK(!data.full()); @@ -617,7 +637,7 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - auto itr = data.erase(data.begin(), data.end()); + auto itr = data.erase(data.cbegin(), data.cend()); CHECK_EQUAL(0U, data.size()); CHECK(!data.full()); @@ -625,7 +645,6 @@ namespace CHECK(itr == data.end()); } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { diff --git a/test/test_unordered_multiset.cpp b/test/test_unordered_multiset.cpp index 63ed873e..eac87514 100644 --- a/test/test_unordered_multiset.cpp +++ b/test/test_unordered_multiset.cpp @@ -162,7 +162,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -443,7 +443,27 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + DataNDC::iterator idata = data.find(N5); + DataNDC::iterator inext = idata; + ++inext; + + DataNDC::iterator iafter = data.erase(idata); + idata = data.find(N5); + + CHECK(idata == data.end()); + CHECK(inext == iafter); + + // Test that erase really does erase from the pool. + CHECK(!data.full()); + CHECK(!data.empty()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_cont_iterator) { DataNDC data(initial_data.begin(), initial_data.end()); @@ -454,7 +474,7 @@ namespace DataNDC::const_iterator iafter = data.erase(idata); idata = data.find(N5); - CHECK(idata == data.end()); + CHECK(idata == data.cend()); CHECK(inext == iafter); // Test that erase really does erase from the pool. @@ -467,10 +487,10 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - DataNDC::iterator idata = data.begin(); + DataNDC::const_iterator idata = data.cbegin(); std::advance(idata, 2); - DataNDC::iterator idata_end = data.begin(); + DataNDC::const_iterator idata_end = data.cbegin(); std::advance(idata_end, 5); data.erase(idata, idata_end); @@ -518,10 +538,10 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - DataNDC::iterator end = data.begin(); + DataNDC::const_iterator end = data.cbegin(); etl::advance(end, data.size() / 2); - auto itr = data.erase(data.begin(), end); + auto itr = data.erase(data.cbegin(), end); CHECK_EQUAL(initial_data.size() / 2, data.size()); CHECK(!data.full()); @@ -534,10 +554,10 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - DataNDC::iterator begin = data.begin(); + DataNDC::const_iterator begin = data.cbegin(); etl::advance(begin, data.size() / 2); - auto itr = data.erase(begin, data.end()); + auto itr = data.erase(begin, data.cend()); CHECK_EQUAL(initial_data.size() / 2, data.size()); CHECK(!data.full()); @@ -550,7 +570,7 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - auto itr = data.erase(data.begin(), data.end()); + auto itr = data.erase(data.cbegin(), data.cend()); CHECK_EQUAL(0U, data.size()); CHECK(!data.full()); @@ -558,7 +578,6 @@ namespace CHECK(itr == data.end()); } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { diff --git a/test/test_unordered_set.cpp b/test/test_unordered_set.cpp index cc1fad79..cfe6eb13 100644 --- a/test/test_unordered_set.cpp +++ b/test/test_unordered_set.cpp @@ -155,7 +155,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -424,7 +424,27 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + DataNDC::iterator idata = data.find(N5); + DataNDC::iterator inext = idata; + ++inext; + + DataNDC::iterator iafter = data.erase(idata); + idata = data.find(N5); + + CHECK(idata == data.end()); + CHECK(inext == iafter); + + // Test that erase really does erase from the pool. + CHECK(!data.full()); + CHECK(!data.empty()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) { DataNDC data(initial_data.begin(), initial_data.end()); @@ -432,10 +452,10 @@ namespace DataNDC::const_iterator inext = idata; ++inext; - DataNDC::const_iterator iafter = data.erase(idata); + DataNDC::iterator iafter = data.erase(idata); idata = data.find(N5); - CHECK(idata == data.end()); + CHECK(idata == data.cend()); CHECK(inext == iafter); // Test that erase really does erase from the pool. @@ -448,10 +468,10 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - DataNDC::iterator idata = data.begin(); + DataNDC::const_iterator idata = data.cbegin(); std::advance(idata, 2); - DataNDC::iterator idata_end = data.begin(); + DataNDC::const_iterator idata_end = data.cbegin(); std::advance(idata_end, 5); data.erase(idata, idata_end); @@ -499,10 +519,10 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - DataNDC::iterator end = data.begin(); + DataNDC::const_iterator end = data.cbegin(); etl::advance(end, data.size() / 2); - auto itr = data.erase(data.begin(), end); + auto itr = data.erase(data.cbegin(), end); CHECK_EQUAL(initial_data.size() / 2, data.size()); CHECK(!data.full()); @@ -515,10 +535,10 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - DataNDC::iterator begin = data.begin(); + DataNDC::const_iterator begin = data.cbegin(); etl::advance(begin, data.size() / 2); - auto itr = data.erase(begin, data.end()); + auto itr = data.erase(begin, data.cend()); CHECK_EQUAL(initial_data.size() / 2, data.size()); CHECK(!data.full()); @@ -531,7 +551,7 @@ namespace { DataNDC data(initial_data.begin(), initial_data.end()); - auto itr = data.erase(data.begin(), data.end()); + auto itr = data.erase(data.cbegin(), data.cend()); CHECK_EQUAL(0U, data.size()); CHECK(!data.full()); @@ -539,7 +559,6 @@ namespace CHECK(itr == data.end()); } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { diff --git a/test/test_vector.cpp b/test/test_vector.cpp index 4ad6aeab..1798f981 100644 --- a/test/test_vector.cpp +++ b/test/test_vector.cpp @@ -83,7 +83,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -740,14 +740,14 @@ namespace data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); - data.insert(data.begin() + offset, INITIAL_VALUE); - compare_data.insert(compare_data.begin() + offset, INITIAL_VALUE); + data.insert(data.cbegin() + offset, INITIAL_VALUE); + compare_data.insert(compare_data.cbegin() + offset, INITIAL_VALUE); CHECK_EQUAL(compare_data.size(), data.size()); - bool is_equal = std::equal(data.begin(), - data.end(), - compare_data.begin()); + bool is_equal = std::equal(data.cbegin(), + data.cend(), + compare_data.cbegin()); CHECK(is_equal); } @@ -767,14 +767,14 @@ namespace data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); - data.emplace(data.begin() + offset, INITIAL_VALUE); - compare_data.emplace(compare_data.begin() + offset, INITIAL_VALUE); + data.emplace(data.cbegin() + offset, INITIAL_VALUE); + compare_data.emplace(compare_data.cbegin() + offset, INITIAL_VALUE); CHECK_EQUAL(compare_data.size(), data.size()); - bool is_equal = std::equal(data.begin(), - data.end(), - compare_data.begin()); + bool is_equal = std::equal(data.cbegin(), + data.cend(), + compare_data.cbegin()); CHECK(is_equal); } @@ -790,15 +790,15 @@ namespace size_t offset = 2; - CHECK_THROW(data.insert(data.begin() + offset, INITIAL_VALUE), etl::vector_full); + CHECK_THROW(data.insert(data.cbegin() + offset, INITIAL_VALUE), etl::vector_full); offset = 0; - CHECK_THROW(data.insert(data.begin() + offset, INITIAL_VALUE), etl::vector_full); + CHECK_THROW(data.insert(data.cbegin() + offset, INITIAL_VALUE), etl::vector_full); offset = data.size(); - CHECK_THROW(data.insert(data.begin() + offset, INITIAL_VALUE), etl::vector_full); + CHECK_THROW(data.insert(data.cbegin() + offset, INITIAL_VALUE), etl::vector_full); } //************************************************************************* @@ -815,14 +815,14 @@ namespace data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); - data.insert(data.begin() + offset, INSERT_SIZE, INITIAL_VALUE); - compare_data.insert(compare_data.begin() + offset, INSERT_SIZE, INITIAL_VALUE); + data.insert(data.cbegin() + offset, INSERT_SIZE, INITIAL_VALUE); + compare_data.insert(compare_data.cbegin() + offset, INSERT_SIZE, INITIAL_VALUE); CHECK_EQUAL(compare_data.size(), data.size()); - bool is_equal = std::equal(data.begin(), - data.end(), - compare_data.begin()); + bool is_equal = std::equal(data.cbegin(), + data.cend(), + compare_data.cbegin()); CHECK(is_equal); } @@ -839,19 +839,19 @@ namespace size_t offset = 0; - CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full); + CHECK_THROW(data.insert(data.cbegin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full); offset = 2; - CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full); + CHECK_THROW(data.insert(data.cbegin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full); offset = 4; - CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full); + CHECK_THROW(data.insert(data.cbegin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full); offset = data.size(); - CHECK_THROW(data.insert(data.begin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full); + CHECK_THROW(data.insert(data.cbegin() + offset, INSERT_SIZE, INITIAL_VALUE), etl::vector_full); } //************************************************************************* @@ -868,14 +868,14 @@ namespace data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); compare_data.assign(initial_data.begin(), initial_data.begin() + INITIAL_SIZE); - data.insert(data.begin() + offset, insert_data.begin(), insert_data.end()); - compare_data.insert(compare_data.begin() + offset, insert_data.begin(), insert_data.end()); + data.insert(data.cbegin() + offset, insert_data.cbegin(), insert_data.cend()); + compare_data.insert(compare_data.cbegin() + offset, insert_data.cbegin(), insert_data.cend()); CHECK_EQUAL(compare_data.size(), data.size()); - bool is_equal = std::equal(data.begin(), - data.end(), - compare_data.begin()); + bool is_equal = std::equal(data.cbegin(), + data.cend(), + compare_data.cbegin()); CHECK(is_equal); } @@ -891,31 +891,61 @@ namespace size_t offset = 0; - CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full); + CHECK_THROW(data.insert(data.cbegin() + offset, initial_data.cbegin(), initial_data.cend()), etl::vector_full); offset = 2; - CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full); + CHECK_THROW(data.insert(data.cbegin() + offset, initial_data.cbegin(), initial_data.cend()), etl::vector_full); offset = 4; - CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full); + CHECK_THROW(data.insert(data.cbegin() + offset, initial_data.cbegin(), initial_data.cend()), etl::vector_full); offset = data.size(); - CHECK_THROW(data.insert(data.begin() + offset, initial_data.begin(), initial_data.end()), etl::vector_full); + CHECK_THROW(data.insert(data.cbegin() + offset, initial_data.cbegin(), initial_data.cend()), etl::vector_full); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single) + TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { Compare_Data compare_data(initial_data.begin(), initial_data.end()); Data data(initial_data.begin(), initial_data.end()); - compare_data.erase(compare_data.begin() + 2); + Compare_Data::iterator const_cdi = compare_data.begin() + 2U; + int compare_value = *(const_cdi + 1U); + Compare_Data::iterator cdi = compare_data.erase(const_cdi); + CHECK_EQUAL(compare_value, *cdi); - data.erase(data.begin() + 2); + Data::iterator const_di = data.begin() + 2U; + int data_value = *(const_di + 1U); + Data::iterator di = data.erase(const_di); + CHECK_EQUAL(data_value, *di); + + CHECK_EQUAL(compare_data.size(), data.size()); + + bool is_equal = std::equal(data.begin(), + data.end(), + compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) + { + Compare_Data compare_data(initial_data.begin(), initial_data.end()); + Data data(initial_data.begin(), initial_data.end()); + + Compare_Data::const_iterator const_cdi = compare_data.cbegin() + 2U; + int compare_value = *(const_cdi + 1U); + Compare_Data::iterator cdi = compare_data.erase(const_cdi); + CHECK_EQUAL(compare_value, *cdi); + + Data::const_iterator const_di = data.cbegin() + 2U; + int data_value = *(const_di + 1U); + Data::iterator di = data.erase(const_di); + CHECK_EQUAL(data_value, *di); CHECK_EQUAL(compare_data.size(), data.size()); @@ -932,9 +962,15 @@ namespace Compare_Data compare_data(initial_data.begin(), initial_data.end()); Data data(initial_data.begin(), initial_data.end()); - compare_data.erase(compare_data.begin() + 2, compare_data.begin() + 4); + Compare_Data::const_iterator const_cdi = compare_data.cbegin() + 2U; + int compare_value = *(const_cdi + 2U); + Compare_Data::iterator cdi = compare_data.erase(const_cdi, const_cdi + 2U); + CHECK_EQUAL(compare_value, *cdi); - data.erase(data.begin() + 2, data.begin() + 4); + Data::const_iterator const_di = data.cbegin() + 2U; + int data_value = *(const_di + 2U); + Data::iterator di = data.erase(const_di, const_di + 2U); + CHECK_EQUAL(data_value, *di); CHECK_EQUAL(compare_data.size(), data.size()); @@ -1276,6 +1312,22 @@ namespace etl::vector v(5, 5); } + //************************************************************************* + TEST(test_two_parameter_assign_same_type_not_iterator) + { + // No compilation error. + etl::vector v; + v.assign(5, 5); + } + + //************************************************************************* + TEST(test_three_parameter_insert_same_type_not_iterator) + { + // No compilation error. + etl::vector v; + v.insert(v.end(), 5, 5); + } + //************************************************************************* TEST(remove) { diff --git a/test/test_vector_non_trivial.cpp b/test/test_vector_non_trivial.cpp index 4ad08846..d620876c 100644 --- a/test/test_vector_non_trivial.cpp +++ b/test/test_vector_non_trivial.cpp @@ -92,7 +92,7 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_vector_pointer.cpp b/test/test_vector_pointer.cpp index 38db7dec..bc335cf2 100644 --- a/test/test_vector_pointer.cpp +++ b/test/test_vector_pointer.cpp @@ -99,7 +99,7 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } -#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) +#if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -1409,9 +1409,10 @@ namespace Compare_Data compare_data(initial_data.begin(), initial_data.end()); Data data(initial_data.begin(), initial_data.end()); - compare_data.erase(compare_data.begin() + 2); + Compare_Data::iterator citr = compare_data.erase(compare_data.begin() + 2); + Data::iterator ditr = data.erase(data.begin() + 2); - data.erase(data.begin() + 2); + CHECK(*citr == *ditr); bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); @@ -1419,14 +1420,31 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_const_erase_single) + TEST_FIXTURE(SetupFixture, test_const_erase_single_iterator) { CCompare_Data compare_data(initial_data.begin(), initial_data.end()); CData data(initial_data.begin(), initial_data.end()); - compare_data.erase(compare_data.begin() + 2); + CCompare_Data::iterator citr = compare_data.erase(compare_data.begin() + 2); + CData::iterator ditr = data.erase(data.begin() + 2); - data.erase(data.begin() + 2); + CHECK(*citr == *ditr); + + bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); + + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_const_erase_single_const_iterator) + { + CCompare_Data compare_data(initial_data.begin(), initial_data.end()); + CData data(initial_data.begin(), initial_data.end()); + + CCompare_Data::iterator citr = compare_data.erase(compare_data.cbegin() + 2); + CData::iterator ditr = data.erase(data.cbegin() + 2); + + CHECK(*citr == *ditr); bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); @@ -1439,9 +1457,10 @@ namespace Compare_Data compare_data(initial_data.begin(), initial_data.end()); Data data(initial_data.begin(), initial_data.end()); - compare_data.erase(compare_data.begin() + 2, compare_data.begin() + 4); + Compare_Data::iterator citr = compare_data.erase(compare_data.cbegin() + 2, compare_data.cbegin() + 4); + Data::iterator ditr = data.erase(data.cbegin() + 2, data.cbegin() + 4); - data.erase(data.begin() + 2, data.begin() + 4); + CHECK(*citr == *ditr); bool is_equal = std::equal(data.begin(), data.end(), compare_data.begin()); diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 12d12b00..b70d2830 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -8422,8 +8422,6 @@ - - diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index 14355af7..0624267d 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -103,18 +103,6 @@ {562466b5-677d-4448-9e9e-f70805cd71ad} - - {1d6ea286-57ad-4960-9343-9d2376087b24} - - - {5eace791-3e53-4205-a04d-2aba3bac6b47} - - - {2b770849-325e-4ec5-a7f3-9a192cd40dca} - - - {0e4d2126-b9b7-4eef-b5ca-18363b1e01ce} - {5b76fd56-eb83-489f-b9a6-798c07c5fa76} @@ -1161,15 +1149,15 @@ ETL\Containers - - ETL\Profiles - ETL\Utilities ETL\Profiles + + ETL\Utilities + @@ -3130,12 +3118,6 @@ Source Files\Scripts - - ETL\Arduino\Examples\Example_0_import_etl - - - ETL\Arduino\Examples\Vector_Examples\Example_Vector_1_simple_use - Resource Files