diff --git a/include/etl/deque.h b/include/etl/deque.h index f45fe82f..5f04068b 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; diff --git a/include/etl/forward_list.h b/include/etl/forward_list.h index 6cb0f8dc..ce269d14 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(const_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/include/etl/list.h b/include/etl/list.h index cbe587c8..d85870b6 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(const_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/include/etl/vector.h b/include/etl/vector.h index b61a1d15..dd346940 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"); @@ -802,7 +802,7 @@ namespace etl ///\param last The last + 1 element to add. //********************************************************************* template - void insert(const_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_forward_list.cpp b/test/test_forward_list.cpp index 17340ea0..d80f52e3 100644 --- a/test/test_forward_list.cpp +++ b/test/test_forward_list.cpp @@ -1350,6 +1350,18 @@ namespace 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()); + } + //************************************************************************* #if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST TEST(test_forward_list_template_deduction) diff --git a/test/test_list.cpp b/test/test_list.cpp index d9e618eb..273a0fc3 100644 --- a/test/test_list.cpp +++ b/test/test_list.cpp @@ -2028,6 +2028,17 @@ namespace 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()); + } + //************************************************************************* #if ETL_CPP17_SUPPORTED && ETL_USING_INITIALIZER_LIST TEST(test_forward_list_template_deduction) diff --git a/test/test_list_shared_pool.cpp b/test/test_list_shared_pool.cpp index 35598e27..d66cdecb 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); } //************************************************************************* diff --git a/test/test_vector.cpp b/test/test_vector.cpp index 4ad6aeab..b6a64192 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) {