From 94507ad1c6cc8a06b5e99b3479a325add62b278b Mon Sep 17 00:00:00 2001 From: Bo Rydberg <2945606+bolry@users.noreply.github.com> Date: Fri, 19 Nov 2021 12:04:10 +0100 Subject: [PATCH 1/4] Fix list insert and assign errors (#468) Also fixing some test asserts related to etl::list. --- include/etl/list.h | 6 +++--- test/test_list.cpp | 10 ++++++++++ test/test_list_shared_pool.cpp | 4 ++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/etl/list.h b/include/etl/list.h index 406bb9fe..665b2b04 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(); @@ -1191,7 +1191,7 @@ 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(iterator position, TIterator first, TIterator last, typename etl::enable_if::value, int>::type = 0) { while (first != last) { diff --git a/test/test_list.cpp b/test/test_list.cpp index 9688c960..c0179762 100644 --- a/test/test_list.cpp +++ b/test/test_list.cpp @@ -2027,5 +2027,15 @@ namespace CHECK_EQUAL(3U, (*itr++).value); // 3 CHECK_EQUAL(4U, (*itr++).value); // 4 } + + 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()); + } }; } diff --git a/test/test_list_shared_pool.cpp b/test/test_list_shared_pool.cpp index 9e51fae8..6da1fb96 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); } //************************************************************************* From e4431d39401a8521f72d85dce37a2e6cc0259417 Mon Sep 17 00:00:00 2001 From: Bo Rydberg <2945606+bolry@users.noreply.github.com> Date: Fri, 19 Nov 2021 12:04:41 +0100 Subject: [PATCH 2/4] Fix compile error insert/assign two same types non-iterator (#467) Assignent and insert_after of count and values of same types has to work --- include/etl/forward_list.h | 4 ++-- test/test_forward_list.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/etl/forward_list.h b/include/etl/forward_list.h index 6919e856..36f3cfa4 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); @@ -977,7 +977,7 @@ namespace etl /// Inserts a range of values to the forward_list after the specified position. //************************************************************************* template - void insert_after(iterator position, TIterator first, TIterator last) + void insert_after(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); diff --git a/test/test_forward_list.cpp b/test/test_forward_list.cpp index e9eaabe0..40746940 100644 --- a/test/test_forward_list.cpp +++ b/test/test_forward_list.cpp @@ -1349,5 +1349,16 @@ namespace CHECK(data1 < data3); CHECK(data3 > data1); } + + 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()); + } }; } From a41418ed91c8dbf22aa7d3748e5084f21f87d556 Mon Sep 17 00:00:00 2001 From: Bo Rydberg <2945606+bolry@users.noreply.github.com> Date: Fri, 19 Nov 2021 12:05:04 +0100 Subject: [PATCH 3/4] Fix compile error for vector assign and insert with same type non-iterator (#466) --- include/etl/vector.h | 4 ++-- test/test_vector.cpp | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/include/etl/vector.h b/include/etl/vector.h index cab5bb3a..9f05d617 100644 --- a/include/etl/vector.h +++ b/include/etl/vector.h @@ -382,7 +382,7 @@ namespace etl ///\param first The iterator to the first element. ///\param last The iterator to the last element + 1. //********************************************************************* - template + template ::value, int>::type = 0> void 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"); @@ -786,7 +786,7 @@ namespace etl ///\param last The last + 1 element to add. //********************************************************************* template - void insert(iterator position, TIterator first, TIterator last) + void insert(iterator position, TIterator first, TIterator last, typename etl::enable_if::value, int>::type = 0) { size_t count = etl::distance(first, last); diff --git a/test/test_vector.cpp b/test/test_vector.cpp index daffb823..45032349 100644 --- a/test/test_vector.cpp +++ b/test/test_vector.cpp @@ -1276,6 +1276,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) { From 7aaf37e21d9b9a512da5b05b6dff4ad67b2dd257 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 19 Nov 2021 11:20:49 +0000 Subject: [PATCH 4/4] Updated deque --- include/etl/deque.h | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/include/etl/deque.h b/include/etl/deque.h index 7fe74a0d..efef7848 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(); @@ -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;