diff --git a/include/etl/stl/alternate/algorithm.h b/include/etl/stl/alternate/algorithm.h index 4248fb31..9dc16b66 100644 --- a/include/etl/stl/alternate/algorithm.h +++ b/include/etl/stl/alternate/algorithm.h @@ -73,7 +73,11 @@ namespace ETLSTD copy(TIterator1 sb, TIterator1 se, TIterator2 db) { typedef typename ETLSTD::iterator_traits::value_type value_t; - return TIterator2(memcpy(db, sb, sizeof(value_t) * (se - sb)) + (se - sb)); + typedef typename ETLSTD::iterator_traits::difference_type difference_t; + + difference_t count = (se - sb); + + return TIterator2(memcpy(db, sb, sizeof(value_t) * count)) + count; } // Other iterator @@ -102,7 +106,7 @@ namespace ETLSTD { typedef typename ETLSTD::iterator_traits::value_type value_t; - return TIterator2(memcpy(db, sb, sizeof(value_t) * count)); + return TIterator2(memcpy(db, sb, sizeof(value_t) * count)) + count; } // Other iterator diff --git a/include/etl/version.h b/include/etl/version.h index 44eab696..924a059f 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 14 #define ETL_VERSION_MINOR 37 -#define ETL_VERSION_PATCH 0 +#define ETL_VERSION_PATCH 1 #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 4ca979ae..3c962aed 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "14.37.0", + "version": "14.37.1", "authors": { "name": "John Wellbelove", "email": "" diff --git a/library.properties b/library.properties index 2b14beb2..776ced92 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=14.37.0 +version=14.37.1 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index c31e9581..46395426 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +14.37.1 +Fix to the return value of alternate STL 'copy' + =============================================================================== 14.37.0 Added etl::indirect_vector diff --git a/test/test_no_stl_algorithm.cpp b/test/test_no_stl_algorithm.cpp index 2f106a7d..6d4e5b98 100644 --- a/test/test_no_stl_algorithm.cpp +++ b/test/test_no_stl_algorithm.cpp @@ -166,8 +166,15 @@ namespace int data1[10]; int data2[10]; - std::copy(std::begin(dataA), std::end(dataA), std::begin(data1)); - etlstd::copy(std::begin(dataA), std::end(dataA), std::begin(data2)); + int* pstl = std::copy(std::begin(dataA), std::end(dataA), std::begin(data1)); + int* petl = etlstd::copy(std::begin(dataA), std::end(dataA), std::begin(data2)); + + using difference_type_t = std::iterator_traits::difference_type; + + difference_type_t dstl = std::distance(data1, pstl); + difference_type_t detl = std::distance(data2, petl); + + CHECK_EQUAL(dstl, detl); bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); CHECK(isEqual); @@ -179,8 +186,15 @@ namespace Data data1[10]; Data data2[10]; - std::copy(std::begin(dataD), std::end(dataD), std::begin(data1)); - etlstd::copy(std::begin(dataD), std::end(dataD), std::begin(data2)); + Data* pstl = std::copy(std::begin(dataD), std::end(dataD), std::begin(data1)); + Data* petl = etlstd::copy(std::begin(dataD), std::end(dataD), std::begin(data2)); + + using difference_type_t = std::iterator_traits::difference_type; + + difference_type_t dstl = std::distance(data1, pstl); + difference_type_t detl = std::distance(data2, petl); + + CHECK_EQUAL(dstl, detl); bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); CHECK(isEqual); @@ -192,8 +206,15 @@ namespace List data1(dataL.size()); List data2(dataL.size()); - std::copy(std::begin(dataA), std::end(dataA), std::begin(data1)); - etlstd::copy(std::begin(dataA), std::end(dataA), std::begin(data2)); + List::iterator pstl = std::copy(std::begin(dataA), std::end(dataA), std::begin(data1)); + List::iterator petl = etlstd::copy(std::begin(dataA), std::end(dataA), std::begin(data2)); + + using difference_type_t = List::difference_type; + + difference_type_t dstl = std::distance(data1.begin(), pstl); + difference_type_t detl = std::distance(data2.begin(), petl); + + CHECK_EQUAL(dstl, detl); bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); CHECK(isEqual); @@ -205,8 +226,15 @@ namespace int data1[10]; int data2[10]; - std::copy_n(std::begin(dataA), 10, std::begin(data1)); - etlstd::copy_n(std::begin(dataA), 10, std::begin(data2)); + int* pstl = std::copy_n(std::begin(dataA), 10, std::begin(data1)); + int* petl = etlstd::copy_n(std::begin(dataA), 10, std::begin(data2)); + + using difference_type_t = std::iterator_traits::difference_type; + + difference_type_t dstl = std::distance(data1, pstl); + difference_type_t detl = std::distance(data2, petl); + + CHECK_EQUAL(dstl, detl); bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); CHECK(isEqual); @@ -218,8 +246,15 @@ namespace Data data1[10]; Data data2[10]; - std::copy_n(std::begin(dataD), 10, std::begin(data1)); - etlstd::copy_n(std::begin(dataD), 10, std::begin(data2)); + Data* pstl = std::copy_n(std::begin(dataD), 10, std::begin(data1)); + Data* petl = etlstd::copy_n(std::begin(dataD), 10, std::begin(data2)); + + using difference_type_t = std::iterator_traits::difference_type; + + difference_type_t dstl = std::distance(data1, pstl); + difference_type_t detl = std::distance(data2, petl); + + CHECK_EQUAL(dstl, detl); bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); CHECK(isEqual); @@ -231,8 +266,15 @@ namespace List data1(dataL.size()); List data2(dataL.size()); - std::copy_n(std::begin(dataA), 10, std::begin(data1)); - etlstd::copy_n(std::begin(dataA), 10, std::begin(data2)); + List::iterator pstl = std::copy_n(std::begin(dataA), 10, std::begin(data1)); + List::iterator petl = etlstd::copy_n(std::begin(dataA), 10, std::begin(data2)); + + using difference_type_t = List::difference_type; + + difference_type_t dstl = std::distance(data1.begin(), pstl); + difference_type_t detl = std::distance(data2.begin(), petl); + + CHECK_EQUAL(dstl, detl); bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); CHECK(isEqual); @@ -244,8 +286,15 @@ namespace int data1[10]; int data2[10]; - std::copy_backward(std::begin(dataA), std::end(dataA), std::end(data1)); - etlstd::copy_backward(std::begin(dataA), std::end(dataA), std::end(data2)); + int* pstl = std::copy_backward(std::begin(dataA), std::end(dataA), std::end(data1)); + int* petl = etlstd::copy_backward(std::begin(dataA), std::end(dataA), std::end(data2)); + + using difference_type_t = std::iterator_traits::difference_type; + + difference_type_t dstl = std::distance(data1, pstl); + difference_type_t detl = std::distance(data2, petl); + + CHECK_EQUAL(dstl, detl); bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); CHECK(isEqual); @@ -257,8 +306,13 @@ namespace Data data1[10]; Data data2[10]; - std::copy_backward(std::begin(dataD), std::end(dataD), std::end(data1)); - etlstd::copy_backward(std::begin(dataD), std::end(dataD), std::end(data2)); + Data* pstl = std::copy_backward(std::begin(dataD), std::end(dataD), std::end(data1)); + Data* petl = etlstd::copy_backward(std::begin(dataD), std::end(dataD), std::end(data2)); + + using difference_type_t = std::iterator_traits::difference_type; + + difference_type_t dstl = std::distance(data1, pstl); + difference_type_t detl = std::distance(data2, petl); bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); CHECK(isEqual); @@ -270,8 +324,13 @@ namespace List data1(dataL.size()); List data2(dataL.size()); - std::copy_backward(std::begin(dataA), std::end(dataA), std::end(data1)); - etlstd::copy_backward(std::begin(dataA), std::end(dataA), std::end(data2)); + List::iterator pstl = copy_backward(std::begin(dataA), std::end(dataA), std::end(data1)); + List::iterator petl = etlstd::copy_backward(std::begin(dataA), std::end(dataA), std::end(data2)); + + using difference_type_t = std::iterator_traits::difference_type; + + difference_type_t dstl = std::distance(data1.begin(), pstl); + difference_type_t detl = std::distance(data2.begin(), petl); bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); CHECK(isEqual);