From 556a529c382309154d2931230f40cf1785b52d29 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 21 Jul 2020 09:58:14 +0100 Subject: [PATCH 01/71] Changed some functions to ETL_CONSTEXPR14 --- include/etl/span.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/etl/span.h b/include/etl/span.h index 2f4f5932..c66ab30d 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -234,7 +234,7 @@ namespace etl //************************************************************************* /// Assign from a span. //************************************************************************* - ETL_CONSTEXPR span& operator =(const span& other) ETL_NOEXCEPT + ETL_CONSTEXPR14 span& operator =(const span& other) ETL_NOEXCEPT { mbegin = other.mbegin; mend = other.mend; From e77729b329498910ac5995d2ed8e12c0668cc136 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 3 Aug 2020 12:01:42 +0100 Subject: [PATCH 02/71] YAML modification Temporarily removed clang-9 section --- .github/workflows/main.yml | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a1d341a3..9a0c7661 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -30,25 +30,4 @@ jobs: name: Testfile path: test/etl_tests - build-clang-9-Linux: - runs-on: ubuntu-18.04 - steps: - - uses: actions/checkout@v2 - - name: Setup cmake - run: | - export CC=clang-9 - export CXX=clang++-9 - cmake -D BUILD_TESTS=ON ./ - - - name: Compile - run: make - - - name: Run tests - run: ./test/etl_tests - - - name: Save artifacts - uses: actions/upload-artifact@v2 - with: - name: Testfile - path: test/etl_tests From 928c9d58893ed73976377dd7145e0c8d2ca01947 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 3 Aug 2020 12:05:12 +0100 Subject: [PATCH 03/71] Github CI YAML modification --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9a0c7661..091a1c31 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,7 +1,7 @@ name: CI on: push: - branches: [ master, hotfix/clang-9 ] + branches: [ master ] pull_request: branches: [ master ] From 7f5fa8d0a56f9576dd7b902e7d2db79c1323010e Mon Sep 17 00:00:00 2001 From: arccosinus0 Date: Fri, 7 Aug 2020 16:13:24 +0200 Subject: [PATCH 04/71] Fix comment for parameter name (#257) --- include/etl/bitset.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/etl/bitset.h b/include/etl/bitset.h index c6538f3e..9d59243d 100644 --- a/include/etl/bitset.h +++ b/include/etl/bitset.h @@ -874,7 +874,7 @@ namespace etl /// The class emulates an array of bool elements, but optimized for space allocation. /// Will accommodate any number of bits. /// Does not use std::string. - ///\tparam N The number of bits. + ///\tparam MAXN The number of bits. ///\ingroup bitset //************************************************************************* template From f339e8d3da3fe1301330d1ba8b83504a5e5b4a93 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 15 Aug 2020 21:00:18 +0100 Subject: [PATCH 05/71] Fixed issue for incorrect operation of erase(const_iterator, const_iterator) when the terminating iterator was end() for etl::unordered_map, etl::unordered_multimap, etl::unordered_set and etl::unordered_multiset. --- include/etl/unordered_map.h | 29 +++++++++++--------- include/etl/unordered_multimap.h | 25 +++++++++++------ include/etl/unordered_multiset.h | 27 ++++++++++++------- include/etl/unordered_set.h | 27 ++++++++++++------- include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 8 +++++- test/test_unordered_map.cpp | 45 +++++++++++++++++++++++++++++++ test/test_unordered_multimap.cpp | 46 ++++++++++++++++++++++++++++++++ test/test_unordered_multiset.cpp | 46 ++++++++++++++++++++++++++++++++ test/test_unordered_set.cpp | 46 ++++++++++++++++++++++++++++++++ test/vs2019/etl.vcxproj | 2 ++ test/vs2019/etl.vcxproj.filters | 6 +++++ 14 files changed, 271 insertions(+), 42 deletions(-) diff --git a/include/etl/unordered_map.h b/include/etl/unordered_map.h index cad0b6d9..2b3c3cf1 100644 --- a/include/etl/unordered_map.h +++ b/include/etl/unordered_map.h @@ -1033,14 +1033,19 @@ namespace etl //********************************************************************* iterator erase(const_iterator first_, const_iterator last_) { - // Make a note of the last. - iterator result((pbuckets + number_of_buckets), last_.get_bucket_list_iterator(), last_.get_local_iterator()); + // Erasing everything? + if ((first_ == begin()) && (last_ == end())) + { + clear(); + return end(); + } // Get the starting point. - bucket_t* pbucket = first_.get_bucket_list_iterator(); - local_iterator iprevious = pbucket->before_begin(); - local_iterator icurrent = first_.get_local_iterator(); - local_iterator iend = last_.get_local_iterator(); // Note: May not be in the same bucket as icurrent. + bucket_t* pbucket = first_.get_bucket_list_iterator(); + bucket_t* pend_bucket = last_.get_bucket_list_iterator(); + local_iterator iprevious = pbucket->before_begin(); + local_iterator icurrent = first_.get_local_iterator(); + local_iterator iend = last_.get_local_iterator(); // Note: May not be in the same bucket as icurrent. // Find the node previous to the first one. while (iprevious->etl_next != &*icurrent) @@ -1048,9 +1053,9 @@ namespace etl ++iprevious; } - while (icurrent != iend) + // Until we reach the end. + while ((icurrent != iend) || (pbucket != pend_bucket)) { - local_iterator inext = pbucket->erase_after(iprevious); // Unlink from the bucket. icurrent->key_value_pair.~value_type(); // Destroy the value. pnodepool->release(&*icurrent); // Release it back to the pool. @@ -1059,8 +1064,8 @@ namespace etl icurrent = inext; - // Are we there yet? - if (icurrent != iend) + // Have we not reached the end? + if ((icurrent != iend) || (pbucket != pend_bucket)) { // At the end of this bucket? if ((icurrent == pbucket->end())) @@ -1072,12 +1077,12 @@ namespace etl } while (pbucket->empty()); iprevious = pbucket->before_begin(); - icurrent = pbucket->begin(); + icurrent = pbucket->begin(); } } } - return result; + return iterator((pbuckets + number_of_buckets), last_.get_bucket_list_iterator(), last_.get_local_iterator()); } //************************************************************************* diff --git a/include/etl/unordered_multimap.h b/include/etl/unordered_multimap.h index fffa8a8d..f1dc9bac 100644 --- a/include/etl/unordered_multimap.h +++ b/include/etl/unordered_multimap.h @@ -909,14 +909,22 @@ namespace etl //********************************************************************* iterator erase(const_iterator first_, const_iterator last_) { + // Erasing everything? + if ((first_ == begin()) && (last_ == end())) + { + clear(); + return end(); + } + // Make a note of the last. iterator result((pbuckets + number_of_buckets), last_.get_bucket_list_iterator(), last_.get_local_iterator()); // Get the starting point. - bucket_t* pbucket = first_.get_bucket_list_iterator(); - local_iterator iprevious = pbucket->before_begin(); - local_iterator icurrent = first_.get_local_iterator(); - local_iterator iend = last_.get_local_iterator(); // Note: May not be in the same bucket as icurrent. + bucket_t* pbucket = first_.get_bucket_list_iterator(); + bucket_t* pend_bucket = last_.get_bucket_list_iterator(); + local_iterator iprevious = pbucket->before_begin(); + local_iterator icurrent = first_.get_local_iterator(); + local_iterator iend = last_.get_local_iterator(); // Note: May not be in the same bucket as icurrent. // Find the node previous to the first one. while (iprevious->etl_next != &*icurrent) @@ -924,7 +932,8 @@ namespace etl ++iprevious; } - while (icurrent != iend) + // Until we reach the end. + while ((icurrent != iend) || (pbucket != pend_bucket)) { local_iterator inext = pbucket->erase_after(iprevious); // Unlink from the bucket. @@ -935,8 +944,8 @@ namespace etl icurrent = inext; - // Are we there yet? - if (icurrent != iend) + // Have we not reached the end? + if ((icurrent != iend) || (pbucket != pend_bucket)) { // At the end of this bucket? if ((icurrent == pbucket->end())) @@ -948,7 +957,7 @@ namespace etl } while (pbucket->empty()); iprevious = pbucket->before_begin(); - icurrent = pbucket->begin(); + icurrent = pbucket->begin(); } } } diff --git a/include/etl/unordered_multiset.h b/include/etl/unordered_multiset.h index decc866e..677a5b1c 100644 --- a/include/etl/unordered_multiset.h +++ b/include/etl/unordered_multiset.h @@ -894,22 +894,31 @@ namespace etl //********************************************************************* iterator erase(const_iterator first_, const_iterator last_) { + // Erasing everything? + if ((first_ == begin()) && (last_ == end())) + { + clear(); + return end(); + } + // Make a note of the last. iterator result((pbuckets + number_of_buckets), last_.get_bucket_list_iterator(), last_.get_local_iterator()); // Get the starting point. - bucket_t* pbucket = first_.get_bucket_list_iterator(); - local_iterator iprevious = pbucket->before_begin(); - local_iterator icurrent = first_.get_local_iterator(); - local_iterator iend = last_.get_local_iterator(); // Note: May not be in the same bucket as icurrent. + bucket_t* pbucket = first_.get_bucket_list_iterator(); + bucket_t* pend_bucket = last_.get_bucket_list_iterator(); + local_iterator iprevious = pbucket->before_begin(); + local_iterator icurrent = first_.get_local_iterator(); + local_iterator iend = last_.get_local_iterator(); // Note: May not be in the same bucket as icurrent. - // Find the node previous to the first one. + // Find the node previous to the first one. while (iprevious->etl_next != &*icurrent) { ++iprevious; } - while (icurrent != iend) + // Until we reach the end. + while ((icurrent != iend) || (pbucket != pend_bucket)) { local_iterator inext = pbucket->erase_after(iprevious); // Unlink from the bucket. @@ -920,8 +929,8 @@ namespace etl icurrent = inext; - // Are we there yet? - if (icurrent != iend) + // Have we not reached the end? + if ((icurrent != iend) || (pbucket != pend_bucket)) { // At the end of this bucket? if ((icurrent == pbucket->end())) @@ -933,7 +942,7 @@ namespace etl } while (pbucket->empty()); iprevious = pbucket->before_begin(); - icurrent = pbucket->begin(); + icurrent = pbucket->begin(); } } } diff --git a/include/etl/unordered_set.h b/include/etl/unordered_set.h index b6257127..4e4322c3 100644 --- a/include/etl/unordered_set.h +++ b/include/etl/unordered_set.h @@ -912,22 +912,31 @@ namespace etl //********************************************************************* iterator erase(const_iterator first_, const_iterator last_) { + // Erasing everything? + if ((first_ == begin()) && (last_ == end())) + { + clear(); + return end(); + } + // Make a note of the last. iterator result((pbuckets + number_of_buckets), last_.get_bucket_list_iterator(), last_.get_local_iterator()); // Get the starting point. - bucket_t* pbucket = first_.get_bucket_list_iterator(); - local_iterator iprevious = pbucket->before_begin(); - local_iterator icurrent = first_.get_local_iterator(); - local_iterator iend = last_.get_local_iterator(); // Note: May not be in the same bucket as icurrent. + bucket_t* pbucket = first_.get_bucket_list_iterator(); + bucket_t* pend_bucket = last_.get_bucket_list_iterator(); + local_iterator iprevious = pbucket->before_begin(); + local_iterator icurrent = first_.get_local_iterator(); + local_iterator iend = last_.get_local_iterator(); // Note: May not be in the same bucket as icurrent. - // Find the node previous to the first one. + // Find the node previous to the first one. while (iprevious->etl_next != &*icurrent) { ++iprevious; } - while (icurrent != iend) + // Until we reach the end. + while ((icurrent != iend) || (pbucket != pend_bucket)) { local_iterator inext = pbucket->erase_after(iprevious); // Unlink from the bucket. @@ -938,8 +947,8 @@ namespace etl icurrent = inext; - // Are we there yet? - if (icurrent != iend) + // Have we not reached the end? + if ((icurrent != iend) || (pbucket != pend_bucket)) { // At the end of this bucket? if ((icurrent == pbucket->end())) @@ -951,7 +960,7 @@ namespace etl } while (pbucket->empty()); iprevious = pbucket->before_begin(); - icurrent = pbucket->begin(); + icurrent = pbucket->begin(); } } } diff --git a/include/etl/version.h b/include/etl/version.h index 93d64b4a..07c33a62 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 18 #define ETL_VERSION_MINOR 12 -#define ETL_VERSION_PATCH 4 +#define ETL_VERSION_PATCH 5 #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) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index ad2a269f..f024aaba 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.12.4", + "version": "18.12.5", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index f28974df..6deb9856 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.12.4 +version=18.12.5 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 6e7cfa7d..360d40d4 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,9 @@ +=============================================================================== +18.12.5 +Fixed issue for incorrect operation of erase(const_iterator, const_iterator) when +the terminating iterator was end() for etl::unordered_map, etl::unordered_multimap, +etl::unordered_set and etl::unordered_multiset. + =============================================================================== 18.12.4 Resolve clang 9 compatibility issues. @@ -84,7 +90,7 @@ Allows set_callback() function to be given run-time and compile-time pointers to =============================================================================== 18.3.4 -Changed std::move to etl::move in std::optional and std::queue +Changed std::move to etl::move in etl::optional and etl::queue Fixed etl::span subspan with etl::dynamic_extent =============================================================================== diff --git a/test/test_unordered_map.cpp b/test/test_unordered_map.cpp index 658e4985..72b36e51 100644 --- a/test/test_unordered_map.cpp +++ b/test/test_unordered_map.cpp @@ -628,6 +628,51 @@ namespace CHECK(idata != data.end()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_first_half) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + DataNDC::iterator end = data.begin(); + etl::advance(end, data.size() / 2); + + auto itr = data.erase(data.begin(), end); + + CHECK_EQUAL(initial_data.size() / 2, data.size()); + CHECK(!data.full()); + CHECK(!data.empty()); + CHECK(itr == end); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_last_half) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + DataNDC::iterator begin = data.begin(); + etl::advance(begin, data.size() / 2); + + auto itr = data.erase(begin, data.end()); + + CHECK_EQUAL(initial_data.size() / 2, data.size()); + CHECK(!data.full()); + CHECK(!data.empty()); + CHECK(itr == data.end()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_all) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + auto itr = data.erase(data.begin(), data.end()); + + CHECK_EQUAL(0U, data.size()); + CHECK(!data.full()); + CHECK(data.empty()); + CHECK(itr == data.end()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { diff --git a/test/test_unordered_multimap.cpp b/test/test_unordered_multimap.cpp index ea6f53b9..95d16f46 100644 --- a/test/test_unordered_multimap.cpp +++ b/test/test_unordered_multimap.cpp @@ -541,6 +541,52 @@ namespace CHECK(idata != data.end()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_first_half) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + DataNDC::iterator end = data.begin(); + etl::advance(end, data.size() / 2); + + auto itr = data.erase(data.begin(), end); + + CHECK_EQUAL(initial_data.size() / 2, data.size()); + CHECK(!data.full()); + CHECK(!data.empty()); + CHECK(itr == end); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_last_half) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + DataNDC::iterator begin = data.begin(); + etl::advance(begin, data.size() / 2); + + auto itr = data.erase(begin, data.end()); + + CHECK_EQUAL(initial_data.size() / 2, data.size()); + CHECK(!data.full()); + CHECK(!data.empty()); + CHECK(itr == data.end()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_all) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + auto itr = data.erase(data.begin(), data.end()); + + CHECK_EQUAL(0U, data.size()); + CHECK(!data.full()); + CHECK(data.empty()); + CHECK(itr == data.end()); + } + + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { diff --git a/test/test_unordered_multiset.cpp b/test/test_unordered_multiset.cpp index 6e47557f..6dbb3dc7 100644 --- a/test/test_unordered_multiset.cpp +++ b/test/test_unordered_multiset.cpp @@ -479,6 +479,52 @@ namespace CHECK(idata != data.end()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_first_half) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + DataNDC::iterator end = data.begin(); + etl::advance(end, data.size() / 2); + + auto itr = data.erase(data.begin(), end); + + CHECK_EQUAL(initial_data.size() / 2, data.size()); + CHECK(!data.full()); + CHECK(!data.empty()); + CHECK(itr == end); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_last_half) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + DataNDC::iterator begin = data.begin(); + etl::advance(begin, data.size() / 2); + + auto itr = data.erase(begin, data.end()); + + CHECK_EQUAL(initial_data.size() / 2, data.size()); + CHECK(!data.full()); + CHECK(!data.empty()); + CHECK(itr == data.end()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_all) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + auto itr = data.erase(data.begin(), data.end()); + + CHECK_EQUAL(0U, data.size()); + CHECK(!data.full()); + CHECK(data.empty()); + CHECK(itr == data.end()); + } + + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { diff --git a/test/test_unordered_set.cpp b/test/test_unordered_set.cpp index f55cd41c..5d316dd0 100644 --- a/test/test_unordered_set.cpp +++ b/test/test_unordered_set.cpp @@ -459,6 +459,52 @@ namespace CHECK(idata != data.end()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_first_half) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + DataNDC::iterator end = data.begin(); + etl::advance(end, data.size() / 2); + + auto itr = data.erase(data.begin(), end); + + CHECK_EQUAL(initial_data.size() / 2, data.size()); + CHECK(!data.full()); + CHECK(!data.empty()); + CHECK(itr == end); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_last_half) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + DataNDC::iterator begin = data.begin(); + etl::advance(begin, data.size() / 2); + + auto itr = data.erase(begin, data.end()); + + CHECK_EQUAL(initial_data.size() / 2, data.size()); + CHECK(!data.full()); + CHECK(!data.empty()); + CHECK(itr == data.end()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_range_all) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + auto itr = data.erase(data.begin(), data.end()); + + CHECK_EQUAL(0U, data.size()); + CHECK(!data.full()); + CHECK(data.empty()); + CHECK(itr == data.end()); + } + + //************************************************************************* TEST_FIXTURE(SetupFixture, test_clear) { diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 59eb876a..262d2618 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -1687,9 +1687,11 @@ + + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index f10c59f7..849cf756 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -1444,6 +1444,9 @@ Resource Files\CI\Github + + Resource Files\Make + @@ -1458,6 +1461,9 @@ Resource Files + + Resource Files\Make + From 6788f2761ec158bc0f67db0eb2a68336051f0b97 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 16 Aug 2020 11:32:23 +0100 Subject: [PATCH 06/71] Fixed issue for incorrect operation of erase(const_iterator, const_iterator) when the terminating iterator was end() for etl::unordered_map, etl::unordered_multimap, etl::unordered_set and etl::unordered_multiset. --- include/etl/unordered_multimap.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/etl/unordered_multimap.h b/include/etl/unordered_multimap.h index f1dc9bac..8810bc8a 100644 --- a/include/etl/unordered_multimap.h +++ b/include/etl/unordered_multimap.h @@ -926,7 +926,7 @@ namespace etl local_iterator icurrent = first_.get_local_iterator(); local_iterator iend = last_.get_local_iterator(); // Note: May not be in the same bucket as icurrent. - // Find the node previous to the first one. + // Find the node previous to the first one. while (iprevious->etl_next != &*icurrent) { ++iprevious; From ae64cfa681b6603fc001dc1007819c6ebe4bf1f2 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 25 Aug 2020 11:44:40 +0100 Subject: [PATCH 07/71] Initial Bresenham line algorithm --- include/etl/bresenham.h | 300 ++++++++++++++++++++++++++++++++ test/vs2019/etl.vcxproj | 1 + test/vs2019/etl.vcxproj.filters | 6 + 3 files changed, 307 insertions(+) create mode 100644 include/etl/bresenham.h diff --git a/include/etl/bresenham.h b/include/etl/bresenham.h new file mode 100644 index 00000000..3ed8df55 --- /dev/null +++ b/include/etl/bresenham.h @@ -0,0 +1,300 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2020 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_BRESENHAM_LINE_INCLUDED +#define ETL_BRESENHAM_LINE_INCLUDED + +#include + +#include "platform.h" +#include "iterator.h" +#include "exception.h" + +namespace etl +{ + //*************************************************************************** + /// A pseudo-container that generates points on a line, using Bresenham's + /// line algorithm. + //*************************************************************************** + template + class bresenham_line + { + public: + + //*************************************************** + /// Standard container types. + //*************************************************** + typedef TPoint value_type; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* pointer; + typedef const value_type* const_pointer; + + friend class const_iterator; + + class const_iterator : public etl::iterator + { + public: + + friend class bresenham_line; + + //*************************************************** + /// + //*************************************************** + const_iterator() + : p_bresenham_line(ETL_NULLPTR) + { + } + + //*************************************************** + /// + //*************************************************** + const_iterator(const const_iterator& other) + : p_bresenham_line(other.p_bresenham_line) + { + } + + //*************************************************** + /// + //*************************************************** + const_iterator& operator =(const const_iterator& rhs) + { + p_bresenham_line = rhs.p_bresenham_line; + } + + //*************************************************** + /// + //*************************************************** + const_iterator& operator ++() + { + // Has the end of the series has been reached? + if (p_bresenham_line->count == 0) + { + // Mark it as an end iterator. + p_bresenham_line = ETL_NULLPTR; + } + else + { + p_bresenham_line->next(); + } + + return *this; + } + + //*************************************************** + /// + //*************************************************** + value_type operator *() const + { + return p_bresenham_line->get_point(); + } + + //*************************************************** + /// + //*************************************************** + value_type operator ->() const + { + return p_bresenham_line->get_point(); + } + + private: + + //*************************************************** + /// + //*************************************************** + const_iterator(bresenham_line* pb) + : p_bresenham_line(pb) + { + } + + bresenham_line* p_bresenham_line; + }; + + //*************************************************** + /// Constructor. + //*************************************************** + bresenham_line(const_reference start_, const_reference end_) + : start(start_) + , end(end_) + , current(start_) + , x_increment((end_.x < start_.x) ? -1 : 1) + , y_increment((end_.y < start_.y) ? -1 : 1) + , do_minor_increment(true) + { + dx = (end_.x < start_.x) ? start_.x - end_.x : end_.x - start_.x; + dy = (end_.y < start_.y) ? start_.y - end_.y : end_.y - start_.y; + + major_axis = (dx < dy) ? Axis::Y : Axis::X; + + if (major_axis == Axis::X) + { + total_count = dx; + dy *= 2; + balance = dy - dx; + dx *= 2; + } + else + { + total_count = dy; + dx *= 2; + balance = dx - dy; + dy *= 2; + } + + current_count = total_count; + } + + //*************************************************** + /// + //*************************************************** + const_iterator begin() const + { + current_count = total_count; + current = start; + + return const_iterator(this); + } + + //*************************************************** + /// + //*************************************************** + const_iterator cbegin() const + { + current_count = total_count; + current = start; + + return const_iterator(this); + } + + //*************************************************** + /// + //*************************************************** + const_iterator end() const + { + return const_iterator(); + } + + //*************************************************** + /// + //*************************************************** + const_iterator cend() const + { + return const_iterator(); + } + + //*************************************************** + /// Get the size of the series. + //*************************************************** + size_t size() const + { + return total_count; + } + + //*************************************************** + /// Get the current number of generated points. + //*************************************************** + size_t count() const + { + return current_count; + } + + private: + + //*************************************************** + /// The major axis. + //*************************************************** + struct Axis + { + enum + { + X, + Y + }; + }; + + //*************************************************** + /// Calculate the next point. + //*************************************************** + void next() + { + if (major_axis == Axis::X) + { + if (do_minor_increment) + { + current.y += y_increment; + balance -= dx; + } + + current.x += x_increment; + balance += dy; + } + else + { + if (do_minor_increment) + { + current.x += x_increment; + balance -= dy; + } + + current.y += y_increment; + balance += dx; + } + + --current_count; + + do_minor_increment = (balance >= 0); + } + + //*************************************************** + /// Get the current point. + //*************************************************** + value_type get_point() const + { + return current; + } + + const value_type start; + const value_type end; + value_type current; + const TIntegral x_increment; + const TIntegral y_increment; + TIntegral dx; + TIntegral dy; + TIntegral major_axis; + TIntegral count; + TIntegral current_count; + TIntegral balance; + bool do_minor_increment; + }; + +#endif + diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 262d2618..a1854ee9 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -1015,6 +1015,7 @@ + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index 849cf756..18871841 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -79,6 +79,9 @@ {c25471f3-451a-4279-925d-cbdcec912ef8} + + {586d2c92-e504-4dea-9b1f-42d725a5272c} + @@ -876,6 +879,9 @@ ETL\Strings + + ETL\Pseudo Containers + From 4f20a9e3db29f7b2717ab7433947c6c2e44d5113 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 25 Aug 2020 12:47:23 +0100 Subject: [PATCH 08/71] Initial Bresenham line algorithm --- include/etl/bresenham.h | 61 +++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/include/etl/bresenham.h b/include/etl/bresenham.h index 3ed8df55..21a76992 100644 --- a/include/etl/bresenham.h +++ b/include/etl/bresenham.h @@ -41,7 +41,7 @@ namespace etl { //*************************************************************************** /// A pseudo-container that generates points on a line, using Bresenham's - /// line algorithm. + /// line algorithm. //*************************************************************************** template class bresenham_line @@ -153,22 +153,20 @@ namespace etl dx = (end_.x < start_.x) ? start_.x - end_.x : end_.x - start_.x; dy = (end_.y < start_.y) ? start_.y - end_.y : end_.y - start_.y; - major_axis = (dx < dy) ? Axis::Y : Axis::X; - - if (major_axis == Axis::X) - { - total_count = dx; - dy *= 2; - balance = dy - dx; - dx *= 2; - } - else + if (is_y_major_axis()) { total_count = dy; dx *= 2; balance = dx - dy; dy *= 2; } + else + { + total_count = dx; + dy *= 2; + balance = dy - dx; + dx *= 2; + } current_count = total_count; } @@ -230,35 +228,21 @@ namespace etl private: //*************************************************** - /// The major axis. + /// Returns true if Y is the major axis. //*************************************************** - struct Axis + int is_y_major_axis() const { - enum - { - X, - Y - }; - }; + return dx < dy; + } //*************************************************** /// Calculate the next point. //*************************************************** void next() { - if (major_axis == Axis::X) - { - if (do_minor_increment) - { - current.y += y_increment; - balance -= dx; - } - - current.x += x_increment; - balance += dy; - } - else + if (is_y_major_axis()) { + // Y major axis. if (do_minor_increment) { current.x += x_increment; @@ -268,6 +252,18 @@ namespace etl current.y += y_increment; balance += dx; } + else + { + // X major axis. + if (do_minor_increment) + { + current.y += y_increment; + balance -= dx; + } + + current.x += x_increment; + balance += dy; + } --current_count; @@ -289,8 +285,7 @@ namespace etl const TIntegral y_increment; TIntegral dx; TIntegral dy; - TIntegral major_axis; - TIntegral count; + TIntegral total_count; TIntegral current_count; TIntegral balance; bool do_minor_increment; From 8e76238439de4bb24ab36e72826e594ca05116e1 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 26 Aug 2020 12:36:47 +0100 Subject: [PATCH 09/71] Added all units tests --- include/etl/{bresenham.h => bresenham_line.h} | 122 +++--- test/test_bresenham_line.cpp | 346 ++++++++++++++++++ test/vs2019/etl.vcxproj | 3 +- test/vs2019/etl.vcxproj.filters | 5 +- 4 files changed, 412 insertions(+), 64 deletions(-) rename include/etl/{bresenham.h => bresenham_line.h} (74%) create mode 100644 test/test_bresenham_line.cpp diff --git a/include/etl/bresenham.h b/include/etl/bresenham_line.h similarity index 74% rename from include/etl/bresenham.h rename to include/etl/bresenham_line.h index 21a76992..7576ff2b 100644 --- a/include/etl/bresenham.h +++ b/include/etl/bresenham_line.h @@ -42,6 +42,8 @@ namespace etl //*************************************************************************** /// A pseudo-container that generates points on a line, using Bresenham's /// line algorithm. + /// TPoint must support integral x & y members. + /// TIntegral is the internal working variable type. Default is int. //*************************************************************************** template class bresenham_line @@ -54,14 +56,12 @@ namespace etl typedef TPoint value_type; typedef size_t size_type; typedef ptrdiff_t difference_type; - typedef value_type& reference; + typedef value_type& reference; typedef const value_type& const_reference; - typedef value_type* pointer; + typedef value_type* pointer; typedef const value_type* const_pointer; - friend class const_iterator; - - class const_iterator : public etl::iterator + class iterator : public etl::iterator { public: @@ -70,7 +70,7 @@ namespace etl //*************************************************** /// //*************************************************** - const_iterator() + iterator() : p_bresenham_line(ETL_NULLPTR) { } @@ -78,7 +78,7 @@ namespace etl //*************************************************** /// //*************************************************** - const_iterator(const const_iterator& other) + iterator(const iterator& other) : p_bresenham_line(other.p_bresenham_line) { } @@ -86,7 +86,7 @@ namespace etl //*************************************************** /// //*************************************************** - const_iterator& operator =(const const_iterator& rhs) + iterator& operator =(const iterator& rhs) { p_bresenham_line = rhs.p_bresenham_line; } @@ -94,10 +94,10 @@ namespace etl //*************************************************** /// //*************************************************** - const_iterator& operator ++() + iterator& operator ++() { // Has the end of the series has been reached? - if (p_bresenham_line->count == 0) + if (p_bresenham_line->current_count == 0) { // Mark it as an end iterator. p_bresenham_line = ETL_NULLPTR; @@ -126,46 +126,62 @@ namespace etl return p_bresenham_line->get_point(); } + //*************************************************** + /// + //*************************************************** + friend bool operator ==(const iterator& lhs, const iterator& rhs) + { + return lhs.p_bresenham_line == rhs.p_bresenham_line; + } + + //*************************************************** + /// + //*************************************************** + friend bool operator !=(const iterator& lhs, const iterator& rhs) + { + return !(lhs == rhs); + } + private: //*************************************************** /// //*************************************************** - const_iterator(bresenham_line* pb) + iterator(bresenham_line* pb) : p_bresenham_line(pb) { } - bresenham_line* p_bresenham_line; + bresenham_line* p_bresenham_line; }; //*************************************************** /// Constructor. //*************************************************** - bresenham_line(const_reference start_, const_reference end_) - : start(start_) - , end(end_) - , current(start_) - , x_increment((end_.x < start_.x) ? -1 : 1) - , y_increment((end_.y < start_.y) ? -1 : 1) - , do_minor_increment(true) + bresenham_line(const_reference first_, const_reference last_) + : first(first_) + , last(last_) + , current(first_) + , x_increment((last_.x < first_.x) ? -1 : 1) + , y_increment((last_.y < first_.y) ? -1 : 1) + , do_minor_increment(false) { - dx = (end_.x < start_.x) ? start_.x - end_.x : end_.x - start_.x; - dy = (end_.y < start_.y) ? start_.y - end_.y : end_.y - start_.y; + dx = (last_.x < first_.x) ? first_.x - last_.x : last_.x - first_.x; + dy = (last_.y < first_.y) ? first_.y - last_.y : last_.y - first_.y; if (is_y_major_axis()) { total_count = dy; - dx *= 2; - balance = dx - dy; - dy *= 2; + dx *= 2; + balance = dx - dy; + dy *= 2; } else { total_count = dx; - dy *= 2; - balance = dy - dx; - dx *= 2; + dy *= 2; + balance = dy - dx; + dx *= 2; } current_count = total_count; @@ -174,39 +190,20 @@ namespace etl //*************************************************** /// //*************************************************** - const_iterator begin() const + iterator begin() { current_count = total_count; - current = start; + current = first; - return const_iterator(this); + return iterator(this); } //*************************************************** /// //*************************************************** - const_iterator cbegin() const + iterator end() const { - current_count = total_count; - current = start; - - return const_iterator(this); - } - - //*************************************************** - /// - //*************************************************** - const_iterator end() const - { - return const_iterator(); - } - - //*************************************************** - /// - //*************************************************** - const_iterator cend() const - { - return const_iterator(); + return iterator(); } //*************************************************** @@ -278,18 +275,19 @@ namespace etl return current; } - const value_type start; - const value_type end; - value_type current; - const TIntegral x_increment; - const TIntegral y_increment; - TIntegral dx; - TIntegral dy; - TIntegral total_count; - TIntegral current_count; - TIntegral balance; - bool do_minor_increment; + const value_type first; + const value_type last; + value_type current; + const TIntegral x_increment; + const TIntegral y_increment; + TIntegral dx; + TIntegral dy; + TIntegral total_count; + TIntegral current_count; + TIntegral balance; + bool do_minor_increment; }; +} #endif diff --git a/test/test_bresenham_line.cpp b/test/test_bresenham_line.cpp new file mode 100644 index 00000000..3de7f2b8 --- /dev/null +++ b/test/test_bresenham_line.cpp @@ -0,0 +1,346 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2020 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "UnitTest++/UnitTest++.h" + +#include "etl/bresenham_line.h" + +#include + +namespace +{ + struct Point + { + int x; + int y; + }; + + bool operator ==(Point lhs, Point rhs) + { + return (lhs.x == rhs.x) && (lhs.y == rhs.y); + } + + std::ostream& operator << (std::ostream& os, Point point) + { + os << "(" << point.x << "," << point.y << ")"; + return os; + } + + using BresenhamLine = etl::bresenham_line; + + SUITE(test_bresenham_line) + { + //************************************************************************* + TEST(horizontal_line_left_right) + { + Point first = { -5, 5 }; + Point last = { 5, 5 }; + + BresenhamLine bl(first, last); + + BresenhamLine::iterator itr = bl.begin(); + + std::vector expected{ Point{-5, 5 }, Point{-4, 5 }, Point{-3, 5 }, Point{-2, 5 }, Point{-1, 5 }, Point{ 0, 5 }, + Point{ 1, 5 }, Point{ 2, 5 }, Point{ 3, 5 }, Point{ 4, 5 }, Point{ 5, 5} }; + std::vector actual; + + while (itr != bl.end()) + { + actual.push_back(*itr); + ++itr; + } + + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(horizontal_line_right_left) + { + Point first = { 5, 5 }; + Point last = { -5, 5 }; + + BresenhamLine bl(first, last); + + BresenhamLine::iterator itr = bl.begin(); + + std::vector expected{ Point{ 5, 5 }, Point{ 4, 5 }, Point{ 3, 5 }, Point{ 2, 5 }, Point{ 1, 5 }, Point{ 0, 5 }, + Point{-1, 5 }, Point{-2, 5 }, Point{-3, 5 }, Point{-4, 5 }, Point{-5, 5} }; + std::vector actual; + + while (itr != bl.end()) + { + actual.push_back(*itr); + ++itr; + } + + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(vertical_line_bottom_top) + { + Point first = { 5, -5 }; + Point last = { 5, 5 }; + + BresenhamLine bl(first, last); + + BresenhamLine::iterator itr = bl.begin(); + + std::vector expected{ Point{ 5, -5 }, Point{ 5, -4 }, Point{ 5, -3 }, Point{ 5, -2 }, Point{ 5, -1 }, Point{ 5, 0 }, + Point{ 5, 1 }, Point{ 5, 2 }, Point{ 5, 3 }, Point{ 5, 4 }, Point{ 5, 5} }; + std::vector actual; + + while (itr != bl.end()) + { + actual.push_back(*itr); + ++itr; + } + + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(vertical_line_top_bottom) + { + Point first = { 5, 5 }; + Point last = { 5, -5 }; + + BresenhamLine bl(first, last); + + BresenhamLine::iterator itr = bl.begin(); + + std::vector expected{ Point{ 5, 5 }, Point{ 5, 4 }, Point{ 5, 3 }, Point{ 5, 2 }, Point{ 5, 1 }, Point{ 5, 0 }, + Point{ 5, -1 }, Point{ 5, -2 }, Point{ 5, -3 }, Point{ 5, -4 }, Point{ 5, -5} }; + std::vector actual; + + while (itr != bl.end()) + { + actual.push_back(*itr); + ++itr; + } + + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(low_slope_diagonal_line_bottom_left_top_right) + { + Point first = { -5, -3 }; + Point last = { 5, 3}; + + BresenhamLine bl(first, last); + + BresenhamLine::iterator itr = bl.begin(); + + std::vector expected{ Point{ -5, -3 }, Point{ -4, -3 }, Point{ -3, -2 }, Point{ -2, -1 }, Point{ -1, -1 }, Point{ 0, 0 }, + Point{ 1, 1 }, Point{ 2, 1 }, Point{ 3, 2 }, Point{ 4, 2 }, Point{ 5, 3 } }; + std::vector actual; + + while (itr != bl.end()) + { + actual.push_back(*itr); + ++itr; + } + + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(low_slope_diagonal_line_top_right_bottom_left) + { + Point first = { 5, 3 }; + Point last = { -5, -3 }; + + BresenhamLine bl(first, last); + + BresenhamLine::iterator itr = bl.begin(); + + std::vector expected{ Point{ 5, 3 }, Point{ 4, 3 }, Point{ 3, 2 }, Point{ 2, 1 }, Point{ 1, 1 }, Point{ 0, 0 }, + Point{ -1, -1 }, Point{ -2, -1 }, Point{ -3, -2 }, Point{ -4, -2 }, Point{ -5, -3 } }; + std::vector actual; + + while (itr != bl.end()) + { + actual.push_back(*itr); + ++itr; + } + + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(low_slope_diagonal_line_bottom_right_top_left) + { + Point first = { 5, -3 }; + Point last = { -5, 3 }; + + BresenhamLine bl(first, last); + + BresenhamLine::iterator itr = bl.begin(); + + std::vector expected{ Point{ 5, -3 }, Point{ 4, -3 }, Point{ 3, -2 }, Point{ 2, -1 }, Point{ 1, -1 }, Point{ 0, 0 }, + Point{ -1, 1 }, Point{ -2, 1 }, Point{ -3, 2 }, Point{ -4, 2 }, Point{ -5, 3 } }; + std::vector actual; + + while (itr != bl.end()) + { + actual.push_back(*itr); + ++itr; + } + + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(low_slope_diagonal_line_top_left_bottom_right) + { + Point first = { -5, 3 }; + Point last = { 5, -3 }; + + BresenhamLine bl(first, last); + + BresenhamLine::iterator itr = bl.begin(); + + std::vector expected{ Point{ -5, 3 }, Point{ -4, 3 }, Point{ -3, 2 }, Point{ -2, 1 }, Point{ -1, 1 }, Point{ 0, 0 }, + Point{ 1, -1 }, Point{ 2, -1 }, Point{ 3, -2 }, Point{ 4, -2 }, Point{ 5, -3 } }; + std::vector actual; + + while (itr != bl.end()) + { + actual.push_back(*itr); + ++itr; + } + + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(high_slope_diagonal_line_bottom_left_top_right) + { + Point first = { -3, -5 }; + Point last = { 3, 5 }; + + BresenhamLine bl(first, last); + + BresenhamLine::iterator itr = bl.begin(); + + std::vector expected{ Point{ -3, -5 }, Point{ -3, -4 }, Point{ -2, -3 }, Point{ -1, -2 }, Point{ -1, -1 }, Point{ 0, 0 }, + Point{ 1, 1 }, Point{ 1, 2 }, Point{ 2, 3 }, Point{ 2, 4 }, Point{ 3, 5 } }; + std::vector actual; + + while (itr != bl.end()) + { + actual.push_back(*itr); + ++itr; + } + + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(high_slope_diagonal_line_top_right_bottom_left) + { + Point first = { 3, 5 }; + Point last = { -3, -5 }; + + BresenhamLine bl(first, last); + + BresenhamLine::iterator itr = bl.begin(); + + std::vector expected{ Point{ 3, 5 }, Point{ 3, 4 }, Point{ 2, 3 }, Point{ 1, 2 }, Point{ 1, 1 }, Point{ 0, 0 }, + Point{ -1, -1 }, Point{ -1, -2 }, Point{ -2, -3 }, Point{ -2, -4 }, Point{ -3, -5 } }; + std::vector actual; + + while (itr != bl.end()) + { + actual.push_back(*itr); + ++itr; + } + + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(high_slope_diagonal_line_bottom_right_top_left) + { + Point first = { 3, -5 }; + Point last = { -3, 5 }; + + BresenhamLine bl(first, last); + + BresenhamLine::iterator itr = bl.begin(); + + std::vector expected{ Point{ 3, -5 }, Point{ 3, -4 }, Point{ 2, -3 }, Point{ 1, -2 }, Point{ 1, -1 }, Point{ 0, 0 }, + Point{ -1, 1 }, Point{ -1, 2 }, Point{ -2, 3 }, Point{ -2, 4 }, Point{ -3, 5 } }; + std::vector actual; + + while (itr != bl.end()) + { + actual.push_back(*itr); + ++itr; + } + + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(high_slope_diagonal_line_top_left_bottom_right) + { + Point first = { -3, 5 }; + Point last = { 3, -5 }; + + BresenhamLine bl(first, last); + + BresenhamLine::iterator itr = bl.begin(); + + std::vector expected{ Point{ -3, 5 }, Point{ -3, 4 }, Point{ -2, 3 }, Point{ -1, 2 }, Point{ -1, 1 }, Point{ 0, 0 }, + Point{ 1, -1 }, Point{ 1, -2 }, Point{ 2, -3 }, Point{ 2, -4 }, Point{ 3, -5 } }; + std::vector actual; + + while (itr != bl.end()) + { + actual.push_back(*itr); + ++itr; + } + + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + }; +} diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index a1854ee9..505f4b3a 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -1015,7 +1015,7 @@ - + @@ -1266,6 +1266,7 @@ + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index 18871841..cdaf4af2 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -879,7 +879,7 @@ ETL\Strings - + ETL\Pseudo Containers @@ -1394,6 +1394,9 @@ Source Files + + Source Files + From 9910569b76ffb812a0f4780f1cfcfee11cc47555 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 27 Aug 2020 10:45:57 +0100 Subject: [PATCH 10/71] Small refactoring --- include/etl/bresenham_line.h | 115 +++++++++++++++++------------------ test/test_bresenham_line.cpp | 96 ++++++++++++++--------------- 2 files changed, 103 insertions(+), 108 deletions(-) diff --git a/include/etl/bresenham_line.h b/include/etl/bresenham_line.h index 7576ff2b..0fbe1eed 100644 --- a/include/etl/bresenham_line.h +++ b/include/etl/bresenham_line.h @@ -42,10 +42,10 @@ namespace etl //*************************************************************************** /// A pseudo-container that generates points on a line, using Bresenham's /// line algorithm. - /// TPoint must support integral x & y members. - /// TIntegral is the internal working variable type. Default is int. + /// TCoordinate must support integral x & y members. + /// TWorking is the internal working variable type. Default is int. //*************************************************************************** - template + template class bresenham_line { public: @@ -53,22 +53,22 @@ namespace etl //*************************************************** /// Standard container types. //*************************************************** - typedef TPoint value_type; + typedef TCoordinate value_type; typedef size_t size_type; typedef ptrdiff_t difference_type; - typedef value_type& reference; + typedef value_type& reference; typedef const value_type& const_reference; - typedef value_type* pointer; + typedef value_type* pointer; typedef const value_type* const_pointer; - class iterator : public etl::iterator + class iterator : public etl::iterator { public: friend class bresenham_line; //*************************************************** - /// + /// Default constructor //*************************************************** iterator() : p_bresenham_line(ETL_NULLPTR) @@ -76,7 +76,7 @@ namespace etl } //*************************************************** - /// + /// Copy constuctor //*************************************************** iterator(const iterator& other) : p_bresenham_line(other.p_bresenham_line) @@ -84,20 +84,22 @@ namespace etl } //*************************************************** - /// + /// Assignment operator //*************************************************** iterator& operator =(const iterator& rhs) { p_bresenham_line = rhs.p_bresenham_line; + + return *this; } //*************************************************** - /// + /// Pre-increment operator //*************************************************** iterator& operator ++() { // Has the end of the series has been reached? - if (p_bresenham_line->current_count == 0) + if (p_bresenham_line->n_coordinates_remaining == TWorking(0)) { // Mark it as an end iterator. p_bresenham_line = ETL_NULLPTR; @@ -111,23 +113,15 @@ namespace etl } //*************************************************** - /// + /// De-reference operator //*************************************************** value_type operator *() const { - return p_bresenham_line->get_point(); + return p_bresenham_line->get_coordinate(); } //*************************************************** - /// - //*************************************************** - value_type operator ->() const - { - return p_bresenham_line->get_point(); - } - - //*************************************************** - /// + /// Equality operator //*************************************************** friend bool operator ==(const iterator& lhs, const iterator& rhs) { @@ -135,7 +129,7 @@ namespace etl } //*************************************************** - /// + /// Inequality operator //*************************************************** friend bool operator !=(const iterator& lhs, const iterator& rhs) { @@ -145,61 +139,61 @@ namespace etl private: //*************************************************** - /// + /// Constructor for use by bresenham_line //*************************************************** - iterator(bresenham_line* pb) + iterator(bresenham_line* pb) : p_bresenham_line(pb) { } - bresenham_line* p_bresenham_line; + bresenham_line* p_bresenham_line; }; //*************************************************** /// Constructor. + /// Supplied first and last coordinates //*************************************************** bresenham_line(const_reference first_, const_reference last_) : first(first_) - , last(last_) - , current(first_) + , coordinate(first_) , x_increment((last_.x < first_.x) ? -1 : 1) , y_increment((last_.y < first_.y) ? -1 : 1) + , dx((last_.x < first_.x) ? first_.x - last_.x : last_.x - first_.x) + , dy((last_.y < first_.y) ? first_.y - last_.y : last_.y - first_.y) , do_minor_increment(false) { - dx = (last_.x < first_.x) ? first_.x - last_.x : last_.x - first_.x; - dy = (last_.y < first_.y) ? first_.y - last_.y : last_.y - first_.y; - if (is_y_major_axis()) { - total_count = dy; + total_n_coordinates = dy + 1; dx *= 2; balance = dx - dy; dy *= 2; } else { - total_count = dx; + total_n_coordinates = dx + 1; dy *= 2; balance = dy - dx; dx *= 2; } - current_count = total_count; + n_coordinates_remaining = total_n_coordinates - 1; // We already have the first coordinate. } //*************************************************** - /// + /// Get an iterator to the first coordinate. + /// Resets the Bresenham line. //*************************************************** iterator begin() { - current_count = total_count; - current = first; + n_coordinates_remaining = total_n_coordinates - 1; // We already have the first coordinate. + coordinate = first; return iterator(this); } //*************************************************** - /// + /// Get an iterator to one past the last coordinate. //*************************************************** iterator end() const { @@ -211,7 +205,7 @@ namespace etl //*************************************************** size_t size() const { - return total_count; + return total_n_coordinates; } //*************************************************** @@ -219,7 +213,7 @@ namespace etl //*************************************************** size_t count() const { - return current_count; + return total_n_coordinates - n_coordinates_remaining; } private: @@ -242,11 +236,11 @@ namespace etl // Y major axis. if (do_minor_increment) { - current.x += x_increment; + coordinate.x += x_increment; balance -= dy; } - current.y += y_increment; + coordinate.y += y_increment; balance += dx; } else @@ -254,38 +248,39 @@ namespace etl // X major axis. if (do_minor_increment) { - current.y += y_increment; + coordinate.y += y_increment; balance -= dx; } - current.x += x_increment; + coordinate.x += x_increment; balance += dy; } - --current_count; + --n_coordinates_remaining; do_minor_increment = (balance >= 0); } //*************************************************** - /// Get the current point. + /// Get the current coordinate. //*************************************************** - value_type get_point() const + value_type get_coordinate() const { - return current; + return coordinate; } - const value_type first; - const value_type last; - value_type current; - const TIntegral x_increment; - const TIntegral y_increment; - TIntegral dx; - TIntegral dy; - TIntegral total_count; - TIntegral current_count; - TIntegral balance; - bool do_minor_increment; + typedef TWorking working_t; + + const value_type first; + value_type coordinate; + const working_t x_increment; + const working_t y_increment; + working_t dx; + working_t dy; + working_t total_n_coordinates; + working_t n_coordinates_remaining; + working_t balance; + bool do_minor_increment; }; } diff --git a/test/test_bresenham_line.cpp b/test/test_bresenham_line.cpp index 3de7f2b8..d3512658 100644 --- a/test/test_bresenham_line.cpp +++ b/test/test_bresenham_line.cpp @@ -63,18 +63,18 @@ namespace BresenhamLine bl(first, last); - BresenhamLine::iterator itr = bl.begin(); - std::vector expected{ Point{-5, 5 }, Point{-4, 5 }, Point{-3, 5 }, Point{-2, 5 }, Point{-1, 5 }, Point{ 0, 5 }, Point{ 1, 5 }, Point{ 2, 5 }, Point{ 3, 5 }, Point{ 4, 5 }, Point{ 5, 5} }; std::vector actual; - while (itr != bl.end()) + CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. + + for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); - ++itr; } + CHECK_EQUAL(expected.size(), bl.count()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -87,18 +87,18 @@ namespace BresenhamLine bl(first, last); - BresenhamLine::iterator itr = bl.begin(); - std::vector expected{ Point{ 5, 5 }, Point{ 4, 5 }, Point{ 3, 5 }, Point{ 2, 5 }, Point{ 1, 5 }, Point{ 0, 5 }, Point{-1, 5 }, Point{-2, 5 }, Point{-3, 5 }, Point{-4, 5 }, Point{-5, 5} }; std::vector actual; - while (itr != bl.end()) + CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. + + for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); - ++itr; } + CHECK_EQUAL(expected.size(), bl.count()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -111,18 +111,18 @@ namespace BresenhamLine bl(first, last); - BresenhamLine::iterator itr = bl.begin(); - std::vector expected{ Point{ 5, -5 }, Point{ 5, -4 }, Point{ 5, -3 }, Point{ 5, -2 }, Point{ 5, -1 }, Point{ 5, 0 }, Point{ 5, 1 }, Point{ 5, 2 }, Point{ 5, 3 }, Point{ 5, 4 }, Point{ 5, 5} }; std::vector actual; - while (itr != bl.end()) + CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. + + for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); - ++itr; } + CHECK_EQUAL(expected.size(), bl.count()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -135,18 +135,18 @@ namespace BresenhamLine bl(first, last); - BresenhamLine::iterator itr = bl.begin(); - std::vector expected{ Point{ 5, 5 }, Point{ 5, 4 }, Point{ 5, 3 }, Point{ 5, 2 }, Point{ 5, 1 }, Point{ 5, 0 }, Point{ 5, -1 }, Point{ 5, -2 }, Point{ 5, -3 }, Point{ 5, -4 }, Point{ 5, -5} }; std::vector actual; - while (itr != bl.end()) + CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. + + for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); - ++itr; } + CHECK_EQUAL(expected.size(), bl.count()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -159,18 +159,18 @@ namespace BresenhamLine bl(first, last); - BresenhamLine::iterator itr = bl.begin(); - std::vector expected{ Point{ -5, -3 }, Point{ -4, -3 }, Point{ -3, -2 }, Point{ -2, -1 }, Point{ -1, -1 }, Point{ 0, 0 }, Point{ 1, 1 }, Point{ 2, 1 }, Point{ 3, 2 }, Point{ 4, 2 }, Point{ 5, 3 } }; std::vector actual; - while (itr != bl.end()) + CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. + + for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); - ++itr; } + CHECK_EQUAL(expected.size(), bl.count()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -183,18 +183,18 @@ namespace BresenhamLine bl(first, last); - BresenhamLine::iterator itr = bl.begin(); - std::vector expected{ Point{ 5, 3 }, Point{ 4, 3 }, Point{ 3, 2 }, Point{ 2, 1 }, Point{ 1, 1 }, Point{ 0, 0 }, Point{ -1, -1 }, Point{ -2, -1 }, Point{ -3, -2 }, Point{ -4, -2 }, Point{ -5, -3 } }; std::vector actual; - while (itr != bl.end()) + CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. + + for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); - ++itr; } + CHECK_EQUAL(expected.size(), bl.count()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -207,18 +207,18 @@ namespace BresenhamLine bl(first, last); - BresenhamLine::iterator itr = bl.begin(); - std::vector expected{ Point{ 5, -3 }, Point{ 4, -3 }, Point{ 3, -2 }, Point{ 2, -1 }, Point{ 1, -1 }, Point{ 0, 0 }, Point{ -1, 1 }, Point{ -2, 1 }, Point{ -3, 2 }, Point{ -4, 2 }, Point{ -5, 3 } }; std::vector actual; - while (itr != bl.end()) + CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. + + for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); - ++itr; } + CHECK_EQUAL(expected.size(), bl.count()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -231,18 +231,18 @@ namespace BresenhamLine bl(first, last); - BresenhamLine::iterator itr = bl.begin(); - std::vector expected{ Point{ -5, 3 }, Point{ -4, 3 }, Point{ -3, 2 }, Point{ -2, 1 }, Point{ -1, 1 }, Point{ 0, 0 }, Point{ 1, -1 }, Point{ 2, -1 }, Point{ 3, -2 }, Point{ 4, -2 }, Point{ 5, -3 } }; std::vector actual; - while (itr != bl.end()) + CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. + + for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); - ++itr; } + CHECK_EQUAL(expected.size(), bl.count()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -255,18 +255,18 @@ namespace BresenhamLine bl(first, last); - BresenhamLine::iterator itr = bl.begin(); - std::vector expected{ Point{ -3, -5 }, Point{ -3, -4 }, Point{ -2, -3 }, Point{ -1, -2 }, Point{ -1, -1 }, Point{ 0, 0 }, Point{ 1, 1 }, Point{ 1, 2 }, Point{ 2, 3 }, Point{ 2, 4 }, Point{ 3, 5 } }; std::vector actual; - while (itr != bl.end()) + CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. + + for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); - ++itr; } + CHECK_EQUAL(expected.size(), bl.count()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -279,18 +279,18 @@ namespace BresenhamLine bl(first, last); - BresenhamLine::iterator itr = bl.begin(); - std::vector expected{ Point{ 3, 5 }, Point{ 3, 4 }, Point{ 2, 3 }, Point{ 1, 2 }, Point{ 1, 1 }, Point{ 0, 0 }, Point{ -1, -1 }, Point{ -1, -2 }, Point{ -2, -3 }, Point{ -2, -4 }, Point{ -3, -5 } }; std::vector actual; - while (itr != bl.end()) + CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. + + for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); - ++itr; } + CHECK_EQUAL(expected.size(), bl.count()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -303,18 +303,18 @@ namespace BresenhamLine bl(first, last); - BresenhamLine::iterator itr = bl.begin(); - std::vector expected{ Point{ 3, -5 }, Point{ 3, -4 }, Point{ 2, -3 }, Point{ 1, -2 }, Point{ 1, -1 }, Point{ 0, 0 }, Point{ -1, 1 }, Point{ -1, 2 }, Point{ -2, 3 }, Point{ -2, 4 }, Point{ -3, 5 } }; std::vector actual; - while (itr != bl.end()) + CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. + + for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); - ++itr; } + CHECK_EQUAL(expected.size(), bl.count()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -327,18 +327,18 @@ namespace BresenhamLine bl(first, last); - BresenhamLine::iterator itr = bl.begin(); - std::vector expected{ Point{ -3, 5 }, Point{ -3, 4 }, Point{ -2, 3 }, Point{ -1, 2 }, Point{ -1, 1 }, Point{ 0, 0 }, Point{ 1, -1 }, Point{ 1, -2 }, Point{ 2, -3 }, Point{ 2, -4 }, Point{ 3, -5 } }; std::vector actual; - while (itr != bl.end()) + CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. + + for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); - ++itr; } + CHECK_EQUAL(expected.size(), bl.count()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } From 482c69f314b1b22ba1e5c9edc700797151b56183 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 27 Aug 2020 13:31:27 +0100 Subject: [PATCH 11/71] Small refactoring --- include/etl/bresenham_line.h | 209 +++++++++++++++++++++-------------- include/etl/utility.h | 21 ++++ test/test_bresenham_line.cpp | 99 +++++++++++++---- test/test_memory.cpp | 2 - 4 files changed, 224 insertions(+), 107 deletions(-) diff --git a/include/etl/bresenham_line.h b/include/etl/bresenham_line.h index 0fbe1eed..88e4e242 100644 --- a/include/etl/bresenham_line.h +++ b/include/etl/bresenham_line.h @@ -31,21 +31,23 @@ SOFTWARE. #ifndef ETL_BRESENHAM_LINE_INCLUDED #define ETL_BRESENHAM_LINE_INCLUDED -#include +#include #include "platform.h" #include "iterator.h" -#include "exception.h" +#include "static_assert.h" +#include "type_traits.h" +#include "utility.h" namespace etl { //*************************************************************************** /// A pseudo-container that generates points on a line, using Bresenham's /// line algorithm. - /// TCoordinate must support integral x & y members. - /// TWorking is the internal working variable type. Default is int. + /// T is the type for the etl::coordinate_2d value type. + /// TWork is the internal working variable type. Default is int16_t. //*************************************************************************** - template + template class bresenham_line { public: @@ -53,15 +55,18 @@ namespace etl //*************************************************** /// Standard container types. //*************************************************** - typedef TCoordinate value_type; - typedef size_t size_type; - typedef ptrdiff_t difference_type; - typedef value_type& reference; - typedef const value_type& const_reference; - typedef value_type* pointer; - typedef const value_type* const_pointer; + typedef etl::coordinate_2d value_type; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef value_type* pointer; + typedef const value_type* const_pointer; - class iterator : public etl::iterator + //*************************************************** + /// Const Iterator + //*************************************************** + class const_iterator : public etl::iterator { public: @@ -70,7 +75,7 @@ namespace etl //*************************************************** /// Default constructor //*************************************************** - iterator() + const_iterator() : p_bresenham_line(ETL_NULLPTR) { } @@ -78,7 +83,7 @@ namespace etl //*************************************************** /// Copy constuctor //*************************************************** - iterator(const iterator& other) + const_iterator(const const_iterator& other) : p_bresenham_line(other.p_bresenham_line) { } @@ -86,7 +91,7 @@ namespace etl //*************************************************** /// Assignment operator //*************************************************** - iterator& operator =(const iterator& rhs) + const_iterator& operator =(const const_iterator& rhs) { p_bresenham_line = rhs.p_bresenham_line; @@ -96,10 +101,10 @@ namespace etl //*************************************************** /// Pre-increment operator //*************************************************** - iterator& operator ++() + const_iterator& operator ++() { // Has the end of the series has been reached? - if (p_bresenham_line->n_coordinates_remaining == TWorking(0)) + if (p_bresenham_line->n_coordinates_remaining == 0) { // Mark it as an end iterator. p_bresenham_line = ETL_NULLPTR; @@ -123,7 +128,7 @@ namespace etl //*************************************************** /// Equality operator //*************************************************** - friend bool operator ==(const iterator& lhs, const iterator& rhs) + friend bool operator ==(const const_iterator& lhs, const const_iterator& rhs) { return lhs.p_bresenham_line == rhs.p_bresenham_line; } @@ -131,7 +136,7 @@ namespace etl //*************************************************** /// Inequality operator //*************************************************** - friend bool operator !=(const iterator& lhs, const iterator& rhs) + friend bool operator !=(const const_iterator& lhs, const const_iterator& rhs) { return !(lhs == rhs); } @@ -141,27 +146,101 @@ namespace etl //*************************************************** /// Constructor for use by bresenham_line //*************************************************** - iterator(bresenham_line* pb) + const_iterator(bresenham_line* pb) : p_bresenham_line(pb) { } - bresenham_line* p_bresenham_line; + bresenham_line* p_bresenham_line; }; //*************************************************** /// Constructor. /// Supplied first and last coordinates //*************************************************** - bresenham_line(const_reference first_, const_reference last_) - : first(first_) - , coordinate(first_) - , x_increment((last_.x < first_.x) ? -1 : 1) - , y_increment((last_.y < first_.y) ? -1 : 1) - , dx((last_.x < first_.x) ? first_.x - last_.x : last_.x - first_.x) - , dy((last_.y < first_.y) ? first_.y - last_.y : last_.y - first_.y) - , do_minor_increment(false) + bresenham_line(etl::coordinate_2d first_, etl::coordinate_2d last_) { + initialise(first_.x, first_.y, last_.x, last_.y); + } + + //*************************************************** + /// Constructor. + /// Supplied first and last coordinates + //*************************************************** + bresenham_line(T first_x, T first_y, T last_x, T last_y) + { + initialise(first_x, first_y, last_x, last_y); + } + + //*************************************************** + /// Update the line. + /// Supplied first and last coordinates + //*************************************************** + void update_line(etl::coordinate_2d first_, etl::coordinate_2d last_) + { + initialise(first_.x, first_.y, last_.x, last_.y); + } + + //*************************************************** + /// Update the line. + /// Supplied first and last coordinates + //*************************************************** + void update_line(T first_x, T first_y, T last_x, T last_y) + { + initialise(first_x, first_y, last_x, last_y); + } + + //*************************************************** + /// Get a const_iterator to the first coordinate. + /// Resets the Bresenham line. + //*************************************************** + const_iterator begin() + { + n_coordinates_remaining = total_n_coordinates - 1; // We already have the first coordinate. + coordinate = first; + + return const_iterator(this); + } + + //*************************************************** + /// Get a const_iterator to one past the last coordinate. + //*************************************************** + const_iterator end() const + { + return const_iterator(); + } + + //*************************************************** + /// Get the size of the series. + //*************************************************** + size_t size() const + { + return size_t(total_n_coordinates); + } + + //*************************************************** + /// Get the current number of generated points. + //*************************************************** + size_t count() const + { + return size_t(total_n_coordinates - n_coordinates_remaining); + } + + private: + + //*************************************************** + /// Get the current number of generated points. + //*************************************************** + void initialise(T first_x, T first_y, T last_x, T last_y) + { + first = value_type(first_x, first_y); + coordinate = value_type(first_x, first_y); + x_increment = (last_x < first_x) ? -1 : 1; + y_increment = (last_y < first_y) ? -1 : 1; + dx = (last_x < first_x) ? first_x - last_x : last_x - first_x; + dy = (last_y < first_y) ? first_y - last_y : last_y - first_y; + do_minor_increment = false; + if (is_y_major_axis()) { total_n_coordinates = dy + 1; @@ -180,48 +259,10 @@ namespace etl n_coordinates_remaining = total_n_coordinates - 1; // We already have the first coordinate. } - //*************************************************** - /// Get an iterator to the first coordinate. - /// Resets the Bresenham line. - //*************************************************** - iterator begin() - { - n_coordinates_remaining = total_n_coordinates - 1; // We already have the first coordinate. - coordinate = first; - - return iterator(this); - } - - //*************************************************** - /// Get an iterator to one past the last coordinate. - //*************************************************** - iterator end() const - { - return iterator(); - } - - //*************************************************** - /// Get the size of the series. - //*************************************************** - size_t size() const - { - return total_n_coordinates; - } - - //*************************************************** - /// Get the current number of generated points. - //*************************************************** - size_t count() const - { - return total_n_coordinates - n_coordinates_remaining; - } - - private: - //*************************************************** /// Returns true if Y is the major axis. //*************************************************** - int is_y_major_axis() const + bool is_y_major_axis() const { return dx < dy; } @@ -236,11 +277,11 @@ namespace etl // Y major axis. if (do_minor_increment) { - coordinate.x += x_increment; + coordinate.x = T(coordinate.x + x_increment); balance -= dy; } - coordinate.y += y_increment; + coordinate.y = T(coordinate.y + y_increment); balance += dx; } else @@ -248,11 +289,11 @@ namespace etl // X major axis. if (do_minor_increment) { - coordinate.y += y_increment; + coordinate.y = T(coordinate.y + y_increment); balance -= dx; } - coordinate.x += x_increment; + coordinate.x = T(coordinate.x + x_increment); balance += dy; } @@ -269,18 +310,18 @@ namespace etl return coordinate; } - typedef TWorking working_t; + typedef TWork work_t; - const value_type first; - value_type coordinate; - const working_t x_increment; - const working_t y_increment; - working_t dx; - working_t dy; - working_t total_n_coordinates; - working_t n_coordinates_remaining; - working_t balance; - bool do_minor_increment; + value_type first; + value_type coordinate; + work_t x_increment; + work_t y_increment; + work_t dx; + work_t dy; + work_t total_n_coordinates; + work_t n_coordinates_remaining; + work_t balance; + bool do_minor_increment; }; } diff --git a/include/etl/utility.h b/include/etl/utility.h index e9901fb5..92960da9 100644 --- a/include/etl/utility.h +++ b/include/etl/utility.h @@ -328,6 +328,27 @@ namespace etl { return t; } + + //****************************************************************************** + /// 2D coordinate type. + template + struct coordinate_2d + { + coordinate_2d() + : x(T(0)) + , y(T(0)) + { + } + + coordinate_2d(T x_, T y_) + : x(x_) + , y(y_) + { + } + + T x; + T y; + }; } #endif diff --git a/test/test_bresenham_line.cpp b/test/test_bresenham_line.cpp index d3512658..faa86eed 100644 --- a/test/test_bresenham_line.cpp +++ b/test/test_bresenham_line.cpp @@ -26,6 +26,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ + #include "UnitTest++/UnitTest++.h" #include "etl/bresenham_line.h" @@ -34,11 +35,9 @@ SOFTWARE. namespace { - struct Point - { - int x; - int y; - }; + using Value = char; + + using Point = etl::coordinate_2d; bool operator ==(Point lhs, Point rhs) { @@ -47,11 +46,11 @@ namespace std::ostream& operator << (std::ostream& os, Point point) { - os << "(" << point.x << "," << point.y << ")"; + os << "(" << point.x << "," << point.x << ")"; return os; } - using BresenhamLine = etl::bresenham_line; + using BresenhamLine = etl::bresenham_line; SUITE(test_bresenham_line) { @@ -61,15 +60,15 @@ namespace Point first = { -5, 5 }; Point last = { 5, 5 }; - BresenhamLine bl(first, last); + BresenhamLine bl(first.x, first.y, last.x, last.y); - std::vector expected{ Point{-5, 5 }, Point{-4, 5 }, Point{-3, 5 }, Point{-2, 5 }, Point{-1, 5 }, Point{ 0, 5 }, + std::vector expected{ Point{-5, 5 }, Point{-4, 5 }, Point{-3, 5 }, Point{-2, 5 }, Point{-1, 5 }, Point{ 0, 5 }, Point{ 1, 5 }, Point{ 2, 5 }, Point{ 3, 5 }, Point{ 4, 5 }, Point{ 5, 5} }; std::vector actual; CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } @@ -93,7 +92,7 @@ namespace CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } @@ -117,7 +116,7 @@ namespace CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } @@ -141,7 +140,7 @@ namespace CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } @@ -165,7 +164,7 @@ namespace CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } @@ -189,7 +188,7 @@ namespace CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } @@ -213,7 +212,7 @@ namespace CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } @@ -237,7 +236,7 @@ namespace CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } @@ -261,7 +260,7 @@ namespace CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } @@ -285,7 +284,7 @@ namespace CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } @@ -309,7 +308,7 @@ namespace CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } @@ -333,7 +332,65 @@ namespace CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::iterator itr = bl.begin(); itr != bl.end(); ++itr) + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) + { + actual.push_back(*itr); + } + + CHECK_EQUAL(expected.size(), bl.count()); + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(update_the_line_from_coordinate_2d) + { + Point first = { 3, -5 }; + Point last = { -3, 5 }; + + BresenhamLine bl(first, last); + + Point new_first = { -3, 5 }; + Point new_last = { 3, -5 }; + + bl.update_line(new_first, new_last); + + std::vector expected{ Point{ -3, 5 }, Point{ -3, 4 }, Point{ -2, 3 }, Point{ -1, 2 }, Point{ -1, 1 }, Point{ 0, 0 }, + Point{ 1, -1 }, Point{ 1, -2 }, Point{ 2, -3 }, Point{ 2, -4 }, Point{ 3, -5 } }; + std::vector actual; + + CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. + + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) + { + actual.push_back(*itr); + } + + CHECK_EQUAL(expected.size(), bl.count()); + CHECK_EQUAL(expected.size(), actual.size()); + CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); + } + + //************************************************************************* + TEST(update_the_line_from_individual_coordinates) + { + Point first = { 3, -5 }; + Point last = { -3, 5 }; + + BresenhamLine bl(first, last); + + Point new_first = { -3, 5 }; + Point new_last = { 3, -5 }; + + bl.update_line(new_first.x, new_first.y, new_last.x, new_last.y); + + std::vector expected{ Point{ -3, 5 }, Point{ -3, 4 }, Point{ -2, 3 }, Point{ -1, 2 }, Point{ -1, 1 }, Point{ 0, 0 }, + Point{ 1, -1 }, Point{ 1, -2 }, Point{ 2, -3 }, Point{ 2, -4 }, Point{ 3, -5 } }; + std::vector actual; + + CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. + + for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } diff --git a/test/test_memory.cpp b/test/test_memory.cpp index 8a01ecf8..68f86d43 100644 --- a/test/test_memory.cpp +++ b/test/test_memory.cpp @@ -887,7 +887,6 @@ namespace { etl::unique_ptr up(new int); - int* p = new int(1); up = nullptr; CHECK(up.get() == nullptr); @@ -1018,7 +1017,6 @@ namespace { etl::unique_ptr up(new int[4]); - int* p = new int[4]; up = nullptr; CHECK(up.get() == nullptr); From f2d6df594438a93320822e15fb26283c0d85fe86 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 27 Aug 2020 18:40:05 +0100 Subject: [PATCH 12/71] Fixed etl::stack top level assignment operator not clearing before copy --- include/etl/stack.h | 7 +++++-- include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 4 ++++ test/test_queue.cpp | 4 ++++ test/test_stack.cpp | 4 ++++ 7 files changed, 20 insertions(+), 5 deletions(-) diff --git a/include/etl/stack.h b/include/etl/stack.h index 901e0e62..8c57dbd5 100644 --- a/include/etl/stack.h +++ b/include/etl/stack.h @@ -447,8 +447,7 @@ namespace etl istack& operator = (istack&& rhs) { if (&rhs != this) - { - clear(); + { clone(etl::move(rhs)); } @@ -463,6 +462,8 @@ namespace etl //************************************************************************* void clone(const istack& other) { + clear(); + size_t index = 0; for (size_t i = 0; i < other.size(); ++i) @@ -477,6 +478,8 @@ namespace etl //************************************************************************* void clone(istack&& other) { + clear(); + size_t index = 0; for (size_t i = 0; i < other.size(); ++i) diff --git a/include/etl/version.h b/include/etl/version.h index 07c33a62..3b339338 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 18 #define ETL_VERSION_MINOR 12 -#define ETL_VERSION_PATCH 5 +#define ETL_VERSION_PATCH 6 #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) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index f024aaba..a7799bed 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.12.5", + "version": "18.12.6", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index 6deb9856..dcb166c2 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.12.5 +version=18.12.6 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 360d40d4..216d9d4b 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +18.12.6 +Fixed etl::stack top level assignment operator not clearing before copy. + =============================================================================== 18.12.5 Fixed issue for incorrect operation of erase(const_iterator, const_iterator) when diff --git a/test/test_queue.cpp b/test/test_queue.cpp index f47a2842..2cf4824c 100644 --- a/test/test_queue.cpp +++ b/test/test_queue.cpp @@ -485,6 +485,10 @@ namespace etl::queue queue2; + // These should be overwritten. + queue2.push(5); + queue2.push(6); + queue2 = queue; CHECK(queue.size() == queue2.size()); diff --git a/test/test_stack.cpp b/test/test_stack.cpp index e0138830..c1b187fb 100644 --- a/test/test_stack.cpp +++ b/test/test_stack.cpp @@ -437,6 +437,10 @@ namespace etl::stack stack2; + // These should be overwritten. + stack2.push(5); + stack2.push(6); + stack2 = stack; CHECK(stack.size() == stack2.size()); From 405de495ec5e98341a7e909f4d29e6d5240da80f Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 27 Aug 2020 18:40:05 +0100 Subject: [PATCH 13/71] Fixed etl::stack top level assignment operator not clearing before copy --- include/etl/stack.h | 7 +++++-- include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 4 ++++ test/test_queue.cpp | 4 ++++ test/test_stack.cpp | 4 ++++ 7 files changed, 20 insertions(+), 5 deletions(-) diff --git a/include/etl/stack.h b/include/etl/stack.h index 901e0e62..8c57dbd5 100644 --- a/include/etl/stack.h +++ b/include/etl/stack.h @@ -447,8 +447,7 @@ namespace etl istack& operator = (istack&& rhs) { if (&rhs != this) - { - clear(); + { clone(etl::move(rhs)); } @@ -463,6 +462,8 @@ namespace etl //************************************************************************* void clone(const istack& other) { + clear(); + size_t index = 0; for (size_t i = 0; i < other.size(); ++i) @@ -477,6 +478,8 @@ namespace etl //************************************************************************* void clone(istack&& other) { + clear(); + size_t index = 0; for (size_t i = 0; i < other.size(); ++i) diff --git a/include/etl/version.h b/include/etl/version.h index 07c33a62..3b339338 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 18 #define ETL_VERSION_MINOR 12 -#define ETL_VERSION_PATCH 5 +#define ETL_VERSION_PATCH 6 #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) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index f024aaba..a7799bed 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.12.5", + "version": "18.12.6", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index 6deb9856..dcb166c2 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.12.5 +version=18.12.6 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 360d40d4..216d9d4b 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +18.12.6 +Fixed etl::stack top level assignment operator not clearing before copy. + =============================================================================== 18.12.5 Fixed issue for incorrect operation of erase(const_iterator, const_iterator) when diff --git a/test/test_queue.cpp b/test/test_queue.cpp index f47a2842..2cf4824c 100644 --- a/test/test_queue.cpp +++ b/test/test_queue.cpp @@ -485,6 +485,10 @@ namespace etl::queue queue2; + // These should be overwritten. + queue2.push(5); + queue2.push(6); + queue2 = queue; CHECK(queue.size() == queue2.size()); diff --git a/test/test_stack.cpp b/test/test_stack.cpp index e0138830..c1b187fb 100644 --- a/test/test_stack.cpp +++ b/test/test_stack.cpp @@ -437,6 +437,10 @@ namespace etl::stack stack2; + // These should be overwritten. + stack2.push(5); + stack2.push(6); + stack2 = stack; CHECK(stack.size() == stack2.size()); From 90cdfc0b5866f510328ac93d0989ec7e42c91740 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 28 Aug 2020 15:10:24 +0100 Subject: [PATCH 14/71] Added header include --- include/etl/integral_limits.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/etl/integral_limits.h b/include/etl/integral_limits.h index 3a33bbde..7b8d4dd0 100644 --- a/include/etl/integral_limits.h +++ b/include/etl/integral_limits.h @@ -32,6 +32,7 @@ SOFTWARE. #define ETL_INTEGRAL_LIMITS_INCLUDED #include +#include #include "platform.h" #include "type_traits.h" From a33a70b5e1365274413c0feca5bab7c47d9a74ae Mon Sep 17 00:00:00 2001 From: Rolan Reznik Date: Fri, 28 Aug 2020 17:12:47 +0300 Subject: [PATCH 15/71] ARM5 (armcc) compiler fixes for C++11. (#261) --- include/etl/alignment.h | 2 +- include/etl/type_traits.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/etl/alignment.h b/include/etl/alignment.h index a24bf23b..f7a258f2 100644 --- a/include/etl/alignment.h +++ b/include/etl/alignment.h @@ -184,7 +184,7 @@ namespace etl return reinterpret_cast(data); } -#if ETL_CPP11_SUPPORTED +#if ETL_CPP11_SUPPORTED && !defined(ETL_COMPILER_ARM5) alignas(ALIGNMENT) char data[LENGTH]; #else union diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 23728d8b..3757f6b7 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -751,7 +751,7 @@ namespace etl //*************************************************************************** /// Alignment templates. /// These require compiler specific intrinsics. -#if ETL_CPP11_SUPPORTED +#if ETL_CPP11_SUPPORTED && !defined(ETL_COMPILER_ARM5) template struct alignment_of : integral_constant { }; #elif ETL_COMPILER_MICROSOFT template struct alignment_of : integral_constant {}; From 5747a861f93ad61b22ad768bcf344cbcf36c332f Mon Sep 17 00:00:00 2001 From: Rolan Reznik Date: Fri, 28 Aug 2020 17:15:51 +0300 Subject: [PATCH 16/71] reference_wrapper change allowing to use it for pure abstract classes (#262) --- include/etl/functional.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/etl/functional.h b/include/etl/functional.h index a540f3a7..b00835f5 100644 --- a/include/etl/functional.h +++ b/include/etl/functional.h @@ -62,7 +62,7 @@ namespace etl return *t; } - reference_wrapper& operator = (T value) + reference_wrapper& operator = (T& value) { *t = value; return *this; From 3a203a975496b055e7f30023e9a433de00497c74 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 28 Aug 2020 16:09:39 +0100 Subject: [PATCH 17/71] Make etl::reference_wrapper API closer to the STL version. Does not support invocation of a callable object. --- include/etl/functional.h | 18 +++++++++--------- include/etl/platform.h | 2 ++ include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 4 ++++ test/test_functional.cpp | 37 +++++-------------------------------- 7 files changed, 23 insertions(+), 44 deletions(-) diff --git a/include/etl/functional.h b/include/etl/functional.h index b00835f5..842cd4c2 100644 --- a/include/etl/functional.h +++ b/include/etl/functional.h @@ -52,23 +52,23 @@ namespace etl typedef T type; - explicit reference_wrapper(T& t_) + ETL_CONSTEXPR20 explicit reference_wrapper(T& t_) ETL_NOEXCEPT : t(&t_) { } - operator T& () const + ETL_CONSTEXPR20 reference_wrapper& operator = (const reference_wrapper& rhs) ETL_NOEXCEPT + { + t = rhs.t; + return *this; + } + + ETL_CONSTEXPR20 T& get() const ETL_NOEXCEPT { return *t; } - reference_wrapper& operator = (T& value) - { - *t = value; - return *this; - } - - T& get() const + ETL_CONSTEXPR20 operator T&() const ETL_NOEXCEPT { return *t; } diff --git a/include/etl/platform.h b/include/etl/platform.h index 6e075bd2..0a2035e2 100644 --- a/include/etl/platform.h +++ b/include/etl/platform.h @@ -159,9 +159,11 @@ SOFTWARE. #if ETL_CPP20_SUPPORTED && !defined(ETL_FORCE_NO_ADVANCED_CPP) #define ETL_LIKELY [[likely]] #define ETL_UNLIKELY [[unlikely]] +#define ETL_CONSTEXPR20 constexpr #else #define ETL_LIKELY #define ETL_UNLIKELY +#define ETL_CONSTEXPR20 #endif // Sort out namespaces for STL/No STL options. diff --git a/include/etl/version.h b/include/etl/version.h index 3b339338..ef007822 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 18 #define ETL_VERSION_MINOR 12 -#define ETL_VERSION_PATCH 6 +#define ETL_VERSION_PATCH 7 #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) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index a7799bed..7236c5c0 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.12.6", + "version": "18.12.7", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index dcb166c2..9b86a10b 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.12.6 +version=18.12.7 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 216d9d4b..a99e254c 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +18.12.7 +Made etl::reference_wrapper API closer to the STL version. Does not support invocation of a callable object. + =============================================================================== 18.12.6 Fixed etl::stack top level assignment operator not clearing before copy. diff --git a/test/test_functional.cpp b/test/test_functional.cpp index d7f106b3..59a42f71 100644 --- a/test/test_functional.cpp +++ b/test/test_functional.cpp @@ -104,7 +104,7 @@ namespace int a = 0; etl::reference_wrapper ra(a); - ra = 1; + ra.get() = 1; CHECK_EQUAL(1, a); CHECK_EQUAL(1, ra); @@ -113,42 +113,15 @@ namespace CHECK_EQUAL(2, ra); } - //************************************************************************* - TEST(test_reference_wrapper_vector) - { - std::vector> ref_int; - - int a = 1; - int b = 2; - - ref_int.push_back(etl::ref(a)); - ref_int.push_back(etl::ref(b)); - - CHECK_EQUAL(a, ref_int[0]); - CHECK_EQUAL(b, ref_int[1]); - - ref_int[0] = 3; - ref_int[1] = 4; - - CHECK_EQUAL(3, a); - CHECK_EQUAL(4, b); - - CHECK_EQUAL(3, ref_int[0]); - CHECK_EQUAL(4, ref_int[1]); - } - //************************************************************************* TEST(test_reference_wrapper_container) { - std::list test = { 0, 1, 2, 3, 4 }; - std::list compare = { 5, 6, 7, 8, 9 }; + std::list test = { 0, 1, 2, 3, 4 }; + std::list compare = { 0, 1, 2, 3, 4 }; std::vector> test_ref(test.begin(), test.end()); - std::iota(test_ref.begin(), test_ref.end(), 5); - - std::list::const_iterator itest = test.begin(); + std::list::const_iterator itest = test.begin(); std::list::const_iterator icompare = compare.begin(); - //std::vector>::const_iterator ivector = test_ref.begin(); while (icompare != compare.end()) { @@ -164,7 +137,7 @@ namespace int a = 0; etl::reference_wrapper ra = etl::ref(a); - ra = 1; + ra.get() = 1; CHECK_EQUAL(1, a); CHECK_EQUAL(1, ra); } From 62f596667e3248e610ed939f614ab3a53cc524a3 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 30 Aug 2020 11:16:07 +0100 Subject: [PATCH 18/71] Bresenham line algorithm - final --- include/etl/bresenham_line.h | 66 ++++++++++++--------- include/etl/utility.h | 10 ++++ test/codeblocks/ETL.cbp | 2 + test/test_bresenham_line.cpp | 111 ++++++++++++++++++----------------- 4 files changed, 107 insertions(+), 82 deletions(-) diff --git a/include/etl/bresenham_line.h b/include/etl/bresenham_line.h index 88e4e242..ed301368 100644 --- a/include/etl/bresenham_line.h +++ b/include/etl/bresenham_line.h @@ -104,7 +104,7 @@ namespace etl const_iterator& operator ++() { // Has the end of the series has been reached? - if (p_bresenham_line->n_coordinates_remaining == 0) + if (p_bresenham_line->get_coordinate() == p_bresenham_line->back()) { // Mark it as an end iterator. p_bresenham_line = ETL_NULLPTR; @@ -173,19 +173,19 @@ namespace etl } //*************************************************** - /// Update the line. + /// Resets the line. /// Supplied first and last coordinates //*************************************************** - void update_line(etl::coordinate_2d first_, etl::coordinate_2d last_) + void reset(etl::coordinate_2d first_, etl::coordinate_2d last_) { initialise(first_.x, first_.y, last_.x, last_.y); } //*************************************************** - /// Update the line. + /// Resets the line. /// Supplied first and last coordinates //*************************************************** - void update_line(T first_x, T first_y, T last_x, T last_y) + void reset(T first_x, T first_y, T last_x, T last_y) { initialise(first_x, first_y, last_x, last_y); } @@ -196,7 +196,6 @@ namespace etl //*************************************************** const_iterator begin() { - n_coordinates_remaining = total_n_coordinates - 1; // We already have the first coordinate. coordinate = first; return const_iterator(this); @@ -210,20 +209,35 @@ namespace etl return const_iterator(); } + //*************************************************** + /// Get the first coordinate. + //*************************************************** + value_type front() + { + return first; + } + + //*************************************************** + /// Get the last coordinate. + //*************************************************** + value_type back() + { + return last; + } + //*************************************************** /// Get the size of the series. //*************************************************** size_t size() const { - return size_t(total_n_coordinates); - } - - //*************************************************** - /// Get the current number of generated points. - //*************************************************** - size_t count() const - { - return size_t(total_n_coordinates - n_coordinates_remaining); + if (y_is_major_axis()) + { + return (dy / 2) + 1; + } + else + { + return (dx / 2) + 1; + } } private: @@ -234,35 +248,32 @@ namespace etl void initialise(T first_x, T first_y, T last_x, T last_y) { first = value_type(first_x, first_y); - coordinate = value_type(first_x, first_y); + last = value_type(last_x, last_y); + coordinate = first; x_increment = (last_x < first_x) ? -1 : 1; y_increment = (last_y < first_y) ? -1 : 1; dx = (last_x < first_x) ? first_x - last_x : last_x - first_x; dy = (last_y < first_y) ? first_y - last_y : last_y - first_y; do_minor_increment = false; - if (is_y_major_axis()) + if (y_is_major_axis()) { - total_n_coordinates = dy + 1; dx *= 2; balance = dx - dy; dy *= 2; } else { - total_n_coordinates = dx + 1; dy *= 2; balance = dy - dx; dx *= 2; } - - n_coordinates_remaining = total_n_coordinates - 1; // We already have the first coordinate. } //*************************************************** /// Returns true if Y is the major axis. //*************************************************** - bool is_y_major_axis() const + bool y_is_major_axis() const { return dx < dy; } @@ -272,9 +283,9 @@ namespace etl //*************************************************** void next() { - if (is_y_major_axis()) + if (y_is_major_axis()) { - // Y major axis. + // Y is major axis. if (do_minor_increment) { coordinate.x = T(coordinate.x + x_increment); @@ -286,7 +297,7 @@ namespace etl } else { - // X major axis. + // X is major axis. if (do_minor_increment) { coordinate.y = T(coordinate.y + y_increment); @@ -297,8 +308,6 @@ namespace etl balance += dy; } - --n_coordinates_remaining; - do_minor_increment = (balance >= 0); } @@ -313,13 +322,12 @@ namespace etl typedef TWork work_t; value_type first; + value_type last; value_type coordinate; work_t x_increment; work_t y_increment; work_t dx; work_t dy; - work_t total_n_coordinates; - work_t n_coordinates_remaining; work_t balance; bool do_minor_increment; }; diff --git a/include/etl/utility.h b/include/etl/utility.h index 92960da9..03c2a37e 100644 --- a/include/etl/utility.h +++ b/include/etl/utility.h @@ -346,6 +346,16 @@ namespace etl { } + friend bool operator ==(const coordinate_2d& lhs, const coordinate_2d& rhs) + { + return (lhs.x == rhs.x) && (lhs.y == rhs.y); + } + + friend bool operator !=(const coordinate_2d& lhs, const coordinate_2d& rhs) + { + return !(lhs == rhs); + } + T x; T y; }; diff --git a/test/codeblocks/ETL.cbp b/test/codeblocks/ETL.cbp index 9d532038..b6bb1220 100644 --- a/test/codeblocks/ETL.cbp +++ b/test/codeblocks/ETL.cbp @@ -234,6 +234,7 @@ + @@ -492,6 +493,7 @@ + diff --git a/test/test_bresenham_line.cpp b/test/test_bresenham_line.cpp index faa86eed..0057a984 100644 --- a/test/test_bresenham_line.cpp +++ b/test/test_bresenham_line.cpp @@ -26,7 +26,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ - #include "UnitTest++/UnitTest++.h" #include "etl/bresenham_line.h" @@ -39,14 +38,9 @@ namespace using Point = etl::coordinate_2d; - bool operator ==(Point lhs, Point rhs) - { - return (lhs.x == rhs.x) && (lhs.y == rhs.y); - } - std::ostream& operator << (std::ostream& os, Point point) { - os << "(" << point.x << "," << point.x << ")"; + os << "(" << int(point.x) << "," << int(point.y) << ")"; return os; } @@ -62,18 +56,19 @@ namespace BresenhamLine bl(first.x, first.y, last.x, last.y); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + std::vector expected{ Point{-5, 5 }, Point{-4, 5 }, Point{-3, 5 }, Point{-2, 5 }, Point{-1, 5 }, Point{ 0, 5 }, Point{ 1, 5 }, Point{ 2, 5 }, Point{ 3, 5 }, Point{ 4, 5 }, Point{ 5, 5} }; std::vector actual; - CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } - CHECK_EQUAL(expected.size(), bl.count()); + CHECK_EQUAL(expected.size(), bl.size()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -86,18 +81,19 @@ namespace BresenhamLine bl(first, last); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + std::vector expected{ Point{ 5, 5 }, Point{ 4, 5 }, Point{ 3, 5 }, Point{ 2, 5 }, Point{ 1, 5 }, Point{ 0, 5 }, Point{-1, 5 }, Point{-2, 5 }, Point{-3, 5 }, Point{-4, 5 }, Point{-5, 5} }; std::vector actual; - CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } - CHECK_EQUAL(expected.size(), bl.count()); + CHECK_EQUAL(expected.size(), bl.size()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -110,18 +106,19 @@ namespace BresenhamLine bl(first, last); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + std::vector expected{ Point{ 5, -5 }, Point{ 5, -4 }, Point{ 5, -3 }, Point{ 5, -2 }, Point{ 5, -1 }, Point{ 5, 0 }, Point{ 5, 1 }, Point{ 5, 2 }, Point{ 5, 3 }, Point{ 5, 4 }, Point{ 5, 5} }; std::vector actual; - CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } - CHECK_EQUAL(expected.size(), bl.count()); + CHECK_EQUAL(expected.size(), bl.size()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -134,18 +131,19 @@ namespace BresenhamLine bl(first, last); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + std::vector expected{ Point{ 5, 5 }, Point{ 5, 4 }, Point{ 5, 3 }, Point{ 5, 2 }, Point{ 5, 1 }, Point{ 5, 0 }, Point{ 5, -1 }, Point{ 5, -2 }, Point{ 5, -3 }, Point{ 5, -4 }, Point{ 5, -5} }; std::vector actual; - CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } - CHECK_EQUAL(expected.size(), bl.count()); + CHECK_EQUAL(expected.size(), bl.size()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -158,18 +156,19 @@ namespace BresenhamLine bl(first, last); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + std::vector expected{ Point{ -5, -3 }, Point{ -4, -3 }, Point{ -3, -2 }, Point{ -2, -1 }, Point{ -1, -1 }, Point{ 0, 0 }, Point{ 1, 1 }, Point{ 2, 1 }, Point{ 3, 2 }, Point{ 4, 2 }, Point{ 5, 3 } }; std::vector actual; - CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } - CHECK_EQUAL(expected.size(), bl.count()); + CHECK_EQUAL(expected.size(), bl.size()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -182,18 +181,19 @@ namespace BresenhamLine bl(first, last); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + std::vector expected{ Point{ 5, 3 }, Point{ 4, 3 }, Point{ 3, 2 }, Point{ 2, 1 }, Point{ 1, 1 }, Point{ 0, 0 }, Point{ -1, -1 }, Point{ -2, -1 }, Point{ -3, -2 }, Point{ -4, -2 }, Point{ -5, -3 } }; std::vector actual; - CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } - CHECK_EQUAL(expected.size(), bl.count()); + CHECK_EQUAL(expected.size(), bl.size()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -206,18 +206,19 @@ namespace BresenhamLine bl(first, last); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + std::vector expected{ Point{ 5, -3 }, Point{ 4, -3 }, Point{ 3, -2 }, Point{ 2, -1 }, Point{ 1, -1 }, Point{ 0, 0 }, Point{ -1, 1 }, Point{ -2, 1 }, Point{ -3, 2 }, Point{ -4, 2 }, Point{ -5, 3 } }; std::vector actual; - CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } - CHECK_EQUAL(expected.size(), bl.count()); + CHECK_EQUAL(expected.size(), bl.size()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -230,18 +231,19 @@ namespace BresenhamLine bl(first, last); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + std::vector expected{ Point{ -5, 3 }, Point{ -4, 3 }, Point{ -3, 2 }, Point{ -2, 1 }, Point{ -1, 1 }, Point{ 0, 0 }, Point{ 1, -1 }, Point{ 2, -1 }, Point{ 3, -2 }, Point{ 4, -2 }, Point{ 5, -3 } }; std::vector actual; - CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } - CHECK_EQUAL(expected.size(), bl.count()); + CHECK_EQUAL(expected.size(), bl.size()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -254,18 +256,19 @@ namespace BresenhamLine bl(first, last); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + std::vector expected{ Point{ -3, -5 }, Point{ -3, -4 }, Point{ -2, -3 }, Point{ -1, -2 }, Point{ -1, -1 }, Point{ 0, 0 }, Point{ 1, 1 }, Point{ 1, 2 }, Point{ 2, 3 }, Point{ 2, 4 }, Point{ 3, 5 } }; std::vector actual; - CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } - CHECK_EQUAL(expected.size(), bl.count()); + CHECK_EQUAL(expected.size(), bl.size()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -278,18 +281,19 @@ namespace BresenhamLine bl(first, last); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + std::vector expected{ Point{ 3, 5 }, Point{ 3, 4 }, Point{ 2, 3 }, Point{ 1, 2 }, Point{ 1, 1 }, Point{ 0, 0 }, Point{ -1, -1 }, Point{ -1, -2 }, Point{ -2, -3 }, Point{ -2, -4 }, Point{ -3, -5 } }; std::vector actual; - CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } - CHECK_EQUAL(expected.size(), bl.count()); + CHECK_EQUAL(expected.size(), bl.size()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -302,18 +306,19 @@ namespace BresenhamLine bl(first, last); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + std::vector expected{ Point{ 3, -5 }, Point{ 3, -4 }, Point{ 2, -3 }, Point{ 1, -2 }, Point{ 1, -1 }, Point{ 0, 0 }, Point{ -1, 1 }, Point{ -1, 2 }, Point{ -2, 3 }, Point{ -2, 4 }, Point{ -3, 5 } }; std::vector actual; - CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } - CHECK_EQUAL(expected.size(), bl.count()); + CHECK_EQUAL(expected.size(), bl.size()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } @@ -326,53 +331,55 @@ namespace BresenhamLine bl(first, last); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + std::vector expected{ Point{ -3, 5 }, Point{ -3, 4 }, Point{ -2, 3 }, Point{ -1, 2 }, Point{ -1, 1 }, Point{ 0, 0 }, Point{ 1, -1 }, Point{ 1, -2 }, Point{ 2, -3 }, Point{ 2, -4 }, Point{ 3, -5 } }; std::vector actual; - CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } - CHECK_EQUAL(expected.size(), bl.count()); + CHECK_EQUAL(expected.size(), bl.size()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } //************************************************************************* - TEST(update_the_line_from_coordinate_2d) + TEST(reset_the_line_from_coordinate_2d) { Point first = { 3, -5 }; Point last = { -3, 5 }; BresenhamLine bl(first, last); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); + Point new_first = { -3, 5 }; Point new_last = { 3, -5 }; - bl.update_line(new_first, new_last); + bl.reset(new_first, new_last); std::vector expected{ Point{ -3, 5 }, Point{ -3, 4 }, Point{ -2, 3 }, Point{ -1, 2 }, Point{ -1, 1 }, Point{ 0, 0 }, Point{ 1, -1 }, Point{ 1, -2 }, Point{ 2, -3 }, Point{ 2, -4 }, Point{ 3, -5 } }; std::vector actual; - CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } - CHECK_EQUAL(expected.size(), bl.count()); + CHECK_EQUAL(expected.size(), bl.size()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } //************************************************************************* - TEST(update_the_line_from_individual_coordinates) + TEST(reset_the_line_from_individual_coordinates) { Point first = { 3, -5 }; Point last = { -3, 5 }; @@ -382,20 +389,18 @@ namespace Point new_first = { -3, 5 }; Point new_last = { 3, -5 }; - bl.update_line(new_first.x, new_first.y, new_last.x, new_last.y); + bl.reset(new_first.x, new_first.y, new_last.x, new_last.y); std::vector expected{ Point{ -3, 5 }, Point{ -3, 4 }, Point{ -2, 3 }, Point{ -1, 2 }, Point{ -1, 1 }, Point{ 0, 0 }, Point{ 1, -1 }, Point{ 1, -2 }, Point{ 2, -3 }, Point{ 2, -4 }, Point{ 3, -5 } }; std::vector actual; - CHECK_EQUAL(1U, bl.count()); // We already have the first coordinate. - for (BresenhamLine::const_iterator itr = bl.begin(); itr != bl.end(); ++itr) { actual.push_back(*itr); } - CHECK_EQUAL(expected.size(), bl.count()); + CHECK_EQUAL(expected.size(), bl.size()); CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } From d234d5ce0d7f0799894259e2980f2be4e5ce87bd Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 30 Aug 2020 11:20:00 +0100 Subject: [PATCH 19/71] Added a line coordinate generator using the Bresenham algorithm. --- include/etl/version.h | 4 ++-- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 5 +++++ test/CMakeLists.txt | 1 + 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/etl/version.h b/include/etl/version.h index ef007822..a55aef44 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,8 +38,8 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 18 -#define ETL_VERSION_MINOR 12 -#define ETL_VERSION_PATCH 7 +#define ETL_VERSION_MINOR 13 +#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) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index 7236c5c0..492c728b 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.12.7", + "version": "18.13.0", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index 9b86a10b..e4c6c169 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.12.7 +version=18.13.0 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index a99e254c..f28eae34 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,8 @@ +=============================================================================== +18.13.0 +Added a line coordinate generator using the Bresenham algorithm. +The API is similar to a container. + =============================================================================== 18.12.7 Made etl::reference_wrapper API closer to the STL version. Does not support invocation of a callable object. diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 06121a05..14cff1d5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -25,6 +25,7 @@ set(TEST_SOURCE_FILES test_bitset.cpp test_bit_stream.cpp test_bloom_filter.cpp + test_bresenham_line.cpp test_bsd_checksum.cpp test_callback_service.cpp test_callback_timer.cpp From a28d5af6af9691a93050de7c4d3cabdccaad7b7a Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 30 Aug 2020 11:47:08 +0100 Subject: [PATCH 20/71] Added default constructor --- include/etl/bresenham_line.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/etl/bresenham_line.h b/include/etl/bresenham_line.h index ed301368..400d8bd5 100644 --- a/include/etl/bresenham_line.h +++ b/include/etl/bresenham_line.h @@ -154,6 +154,14 @@ namespace etl bresenham_line* p_bresenham_line; }; + //*************************************************** + /// Constructor. + //*************************************************** + bresenham_line() + { + initialise(T(0), T(0), T(0), T(0)); + } + //*************************************************** /// Constructor. /// Supplied first and last coordinates From 0ab92304c0a00792ad978ea786d306c185704080 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 30 Aug 2020 11:51:52 +0100 Subject: [PATCH 21/71] Changed front & back to return const_reference --- include/etl/bresenham_line.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/etl/bresenham_line.h b/include/etl/bresenham_line.h index ed301368..b460de2d 100644 --- a/include/etl/bresenham_line.h +++ b/include/etl/bresenham_line.h @@ -212,7 +212,7 @@ namespace etl //*************************************************** /// Get the first coordinate. //*************************************************** - value_type front() + const_reference front() { return first; } @@ -220,7 +220,7 @@ namespace etl //*************************************************** /// Get the last coordinate. //*************************************************** - value_type back() + const_reference back() { return last; } From 8526b2187cdc9d26791b5c59e71840a2e1da8015 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 30 Aug 2020 12:02:58 +0100 Subject: [PATCH 22/71] Changed front & back to const functions --- include/etl/bresenham_line.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/etl/bresenham_line.h b/include/etl/bresenham_line.h index b460de2d..0fe200be 100644 --- a/include/etl/bresenham_line.h +++ b/include/etl/bresenham_line.h @@ -212,7 +212,7 @@ namespace etl //*************************************************** /// Get the first coordinate. //*************************************************** - const_reference front() + const_reference front() const { return first; } @@ -220,7 +220,7 @@ namespace etl //*************************************************** /// Get the last coordinate. //*************************************************** - const_reference back() + const_reference back() const { return last; } From f8ddfb170018a6dcad4f65d70eec47b03d5d0260 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 30 Aug 2020 12:11:26 +0100 Subject: [PATCH 23/71] Added equality and inequality operators --- include/etl/bresenham_line.h | 16 ++++++++++++++++ test/test_bresenham_line.cpp | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/etl/bresenham_line.h b/include/etl/bresenham_line.h index 0fe200be..d7819274 100644 --- a/include/etl/bresenham_line.h +++ b/include/etl/bresenham_line.h @@ -240,6 +240,22 @@ namespace etl } } + //*************************************************** + /// Equality operator + //*************************************************** + friend bool operator ==(const bresenham_line& lhs, const bresenham_line& rhs) + { + return (lhs.front() == rhs.front()) && (lhs.back() == rhs.back()); + } + + //*************************************************** + /// Inequality operator + //*************************************************** + friend bool operator !=(const bresenham_line& lhs, const bresenham_line& rhs) + { + return !(lhs == rhs); + } + private: //*************************************************** diff --git a/test/test_bresenham_line.cpp b/test/test_bresenham_line.cpp index 0057a984..8ab7906e 100644 --- a/test/test_bresenham_line.cpp +++ b/test/test_bresenham_line.cpp @@ -404,5 +404,23 @@ namespace CHECK_EQUAL(expected.size(), actual.size()); CHECK_ARRAY_EQUAL(expected.data(), actual.data(), (std::max(expected.size(), actual.size()))); } + + //************************************************************************* + TEST(test_equality) + { + BresenhamLine bl1(0, 1, 2, 3); + BresenhamLine bl2(0, 1, 2, 3); + BresenhamLine bl3(0, 1, 2, 4); + BresenhamLine bl4(0, 2, 2, 3); + + CHECK(bl1 == bl2); + CHECK(!(bl1 != bl2)); + + CHECK(bl1 != bl3); + CHECK(!(bl1 == bl3)); + + CHECK(bl1 != bl4); + CHECK(!(bl1 == bl4)); + } }; } From 595a63e6f0b3be4c1d049f1565ee9a6ca35a67ab Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 31 Aug 2020 10:26:38 +0100 Subject: [PATCH 24/71] Minor change to Bresenham line unit test --- test/test_bresenham_line.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_bresenham_line.cpp b/test/test_bresenham_line.cpp index 8ab7906e..2478d285 100644 --- a/test/test_bresenham_line.cpp +++ b/test/test_bresenham_line.cpp @@ -38,7 +38,7 @@ namespace using Point = etl::coordinate_2d; - std::ostream& operator << (std::ostream& os, Point point) + std::ostream& operator << (std::ostream& os, const Point& point) { os << "(" << int(point.x) << "," << int(point.y) << ")"; return os; From d400fe2f92d959d97d0f93f4eb7a2d1960f19e35 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 31 Aug 2020 10:45:05 +0100 Subject: [PATCH 25/71] Minor change to Bresenham line unit test --- test/test_bresenham_line.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_bresenham_line.cpp b/test/test_bresenham_line.cpp index 2478d285..f1642a1a 100644 --- a/test/test_bresenham_line.cpp +++ b/test/test_bresenham_line.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include "etl/bresenham_line.h" #include +#include namespace { From 0a7148a796ff56f64c23a08fa127897222a13cb4 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 31 Aug 2020 11:01:55 +0100 Subject: [PATCH 26/71] Minor change to Bresenham line unit test --- test/test_bresenham_line.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/test_bresenham_line.cpp b/test/test_bresenham_line.cpp index f1642a1a..2ad91abf 100644 --- a/test/test_bresenham_line.cpp +++ b/test/test_bresenham_line.cpp @@ -39,16 +39,16 @@ namespace using Point = etl::coordinate_2d; - std::ostream& operator << (std::ostream& os, const Point& point) - { - os << "(" << int(point.x) << "," << int(point.y) << ")"; - return os; - } - using BresenhamLine = etl::bresenham_line; SUITE(test_bresenham_line) { + std::ostream& operator << (std::ostream & os, const Point & point) + { + os << "(" << int(point.x) << "," << int(point.y) << ")"; + return os; + } + //************************************************************************* TEST(horizontal_line_left_right) { From 360afcf0e56b46dc13831eefbb5eb37054e581a2 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 31 Aug 2020 11:07:17 +0100 Subject: [PATCH 27/71] Minor change to Bresenham line unit test --- test/test_bresenham_line.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/test_bresenham_line.cpp b/test/test_bresenham_line.cpp index 2ad91abf..efdfefaf 100644 --- a/test/test_bresenham_line.cpp +++ b/test/test_bresenham_line.cpp @@ -33,22 +33,22 @@ SOFTWARE. #include #include +using Value = char; + +using Point = etl::coordinate_2d; + +std::ostream& operator << (std::ostream& os, const Point& point) +{ + os << "(" << int(point.x) << "," << int(point.y) << ")"; + return os; +} + namespace { - using Value = char; - - using Point = etl::coordinate_2d; - using BresenhamLine = etl::bresenham_line; SUITE(test_bresenham_line) { - std::ostream& operator << (std::ostream & os, const Point & point) - { - os << "(" << int(point.x) << "," << int(point.y) << ")"; - return os; - } - //************************************************************************* TEST(horizontal_line_left_right) { From 2b33a7c2115c7f392d18f6573903327696a674dc Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 31 Aug 2020 11:16:42 +0100 Subject: [PATCH 28/71] Revert changes --- test/test_bresenham_line.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/test/test_bresenham_line.cpp b/test/test_bresenham_line.cpp index efdfefaf..2478d285 100644 --- a/test/test_bresenham_line.cpp +++ b/test/test_bresenham_line.cpp @@ -31,20 +31,19 @@ SOFTWARE. #include "etl/bresenham_line.h" #include -#include - -using Value = char; - -using Point = etl::coordinate_2d; - -std::ostream& operator << (std::ostream& os, const Point& point) -{ - os << "(" << int(point.x) << "," << int(point.y) << ")"; - return os; -} namespace { + using Value = char; + + using Point = etl::coordinate_2d; + + std::ostream& operator << (std::ostream& os, const Point& point) + { + os << "(" << int(point.x) << "," << int(point.y) << ")"; + return os; + } + using BresenhamLine = etl::bresenham_line; SUITE(test_bresenham_line) From df5dee660923528d212e87946c0e3ef1032bd4d8 Mon Sep 17 00:00:00 2001 From: Shiven Gupta <48270070+sgupta20@users.noreply.github.com> Date: Wed, 9 Sep 2020 03:29:07 -0400 Subject: [PATCH 29/71] Add template deduction guides for array and array_view (#263) --- include/etl/array.h | 10 +++++++++- include/etl/array_view.h | 20 +++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/etl/array.h b/include/etl/array.h index e92f25cc..87a036d4 100644 --- a/include/etl/array.h +++ b/include/etl/array.h @@ -552,6 +552,15 @@ namespace etl T _buffer[SIZE]; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#ifdef ETL_CPP17_SUPPORTED + template + array(T, Ts...) + -> array && ...), T>, 1 + sizeof...(Ts)>; +#endif + //************************************************************************* /// Overloaded swap for etl::array ///\param lhs The first array. @@ -670,4 +679,3 @@ namespace etl } #endif - diff --git a/include/etl/array_view.h b/include/etl/array_view.h index 9f333b41..530f354c 100644 --- a/include/etl/array_view.h +++ b/include/etl/array_view.h @@ -40,6 +40,7 @@ SOFTWARE. #include "hash.h" #include "algorithm.h" #include "memory.h" +#include "type_traits.h" ///\defgroup array array /// A wrapper for arrays @@ -505,6 +506,24 @@ namespace etl T* mend; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#ifdef ETL_CPP17_SUPPORTED + template + array_view(TArray& a) + -> array_view; + + template + array_view(const TIterator begin_, const TIterator end_) + -> array_view>; + + template + array_view(const TIterator begin_, const TSize size_) + -> array_view>; +#endif + //************************************************************************* /// Hash function. //************************************************************************* @@ -533,4 +552,3 @@ void swap(etl::array_view& lhs, etl::array_view& rhs) #undef ETL_FILE #endif - From 14d1b96c649d4a607c5eacb9a53423e996740fcc Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 10 Sep 2020 13:07:04 +0100 Subject: [PATCH 30/71] Added template deduction guides for array and array_view --- include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 4 ++++ test/test_array.cpp | 10 ++++++++++ test/test_array_view.cpp | 31 +++++++++++++++++++++++++++++++ 6 files changed, 48 insertions(+), 3 deletions(-) diff --git a/include/etl/version.h b/include/etl/version.h index a55aef44..47a98a93 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,7 +38,7 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 18 -#define ETL_VERSION_MINOR 13 +#define ETL_VERSION_MINOR 14 #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 492c728b..43b5118a 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.13.0", + "version": "18.14.0", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index e4c6c169..bb380c9a 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.13.0 +version=18.14.0 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index f28eae34..1d30d3fd 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +18.14.0 +Added template deduction guides for array and array_view + =============================================================================== 18.13.0 Added a line coordinate generator using the Bresenham algorithm. diff --git a/test/test_array.cpp b/test/test_array.cpp index 89965a17..5111a087 100644 --- a/test/test_array.cpp +++ b/test/test_array.cpp @@ -57,6 +57,16 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::array data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + Data compare = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + bool isEqual = std::equal(data.begin(), data.end(), compare.begin()); + CHECK(isEqual); + } + //************************************************************************* TEST(test_assignment) { diff --git a/test/test_array_view.cpp b/test/test_array_view.cpp index 89750b0a..dfabc9a7 100644 --- a/test/test_array_view.cpp +++ b/test/test_array_view.cpp @@ -247,6 +247,37 @@ namespace CHECK(isEqual); } + //************************************************************************* + TEST(test_cpp17_dedused_constructor) + { + etl::array data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + etl::array_view view1{ data }; + etl::array_view view2{ data.begin(), data.end() }; + etl::array_view view3{ data.begin(), data.size() }; + etl::array_view view4{ view1 }; + + int c_array[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + etl::array_view view5{ c_array }; + + bool isEqual = false; + + isEqual = std::equal(view1.begin(), view1.end(), data.begin()); + CHECK(isEqual); + + isEqual = std::equal(view2.begin(), view2.end(), data.begin()); + CHECK(isEqual); + + isEqual = std::equal(view3.begin(), view3.end(), data.begin()); + CHECK(isEqual); + + isEqual = std::equal(view4.begin(), view4.end(), data.begin()); + CHECK(isEqual); + + isEqual = std::equal(view5.begin(), view5.end(), c_array); + CHECK(isEqual); + } + //************************************************************************* TEST(test_constructor_range) { From 2abc4ee96211365ebff99cd85787691171c853ce Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 12 Sep 2020 13:55:09 +0100 Subject: [PATCH 31/71] Fixed conditional compilation macro use for template deduction guides --- include/etl/array.h | 2 +- include/etl/array_view.h | 2 +- include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 4 ++++ 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/etl/array.h b/include/etl/array.h index 87a036d4..188ce506 100644 --- a/include/etl/array.h +++ b/include/etl/array.h @@ -555,7 +555,7 @@ namespace etl //************************************************************************* /// Template deduction guides. //************************************************************************* -#ifdef ETL_CPP17_SUPPORTED +#if ETL_CPP17_SUPPORTED template array(T, Ts...) -> array && ...), T>, 1 + sizeof...(Ts)>; diff --git a/include/etl/array_view.h b/include/etl/array_view.h index 530f354c..83f102b2 100644 --- a/include/etl/array_view.h +++ b/include/etl/array_view.h @@ -509,7 +509,7 @@ namespace etl //************************************************************************* /// Template deduction guides. //************************************************************************* -#ifdef ETL_CPP17_SUPPORTED +#if ETL_CPP17_SUPPORTED template array_view(TArray& a) -> array_view; diff --git a/include/etl/version.h b/include/etl/version.h index 47a98a93..d09a042f 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 18 #define ETL_VERSION_MINOR 14 -#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) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index 43b5118a..f519d66c 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.14.0", + "version": "18.14.1", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index bb380c9a..f359f708 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.14.0 +version=18.14.1 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 1d30d3fd..84c36e41 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +18.14.1 +Fixed conditional compilation macro use for template deduction guides. + =============================================================================== 18.14.0 Added template deduction guides for array and array_view From 5aa3d734a65aa59abe7590c47bd692bcb47034a4 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 12 Sep 2020 14:10:36 +0100 Subject: [PATCH 32/71] Changed #if defined (ETL_NO_STL) to #if ETL_NOT_USING_STL --- include/etl/algorithm.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/include/etl/algorithm.h b/include/etl/algorithm.h index 0fb55434..48f4c36d 100644 --- a/include/etl/algorithm.h +++ b/include/etl/algorithm.h @@ -690,7 +690,7 @@ namespace etl } #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // count_if template @@ -722,7 +722,7 @@ namespace etl } #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // equal template @@ -761,7 +761,7 @@ namespace etl } #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // lexicographical_compare template @@ -823,7 +823,7 @@ namespace etl } #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // min template @@ -859,7 +859,7 @@ namespace etl } #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // max template @@ -895,7 +895,7 @@ namespace etl } #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // transform template @@ -935,7 +935,7 @@ namespace etl } #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // replace template @@ -1056,7 +1056,7 @@ namespace etl } } - #if defined (ETL_NO_STL) + #if ETL_NOT_USING_STL // Pop Heap template void pop_heap(TIterator first, TIterator last, TCompare compare) @@ -1258,7 +1258,7 @@ namespace etl #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // Search template @@ -1323,7 +1323,7 @@ namespace etl } #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // Rotate template @@ -1361,7 +1361,7 @@ namespace etl } #endif -#if defined (ETL_NO_STL) +#if ETL_NOT_USING_STL //*************************************************************************** // find_end // Predicate From 83f710d6362cee4ee00b901f8e4bf7a5e1a81ac4 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 12 Sep 2020 14:24:55 +0100 Subject: [PATCH 33/71] Try to detect Appveyor --- test/test_array.cpp | 2 ++ test/test_array_view.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/test/test_array.cpp b/test/test_array.cpp index 5111a087..42a6c2e7 100644 --- a/test/test_array.cpp +++ b/test/test_array.cpp @@ -57,6 +57,7 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } +#ifndef APPVEYOR //************************************************************************* TEST(test_cpp17_deduced_constructor) { @@ -66,6 +67,7 @@ namespace bool isEqual = std::equal(data.begin(), data.end(), compare.begin()); CHECK(isEqual); } +#endif //************************************************************************* TEST(test_assignment) diff --git a/test/test_array_view.cpp b/test/test_array_view.cpp index dfabc9a7..77e54633 100644 --- a/test/test_array_view.cpp +++ b/test/test_array_view.cpp @@ -248,6 +248,7 @@ namespace } //************************************************************************* +#ifndef APPVEYOR TEST(test_cpp17_dedused_constructor) { etl::array data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; @@ -277,6 +278,7 @@ namespace isEqual = std::equal(view5.begin(), view5.end(), c_array); CHECK(isEqual); } +#endif //************************************************************************* TEST(test_constructor_range) From 911ec65e1bff99ced5b3533b2efbcca44bebb220 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 12 Sep 2020 14:45:48 +0100 Subject: [PATCH 34/71] Exclude MSVC compiler due to Appveyor reporting an internal compiler error --- test/test_array.cpp | 2 +- test/test_array_view.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_array.cpp b/test/test_array.cpp index 42a6c2e7..98368651 100644 --- a/test/test_array.cpp +++ b/test/test_array.cpp @@ -57,7 +57,7 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } -#ifndef APPVEYOR +#ifndef ETL_COMPILER_MICROSOFT // Temporarily disabled as Appveyor reports an "internal compiler error //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_array_view.cpp b/test/test_array_view.cpp index 77e54633..be415938 100644 --- a/test/test_array_view.cpp +++ b/test/test_array_view.cpp @@ -248,7 +248,7 @@ namespace } //************************************************************************* -#ifndef APPVEYOR +#ifndef ETL_COMPILER_MICROSOFT // Temporarily disabled as Appveyor reports an "internal compiler error TEST(test_cpp17_dedused_constructor) { etl::array data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; From 33842f4fe50f156acd5716b88002b3e387042c7d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 12 Sep 2020 15:02:02 +0100 Subject: [PATCH 35/71] Work around for Clang error in etl::bresenham_line tests. --- test/test_bresenham_line.cpp | 78 ++++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/test/test_bresenham_line.cpp b/test/test_bresenham_line.cpp index 2478d285..17b9b15d 100644 --- a/test/test_bresenham_line.cpp +++ b/test/test_bresenham_line.cpp @@ -56,8 +56,10 @@ namespace BresenhamLine bl(first.x, first.y, last.x, last.y); - CHECK_EQUAL(first, bl.front()); - CHECK_EQUAL(last, bl.back()); + CHECK_EQUAL(first.x, bl.front().x); + CHECK_EQUAL(first.y, bl.front().y); + CHECK_EQUAL(last.x, bl.back().x); + CHECK_EQUAL(last.y, bl.back().y); std::vector expected{ Point{-5, 5 }, Point{-4, 5 }, Point{-3, 5 }, Point{-2, 5 }, Point{-1, 5 }, Point{ 0, 5 }, Point{ 1, 5 }, Point{ 2, 5 }, Point{ 3, 5 }, Point{ 4, 5 }, Point{ 5, 5} }; @@ -81,8 +83,10 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first, bl.front()); - CHECK_EQUAL(last, bl.back()); + CHECK_EQUAL(first.x, bl.front().x); + CHECK_EQUAL(first.y, bl.front().y); + CHECK_EQUAL(last.x, bl.back().x); + CHECK_EQUAL(last.y, bl.back().y); std::vector expected{ Point{ 5, 5 }, Point{ 4, 5 }, Point{ 3, 5 }, Point{ 2, 5 }, Point{ 1, 5 }, Point{ 0, 5 }, Point{-1, 5 }, Point{-2, 5 }, Point{-3, 5 }, Point{-4, 5 }, Point{-5, 5} }; @@ -106,8 +110,10 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first, bl.front()); - CHECK_EQUAL(last, bl.back()); + CHECK_EQUAL(first.x, bl.front().x); + CHECK_EQUAL(first.y, bl.front().y); + CHECK_EQUAL(last.x, bl.back().x); + CHECK_EQUAL(last.y, bl.back().y); std::vector expected{ Point{ 5, -5 }, Point{ 5, -4 }, Point{ 5, -3 }, Point{ 5, -2 }, Point{ 5, -1 }, Point{ 5, 0 }, Point{ 5, 1 }, Point{ 5, 2 }, Point{ 5, 3 }, Point{ 5, 4 }, Point{ 5, 5} }; @@ -131,8 +137,10 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first, bl.front()); - CHECK_EQUAL(last, bl.back()); + CHECK_EQUAL(first.x, bl.front().x); + CHECK_EQUAL(first.y, bl.front().y); + CHECK_EQUAL(last.x, bl.back().x); + CHECK_EQUAL(last.y, bl.back().y); std::vector expected{ Point{ 5, 5 }, Point{ 5, 4 }, Point{ 5, 3 }, Point{ 5, 2 }, Point{ 5, 1 }, Point{ 5, 0 }, Point{ 5, -1 }, Point{ 5, -2 }, Point{ 5, -3 }, Point{ 5, -4 }, Point{ 5, -5} }; @@ -156,8 +164,10 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first, bl.front()); - CHECK_EQUAL(last, bl.back()); + CHECK_EQUAL(first.x, bl.front().x); + CHECK_EQUAL(first.y, bl.front().y); + CHECK_EQUAL(last.x, bl.back().x); + CHECK_EQUAL(last.y, bl.back().y); std::vector expected{ Point{ -5, -3 }, Point{ -4, -3 }, Point{ -3, -2 }, Point{ -2, -1 }, Point{ -1, -1 }, Point{ 0, 0 }, Point{ 1, 1 }, Point{ 2, 1 }, Point{ 3, 2 }, Point{ 4, 2 }, Point{ 5, 3 } }; @@ -181,8 +191,10 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first, bl.front()); - CHECK_EQUAL(last, bl.back()); + CHECK_EQUAL(first.x, bl.front().x); + CHECK_EQUAL(first.y, bl.front().y); + CHECK_EQUAL(last.x, bl.back().x); + CHECK_EQUAL(last.y, bl.back().y); std::vector expected{ Point{ 5, 3 }, Point{ 4, 3 }, Point{ 3, 2 }, Point{ 2, 1 }, Point{ 1, 1 }, Point{ 0, 0 }, Point{ -1, -1 }, Point{ -2, -1 }, Point{ -3, -2 }, Point{ -4, -2 }, Point{ -5, -3 } }; @@ -206,8 +218,10 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first, bl.front()); - CHECK_EQUAL(last, bl.back()); + CHECK_EQUAL(first.x, bl.front().x); + CHECK_EQUAL(first.y, bl.front().y); + CHECK_EQUAL(last.x, bl.back().x); + CHECK_EQUAL(last.y, bl.back().y); std::vector expected{ Point{ 5, -3 }, Point{ 4, -3 }, Point{ 3, -2 }, Point{ 2, -1 }, Point{ 1, -1 }, Point{ 0, 0 }, Point{ -1, 1 }, Point{ -2, 1 }, Point{ -3, 2 }, Point{ -4, 2 }, Point{ -5, 3 } }; @@ -231,8 +245,10 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first, bl.front()); - CHECK_EQUAL(last, bl.back()); + CHECK_EQUAL(first.x, bl.front().x); + CHECK_EQUAL(first.y, bl.front().y); + CHECK_EQUAL(last.x, bl.back().x); + CHECK_EQUAL(last.y, bl.back().y); std::vector expected{ Point{ -5, 3 }, Point{ -4, 3 }, Point{ -3, 2 }, Point{ -2, 1 }, Point{ -1, 1 }, Point{ 0, 0 }, Point{ 1, -1 }, Point{ 2, -1 }, Point{ 3, -2 }, Point{ 4, -2 }, Point{ 5, -3 } }; @@ -256,8 +272,10 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first, bl.front()); - CHECK_EQUAL(last, bl.back()); + CHECK_EQUAL(first.x, bl.front().x); + CHECK_EQUAL(first.y, bl.front().y); + CHECK_EQUAL(last.x, bl.back().x); + CHECK_EQUAL(last.y, bl.back().y); std::vector expected{ Point{ -3, -5 }, Point{ -3, -4 }, Point{ -2, -3 }, Point{ -1, -2 }, Point{ -1, -1 }, Point{ 0, 0 }, Point{ 1, 1 }, Point{ 1, 2 }, Point{ 2, 3 }, Point{ 2, 4 }, Point{ 3, 5 } }; @@ -281,8 +299,10 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first, bl.front()); - CHECK_EQUAL(last, bl.back()); + CHECK_EQUAL(first.x, bl.front().x); + CHECK_EQUAL(first.y, bl.front().y); + CHECK_EQUAL(last.x, bl.back().x); + CHECK_EQUAL(last.y, bl.back().y); std::vector expected{ Point{ 3, 5 }, Point{ 3, 4 }, Point{ 2, 3 }, Point{ 1, 2 }, Point{ 1, 1 }, Point{ 0, 0 }, Point{ -1, -1 }, Point{ -1, -2 }, Point{ -2, -3 }, Point{ -2, -4 }, Point{ -3, -5 } }; @@ -306,8 +326,10 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first, bl.front()); - CHECK_EQUAL(last, bl.back()); + CHECK_EQUAL(first.x, bl.front().x); + CHECK_EQUAL(first.y, bl.front().y); + CHECK_EQUAL(last.x, bl.back().x); + CHECK_EQUAL(last.y, bl.back().y); std::vector expected{ Point{ 3, -5 }, Point{ 3, -4 }, Point{ 2, -3 }, Point{ 1, -2 }, Point{ 1, -1 }, Point{ 0, 0 }, Point{ -1, 1 }, Point{ -1, 2 }, Point{ -2, 3 }, Point{ -2, 4 }, Point{ -3, 5 } }; @@ -331,8 +353,10 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first, bl.front()); - CHECK_EQUAL(last, bl.back()); + CHECK_EQUAL(first.x, bl.front().x); + CHECK_EQUAL(first.y, bl.front().y); + CHECK_EQUAL(last.x, bl.back().x); + CHECK_EQUAL(last.y, bl.back().y); std::vector expected{ Point{ -3, 5 }, Point{ -3, 4 }, Point{ -2, 3 }, Point{ -1, 2 }, Point{ -1, 1 }, Point{ 0, 0 }, Point{ 1, -1 }, Point{ 1, -2 }, Point{ 2, -3 }, Point{ 2, -4 }, Point{ 3, -5 } }; @@ -356,8 +380,10 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first, bl.front()); - CHECK_EQUAL(last, bl.back()); + CHECK_EQUAL(first.x, bl.front().x); + CHECK_EQUAL(first.y, bl.front().y); + CHECK_EQUAL(last.x, bl.back().x); + CHECK_EQUAL(last.y, bl.back().y); Point new_first = { -3, 5 }; Point new_last = { 3, -5 }; From e7d58dd52b63de05759cd0042347027da7f66a7b Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 12 Sep 2020 15:02:02 +0100 Subject: [PATCH 36/71] Work around for Clang error in etl::bresenham_line tests. --- test/test_bresenham_line.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_bresenham_line.cpp b/test/test_bresenham_line.cpp index 17b9b15d..887df3d0 100644 --- a/test/test_bresenham_line.cpp +++ b/test/test_bresenham_line.cpp @@ -38,7 +38,7 @@ namespace using Point = etl::coordinate_2d; - std::ostream& operator << (std::ostream& os, const Point& point) + std::ostream& operator << (std::ostream& os, const etl::coordinate_2d& point) { os << "(" << int(point.x) << "," << int(point.y) << ")"; return os; From 1b2aca4606fe588596199164f074be274c433040 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 12 Sep 2020 15:02:02 +0100 Subject: [PATCH 37/71] Work around for Clang error in etl::bresenham_line tests. --- test/test_bresenham_line.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/test_bresenham_line.cpp b/test/test_bresenham_line.cpp index 887df3d0..2510117e 100644 --- a/test/test_bresenham_line.cpp +++ b/test/test_bresenham_line.cpp @@ -37,13 +37,19 @@ namespace using Value = char; using Point = etl::coordinate_2d; +} - std::ostream& operator << (std::ostream& os, const etl::coordinate_2d& point) +namespace etl +{ + std::ostream& operator << (std::ostream& os, const Point& point) { os << "(" << int(point.x) << "," << int(point.y) << ")"; return os; } +} +namespace +{ using BresenhamLine = etl::bresenham_line; SUITE(test_bresenham_line) From f7901c28991e01ce64cb6daa5259a1250ad82756 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 12 Sep 2020 15:34:07 +0100 Subject: [PATCH 38/71] Work around for Clang error in etl::bresenham_line tests. --- test/test_bresenham_line.cpp | 98 ++++++++++++++---------------------- 1 file changed, 38 insertions(+), 60 deletions(-) diff --git a/test/test_bresenham_line.cpp b/test/test_bresenham_line.cpp index 2510117e..dacaaad3 100644 --- a/test/test_bresenham_line.cpp +++ b/test/test_bresenham_line.cpp @@ -32,16 +32,10 @@ SOFTWARE. #include -namespace -{ - using Value = char; - - using Point = etl::coordinate_2d; -} - namespace etl { - std::ostream& operator << (std::ostream& os, const Point& point) + template + std::ostream& operator << (std::ostream& os, const etl::coordinate_2d& point) { os << "(" << int(point.x) << "," << int(point.y) << ")"; return os; @@ -50,6 +44,16 @@ namespace etl namespace { + using Value = char; + + using Point = etl::coordinate_2d; + + std::ostream& operator << (std::ostream& os, const Point& point) + { + os << "(" << int(point.x) << "," << int(point.y) << ")"; + return os; + } + using BresenhamLine = etl::bresenham_line; SUITE(test_bresenham_line) @@ -62,10 +66,8 @@ namespace BresenhamLine bl(first.x, first.y, last.x, last.y); - CHECK_EQUAL(first.x, bl.front().x); - CHECK_EQUAL(first.y, bl.front().y); - CHECK_EQUAL(last.x, bl.back().x); - CHECK_EQUAL(last.y, bl.back().y); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); std::vector expected{ Point{-5, 5 }, Point{-4, 5 }, Point{-3, 5 }, Point{-2, 5 }, Point{-1, 5 }, Point{ 0, 5 }, Point{ 1, 5 }, Point{ 2, 5 }, Point{ 3, 5 }, Point{ 4, 5 }, Point{ 5, 5} }; @@ -89,10 +91,8 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first.x, bl.front().x); - CHECK_EQUAL(first.y, bl.front().y); - CHECK_EQUAL(last.x, bl.back().x); - CHECK_EQUAL(last.y, bl.back().y); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); std::vector expected{ Point{ 5, 5 }, Point{ 4, 5 }, Point{ 3, 5 }, Point{ 2, 5 }, Point{ 1, 5 }, Point{ 0, 5 }, Point{-1, 5 }, Point{-2, 5 }, Point{-3, 5 }, Point{-4, 5 }, Point{-5, 5} }; @@ -116,10 +116,8 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first.x, bl.front().x); - CHECK_EQUAL(first.y, bl.front().y); - CHECK_EQUAL(last.x, bl.back().x); - CHECK_EQUAL(last.y, bl.back().y); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); std::vector expected{ Point{ 5, -5 }, Point{ 5, -4 }, Point{ 5, -3 }, Point{ 5, -2 }, Point{ 5, -1 }, Point{ 5, 0 }, Point{ 5, 1 }, Point{ 5, 2 }, Point{ 5, 3 }, Point{ 5, 4 }, Point{ 5, 5} }; @@ -143,10 +141,8 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first.x, bl.front().x); - CHECK_EQUAL(first.y, bl.front().y); - CHECK_EQUAL(last.x, bl.back().x); - CHECK_EQUAL(last.y, bl.back().y); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); std::vector expected{ Point{ 5, 5 }, Point{ 5, 4 }, Point{ 5, 3 }, Point{ 5, 2 }, Point{ 5, 1 }, Point{ 5, 0 }, Point{ 5, -1 }, Point{ 5, -2 }, Point{ 5, -3 }, Point{ 5, -4 }, Point{ 5, -5} }; @@ -170,10 +166,8 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first.x, bl.front().x); - CHECK_EQUAL(first.y, bl.front().y); - CHECK_EQUAL(last.x, bl.back().x); - CHECK_EQUAL(last.y, bl.back().y); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); std::vector expected{ Point{ -5, -3 }, Point{ -4, -3 }, Point{ -3, -2 }, Point{ -2, -1 }, Point{ -1, -1 }, Point{ 0, 0 }, Point{ 1, 1 }, Point{ 2, 1 }, Point{ 3, 2 }, Point{ 4, 2 }, Point{ 5, 3 } }; @@ -197,10 +191,8 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first.x, bl.front().x); - CHECK_EQUAL(first.y, bl.front().y); - CHECK_EQUAL(last.x, bl.back().x); - CHECK_EQUAL(last.y, bl.back().y); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); std::vector expected{ Point{ 5, 3 }, Point{ 4, 3 }, Point{ 3, 2 }, Point{ 2, 1 }, Point{ 1, 1 }, Point{ 0, 0 }, Point{ -1, -1 }, Point{ -2, -1 }, Point{ -3, -2 }, Point{ -4, -2 }, Point{ -5, -3 } }; @@ -224,10 +216,8 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first.x, bl.front().x); - CHECK_EQUAL(first.y, bl.front().y); - CHECK_EQUAL(last.x, bl.back().x); - CHECK_EQUAL(last.y, bl.back().y); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); std::vector expected{ Point{ 5, -3 }, Point{ 4, -3 }, Point{ 3, -2 }, Point{ 2, -1 }, Point{ 1, -1 }, Point{ 0, 0 }, Point{ -1, 1 }, Point{ -2, 1 }, Point{ -3, 2 }, Point{ -4, 2 }, Point{ -5, 3 } }; @@ -251,10 +241,8 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first.x, bl.front().x); - CHECK_EQUAL(first.y, bl.front().y); - CHECK_EQUAL(last.x, bl.back().x); - CHECK_EQUAL(last.y, bl.back().y); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); std::vector expected{ Point{ -5, 3 }, Point{ -4, 3 }, Point{ -3, 2 }, Point{ -2, 1 }, Point{ -1, 1 }, Point{ 0, 0 }, Point{ 1, -1 }, Point{ 2, -1 }, Point{ 3, -2 }, Point{ 4, -2 }, Point{ 5, -3 } }; @@ -278,10 +266,8 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first.x, bl.front().x); - CHECK_EQUAL(first.y, bl.front().y); - CHECK_EQUAL(last.x, bl.back().x); - CHECK_EQUAL(last.y, bl.back().y); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); std::vector expected{ Point{ -3, -5 }, Point{ -3, -4 }, Point{ -2, -3 }, Point{ -1, -2 }, Point{ -1, -1 }, Point{ 0, 0 }, Point{ 1, 1 }, Point{ 1, 2 }, Point{ 2, 3 }, Point{ 2, 4 }, Point{ 3, 5 } }; @@ -305,10 +291,8 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first.x, bl.front().x); - CHECK_EQUAL(first.y, bl.front().y); - CHECK_EQUAL(last.x, bl.back().x); - CHECK_EQUAL(last.y, bl.back().y); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); std::vector expected{ Point{ 3, 5 }, Point{ 3, 4 }, Point{ 2, 3 }, Point{ 1, 2 }, Point{ 1, 1 }, Point{ 0, 0 }, Point{ -1, -1 }, Point{ -1, -2 }, Point{ -2, -3 }, Point{ -2, -4 }, Point{ -3, -5 } }; @@ -332,10 +316,8 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first.x, bl.front().x); - CHECK_EQUAL(first.y, bl.front().y); - CHECK_EQUAL(last.x, bl.back().x); - CHECK_EQUAL(last.y, bl.back().y); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); std::vector expected{ Point{ 3, -5 }, Point{ 3, -4 }, Point{ 2, -3 }, Point{ 1, -2 }, Point{ 1, -1 }, Point{ 0, 0 }, Point{ -1, 1 }, Point{ -1, 2 }, Point{ -2, 3 }, Point{ -2, 4 }, Point{ -3, 5 } }; @@ -359,10 +341,8 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first.x, bl.front().x); - CHECK_EQUAL(first.y, bl.front().y); - CHECK_EQUAL(last.x, bl.back().x); - CHECK_EQUAL(last.y, bl.back().y); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); std::vector expected{ Point{ -3, 5 }, Point{ -3, 4 }, Point{ -2, 3 }, Point{ -1, 2 }, Point{ -1, 1 }, Point{ 0, 0 }, Point{ 1, -1 }, Point{ 1, -2 }, Point{ 2, -3 }, Point{ 2, -4 }, Point{ 3, -5 } }; @@ -386,10 +366,8 @@ namespace BresenhamLine bl(first, last); - CHECK_EQUAL(first.x, bl.front().x); - CHECK_EQUAL(first.y, bl.front().y); - CHECK_EQUAL(last.x, bl.back().x); - CHECK_EQUAL(last.y, bl.back().y); + CHECK_EQUAL(first, bl.front()); + CHECK_EQUAL(last, bl.back()); Point new_first = { -3, 5 }; Point new_last = { 3, -5 }; From f6ce3f59bd9da826817d79947165991ca8655b22 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 15 Sep 2020 19:51:06 +0100 Subject: [PATCH 39/71] Allow strings with external buffers to use a pre-initialised buffer. --- include/etl/cstring.h | 58 ++++++++++------ include/etl/u16string.h | 58 ++++++++++------ include/etl/u32string.h | 58 ++++++++++------ include/etl/version.h | 4 +- include/etl/wstring.h | 58 ++++++++++------ library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 4 ++ test/test_string_char_external_buffer.cpp | 71 ++++++++++++++++++++ test/test_string_u16_external_buffer.cpp | 71 ++++++++++++++++++++ test/test_string_u32_external_buffer.cpp | 71 ++++++++++++++++++++ test/test_string_wchar_t_external_buffer.cpp | 71 ++++++++++++++++++++ 12 files changed, 440 insertions(+), 88 deletions(-) diff --git a/include/etl/cstring.h b/include/etl/cstring.h index a6b424aa..806a5555 100644 --- a/include/etl/cstring.h +++ b/include/etl/cstring.h @@ -274,18 +274,34 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - string(value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) + string(value_type* buffer, size_t buffer_size, bool use_buffer_contents = false) + : istring(buffer, buffer_size - 1U) { - this->initialise(); + if (use_buffer_contents) + { + this->current_size = etl::strlen(buffer); + } + else + { + this->initialise(); + } + } + + //************************************************************************* + /// Constructor direct from buffer. + //************************************************************************* + string(value_type* buffer) + : istring(buffer, etl::strlen(buffer)) + { + this->current_size = etl::strlen(buffer); } //************************************************************************* /// Copy constructor. ///\param other The other string. //************************************************************************* - string(const etl::string<0U>& other, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) + string(const etl::string<0U>& other, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) { this->assign(other); } @@ -294,8 +310,8 @@ namespace etl /// From other istring. ///\param other The other istring. //************************************************************************* - string(const etl::istring& other, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) + string(const etl::istring& other, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) { this->assign(other); } @@ -306,8 +322,8 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - string(const etl::istring& other, value_type* buffer, size_t max_size, size_t position, size_t length_ = npos) - : istring(buffer, max_size - 1) + string(const etl::istring& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos) + : istring(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); @@ -327,8 +343,8 @@ namespace etl /// Constructor, from null terminated text. ///\param text The initial text of the string. //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR string(const value_type* text, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) + ETL_EXPLICIT_STRING_FROM_CHAR string(const value_type* text, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) { this->assign(text, text + etl::char_traits::length(text)); } @@ -338,8 +354,8 @@ namespace etl ///\param text The initial text of the string. ///\param count The number of characters to copy. //************************************************************************* - string(const value_type* text, size_t count, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) + string(const value_type* text, size_t count, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) { this->assign(text, text + count); } @@ -349,8 +365,8 @@ namespace etl ///\param initialSize The initial size of the string. ///\param value The value to fill the string with. //************************************************************************* - string(size_t count, value_type c, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) + string(size_t count, value_type c, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) { this->initialise(); this->resize(count, c); @@ -363,8 +379,8 @@ namespace etl ///\param last The iterator to the last element + 1. //************************************************************************* template - string(TIterator first, TIterator last, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) + string(TIterator first, TIterator last, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) { this->assign(first, last); } @@ -373,8 +389,8 @@ namespace etl //************************************************************************* /// Construct from initializer_list. //************************************************************************* - string(std::initializer_list init, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) + string(std::initializer_list init, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) { this->assign(init.begin(), init.end()); } @@ -384,8 +400,8 @@ namespace etl /// From string_view. ///\param view The string_view. //************************************************************************* - explicit string(const etl::string_view& view, value_type* buffer, size_t max_size) - : istring(buffer, max_size - 1) + explicit string(const etl::string_view& view, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) { this->assign(view.begin(), view.end()); } diff --git a/include/etl/u16string.h b/include/etl/u16string.h index c3911002..f65c9fcf 100644 --- a/include/etl/u16string.h +++ b/include/etl/u16string.h @@ -260,18 +260,34 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - u16string(value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(value_type* buffer, size_t buffer_size, bool use_buffer_contents = false) + : iu16string(buffer, buffer_size - 1U) { - this->initialise(); + if (use_buffer_contents) + { + this->current_size = etl::strlen(buffer); + } + else + { + this->initialise(); + } + } + + //************************************************************************* + /// Constructor direct from buffer. + //************************************************************************* + u16string(value_type* buffer) + : iu16string(buffer, etl::strlen(buffer)) + { + this->current_size = etl::strlen(buffer); } //************************************************************************* /// Copy constructor. ///\param other The other u16string. //************************************************************************* - u16string(const etl::u16string<0U>& other, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(const etl::u16string<0U>& other, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(other); } @@ -280,8 +296,8 @@ namespace etl /// From other iu16string. ///\param other The other iu16string. //************************************************************************* - u16string(const etl::iu16string& other, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(const etl::iu16string& other, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(other); } @@ -292,8 +308,8 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - u16string(const etl::iu16string& other, value_type* buffer, size_t max_size, size_t position, size_t length_ = npos) - : iu16string(buffer, max_size - 1) + u16string(const etl::iu16string& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos) + : iu16string(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); @@ -313,8 +329,8 @@ namespace etl /// Constructor, from null terminated text. ///\param text The initial text of the u16string. //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR u16string(const value_type* text, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + ETL_EXPLICIT_STRING_FROM_CHAR u16string(const value_type* text, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(text, text + etl::char_traits::length(text)); } @@ -324,8 +340,8 @@ namespace etl ///\param text The initial text of the u16string. ///\param count The number of characters to copy. //************************************************************************* - u16string(const value_type* text, size_t count, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(const value_type* text, size_t count, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(text, text + count); } @@ -335,8 +351,8 @@ namespace etl ///\param initialSize The initial size of the u16string. ///\param value The value to fill the u16string with. //************************************************************************* - u16string(size_t count, value_type c, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(size_t count, value_type c, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->initialise(); this->resize(count, c); @@ -349,8 +365,8 @@ namespace etl ///\param last The iterator to the last element + 1. //************************************************************************* template - u16string(TIterator first, TIterator last, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(TIterator first, TIterator last, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(first, last); } @@ -359,8 +375,8 @@ namespace etl //************************************************************************* /// Construct from initializer_list. //************************************************************************* - u16string(std::initializer_list init, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + u16string(std::initializer_list init, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(init.begin(), init.end()); } @@ -370,8 +386,8 @@ namespace etl /// From u16string_view. ///\param view The u16string_view. //************************************************************************* - explicit u16string(const etl::u16string_view& view, value_type* buffer, size_t max_size) - : iu16string(buffer, max_size - 1) + explicit u16string(const etl::u16string_view& view, value_type* buffer, size_t buffer_size) + : iu16string(buffer, buffer_size - 1U) { this->assign(view.begin(), view.end()); } diff --git a/include/etl/u32string.h b/include/etl/u32string.h index 7de99cb6..38c24b4b 100644 --- a/include/etl/u32string.h +++ b/include/etl/u32string.h @@ -260,18 +260,34 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - u32string(value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(value_type* buffer, size_t buffer_size, bool use_buffer_contents = false) + : iu32string(buffer, buffer_size - 1U) { - this->initialise(); + if (use_buffer_contents) + { + this->current_size = etl::strlen(buffer); + } + else + { + this->initialise(); + } + } + + //************************************************************************* + /// Constructor direct from buffer. + //************************************************************************* + u32string(value_type* buffer) + : iu32string(buffer, etl::strlen(buffer)) + { + this->current_size = etl::strlen(buffer); } //************************************************************************* /// Copy constructor. ///\param other The other u32string. //************************************************************************* - u32string(const etl::u32string<0U>& other, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(const etl::u32string<0U>& other, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(other); } @@ -280,8 +296,8 @@ namespace etl /// From other iu32string. ///\param other The other iu32string. //************************************************************************* - u32string(const etl::iu32string& other, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(const etl::iu32string& other, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(other); } @@ -292,8 +308,8 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - u32string(const etl::iu32string& other, value_type* buffer, size_t max_size, size_t position, size_t length_ = npos) - : iu32string(buffer, max_size - 1) + u32string(const etl::iu32string& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos) + : iu32string(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); @@ -313,8 +329,8 @@ namespace etl /// Constructor, from null terminated text. ///\param text The initial text of the u32string. //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR u32string(const value_type* text, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + ETL_EXPLICIT_STRING_FROM_CHAR u32string(const value_type* text, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(text, text + etl::char_traits::length(text)); } @@ -324,8 +340,8 @@ namespace etl ///\param text The initial text of the u32string. ///\param count The number of characters to copy. //************************************************************************* - u32string(const value_type* text, size_t count, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(const value_type* text, size_t count, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(text, text + count); } @@ -335,8 +351,8 @@ namespace etl ///\param initialSize The initial size of the u32string. ///\param value The value to fill the u32string with. //************************************************************************* - u32string(size_t count, value_type c, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(size_t count, value_type c, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->initialise(); this->resize(count, c); @@ -349,8 +365,8 @@ namespace etl ///\param last The iterator to the last element + 1. //************************************************************************* template - u32string(TIterator first, TIterator last, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(TIterator first, TIterator last, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(first, last); } @@ -359,8 +375,8 @@ namespace etl //************************************************************************* /// Construct from initializer_list. //************************************************************************* - u32string(std::initializer_list init, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + u32string(std::initializer_list init, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(init.begin(), init.end()); } @@ -370,8 +386,8 @@ namespace etl /// From u32string_view. ///\param view The u32string_view. //************************************************************************* - explicit u32string(const etl::u32string_view& view, value_type* buffer, size_t max_size) - : iu32string(buffer, max_size - 1) + explicit u32string(const etl::u32string_view& view, value_type* buffer, size_t buffer_size) + : iu32string(buffer, buffer_size - 1U) { this->assign(view.begin(), view.end()); } diff --git a/include/etl/version.h b/include/etl/version.h index d09a042f..eb0b5456 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,8 +38,8 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 18 -#define ETL_VERSION_MINOR 14 -#define ETL_VERSION_PATCH 1 +#define ETL_VERSION_MINOR 15 +#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) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/include/etl/wstring.h b/include/etl/wstring.h index 562ac06e..d5c89661 100644 --- a/include/etl/wstring.h +++ b/include/etl/wstring.h @@ -261,18 +261,34 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - wstring(value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(value_type* buffer, size_t buffer_size, bool use_buffer_contents = false) + : iwstring(buffer, buffer_size - 1U) { - this->initialise(); + if (use_buffer_contents) + { + this->current_size = etl::strlen(buffer); + } + else + { + this->initialise(); + } + } + + //************************************************************************* + /// Constructor direct from buffer. + //************************************************************************* + wstring(value_type* buffer) + : iwstring(buffer, etl::strlen(buffer)) + { + this->current_size = etl::strlen(buffer); } //************************************************************************* /// Copy constructor. ///\param other The other wstring. //************************************************************************* - wstring(const etl::wstring<0U>& other, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(const etl::wstring<0U>& other, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(other); } @@ -281,8 +297,8 @@ namespace etl /// From other iwstring. ///\param other The other iwstring. //************************************************************************* - wstring(const etl::iwstring& other, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(const etl::iwstring& other, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(other); } @@ -293,8 +309,8 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - wstring(const etl::iwstring& other, value_type* buffer, size_t max_size, size_t position, size_t length_ = npos) - : iwstring(buffer, max_size - 1) + wstring(const etl::iwstring& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos) + : iwstring(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); @@ -314,8 +330,8 @@ namespace etl /// Constructor, from null terminated text. ///\param text The initial text of the wstring. //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR wstring(const value_type* text, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + ETL_EXPLICIT_STRING_FROM_CHAR wstring(const value_type* text, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(text, text + etl::char_traits::length(text)); } @@ -325,8 +341,8 @@ namespace etl ///\param text The initial text of the wstring. ///\param count The number of characters to copy. //************************************************************************* - wstring(const value_type* text, size_t count, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(const value_type* text, size_t count, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(text, text + count); } @@ -336,8 +352,8 @@ namespace etl ///\param initialSize The initial size of the wstring. ///\param value The value to fill the wstring with. //************************************************************************* - wstring(size_t count, value_type c, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(size_t count, value_type c, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->initialise(); this->resize(count, c); @@ -350,8 +366,8 @@ namespace etl ///\param last The iterator to the last element + 1. //************************************************************************* template - wstring(TIterator first, TIterator last, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(TIterator first, TIterator last, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(first, last); } @@ -360,8 +376,8 @@ namespace etl //************************************************************************* /// Construct from initializer_list. //************************************************************************* - wstring(std::initializer_list init, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + wstring(std::initializer_list init, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(init.begin(), init.end()); } @@ -371,8 +387,8 @@ namespace etl /// From wstring_view. ///\param view The wstring_view. //************************************************************************* - explicit wstring(const etl::wstring_view& view, value_type* buffer, size_t max_size) - : iwstring(buffer, max_size - 1) + explicit wstring(const etl::wstring_view& view, value_type* buffer, size_t buffer_size) + : iwstring(buffer, buffer_size - 1U) { this->assign(view.begin(), view.end()); } diff --git a/library.json b/library.json index f519d66c..4ea5c97a 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.14.1", + "version": "18.15.0", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index f359f708..7acb642c 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.14.1 +version=18.15.0 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 84c36e41..8f897939 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +18.15.0 +Allow strings with external buffers to use a pre-initialised buffer. + =============================================================================== 18.14.1 Fixed conditional compilation macro use for template deduction guides. diff --git a/test/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index d4f8d9ff..354ed5ca 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -73,6 +73,9 @@ namespace Compare_Text short_text; const value_t* pinitial_text = STR("Hello World"); + + value_t array_text[12]; + value_t* p_text = array_text; //************************************************************************* template @@ -94,6 +97,8 @@ namespace different_text = STR("Byee Planet"); longer_text = STR("Hello World There"); short_text = STR("Hello"); + + std::copy(pinitial_text, pinitial_text + etl::strlen(pinitial_text), array_text); } }; @@ -111,6 +116,72 @@ namespace CHECK(!text.truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text) + { + Text text(p_text); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size) + { + size_t length = etl::strlen(p_text); + Text text(p_text, length + 1); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(length, text.capacity()); + CHECK_EQUAL(length, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size) + { + Text text(p_text, etl::strlen(p_text) + 1, true); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer) + { + Text text(array_text, etl::size(array_text)); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text) + { + Text text(array_text, etl::size(array_text), true); + + CHECK_EQUAL(text.size(), etl::strlen(array_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + //************************************************************************* TEST(test_iterator_comparison_empty) { diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index 08115e6b..2f14651d 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -74,6 +74,9 @@ namespace const value_t* pinitial_text = STR("Hello World"); + value_t array_text[12]; + value_t* p_text = array_text; + //************************************************************************* template bool Equal(const T1& compare_text, const T2& text) @@ -94,6 +97,8 @@ namespace different_text = STR("Byee Planet"); longer_text = STR("Hello World There"); short_text = STR("Hello"); + + std::copy(pinitial_text, pinitial_text + etl::strlen(pinitial_text), array_text); } }; @@ -111,6 +116,72 @@ namespace CHECK(!text.truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text) + { + Text text(p_text); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size) + { + size_t length = etl::strlen(p_text); + Text text(p_text, length + 1); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(length, text.capacity()); + CHECK_EQUAL(length, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size) + { + Text text(p_text, etl::strlen(p_text) + 1, true); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer) + { + Text text(array_text, etl::size(array_text)); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text) + { + Text text(array_text, etl::size(array_text), true); + + CHECK_EQUAL(text.size(), etl::strlen(array_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + //************************************************************************* TEST(test_iterator_comparison_empty) { diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index cdc8d4a1..5500699c 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -74,6 +74,9 @@ namespace const value_t* pinitial_text = STR("Hello World"); + value_t array_text[12]; + value_t* p_text = array_text; + //************************************************************************* template bool Equal(const T1& compare_text, const T2& text) @@ -94,6 +97,8 @@ namespace different_text = STR("Byee Planet"); longer_text = STR("Hello World There"); short_text = STR("Hello"); + + std::copy(pinitial_text, pinitial_text + etl::strlen(pinitial_text), array_text); } }; @@ -111,6 +116,72 @@ namespace CHECK(!text.truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text) + { + Text text(p_text); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size) + { + size_t length = etl::strlen(p_text); + Text text(p_text, length + 1); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(length, text.capacity()); + CHECK_EQUAL(length, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size) + { + Text text(p_text, etl::strlen(p_text) + 1, true); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer) + { + Text text(array_text, etl::size(array_text)); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text) + { + Text text(array_text, etl::size(array_text), true); + + CHECK_EQUAL(text.size(), etl::strlen(array_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + //************************************************************************* TEST(test_iterator_comparison_empty) { diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index b6c851bc..2814f5eb 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -74,6 +74,9 @@ namespace const value_t* pinitial_text = STR("Hello World"); + value_t array_text[12]; + value_t* p_text = array_text; + //************************************************************************* template bool Equal(const T1& compare_text, const T2& text) @@ -94,6 +97,8 @@ namespace different_text = STR("Byee Planet"); longer_text = STR("Hello World There"); short_text = STR("Hello"); + + std::copy(pinitial_text, pinitial_text + etl::strlen(pinitial_text), array_text); } }; @@ -111,6 +116,72 @@ namespace CHECK(!text.truncated()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text) + { + Text text(p_text); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size) + { + size_t length = etl::strlen(p_text); + Text text(p_text, length + 1); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(length, text.capacity()); + CHECK_EQUAL(length, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size) + { + Text text(p_text, etl::strlen(p_text) + 1, true); + + CHECK_EQUAL(text.size(), etl::strlen(p_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::strlen(p_text), text.capacity()); + CHECK_EQUAL(etl::strlen(p_text), text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer) + { + Text text(array_text, etl::size(array_text)); + + CHECK_EQUAL(0U, text.size()); + CHECK(text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() == text.end()); + CHECK(!text.truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text) + { + Text text(array_text, etl::size(array_text), true); + + CHECK_EQUAL(text.size(), etl::strlen(array_text)); + CHECK(!text.empty()); + CHECK_EQUAL(etl::size(array_text) - 1, text.capacity()); + CHECK_EQUAL(etl::size(array_text) - 1, text.max_size()); + CHECK(text.begin() != text.end()); + CHECK(!text.truncated()); + } + //************************************************************************* TEST(test_iterator_comparison_empty) { From 5a5579df7a8a66707399b630e11e67a7fdfcd0d3 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 18 Sep 2020 09:26:02 +0100 Subject: [PATCH 40/71] cstring.h code moved to to string.h --- include/etl/cstring.h | 478 +------------------- include/etl/format_spec.h | 2 +- include/etl/string.h | 503 ++++++++++++++++++++++ include/etl/string_stream.h | 2 +- include/etl/to_string.h | 2 +- include/etl/wstring_stream.h | 2 +- test/test_make_string.cpp | 2 +- test/test_string_char.cpp | 2 +- test/test_string_char_external_buffer.cpp | 2 +- test/test_string_stream.cpp | 2 +- test/test_string_utilities.cpp | 2 +- test/test_string_view.cpp | 2 +- test/test_to_string.cpp | 2 +- test/vs2019/etl.vcxproj | 2 +- test/vs2019/etl.vcxproj.filters | 6 +- 15 files changed, 524 insertions(+), 487 deletions(-) create mode 100644 include/etl/string.h diff --git a/include/etl/cstring.h b/include/etl/cstring.h index 806a5555..4dc5960a 100644 --- a/include/etl/cstring.h +++ b/include/etl/cstring.h @@ -7,7 +7,7 @@ Embedded Template Library. https://github.com/ETLCPP/etl https://www.etlcpp.com -Copyright(c) 2016 jwellbelove +Copyright(c) 2020 jwellbelove Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the "Software"), to deal @@ -28,476 +28,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -#ifndef ETL_STRING_INCLUDED -#define ETL_STRING_INCLUDED +//***************************************************************************** +// This header is deprecated. Use "string.h" +//***************************************************************************** -#include "platform.h" -#include "basic_string.h" -#include "string_view.h" -#include "hash.h" +#pragma message ("This header is deprecated. Use 'etl/string.h'") -#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL - #include -#endif - -#include "private/minmax_push.h" - -namespace etl -{ - typedef etl::ibasic_string istring; - - //*************************************************************************** - /// A string implementation that uses a fixed size buffer. - ///\tparam MAX_SIZE_ The maximum number of elements that can be stored. - ///\ingroup string - //*************************************************************************** - template - class string : public istring - { - public: - - typedef istring base_type; - typedef istring interface_type; - - typedef istring::value_type value_type; - - static const size_t MAX_SIZE = MAX_SIZE_; - - //************************************************************************* - /// Constructor. - //************************************************************************* - string() - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->initialise(); - } - - //************************************************************************* - /// Copy constructor. - ///\param other The other string. - //************************************************************************* - string(const etl::string& other) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(other); - } - - //************************************************************************* - /// From other istring. - ///\param other The other istring. - //************************************************************************* - string(const etl::istring& other) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(other); - } - - //************************************************************************* - /// From other string, position, length. - ///\param other The other string. - ///\param position The position of the first character. - ///\param length The number of characters. Default = npos. - //************************************************************************* - string(const etl::istring& other, size_t position, size_t length_ = npos) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - - this->assign(other.begin() + position, other.begin() + position + length_); - - if (other.truncated()) - { - this->is_truncated = true; - -#if defined(ETL_STRING_TRUNCATION_IS_ERROR) - ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); -#endif - } - } - - //************************************************************************* - /// Constructor, from null terminated text. - ///\param text The initial text of the string. - //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR string(const value_type* text) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(text, text + etl::char_traits::length(text)); - } - - //************************************************************************* - /// Constructor, from null terminated text and count. - ///\param text The initial text of the string. - ///\param count The number of characters to copy. - //************************************************************************* - string(const value_type* text, size_t count) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(text, text + count); - } - - //************************************************************************* - /// Constructor, from initial size and value. - ///\param initialSize The initial size of the string. - ///\param value The value to fill the string with. - //************************************************************************* - string(size_t count, value_type c) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->initialise(); - this->resize(count, c); - } - - //************************************************************************* - /// Constructor, from an iterator range. - ///\tparam TIterator The iterator type. - ///\param first The iterator to the first element. - ///\param last The iterator to the last element + 1. - //************************************************************************* - template - string(TIterator first, TIterator last) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(first, last); - } - -#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL - //************************************************************************* - /// Construct from initializer_list. - //************************************************************************* - string(std::initializer_list init) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(init.begin(), init.end()); - } -#endif - - //************************************************************************* - /// From string_view. - ///\param view The string_view. - //************************************************************************* - explicit string(const etl::string_view& view) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(view.begin(), view.end()); - } - - //************************************************************************* - /// Returns a sub-string. - ///\param position The position of the first character. Default = 0. - ///\param length The number of characters. Default = npos. - //************************************************************************* - etl::string substr(size_t position = 0, size_t length_ = npos) const - { - etl::string new_string; - - if (position != this->size()) - { - ETL_ASSERT(position < this->size(), ETL_ERROR(string_out_of_bounds)); - - length_ = etl::min(length_, this->size() - position); - - new_string.assign(buffer + position, buffer + position + length_); - } - - return new_string; - } - - //************************************************************************* - /// Assignment operator. - //************************************************************************* - string& operator = (const string& rhs) - { - if (&rhs != this) - { - this->assign(rhs); - } - - return *this; - } - - - //************************************************************************* - /// Assignment operator. - //************************************************************************* - string& operator = (const istring& rhs) - { - if (&rhs != this) - { - this->assign(rhs); - } - - return *this; - } - - //************************************************************************* - /// Assignment operator. - //************************************************************************* - string& operator = (const value_type* text) - { - this->assign(text); - - return *this; - } - - //************************************************************************* - /// Fix the internal pointers after a low level memory copy. - //************************************************************************* - void repair() -#ifdef ETL_ISTRING_REPAIR_ENABLE - ETL_OVERRIDE -#endif - { - etl::istring::repair_buffer(buffer); - } - - private: - - value_type buffer[MAX_SIZE + 1]; - }; - - //*************************************************************************** - /// A string implementation that uses a fixed size buffer. - /// A specilisation that requires an external buffer to be specified. - ///\ingroup string - //*************************************************************************** - template <> - class string<0U> : public istring - { - public: - - typedef istring base_type; - typedef istring interface_type; - - typedef istring::value_type value_type; - - //************************************************************************* - /// Constructor. - //************************************************************************* - string(value_type* buffer, size_t buffer_size, bool use_buffer_contents = false) - : istring(buffer, buffer_size - 1U) - { - if (use_buffer_contents) - { - this->current_size = etl::strlen(buffer); - } - else - { - this->initialise(); - } - } - - //************************************************************************* - /// Constructor direct from buffer. - //************************************************************************* - string(value_type* buffer) - : istring(buffer, etl::strlen(buffer)) - { - this->current_size = etl::strlen(buffer); - } - - //************************************************************************* - /// Copy constructor. - ///\param other The other string. - //************************************************************************* - string(const etl::string<0U>& other, value_type* buffer, size_t buffer_size) - : istring(buffer, buffer_size - 1U) - { - this->assign(other); - } - - //************************************************************************* - /// From other istring. - ///\param other The other istring. - //************************************************************************* - string(const etl::istring& other, value_type* buffer, size_t buffer_size) - : istring(buffer, buffer_size - 1U) - { - this->assign(other); - } - - //************************************************************************* - /// From other string, position, length. - ///\param other The other string. - ///\param position The position of the first character. - ///\param length The number of characters. Default = npos. - //************************************************************************* - string(const etl::istring& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos) - : istring(buffer, buffer_size - 1U) - { - ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - - this->assign(other.begin() + position, other.begin() + position + length_); - - if (other.truncated()) - { - this->is_truncated = true; - -#if defined(ETL_STRING_TRUNCATION_IS_ERROR) - ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); -#endif - } - } - - //************************************************************************* - /// Constructor, from null terminated text. - ///\param text The initial text of the string. - //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR string(const value_type* text, value_type* buffer, size_t buffer_size) - : istring(buffer, buffer_size - 1U) - { - this->assign(text, text + etl::char_traits::length(text)); - } - - //************************************************************************* - /// Constructor, from null terminated text and count. - ///\param text The initial text of the string. - ///\param count The number of characters to copy. - //************************************************************************* - string(const value_type* text, size_t count, value_type* buffer, size_t buffer_size) - : istring(buffer, buffer_size - 1U) - { - this->assign(text, text + count); - } - - //************************************************************************* - /// Constructor, from initial size and value. - ///\param initialSize The initial size of the string. - ///\param value The value to fill the string with. - //************************************************************************* - string(size_t count, value_type c, value_type* buffer, size_t buffer_size) - : istring(buffer, buffer_size - 1U) - { - this->initialise(); - this->resize(count, c); - } - - //************************************************************************* - /// Constructor, from an iterator range. - ///\tparam TIterator The iterator type. - ///\param first The iterator to the first element. - ///\param last The iterator to the last element + 1. - //************************************************************************* - template - string(TIterator first, TIterator last, value_type* buffer, size_t buffer_size) - : istring(buffer, buffer_size - 1U) - { - this->assign(first, last); - } - -#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL - //************************************************************************* - /// Construct from initializer_list. - //************************************************************************* - string(std::initializer_list init, value_type* buffer, size_t buffer_size) - : istring(buffer, buffer_size - 1U) - { - this->assign(init.begin(), init.end()); - } -#endif - - //************************************************************************* - /// From string_view. - ///\param view The string_view. - //************************************************************************* - explicit string(const etl::string_view& view, value_type* buffer, size_t buffer_size) - : istring(buffer, buffer_size - 1U) - { - this->assign(view.begin(), view.end()); - } - - //************************************************************************* - /// Assignment operator. - //************************************************************************* - string& operator = (const string& rhs) - { - if (&rhs != this) - { - this->assign(rhs); - } - - return *this; - } - - - //************************************************************************* - /// Assignment operator. - //************************************************************************* - string& operator = (const istring& rhs) - { - if (&rhs != this) - { - this->assign(rhs); - } - - return *this; - } - - //************************************************************************* - /// Assignment operator. - //************************************************************************* - string& operator = (const value_type* text) - { - this->assign(text); - - return *this; - } - - //************************************************************************* - /// Fix the internal pointers after a low level memory copy. - //************************************************************************* - void repair() -#ifdef ETL_ISTRING_REPAIR_ENABLE - ETL_OVERRIDE -#endif - { - } - }; - - //************************************************************************* - /// Hash function. - //************************************************************************* -#if ETL_8BIT_SUPPORT - template <> - struct hash - { - size_t operator()(const etl::istring& text) const - { - return etl::private_hash::generic_hash(reinterpret_cast(&text[0]), - reinterpret_cast(&text[text.size()])); - } - }; - - template - struct hash > - { - size_t operator()(const etl::string& text) const - { - return etl::private_hash::generic_hash(reinterpret_cast(&text[0]), - reinterpret_cast(&text[text.size()])); - } - }; -#endif - - //*************************************************************************** - /// Make string from string literal or char array - //*************************************************************************** - template - etl::string make_string(const char (&text) [MAX_SIZE]) - { - return etl::string(text, MAX_SIZE - 1); - } - - //*************************************************************************** - /// Make string with max capacity from string literal or char array - //*************************************************************************** - template - etl::string make_string_with_capacity(const char(&text)[SIZE]) - { - return etl::string(text, SIZE - 1); - } -} - -#include "private/minmax_pop.h" - -#endif +#include "string.h" diff --git a/include/etl/format_spec.h b/include/etl/format_spec.h index 27cbcaa0..3ea29cab 100644 --- a/include/etl/format_spec.h +++ b/include/etl/format_spec.h @@ -35,7 +35,7 @@ SOFTWARE. #include "platform.h" #include "basic_format_spec.h" -#include "cstring.h" +#include "string.h" namespace etl { diff --git a/include/etl/string.h b/include/etl/string.h new file mode 100644 index 00000000..aab0f55f --- /dev/null +++ b/include/etl/string.h @@ -0,0 +1,503 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2016 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_STRING_INCLUDED +#define ETL_STRING_INCLUDED + +#include "platform.h" +#include "basic_string.h" +#include "string_view.h" +#include "hash.h" + +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL +#include +#endif + +#include "private/minmax_push.h" + +namespace etl +{ + typedef etl::ibasic_string istring; + + //*************************************************************************** + /// A string implementation that uses a fixed size buffer. + ///\tparam MAX_SIZE_ The maximum number of elements that can be stored. + ///\ingroup string + //*************************************************************************** + template + class string : public istring + { + public: + + typedef istring base_type; + typedef istring interface_type; + + typedef istring::value_type value_type; + + static const size_t MAX_SIZE = MAX_SIZE_; + + //************************************************************************* + /// Constructor. + //************************************************************************* + string() + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->initialise(); + } + + //************************************************************************* + /// Copy constructor. + ///\param other The other string. + //************************************************************************* + string(const etl::string& other) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(other); + } + + //************************************************************************* + /// From other istring. + ///\param other The other istring. + //************************************************************************* + string(const etl::istring& other) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(other); + } + + //************************************************************************* + /// From other string, position, length. + ///\param other The other string. + ///\param position The position of the first character. + ///\param length The number of characters. Default = npos. + //************************************************************************* + string(const etl::istring& other, size_t position, size_t length_ = npos) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); + + this->assign(other.begin() + position, other.begin() + position + length_); + + if (other.truncated()) + { + this->is_truncated = true; + +#if defined(ETL_STRING_TRUNCATION_IS_ERROR) + ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); +#endif + } + } + + //************************************************************************* + /// Constructor, from null terminated text. + ///\param text The initial text of the string. + //************************************************************************* + ETL_EXPLICIT_STRING_FROM_CHAR string(const value_type* text) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(text, text + etl::char_traits::length(text)); + } + + //************************************************************************* + /// Constructor, from null terminated text and count. + ///\param text The initial text of the string. + ///\param count The number of characters to copy. + //************************************************************************* + string(const value_type* text, size_t count) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(text, text + count); + } + + //************************************************************************* + /// Constructor, from initial size and value. + ///\param initialSize The initial size of the string. + ///\param value The value to fill the string with. + //************************************************************************* + string(size_t count, value_type c) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->initialise(); + this->resize(count, c); + } + + //************************************************************************* + /// Constructor, from an iterator range. + ///\tparam TIterator The iterator type. + ///\param first The iterator to the first element. + ///\param last The iterator to the last element + 1. + //************************************************************************* + template + string(TIterator first, TIterator last) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(first, last); + } + +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + //************************************************************************* + /// Construct from initializer_list. + //************************************************************************* + string(std::initializer_list init) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(init.begin(), init.end()); + } +#endif + + //************************************************************************* + /// From string_view. + ///\param view The string_view. + //************************************************************************* + explicit string(const etl::string_view& view) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(view.begin(), view.end()); + } + + //************************************************************************* + /// Returns a sub-string. + ///\param position The position of the first character. Default = 0. + ///\param length The number of characters. Default = npos. + //************************************************************************* + etl::string substr(size_t position = 0, size_t length_ = npos) const + { + etl::string new_string; + + if (position != this->size()) + { + ETL_ASSERT(position < this->size(), ETL_ERROR(string_out_of_bounds)); + + length_ = etl::min(length_, this->size() - position); + + new_string.assign(buffer + position, buffer + position + length_); + } + + return new_string; + } + + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string& operator = (const string& rhs) + { + if (&rhs != this) + { + this->assign(rhs); + } + + return *this; + } + + + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string& operator = (const istring& rhs) + { + if (&rhs != this) + { + this->assign(rhs); + } + + return *this; + } + + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string& operator = (const value_type* text) + { + this->assign(text); + + return *this; + } + + //************************************************************************* + /// Fix the internal pointers after a low level memory copy. + //************************************************************************* + void repair() +#ifdef ETL_ISTRING_REPAIR_ENABLE + ETL_OVERRIDE +#endif + { + etl::istring::repair_buffer(buffer); + } + + private: + + value_type buffer[MAX_SIZE + 1]; + }; + + //*************************************************************************** + /// A string implementation that uses a fixed size buffer. + /// A specilisation that requires an external buffer to be specified. + ///\ingroup string + //*************************************************************************** + template <> + class string<0U> : public istring + { + public: + + typedef istring base_type; + typedef istring interface_type; + + typedef istring::value_type value_type; + + //************************************************************************* + /// Constructor. + //************************************************************************* + string(value_type* buffer, size_t buffer_size, bool use_buffer_contents = false) + : istring(buffer, buffer_size - 1U) + { + if (use_buffer_contents) + { + this->current_size = etl::strlen(buffer); + } + else + { + this->initialise(); + } + } + + //************************************************************************* + /// Constructor direct from buffer. + //************************************************************************* + string(value_type* buffer) + : istring(buffer, etl::strlen(buffer)) + { + this->current_size = etl::strlen(buffer); + } + + //************************************************************************* + /// Copy constructor. + ///\param other The other string. + //************************************************************************* + string(const etl::string<0U>& other, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->assign(other); + } + + //************************************************************************* + /// From other istring. + ///\param other The other istring. + //************************************************************************* + string(const etl::istring& other, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->assign(other); + } + + //************************************************************************* + /// From other string, position, length. + ///\param other The other string. + ///\param position The position of the first character. + ///\param length The number of characters. Default = npos. + //************************************************************************* + string(const etl::istring& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos) + : istring(buffer, buffer_size - 1U) + { + ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); + + this->assign(other.begin() + position, other.begin() + position + length_); + + if (other.truncated()) + { + this->is_truncated = true; + +#if defined(ETL_STRING_TRUNCATION_IS_ERROR) + ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); +#endif + } + } + + //************************************************************************* + /// Constructor, from null terminated text. + ///\param text The initial text of the string. + //************************************************************************* + ETL_EXPLICIT_STRING_FROM_CHAR string(const value_type* text, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->assign(text, text + etl::char_traits::length(text)); + } + + //************************************************************************* + /// Constructor, from null terminated text and count. + ///\param text The initial text of the string. + ///\param count The number of characters to copy. + //************************************************************************* + string(const value_type* text, size_t count, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->assign(text, text + count); + } + + //************************************************************************* + /// Constructor, from initial size and value. + ///\param initialSize The initial size of the string. + ///\param value The value to fill the string with. + //************************************************************************* + string(size_t count, value_type c, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->initialise(); + this->resize(count, c); + } + + //************************************************************************* + /// Constructor, from an iterator range. + ///\tparam TIterator The iterator type. + ///\param first The iterator to the first element. + ///\param last The iterator to the last element + 1. + //************************************************************************* + template + string(TIterator first, TIterator last, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->assign(first, last); + } + +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + //************************************************************************* + /// Construct from initializer_list. + //************************************************************************* + string(std::initializer_list init, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->assign(init.begin(), init.end()); + } +#endif + + //************************************************************************* + /// From string_view. + ///\param view The string_view. + //************************************************************************* + explicit string(const etl::string_view& view, value_type* buffer, size_t buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->assign(view.begin(), view.end()); + } + + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string& operator = (const string& rhs) + { + if (&rhs != this) + { + this->assign(rhs); + } + + return *this; + } + + + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string& operator = (const istring& rhs) + { + if (&rhs != this) + { + this->assign(rhs); + } + + return *this; + } + + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string& operator = (const value_type* text) + { + this->assign(text); + + return *this; + } + + //************************************************************************* + /// Fix the internal pointers after a low level memory copy. + //************************************************************************* + void repair() +#ifdef ETL_ISTRING_REPAIR_ENABLE + ETL_OVERRIDE +#endif + { + } + }; + + //************************************************************************* + /// Hash function. + //************************************************************************* +#if ETL_8BIT_SUPPORT + template <> + struct hash + { + size_t operator()(const etl::istring& text) const + { + return etl::private_hash::generic_hash(reinterpret_cast(&text[0]), + reinterpret_cast(&text[text.size()])); + } + }; + + template + struct hash > + { + size_t operator()(const etl::string& text) const + { + return etl::private_hash::generic_hash(reinterpret_cast(&text[0]), + reinterpret_cast(&text[text.size()])); + } + }; +#endif + + //*************************************************************************** + /// Make string from string literal or char array + //*************************************************************************** + template + etl::string make_string(const char(&text)[MAX_SIZE]) + { + return etl::string(text, MAX_SIZE - 1); + } + + //*************************************************************************** + /// Make string with max capacity from string literal or char array + //*************************************************************************** + template + etl::string make_string_with_capacity(const char(&text)[SIZE]) + { + return etl::string(text, SIZE - 1); + } +} + +#include "private/minmax_pop.h" + +#endif diff --git a/include/etl/string_stream.h b/include/etl/string_stream.h index de244492..d6e2c231 100644 --- a/include/etl/string_stream.h +++ b/include/etl/string_stream.h @@ -34,7 +34,7 @@ SOFTWARE. ///\ingroup string #include "platform.h" -#include "cstring.h" +#include "string.h" #include "format_spec.h" #include "to_string.h" #include "string_view.h" diff --git a/include/etl/to_string.h b/include/etl/to_string.h index c8fe60b0..4535d2c9 100644 --- a/include/etl/to_string.h +++ b/include/etl/to_string.h @@ -35,7 +35,7 @@ SOFTWARE. #include "platform.h" #include "type_traits.h" -#include "cstring.h" +#include "string.h" #include "format_spec.h" #include "private/to_string_helper.h" diff --git a/include/etl/wstring_stream.h b/include/etl/wstring_stream.h index 6139937f..d3a6000e 100644 --- a/include/etl/wstring_stream.h +++ b/include/etl/wstring_stream.h @@ -34,7 +34,7 @@ SOFTWARE. ///\ingroup string #include "platform.h" -#include "cstring.h" +#include "string.h" #include "wformat_spec.h" #include "to_wstring.h" #include "string_view.h" diff --git a/test/test_make_string.cpp b/test/test_make_string.cpp index 5d6035e1..202bc66d 100644 --- a/test/test_make_string.cpp +++ b/test/test_make_string.cpp @@ -30,7 +30,7 @@ SOFTWARE. #include -#include "etl/cstring.h" +#include "etl/string.h" #include "etl/wstring.h" #include "etl/u16string.h" #include "etl/u32string.h" diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 261afe5c..e932bf94 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -32,7 +32,7 @@ SOFTWARE. #include #include -#include "etl/cstring.h" +#include "etl/string.h" #include "etl/fnv_1.h" #undef STR diff --git a/test/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index 354ed5ca..a2e6bf9c 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -32,7 +32,7 @@ SOFTWARE. #include #include -#include "etl/cstring.h" +#include "etl/string.h" #include "etl/fnv_1.h" #undef STR diff --git a/test/test_string_stream.cpp b/test/test_string_stream.cpp index c2a7bb61..3aa81d03 100644 --- a/test/test_string_stream.cpp +++ b/test/test_string_stream.cpp @@ -33,7 +33,7 @@ SOFTWARE. #include #include "etl/string_stream.h" -#include "etl/cstring.h" +#include "etl/string.h" #include "etl/format_spec.h" #undef STR diff --git a/test/test_string_utilities.cpp b/test/test_string_utilities.cpp index 19266338..94c2ae41 100644 --- a/test/test_string_utilities.cpp +++ b/test/test_string_utilities.cpp @@ -28,7 +28,7 @@ SOFTWARE. #include "UnitTest++/UnitTest++.h" -#include "etl/cstring.h" +#include "etl/string.h" #include "etl/string_view.h" #include "etl/string_utilities.h" #include "etl/vector.h" diff --git a/test/test_string_view.cpp b/test/test_string_view.cpp index 4da60391..c1445b6d 100644 --- a/test/test_string_view.cpp +++ b/test/test_string_view.cpp @@ -29,7 +29,7 @@ SOFTWARE. #include "UnitTest++/UnitTest++.h" #include "etl/string_view.h" -#include "etl/cstring.h" +#include "etl/string.h" #include "etl/wstring.h" #include "etl/u16string.h" #include "etl/u32string.h" diff --git a/test/test_to_string.cpp b/test/test_to_string.cpp index 2bbe5bf7..3f8ec92b 100644 --- a/test/test_to_string.cpp +++ b/test/test_to_string.cpp @@ -33,7 +33,7 @@ SOFTWARE. #include #include "etl/to_string.h" -#include "etl/cstring.h" +#include "etl/string.h" #include "etl/format_spec.h" #undef STR diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 505f4b3a..9b22a8df 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -1123,6 +1123,7 @@ + @@ -1155,7 +1156,6 @@ - diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index cdaf4af2..5e960783 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -669,9 +669,6 @@ ETL\Frameworks - - ETL\Strings - ETL\Strings @@ -882,6 +879,9 @@ ETL\Pseudo Containers + + ETL\Strings + From 6f3995a4e7973e82320a42638c8cd37b40f7ac3e Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 19 Sep 2020 01:04:44 +0100 Subject: [PATCH 41/71] Refactor string initialise with external buffer --- include/etl/string.h | 32 ++++++-------- include/etl/u16string.h | 32 ++++++-------- include/etl/u32string.h | 30 +++++-------- include/etl/wstring.h | 32 ++++++-------- test/test_string_char_external_buffer.cpp | 45 +++++++------------- test/test_string_u16_external_buffer.cpp | 17 +------- test/test_string_u32_external_buffer.cpp | 17 +------- test/test_string_wchar_t_external_buffer.cpp | 17 +------- 8 files changed, 69 insertions(+), 153 deletions(-) diff --git a/include/etl/string.h b/include/etl/string.h index aab0f55f..be996692 100644 --- a/include/etl/string.h +++ b/include/etl/string.h @@ -274,26 +274,10 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - string(value_type* buffer, size_t buffer_size, bool use_buffer_contents = false) + string(value_type* buffer, size_t buffer_size) : istring(buffer, buffer_size - 1U) { - if (use_buffer_contents) - { - this->current_size = etl::strlen(buffer); - } - else - { - this->initialise(); - } - } - - //************************************************************************* - /// Constructor direct from buffer. - //************************************************************************* - string(value_type* buffer) - : istring(buffer, etl::strlen(buffer)) - { - this->current_size = etl::strlen(buffer); + this->initialise(); } //************************************************************************* @@ -343,10 +327,18 @@ namespace etl /// Constructor, from null terminated text. ///\param text The initial text of the string. //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR string(const value_type* text, value_type* buffer, size_t buffer_size) + string(const value_type* text, value_type* buffer, size_t buffer_size) : istring(buffer, buffer_size - 1U) { - this->assign(text, text + etl::char_traits::length(text)); + // Is the initial text at the same address as the buffer? + if (text == buffer) + { + this->current_size = etl::strlen(buffer); + } + else + { + this->assign(text, text + etl::strlen(text)); + } } //************************************************************************* diff --git a/include/etl/u16string.h b/include/etl/u16string.h index f65c9fcf..c2a7db6e 100644 --- a/include/etl/u16string.h +++ b/include/etl/u16string.h @@ -260,26 +260,10 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - u16string(value_type* buffer, size_t buffer_size, bool use_buffer_contents = false) + u16string(value_type* buffer, size_t buffer_size) : iu16string(buffer, buffer_size - 1U) { - if (use_buffer_contents) - { - this->current_size = etl::strlen(buffer); - } - else - { - this->initialise(); - } - } - - //************************************************************************* - /// Constructor direct from buffer. - //************************************************************************* - u16string(value_type* buffer) - : iu16string(buffer, etl::strlen(buffer)) - { - this->current_size = etl::strlen(buffer); + this->initialise(); } //************************************************************************* @@ -329,10 +313,18 @@ namespace etl /// Constructor, from null terminated text. ///\param text The initial text of the u16string. //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR u16string(const value_type* text, value_type* buffer, size_t buffer_size) + u16string(const value_type* text, value_type* buffer, size_t buffer_size) : iu16string(buffer, buffer_size - 1U) { - this->assign(text, text + etl::char_traits::length(text)); + // Is the initial text at the same address as the buffer? + if (text == buffer) + { + this->current_size = etl::strlen(buffer); + } + else + { + this->assign(text, text + etl::strlen(text)); + } } //************************************************************************* diff --git a/include/etl/u32string.h b/include/etl/u32string.h index 38c24b4b..7e729260 100644 --- a/include/etl/u32string.h +++ b/include/etl/u32string.h @@ -260,26 +260,10 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - u32string(value_type* buffer, size_t buffer_size, bool use_buffer_contents = false) + u32string(value_type* buffer, size_t buffer_size) : iu32string(buffer, buffer_size - 1U) { - if (use_buffer_contents) - { - this->current_size = etl::strlen(buffer); - } - else - { - this->initialise(); - } - } - - //************************************************************************* - /// Constructor direct from buffer. - //************************************************************************* - u32string(value_type* buffer) - : iu32string(buffer, etl::strlen(buffer)) - { - this->current_size = etl::strlen(buffer); + this->initialise(); } //************************************************************************* @@ -332,7 +316,15 @@ namespace etl ETL_EXPLICIT_STRING_FROM_CHAR u32string(const value_type* text, value_type* buffer, size_t buffer_size) : iu32string(buffer, buffer_size - 1U) { - this->assign(text, text + etl::char_traits::length(text)); + // Is the initial text at the same address as the buffer? + if (text == buffer) + { + this->current_size = etl::strlen(buffer); + } + else + { + this->assign(text, text + etl::strlen(text)); + } } //************************************************************************* diff --git a/include/etl/wstring.h b/include/etl/wstring.h index d5c89661..22403529 100644 --- a/include/etl/wstring.h +++ b/include/etl/wstring.h @@ -261,26 +261,10 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - wstring(value_type* buffer, size_t buffer_size, bool use_buffer_contents = false) + wstring(value_type* buffer, size_t buffer_size) : iwstring(buffer, buffer_size - 1U) { - if (use_buffer_contents) - { - this->current_size = etl::strlen(buffer); - } - else - { - this->initialise(); - } - } - - //************************************************************************* - /// Constructor direct from buffer. - //************************************************************************* - wstring(value_type* buffer) - : iwstring(buffer, etl::strlen(buffer)) - { - this->current_size = etl::strlen(buffer); + this->initialise(); } //************************************************************************* @@ -330,10 +314,18 @@ namespace etl /// Constructor, from null terminated text. ///\param text The initial text of the wstring. //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR wstring(const value_type* text, value_type* buffer, size_t buffer_size) + wstring(const value_type* text, value_type* buffer, size_t buffer_size) : iwstring(buffer, buffer_size - 1U) { - this->assign(text, text + etl::char_traits::length(text)); + // Is the initial text at the same address as the buffer? + if (text == buffer) + { + this->current_size = etl::strlen(buffer); + } + else + { + this->assign(text, text + etl::strlen(text)); + } } //************************************************************************* diff --git a/test/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index a2e6bf9c..62612d8b 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -116,19 +116,6 @@ namespace CHECK(!text.truncated()); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text) - { - Text text(p_text); - - CHECK_EQUAL(text.size(), etl::strlen(p_text)); - CHECK(!text.empty()); - CHECK_EQUAL(etl::strlen(p_text), text.capacity()); - CHECK_EQUAL(etl::strlen(p_text), text.max_size()); - CHECK(text.begin() != text.end()); - CHECK(!text.truncated()); - } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size) { @@ -146,7 +133,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size) { - Text text(p_text, etl::strlen(p_text) + 1, true); + Text text(p_text, p_text, etl::strlen(p_text) + 1); CHECK_EQUAL(text.size(), etl::strlen(p_text)); CHECK(!text.empty()); @@ -172,7 +159,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text) { - Text text(array_text, etl::size(array_text), true); + Text text(array_text, array_text, etl::size(array_text)); CHECK_EQUAL(text.size(), etl::strlen(array_text)); CHECK(!text.empty()); @@ -257,16 +244,16 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - Compare_Text compare_text(SIZE, STR('A')); + Compare_Text compare_text(SIZE, STR('A')); - TextBuffer buffer; - Text text(SIZE, STR('A'), buffer.data(), buffer.size()); + TextBuffer buffer; + Text text(SIZE, STR('A'), buffer.data(), buffer.size()); - CHECK(!text.empty()); + CHECK(!text.empty()); - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); - CHECK(!text.truncated()); + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* @@ -287,16 +274,16 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - Compare_Text compare_text(initial_text.c_str(), initial_text.size() / 2); + Compare_Text compare_text(initial_text.c_str(), initial_text.size() / 2); - TextBuffer buffer; - Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); + TextBuffer buffer; + Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); - CHECK(!text.empty()); + CHECK(!text.empty()); - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); - CHECK(!text.truncated()); + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); + CHECK(!text.truncated()); } //************************************************************************* diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index 2f14651d..b1487bcf 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -116,19 +116,6 @@ namespace CHECK(!text.truncated()); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text) - { - Text text(p_text); - - CHECK_EQUAL(text.size(), etl::strlen(p_text)); - CHECK(!text.empty()); - CHECK_EQUAL(etl::strlen(p_text), text.capacity()); - CHECK_EQUAL(etl::strlen(p_text), text.max_size()); - CHECK(text.begin() != text.end()); - CHECK(!text.truncated()); - } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size) { @@ -146,7 +133,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size) { - Text text(p_text, etl::strlen(p_text) + 1, true); + Text text(p_text, p_text, etl::strlen(p_text) + 1); CHECK_EQUAL(text.size(), etl::strlen(p_text)); CHECK(!text.empty()); @@ -172,7 +159,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text) { - Text text(array_text, etl::size(array_text), true); + Text text(array_text, array_text, etl::size(array_text)); CHECK_EQUAL(text.size(), etl::strlen(array_text)); CHECK(!text.empty()); diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index 5500699c..4e57284c 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -116,19 +116,6 @@ namespace CHECK(!text.truncated()); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text) - { - Text text(p_text); - - CHECK_EQUAL(text.size(), etl::strlen(p_text)); - CHECK(!text.empty()); - CHECK_EQUAL(etl::strlen(p_text), text.capacity()); - CHECK_EQUAL(etl::strlen(p_text), text.max_size()); - CHECK(text.begin() != text.end()); - CHECK(!text.truncated()); - } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size) { @@ -146,7 +133,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size) { - Text text(p_text, etl::strlen(p_text) + 1, true); + Text text(p_text, p_text, etl::strlen(p_text) + 1); CHECK_EQUAL(text.size(), etl::strlen(p_text)); CHECK(!text.empty()); @@ -172,7 +159,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text) { - Text text(array_text, etl::size(array_text), true); + Text text(array_text, array_text, etl::size(array_text)); CHECK_EQUAL(text.size(), etl::strlen(array_text)); CHECK(!text.empty()); diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index 2814f5eb..7ab208fa 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -116,19 +116,6 @@ namespace CHECK(!text.truncated()); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text) - { - Text text(p_text); - - CHECK_EQUAL(text.size(), etl::strlen(p_text)); - CHECK(!text.empty()); - CHECK_EQUAL(etl::strlen(p_text), text.capacity()); - CHECK_EQUAL(etl::strlen(p_text), text.max_size()); - CHECK(text.begin() != text.end()); - CHECK(!text.truncated()); - } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_and_size) { @@ -146,7 +133,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_default_constructor_use_buffer_text_and_size) { - Text text(p_text, etl::strlen(p_text) + 1, true); + Text text(p_text, p_text, etl::strlen(p_text) + 1); CHECK_EQUAL(text.size(), etl::strlen(p_text)); CHECK(!text.empty()); @@ -172,7 +159,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_default_constructor_use_array_buffer_text) { - Text text(array_text, etl::size(array_text), true); + Text text(array_text, array_text, etl::size(array_text)); CHECK_EQUAL(text.size(), etl::strlen(array_text)); CHECK(!text.empty()); From fa25f02bb101997d63db6795b04a0ba0b79c320a Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 19 Sep 2020 10:31:44 +0100 Subject: [PATCH 42/71] Refactoring of 18.15.0. Modified constructor syntax. --- include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 5 +++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/etl/version.h b/include/etl/version.h index eb0b5456..30a1f179 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 18 #define ETL_VERSION_MINOR 15 -#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) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index 4ea5c97a..dae982e6 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.15.0", + "version": "18.15.1", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index 7acb642c..63ddfc08 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.15.0 +version=18.15.1 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 8f897939..3c05ce9c 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,8 @@ +=============================================================================== +18.15.1 +Refactoring of 18.15.0. +Modified constructor syntax. + =============================================================================== 18.15.0 Allow strings with external buffers to use a pre-initialised buffer. From 1643be47bafa5249104a260f40b7215f5e68ee96 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 21 Sep 2020 15:03:17 +0100 Subject: [PATCH 43/71] Experimental changes for issue #269 lto1: fatal error: multiple prevailing defs for 'invocation' --- include/etl/error_handler.h | 69 +++++++++++++++---------------------- 1 file changed, 27 insertions(+), 42 deletions(-) diff --git a/include/etl/error_handler.h b/include/etl/error_handler.h index 5f59f5a6..83030acd 100644 --- a/include/etl/error_handler.h +++ b/include/etl/error_handler.h @@ -45,38 +45,6 @@ SOFTWARE. namespace etl { - namespace private_error_handler - { - // A wrapper template to allow static definition in header. - template - struct wrapper - { - typedef void(*stub_type)(void* object, const etl::exception&); - - //************************************************************************* - /// The internal invocation object. - //************************************************************************* - struct invocation_element - { - //*********************************************************************** - invocation_element() - : object(ETL_NULLPTR) - , stub(ETL_NULLPTR) - { - } - - //*********************************************************************** - void* object; - stub_type stub; - }; - - static invocation_element invocation; - }; - - template - typename wrapper::invocation_element wrapper::invocation; - } - //*************************************************************************** /// Error handler for when throwing exceptions is not required. ///\ingroup error_handler @@ -86,7 +54,7 @@ namespace etl public: //************************************************************************* - /// Callback class for free handler functions. + /// Callback class for free handler functions. Deprecated. //************************************************************************* struct free_function : public etl::function { @@ -97,7 +65,7 @@ namespace etl }; //************************************************************************* - /// Callback class for member handler functions. + /// Callback class for member handler functions. Deprecated. //************************************************************************* template struct member_function : public etl::function @@ -109,7 +77,7 @@ namespace etl }; //***************************************************************************** - /// Sets the error callback function. + /// Sets the error callback function. Deprecated. ///\param f A reference to an etl::function object that will handler errors. //***************************************************************************** static void set_callback(ifunction& f) @@ -168,9 +136,11 @@ namespace etl //***************************************************************************** static void error(const etl::exception& e) { - if (private_error_handler::wrapper::invocation.stub != ETL_NULLPTR) + invocation_element& invocation = get_invocation_element(); + + if (invocation.stub != ETL_NULLPTR) { - (*private_error_handler::wrapper::invocation.stub)(private_error_handler::wrapper::invocation.object, e); + (*invocation.stub)(invocation.object, e); } } @@ -183,24 +153,37 @@ namespace etl //************************************************************************* struct invocation_element { + //*********************************************************************** invocation_element() : object(ETL_NULLPTR) , stub(ETL_NULLPTR) { } - + //*********************************************************************** void* object; stub_type stub; }; + //************************************************************************* + /// Returns the static invocation element. + //************************************************************************* + static invocation_element& get_invocation_element() + { + static invocation_element invocation; + + return invocation; + } + //************************************************************************* /// Constructs a callback from an object and stub. //************************************************************************* static void create(void* object, stub_type stub) { - private_error_handler::wrapper::invocation.object = object; - private_error_handler::wrapper::invocation.stub = stub; + invocation_element& invocation = get_invocation_element(); + + invocation.object = object; + invocation.stub = stub; } //************************************************************************* @@ -208,8 +191,10 @@ namespace etl //************************************************************************* static void create(stub_type stub) { - private_error_handler::wrapper::invocation.object = ETL_NULLPTR; - private_error_handler::wrapper::invocation.stub = stub; + invocation_element& invocation = get_invocation_element(); + + invocation.object = ETL_NULLPTR; + invocation.stub = stub; } //************************************************************************* From c38d2db118c0dab0cd81bd77d447a632bf735434 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 22 Sep 2020 09:30:06 +0100 Subject: [PATCH 44/71] array_view-not-explicit --- include/etl/array_view.h | 4 ++-- include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 4 ++++ 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/include/etl/array_view.h b/include/etl/array_view.h index 83f102b2..0fc43e86 100644 --- a/include/etl/array_view.h +++ b/include/etl/array_view.h @@ -133,7 +133,7 @@ namespace etl /// data() and size() member functions. //************************************************************************* template - ETL_CONSTEXPR explicit array_view(TArray& a) + ETL_CONSTEXPR array_view(TArray& a) : mbegin(a.data()), mend(a.data() + a.size()) { @@ -163,7 +163,7 @@ namespace etl //************************************************************************* /// Construct from C array //************************************************************************* - template + template ETL_CONSTEXPR explicit array_view(T(&begin_)[ARRAY_SIZE]) : mbegin(begin_), mend(begin_ + ARRAY_SIZE) diff --git a/include/etl/version.h b/include/etl/version.h index 30a1f179..bd64b88b 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 18 #define ETL_VERSION_MINOR 15 -#define ETL_VERSION_PATCH 1 +#define ETL_VERSION_PATCH 2 #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) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index dae982e6..9f64db34 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.15.1", + "version": "18.15.2", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index 63ddfc08..128b76c9 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.15.1 +version=18.15.2 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 3c05ce9c..4b0fbf53 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +18.15.2 +etl::array_view constructor from etl or std array is no longer explicit. + =============================================================================== 18.15.1 Refactoring of 18.15.0. From 3eeeb5d5f60696abd34b9426893f5c50673e739d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 22 Sep 2020 10:18:08 +0100 Subject: [PATCH 45/71] segger-multiple-prevailing-defs-for-invocation' into development --- support/Release notes.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/support/Release notes.txt b/support/Release notes.txt index 4b0fbf53..ee5b570c 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,5 +1,6 @@ =============================================================================== 18.15.2 +Workaround for Segger ARM Link-Time-Optimisation (LTO) bug. etl::array_view constructor from etl or std array is no longer explicit. =============================================================================== From 9f018d9a437e420453189daeb2c6f8de2c803444 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 22 Sep 2020 17:49:07 +0100 Subject: [PATCH 46/71] Removed explicit from C array constructor --- include/etl/array_view.h | 2 +- test/test_array_view.cpp | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/include/etl/array_view.h b/include/etl/array_view.h index 0fc43e86..e302739a 100644 --- a/include/etl/array_view.h +++ b/include/etl/array_view.h @@ -164,7 +164,7 @@ namespace etl /// Construct from C array //************************************************************************* template - ETL_CONSTEXPR explicit array_view(T(&begin_)[ARRAY_SIZE]) + ETL_CONSTEXPR array_view(T(&begin_)[ARRAY_SIZE]) : mbegin(begin_), mend(begin_ + ARRAY_SIZE) { diff --git a/test/test_array_view.cpp b/test/test_array_view.cpp index be415938..bc172493 100644 --- a/test/test_array_view.cpp +++ b/test/test_array_view.cpp @@ -91,6 +91,18 @@ namespace CHECK(isEqual); } + //************************************************************************* + TEST(test_implicit_constructor_etl_array_1) + { + View view = etldata; + + CHECK_EQUAL(etldata.size(), view.size()); + CHECK_EQUAL(etldata.max_size(), view.max_size()); + + bool isEqual = std::equal(view.begin(), view.end(), etldata.begin()); + CHECK(isEqual); + } + //************************************************************************* TEST(test_constructor_etl_array_1_const) { @@ -139,6 +151,18 @@ namespace CHECK(isEqual); } + //************************************************************************* + TEST(test_implicit_constructor_stl_array_1) + { + View view = stldata; + + CHECK_EQUAL(stldata.size(), view.size()); + CHECK_EQUAL(stldata.max_size(), view.max_size()); + + bool isEqual = std::equal(view.begin(), view.end(), stldata.begin()); + CHECK(isEqual); + } + //************************************************************************* TEST(test_constructor_stl_array_1_const) { @@ -235,6 +259,18 @@ namespace CHECK(isEqual); } + //************************************************************************* + TEST(test_implicit_constructor_c_array) + { + View view = cdata; + + CHECK_EQUAL(SIZE, view.size()); + CHECK_EQUAL(SIZE, view.max_size()); + + bool isEqual = std::equal(view.begin(), view.end(), cdata); + CHECK(isEqual); + } + //************************************************************************* TEST(test_constructor_c_array_2_const) { From 5544633c3957907a9c38529844dac087a2f35485 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 22 Sep 2020 17:54:46 +0100 Subject: [PATCH 47/71] etl::array_view constructor from C array is no longer explicit --- include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 4 ++++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/etl/version.h b/include/etl/version.h index bd64b88b..fc6bc3ec 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 18 #define ETL_VERSION_MINOR 15 -#define ETL_VERSION_PATCH 2 +#define ETL_VERSION_PATCH 3 #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) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index 9f64db34..3f73d4fb 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.15.2", + "version": "18.15.3", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index 128b76c9..d7215c1d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.15.2 +version=18.15.3 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index ee5b570c..21448409 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +18.15.3 +etl::array_view constructor from C array is no longer explicit. + =============================================================================== 18.15.2 Workaround for Segger ARM Link-Time-Optimisation (LTO) bug. From adf6243de6e380d34b3b2238cf81980ff0f8ac7d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 24 Sep 2020 23:19:33 +0100 Subject: [PATCH 48/71] Performance optimisations for etl::rotate, etl::move & etl::move_backward when not using the STL, iterators are pointers and the objects are trivially copyable (currently POD types). --- include/etl/algorithm.h | 150 ++++++++++++++++++++++++++++++-------- include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 6 ++ test/test_algorithm.cpp | 21 +++++- 6 files changed, 149 insertions(+), 34 deletions(-) diff --git a/include/etl/algorithm.h b/include/etl/algorithm.h index 48f4c36d..62634298 100644 --- a/include/etl/algorithm.h +++ b/include/etl/algorithm.h @@ -127,7 +127,7 @@ namespace etl template typename etl::enable_if::value && etl::is_pointer::value && - etl::is_pod::value_type>::value, TIterator2>::type + etl::is_trivially_copyable::value_type>::value, TIterator2>::type copy(TIterator1 sb, TIterator1 se, TIterator2 db) { typedef typename etl::iterator_traits::value_type value_t; @@ -142,7 +142,7 @@ namespace etl template typename etl::enable_if::value || !etl::is_pointer::value || - !etl::is_pod::value_type>::value, TIterator2>::type + !etl::is_trivially_copyable::value_type>::value, TIterator2>::type copy(TIterator1 sb, TIterator1 se, TIterator2 db) { while (sb != se) @@ -192,7 +192,7 @@ namespace etl template typename etl::enable_if::value && etl::is_pointer::value && - etl::is_pod::value_type>::value, TIterator2>::type + etl::is_trivially_copyable::value_type>::value, TIterator2>::type copy_n(TIterator1 sb, TSize count, TIterator2 db) { typedef typename etl::iterator_traits::value_type value_t; @@ -204,7 +204,7 @@ namespace etl template typename etl::enable_if::value || !etl::is_pointer::value || - !etl::is_pod::value_type>::value, TIterator2>::type + !etl::is_trivially_copyable::value_type>::value, TIterator2>::type copy_n(TIterator1 sb, TSize count, TIterator2 db) { while (count != 0) @@ -236,8 +236,8 @@ namespace etl // Pointer template typename etl::enable_if::value && - etl::is_pointer::value && - etl::is_pod::value_type>::value, TIterator2>::type + etl::is_pointer::value && + etl::is_trivially_copyable::value_type>::value, TIterator2>::type copy_backward(TIterator1 sb, TIterator1 se, TIterator2 de) { typedef typename etl::iterator_traits::value_type value_t; @@ -250,8 +250,8 @@ namespace etl // Other iterator template typename etl::enable_if::value || - !etl::is_pointer::value || - !etl::is_pod::value_type>::value, TIterator2>::type + !etl::is_pointer::value || + !etl::is_trivially_copyable::value_type>::value, TIterator2>::type copy_backward(TIterator1 sb, TIterator1 se, TIterator2 de) { while (se != sb) @@ -275,8 +275,12 @@ namespace etl #if ETL_NOT_USING_STL //*************************************************************************** // move + // non-pointer, non-pod template - TIterator2 move(TIterator1 sb, TIterator1 se, TIterator2 db) + typename etl::enable_if::value || + !etl::is_pointer::value || + !etl::is_trivially_copyable::value_type>::value, TIterator2>::type + move(TIterator1 sb, TIterator1 se, TIterator2 db) { while (sb != se) { @@ -285,6 +289,21 @@ namespace etl return db; } + + // pointer and pod + template + typename etl::enable_if::value && + etl::is_pointer::value && + etl::is_trivially_copyable::value_type>::value, TIterator2>::type + move(TIterator1 sb, TIterator1 se, TIterator2 db) + { + typedef typename etl::iterator_traits::value_type value_t; + typedef typename etl::iterator_traits::difference_type difference_t; + + difference_t count = (se - sb); + + return TIterator2(memmove(db, sb, sizeof(value_t) * count)) + count; + } #else //*************************************************************************** // move @@ -310,8 +329,12 @@ namespace etl #if ETL_NOT_USING_STL //*************************************************************************** // move_backward + // non-pointer, non-pod template - TIterator2 move_backward(TIterator1 sb, TIterator1 se, TIterator2 de) + typename etl::enable_if::value || + !etl::is_pointer::value || + !etl::is_trivially_copyable::value_type>::value, TIterator2>::type + move_backward(TIterator1 sb, TIterator1 se, TIterator2 de) { while (sb != se) { @@ -320,6 +343,22 @@ namespace etl return de; } + + // pointer and pod + template + typename etl::enable_if::value && + etl::is_pointer::value && + etl::is_trivially_copyable::value_type>::value, TIterator2>::type + move_backward(TIterator1 sb, TIterator1 se, TIterator2 de) + { + typedef typename etl::iterator_traits::value_type value_t; + typedef typename etl::iterator_traits::difference_type difference_t; + + difference_t count = (se - sb); + TIterator2 db = de - count; + + return TIterator2(memmove(db, sb, sizeof(value_t) * count)) + count; + } #else //*************************************************************************** // move_backward @@ -727,7 +766,7 @@ namespace etl // equal template ETL_NODISCARD - typename etl::enable_if::value || !etl::is_pointer::value || !etl::is_pod::value_type>::value, bool>::type + typename etl::enable_if::value || !etl::is_pointer::value || !etl::is_trivially_copyable::value_type>::value, bool>::type equal(TIterator1 first1, TIterator1 last1, TIterator2 first2) { while (first1 != last1) @@ -743,7 +782,7 @@ namespace etl template ETL_NODISCARD - typename etl::enable_if::value && etl::is_pointer::value && etl::is_pod::value_type>::value, bool>::type + typename etl::enable_if::value && etl::is_pointer::value && etl::is_trivially_copyable::value_type>::value, bool>::type equal(TIterator1 first1, TIterator1 last1, TIterator2 first2) { typedef typename etl::iterator_traits::value_type value_t; @@ -1326,30 +1365,81 @@ namespace etl #if ETL_NOT_USING_STL //*************************************************************************** // Rotate + namespace private_algorithm + { + //********************************* + template + TIterator rotate_general(TIterator first, TIterator middle, TIterator last) + { + TIterator next = middle; + + while (first != next) + { + using ETL_OR_STD::swap; // Allow ADL + + swap(*first++, *next++); + + if (next == last) + { + next = middle; + } + else if (first == middle) + { + middle = next; + } + } + + return first; + } + + //********************************* + template + TIterator rotate_left_by_one(TIterator first, TIterator last) + { + typedef typename etl::iterator_traits::value_type value_type; + + value_type temp(etl::move(*first)); + + TIterator result = etl::move(etl::next(first), last, first); + + *result = etl::move(temp); + + return result; + } + + //********************************* + template + TIterator rotate_right_by_one(TIterator first, TIterator last) + { + typedef typename etl::iterator_traits::value_type value_type; + + TIterator previous = etl::prev(last); + + value_type temp(etl::move(*previous)); + + TIterator result = etl::move_backward(first, previous, last); + + *first = etl::move(temp); + + return result; + } + } + + //********************************* template TIterator rotate(TIterator first, TIterator middle, TIterator last) { - using ETL_OR_STD::swap; // Allow ADL - - TIterator next = middle; - - while (first != next) + if (etl::next(first) == middle) { - using ETL_OR_STD::swap; - - swap(*first++, *next++); - - if (next == last) - { - next = middle; - } - else if (first == middle) - { - middle = next; - } + return private_algorithm::rotate_left_by_one(first, last); } - return first; + if (etl::next(middle) == last) + { + return private_algorithm::rotate_right_by_one(first, last); + } + + return private_algorithm::rotate_general(first, middle, last); } #else //*************************************************************************** diff --git a/include/etl/version.h b/include/etl/version.h index fc6bc3ec..cb565d5a 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 18 #define ETL_VERSION_MINOR 15 -#define ETL_VERSION_PATCH 3 +#define ETL_VERSION_PATCH 4 #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) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index 3f73d4fb..367ab271 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.15.3", + "version": "18.15.4", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index d7215c1d..78e728bf 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.15.3 +version=18.15.4 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 21448409..67177dc9 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,9 @@ +=============================================================================== +18.15.4 +Performance optimisations for etl::rotate, etl::move & etl::move_backward +when not using the STL, iterators are pointers and the objects are trivially +copyable (currently POD types). + =============================================================================== 18.15.3 etl::array_view constructor from C array is no longer explicit. diff --git a/test/test_algorithm.cpp b/test/test_algorithm.cpp index 8657383e..aefc9c50 100644 --- a/test/test_algorithm.cpp +++ b/test/test_algorithm.cpp @@ -1099,7 +1099,7 @@ namespace } //************************************************************************* - TEST(rotate) + TEST(rotate_pod) { std::vector initial_data = { 1, 2, 3, 4, 5, 6, 7 }; @@ -1116,6 +1116,25 @@ namespace } } + + //************************************************************************* + TEST(rotate_non_pod) + { + std::vector initial_data = { NDC(1), NDC(2), NDC(3), NDC(4), NDC(5), NDC(6), NDC(7) }; + + for (size_t i = 0; i < initial_data.size(); ++i) + { + std::vector data1(initial_data); + std::vector data2(initial_data); + + std::rotate(data1.data(), data1.data() + i, data1.data() + data1.size()); + etl::rotate(data2.data(), data2.data() + i, data2.data() + data2.size()); + + bool isEqual = std::equal(std::begin(data1), std::end(data1), std::begin(data2)); + CHECK(isEqual); + } + } + //************************************************************************* TEST(any_of) { From 96a4c82a5820cffcdf78948ca674cb119f085dc1 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 24 Sep 2020 23:19:33 +0100 Subject: [PATCH 49/71] Performance optimisations for etl::rotate, etl::move & etl::move_backward when not using the STL, iterators are pointers and the objects are trivially copyable (currently POD types). --- include/etl/algorithm.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/include/etl/algorithm.h b/include/etl/algorithm.h index 62634298..d0d8eaba 100644 --- a/include/etl/algorithm.h +++ b/include/etl/algorithm.h @@ -275,7 +275,7 @@ namespace etl #if ETL_NOT_USING_STL //*************************************************************************** // move - // non-pointer, non-pod + // non-pointer or not trivially copyable template typename etl::enable_if::value || !etl::is_pointer::value || @@ -290,7 +290,7 @@ namespace etl return db; } - // pointer and pod + // pointer and trivially copyable template typename etl::enable_if::value && etl::is_pointer::value && @@ -1398,12 +1398,16 @@ namespace etl { typedef typename etl::iterator_traits::value_type value_type; + // Save the first item. value_type temp(etl::move(*first)); + // Move the rest. TIterator result = etl::move(etl::next(first), last, first); + // Restore the first item in its rotated position. *result = etl::move(temp); + // The new position of the first item. return result; } @@ -1413,14 +1417,17 @@ namespace etl { typedef typename etl::iterator_traits::value_type value_type; + // Save the last item. TIterator previous = etl::prev(last); - value_type temp(etl::move(*previous)); + // Move the rest. TIterator result = etl::move_backward(first, previous, last); + // Restore the last item in its rotated position. *first = etl::move(temp); + // The new position of the first item. return result; } } From 2b162f4e7f3e76438d6c3c32630ef08a4d02f18c Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 25 Sep 2020 13:33:18 +0100 Subject: [PATCH 50/71] Fixed inifinite loop for default constructed etl::string_view to get_token() --- include/etl/string_utilities.h | 18 ++++++++++++------ test/test_string_utilities.cpp | 16 ++++++++++++++++ test/test_string_utilities_std.cpp | 16 ++++++++++++++++ test/test_string_utilities_std_u16.cpp | 16 ++++++++++++++++ test/test_string_utilities_std_u32.cpp | 16 ++++++++++++++++ test/test_string_utilities_std_wchar_t.cpp | 16 ++++++++++++++++ test/test_string_utilities_u16.cpp | 16 ++++++++++++++++ test/test_string_utilities_u32.cpp | 16 ++++++++++++++++ test/test_string_utilities_wchar_t.cpp | 16 ++++++++++++++++ 9 files changed, 140 insertions(+), 6 deletions(-) diff --git a/include/etl/string_utilities.h b/include/etl/string_utilities.h index 02c5e604..6701b579 100644 --- a/include/etl/string_utilities.h +++ b/include/etl/string_utilities.h @@ -697,16 +697,22 @@ namespace etl //*************************************************************************** /// get_token //*************************************************************************** - template - etl::optional get_token(const TIString& s, typename TIString::const_pointer delimiters, const etl::optional& last_view, bool ignore_empty_tokens) + template + etl::optional get_token(const TInput& input, typename TInput::const_pointer delimiters, const etl::optional& last_view, bool ignore_empty_tokens) { - typedef typename TIString::const_pointer const_pointer; + typedef typename TInput::const_pointer const_pointer; bool token_found = false; size_t position = 0U; TStringView view = last_view.value_or(TStringView()); - const_pointer begin_ptr = s.data(); - const_pointer end_ptr = begin_ptr + s.size(); + const_pointer begin_ptr = input.data(); + + if (begin_ptr == ETL_NULLPTR) + { + return etl::optional(); + } + + const_pointer end_ptr = begin_ptr + input.size(); while (!token_found) { @@ -716,7 +722,7 @@ namespace etl position = etl::distance(begin_ptr, view.data() + view.size() + 1U); // Have we reached the end of the string? - if (position > s.size()) + if (position > input.size()) { return etl::optional(); } diff --git a/test/test_string_utilities.cpp b/test/test_string_utilities.cpp index 94c2ae41..67dc70f5 100644 --- a/test/test_string_utilities.cpp +++ b/test/test_string_utilities.cpp @@ -1059,6 +1059,22 @@ namespace CHECK_EQUAL(1U, tokens.size()); } + //************************************************************************* + TEST(test_get_token_delimiters_empty_string_view) + { + Vector tokens; + + StringView textview; + etl::optional token; + + while ((token = etl::get_token(textview, Whitespace, token, true))) + { + tokens.emplace_back(token.value()); + } + + CHECK_EQUAL(0U, tokens.size()); + } + //************************************************************************* TEST(test_pad_left) { diff --git a/test/test_string_utilities_std.cpp b/test/test_string_utilities_std.cpp index 0d806a10..1b711c38 100644 --- a/test/test_string_utilities_std.cpp +++ b/test/test_string_utilities_std.cpp @@ -1061,6 +1061,22 @@ namespace CHECK_EQUAL(1U, tokens.size()); } + //************************************************************************* + TEST(test_get_token_delimiters_empty_string_view) + { + Vector tokens; + + StringView textview; + etl::optional token; + + while ((token = etl::get_token(textview, Whitespace, token, true))) + { + tokens.emplace_back(token.value()); + } + + CHECK_EQUAL(0U, tokens.size()); + } + //************************************************************************* TEST(test_pad_left) { diff --git a/test/test_string_utilities_std_u16.cpp b/test/test_string_utilities_std_u16.cpp index 18ad0dae..cdf38513 100644 --- a/test/test_string_utilities_std_u16.cpp +++ b/test/test_string_utilities_std_u16.cpp @@ -1061,6 +1061,22 @@ namespace CHECK_EQUAL(1U, tokens.size()); } + //************************************************************************* + TEST(test_get_token_delimiters_empty_string_view) + { + Vector tokens; + + StringView textview; + etl::optional token; + + while ((token = etl::get_token(textview, Whitespace, token, true))) + { + tokens.emplace_back(token.value()); + } + + CHECK_EQUAL(0U, tokens.size()); + } + //************************************************************************* TEST(test_pad_left) { diff --git a/test/test_string_utilities_std_u32.cpp b/test/test_string_utilities_std_u32.cpp index 6d90e111..fa3e8fcd 100644 --- a/test/test_string_utilities_std_u32.cpp +++ b/test/test_string_utilities_std_u32.cpp @@ -1061,6 +1061,22 @@ namespace CHECK_EQUAL(1U, tokens.size()); } + //************************************************************************* + TEST(test_get_token_delimiters_empty_string_view) + { + Vector tokens; + + StringView textview; + etl::optional token; + + while ((token = etl::get_token(textview, Whitespace, token, true))) + { + tokens.emplace_back(token.value()); + } + + CHECK_EQUAL(0U, tokens.size()); + } + //************************************************************************* TEST(test_pad_left) { diff --git a/test/test_string_utilities_std_wchar_t.cpp b/test/test_string_utilities_std_wchar_t.cpp index 6da25f17..775735a4 100644 --- a/test/test_string_utilities_std_wchar_t.cpp +++ b/test/test_string_utilities_std_wchar_t.cpp @@ -1061,6 +1061,22 @@ namespace CHECK_EQUAL(1U, tokens.size()); } + //************************************************************************* + TEST(test_get_token_delimiters_empty_string_view) + { + Vector tokens; + + StringView textview; + etl::optional token; + + while ((token = etl::get_token(textview, Whitespace, token, true))) + { + tokens.emplace_back(token.value()); + } + + CHECK_EQUAL(0U, tokens.size()); + } + //************************************************************************* TEST(test_pad_left) { diff --git a/test/test_string_utilities_u16.cpp b/test/test_string_utilities_u16.cpp index fd0e8e88..ecd1f235 100644 --- a/test/test_string_utilities_u16.cpp +++ b/test/test_string_utilities_u16.cpp @@ -1059,6 +1059,22 @@ namespace CHECK_EQUAL(1U, tokens.size()); } + //************************************************************************* + TEST(test_get_token_delimiters_empty_string_view) + { + Vector tokens; + + StringView textview; + etl::optional token; + + while ((token = etl::get_token(textview, Whitespace, token, true))) + { + tokens.emplace_back(token.value()); + } + + CHECK_EQUAL(0U, tokens.size()); + } + //************************************************************************* TEST(test_pad_left) { diff --git a/test/test_string_utilities_u32.cpp b/test/test_string_utilities_u32.cpp index 4c716e4c..a2c17923 100644 --- a/test/test_string_utilities_u32.cpp +++ b/test/test_string_utilities_u32.cpp @@ -1059,6 +1059,22 @@ namespace CHECK_EQUAL(1U, tokens.size()); } + //************************************************************************* + TEST(test_get_token_delimiters_empty_string_view) + { + Vector tokens; + + StringView textview; + etl::optional token; + + while ((token = etl::get_token(textview, Whitespace, token, true))) + { + tokens.emplace_back(token.value()); + } + + CHECK_EQUAL(0U, tokens.size()); + } + //************************************************************************* TEST(test_pad_left) { diff --git a/test/test_string_utilities_wchar_t.cpp b/test/test_string_utilities_wchar_t.cpp index 531701f9..e41f294a 100644 --- a/test/test_string_utilities_wchar_t.cpp +++ b/test/test_string_utilities_wchar_t.cpp @@ -1059,6 +1059,22 @@ namespace CHECK_EQUAL(1U, tokens.size()); } + //************************************************************************* + TEST(test_get_token_delimiters_empty_string_view) + { + Vector tokens; + + StringView textview; + etl::optional token; + + while ((token = etl::get_token(textview, Whitespace, token, true))) + { + tokens.emplace_back(token.value()); + } + + CHECK_EQUAL(0U, tokens.size()); + } + //************************************************************************* TEST(test_pad_left) { From 3440c463fa328e472c00c54ec83b73691cddb0df Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 25 Sep 2020 13:34:28 +0100 Subject: [PATCH 51/71] etl::fsm now reports itself as a consumer of messages. --- include/etl/fsm.h | 2 +- include/etl/generators/fsm_generator.h | 2 +- test/test_fsm.cpp | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/include/etl/fsm.h b/include/etl/fsm.h index 7bc2eefd..2f83fb7e 100644 --- a/include/etl/fsm.h +++ b/include/etl/fsm.h @@ -386,7 +386,7 @@ namespace etl //******************************************** bool is_consumer() const ETL_OVERRIDE { - return false; + return true; } private: diff --git a/include/etl/generators/fsm_generator.h b/include/etl/generators/fsm_generator.h index 85552006..b812684d 100644 --- a/include/etl/generators/fsm_generator.h +++ b/include/etl/generators/fsm_generator.h @@ -398,7 +398,7 @@ namespace etl //******************************************** bool is_consumer() const ETL_OVERRIDE { - return false; + return true; } private: diff --git a/test/test_fsm.cpp b/test/test_fsm.cpp index dd334fa3..f34ebbf3 100644 --- a/test/test_fsm.cpp +++ b/test/test_fsm.cpp @@ -338,6 +338,9 @@ namespace { etl::null_message_router nmr; + CHECK(motorControl.is_producer()); + CHECK(motorControl.is_consumer()); + motorControl.Initialise(stateList, etl::size(stateList)); motorControl.reset(); motorControl.ClearStatistics(); From a02b0f7012a74440e57eb7b425c75bd35db26cfe Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 25 Sep 2020 13:35:06 +0100 Subject: [PATCH 52/71] etl::error_handler is not compiled unless error logging is enabled --- include/etl/error_handler.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/etl/error_handler.h b/include/etl/error_handler.h index 83030acd..760248fe 100644 --- a/include/etl/error_handler.h +++ b/include/etl/error_handler.h @@ -43,6 +43,7 @@ SOFTWARE. #include "function.h" #include "nullptr.h" +#if defined(ETL_LOG_ERRORS) || defined(ETL_IN_UNIT_TEST) namespace etl { //*************************************************************************** @@ -254,6 +255,7 @@ namespace etl } }; } +#endif //*************************************************************************** /// Asserts a condition. From 6287a539364b1cebdd45b05997c1d49e22f40501 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 26 Sep 2020 11:48:51 +0100 Subject: [PATCH 53/71] Updated Code:Blocks project --- test/codeblocks/ETL.cbp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/codeblocks/ETL.cbp b/test/codeblocks/ETL.cbp index b6bb1220..7c1393ad 100644 --- a/test/codeblocks/ETL.cbp +++ b/test/codeblocks/ETL.cbp @@ -546,6 +546,7 @@ + @@ -580,15 +581,19 @@ + + + + @@ -599,6 +604,7 @@ + From 8ae3437aee50d3a41dbb5931b6a3b35b8f88d1e1 Mon Sep 17 00:00:00 2001 From: Bo Rydberg <2945606+bolry@users.noreply.github.com> Date: Sun, 27 Sep 2020 10:53:23 +0200 Subject: [PATCH 54/71] Add missing `rend() const` to list.h (#273) The `etl::list` class has a missing overload of `rend() const` causing unwarranted compile errors. --- include/etl/list.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/etl/list.h b/include/etl/list.h index 269e410e..6829c275 100644 --- a/include/etl/list.h +++ b/include/etl/list.h @@ -756,6 +756,14 @@ namespace etl return reverse_iterator(get_head()); } + //************************************************************************* + /// Gets the reverse end of the list. + //************************************************************************* + const_reverse_iterator rend() const + { + return const_reverse_iterator(get_head()); + } + //************************************************************************* /// Gets the reverse beginning of the list. //************************************************************************* From 663c4311fc50db7f1e22b58bf85aba3be25944e9 Mon Sep 17 00:00:00 2001 From: Bo Rydberg <2945606+bolry@users.noreply.github.com> Date: Sun, 27 Sep 2020 11:09:27 +0200 Subject: [PATCH 55/71] etl::list::full() asserts (#274) * Changed some functions to ETL_CONSTEXPR14 * Updated Code:Blocks project * etl::list::full() asserts The list::full method asserts for lists with maxsize zero. Co-authored-by: John Wellbelove --- include/etl/list.h | 11 +++++++++-- include/etl/span.h | 2 +- test/codeblocks/ETL.cbp | 6 ++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/etl/list.h b/include/etl/list.h index 6829c275..ad1add05 100644 --- a/include/etl/list.h +++ b/include/etl/list.h @@ -281,8 +281,15 @@ namespace etl //************************************************************************* bool full() const { - ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); - return p_node_pool->size() == MAX_SIZE; + if (has_shared_pool()) + { + return size() == MAX_SIZE; + } + else + { + ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); + return p_node_pool->size() == MAX_SIZE; + } } //************************************************************************* diff --git a/include/etl/span.h b/include/etl/span.h index 2f4f5932..c66ab30d 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -234,7 +234,7 @@ namespace etl //************************************************************************* /// Assign from a span. //************************************************************************* - ETL_CONSTEXPR span& operator =(const span& other) ETL_NOEXCEPT + ETL_CONSTEXPR14 span& operator =(const span& other) ETL_NOEXCEPT { mbegin = other.mbegin; mend = other.mend; diff --git a/test/codeblocks/ETL.cbp b/test/codeblocks/ETL.cbp index b6bb1220..7c1393ad 100644 --- a/test/codeblocks/ETL.cbp +++ b/test/codeblocks/ETL.cbp @@ -546,6 +546,7 @@ + @@ -580,15 +581,19 @@ + + + + @@ -599,6 +604,7 @@ + From 0fee1fc0b67d73582f318bbf84546e80349a96d9 Mon Sep 17 00:00:00 2001 From: Bo Rydberg <2945606+bolry@users.noreply.github.com> Date: Sun, 27 Sep 2020 11:09:48 +0200 Subject: [PATCH 56/71] Fix faulty assert in `list::available` (#275) Prevent zero sized `list x;` from always asserting. --- include/etl/list.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/etl/list.h b/include/etl/list.h index ad1add05..b854ace7 100644 --- a/include/etl/list.h +++ b/include/etl/list.h @@ -298,8 +298,15 @@ namespace etl //************************************************************************* size_t available() const { - ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); - return max_size() - p_node_pool->size(); + if (has_shared_pool()) + { + return max_size() - size(); + } + else + { + ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); + return max_size() - p_node_pool->size(); + } } protected: From 04c479279e3cb8155f3893e3b1c38579b3fce7d5 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 27 Sep 2020 12:47:20 +0100 Subject: [PATCH 57/71] Refactored empty(), full(), available() member functions for etl::list and etl::forward_list --- include/etl/forward_list.h | 27 +++++++------------ include/etl/list.h | 37 +++++--------------------- include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 4 +++ test/test_forward_list_shared_pool.cpp | 14 ++++++++++ test/test_list_shared_pool.cpp | 13 +++++++++ 8 files changed, 50 insertions(+), 51 deletions(-) diff --git a/include/etl/forward_list.h b/include/etl/forward_list.h index deca5907..3e016567 100644 --- a/include/etl/forward_list.h +++ b/include/etl/forward_list.h @@ -172,6 +172,14 @@ namespace etl return pool_is_shared; } + //************************************************************************* + /// Gets the maximum possible size of the forward_list. + //************************************************************************* + size_type max_size() const + { + return MAX_SIZE; + } + //************************************************************************* /// Gets the size of the forward_list. //************************************************************************* @@ -194,33 +202,16 @@ namespace etl } else { - ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(forward_list_no_pool)); return p_node_pool->size(); } } - //************************************************************************* - /// Gets the maximum possible size of the forward_list. - //************************************************************************* - size_type max_size() const - { - return MAX_SIZE; - } - //************************************************************************* /// Checks to see if the forward_list is empty. //************************************************************************* bool empty() const { - if (has_shared_pool()) - { - return (size() == 0); - } - else - { - ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(forward_list_no_pool)); - return p_node_pool->empty(); - } + return (start_node.next == ETL_NULLPTR); } //************************************************************************* diff --git a/include/etl/list.h b/include/etl/list.h index b854ace7..1759db7f 100644 --- a/include/etl/list.h +++ b/include/etl/list.h @@ -241,7 +241,7 @@ namespace etl if (has_shared_pool()) { // We have to count what we actually own. - size_type count = 0; + size_type count = 0U; node_t* p_node = terminal_node.next; @@ -255,7 +255,6 @@ namespace etl } else { - ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); return p_node_pool->size(); } } @@ -265,15 +264,7 @@ namespace etl //************************************************************************* bool empty() const { - if (has_shared_pool()) - { - return (size() == 0); - } - else - { - ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); - return p_node_pool->empty(); - } + return (terminal_node.next == &terminal_node); } //************************************************************************* @@ -281,32 +272,18 @@ namespace etl //************************************************************************* bool full() const { - if (has_shared_pool()) - { - return size() == MAX_SIZE; - } - else - { - ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); - return p_node_pool->size() == MAX_SIZE; - } + ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); + return p_node_pool->full(); } //************************************************************************* /// Returns the remaining capacity. ///\return The remaining capacity. //************************************************************************* - size_t available() const + size_type available() const { - if (has_shared_pool()) - { - return max_size() - size(); - } - else - { - ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); - return max_size() - p_node_pool->size(); - } + ETL_ASSERT(p_node_pool != ETL_NULLPTR, ETL_ERROR(list_no_pool)); + return p_node_pool->available(); } protected: diff --git a/include/etl/version.h b/include/etl/version.h index cb565d5a..31d47e3d 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 18 #define ETL_VERSION_MINOR 15 -#define ETL_VERSION_PATCH 4 +#define ETL_VERSION_PATCH 5 #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) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index 367ab271..7c3ac2ec 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.15.4", + "version": "18.15.5", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index 78e728bf..fb402258 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.15.4 +version=18.15.5 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 67177dc9..3aad4c64 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +18.15.5 +Refactored empty(), full(), available() member functions for etl::list and etl::forward_list + =============================================================================== 18.15.4 Performance optimisations for etl::rotate, etl::move & etl::move_backward diff --git a/test/test_forward_list_shared_pool.cpp b/test/test_forward_list_shared_pool.cpp index 52b7cf2c..39873f21 100644 --- a/test/test_forward_list_shared_pool.cpp +++ b/test/test_forward_list_shared_pool.cpp @@ -97,7 +97,10 @@ namespace PoolDC pool; DataDC data(pool); + CHECK_EQUAL(data.size(), size_t(0)); CHECK(data.empty()); + CHECK(!data.full()); + CHECK_EQUAL(data.available(), SIZE); CHECK_EQUAL(data.max_size(), SIZE); CHECK(data.begin() == data.end()); CHECK(data.has_shared_pool()); @@ -109,6 +112,8 @@ namespace DataNDC data; CHECK_THROW(data.push_front(ItemNDC("1")), etl::forward_list_no_pool); + CHECK_THROW(data.full(), etl::forward_list_no_pool); + CHECK_THROW(data.available(), etl::forward_list_no_pool); } //************************************************************************* @@ -123,6 +128,10 @@ namespace CHECK(!data2.empty()); CHECK_EQUAL(INITIAL_SIZE, data1.size()); CHECK_EQUAL(INITIAL_SIZE, data2.size()); + + CHECK_EQUAL(SIZE - (INITIAL_SIZE * 2), data1.available()); + CHECK_EQUAL(SIZE - (INITIAL_SIZE * 2), data2.available()); + CHECK_EQUAL((2 * INITIAL_SIZE), pool.size()); } @@ -533,9 +542,14 @@ namespace data1.assign(compare_data.begin(), compare_data.end()); data1.assign(compare_data.begin(), compare_data.end()); + CHECK_EQUAL(pool.available(), data1.available()); + CHECK_EQUAL(pool.available(), data2.available()); + data2.assign(compare_data.begin(), compare_data.end()); data2.assign(compare_data.begin(), compare_data.end()); + CHECK_EQUAL(pool.available(), data1.available()); + CHECK_EQUAL(pool.available(), data2.available()); CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data1.size()); CHECK_EQUAL(size_t(std::distance(compare_data.begin(), compare_data.end())), data2.size()); diff --git a/test/test_list_shared_pool.cpp b/test/test_list_shared_pool.cpp index 5a557623..b006a1b2 100644 --- a/test/test_list_shared_pool.cpp +++ b/test/test_list_shared_pool.cpp @@ -106,6 +106,8 @@ namespace DataNDC data; CHECK_EQUAL(data.max_size(), 0U); + CHECK_EQUAL(data.size(), 0U); + CHECK(data.empty()); CHECK(data.has_shared_pool()); } @@ -115,6 +117,8 @@ namespace DataNDC data; CHECK_THROW(data.push_back(ItemNDC("1")), etl::list_no_pool); + CHECK_THROW(data.full(), etl::list_no_pool); + CHECK_THROW(data.available(), etl::list_no_pool); } //************************************************************************* @@ -125,6 +129,8 @@ namespace CHECK_EQUAL(data.size(), size_t(0)); CHECK(data.empty()); + CHECK(!data.full()); + CHECK_EQUAL(data.available(), SIZE); CHECK_EQUAL(data.max_size(), SIZE); CHECK(data.begin() == data.end()); @@ -524,12 +530,19 @@ namespace DataNDC data1(pool); DataNDC data2(pool); + CHECK_EQUAL(pool.available(), data1.available()); + CHECK_EQUAL(pool.available(), data2.available()); + data1.assign(compare_data.begin(), compare_data.end()); CHECK(!data1.empty()); CHECK(data2.empty()); + CHECK_EQUAL(pool.available(), data1.available()); + CHECK_EQUAL(pool.available(), data2.available()); data2.assign(compare_data.begin(), compare_data.end()); CHECK(!data1.empty()); CHECK(!data2.empty()); + CHECK_EQUAL(pool.available(), data1.available()); + CHECK_EQUAL(pool.available(), data2.available()); CHECK_EQUAL(compare_data.size(), data1.size()); CHECK_EQUAL(compare_data.size(), data2.size()); From 509089c0e25eadadea531c2f54875607c0479b5e Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 28 Sep 2020 13:14:12 +0100 Subject: [PATCH 58/71] Added template deduction guides --- include/etl/array.h | 2 +- include/etl/char_traits.h | 6 ++-- include/etl/deque.h | 18 ++++++++++++ include/etl/flat_map.h | 11 +++++++ include/etl/flat_multimap.h | 11 +++++++ include/etl/flat_multiset.h | 9 ++++++ include/etl/flat_set.h | 9 ++++++ include/etl/forward_list.h | 17 +++++++++++ include/etl/indirect_vector.h | 9 ++++++ include/etl/list.h | 17 +++++++++++ include/etl/map.h | 11 +++++++ include/etl/multimap.h | 12 +++++++- include/etl/multiset.h | 9 ++++++ include/etl/optional.h | 8 ++++++ include/etl/pool.h | 9 +++--- include/etl/set.h | 9 ++++++ include/etl/span.h | 18 ++++++++++++ include/etl/unordered_map.h | 34 ++++++++++++++++++++++ include/etl/unordered_multimap.h | 34 ++++++++++++++++++++++ include/etl/unordered_multiset.h | 32 +++++++++++++++++++++ include/etl/unordered_set.h | 32 +++++++++++++++++++++ include/etl/utility.h | 8 ++++++ include/etl/vector.h | 18 ++++++++++++ include/etl/version.h | 4 +-- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 4 +++ test/test_array_view.cpp | 2 +- test/test_deque.cpp | 18 ++++++++++++ test/test_flat_map.cpp | 20 +++++++++++++ test/test_flat_multimap.cpp | 20 +++++++++++++ test/test_flat_multiset.cpp | 18 ++++++++++++ test/test_flat_set.cpp | 18 ++++++++++++ test/test_forward_list.cpp | 18 ++++++++++++ test/test_indirect_vector.cpp | 18 ++++++++++++ test/test_list.cpp | 18 ++++++++++++ test/test_map.cpp | 20 +++++++++++++ test/test_multimap.cpp | 20 +++++++++++++ test/test_multiset.cpp | 18 ++++++++++++ test/test_optional.cpp | 12 +++++++- test/test_set.cpp | 23 +++++++++++++-- test/test_span.cpp | 30 +++++++++++++++++++ test/test_unordered_map.cpp | 49 ++++++++++++++++++++++++++++---- test/test_unordered_multimap.cpp | 39 +++++++++++++++++++++++++ test/test_unordered_multiset.cpp | 40 ++++++++++++++++++++++++-- test/test_unordered_set.cpp | 41 ++++++++++++++++++++++++-- test/test_utility.cpp | 34 +++++++++++++++------- test/test_vector.cpp | 18 ++++++++++++ test/test_vector_non_trivial.cpp | 18 ++++++++++++ test/test_vector_pointer.cpp | 47 ++++++++++++++++++++---------- 50 files changed, 859 insertions(+), 55 deletions(-) diff --git a/include/etl/array.h b/include/etl/array.h index 188ce506..410603c0 100644 --- a/include/etl/array.h +++ b/include/etl/array.h @@ -558,7 +558,7 @@ namespace etl #if ETL_CPP17_SUPPORTED template array(T, Ts...) - -> array && ...), T>, 1 + sizeof...(Ts)>; + -> array && ...), T>, 1U + sizeof...(Ts)>; #endif //************************************************************************* diff --git a/include/etl/char_traits.h b/include/etl/char_traits.h index 36cffb37..8cbc0344 100644 --- a/include/etl/char_traits.h +++ b/include/etl/char_traits.h @@ -102,19 +102,19 @@ namespace etl typedef typename char_traits_types::state_type state_type; //************************************************************************* - static bool eq(char_type a, char_type b) + ETL_CONSTEXPR static bool eq(char_type a, char_type b) { return a == b; } //************************************************************************* - static bool lt(char_type a, char_type b) + ETL_CONSTEXPR static bool lt(char_type a, char_type b) { return a < b; } //************************************************************************* - static size_t length(const char_type* str) + ETL_CONSTEXPR14 static size_t length(const char_type* str) { size_t count = 0; diff --git a/include/etl/deque.h b/include/etl/deque.h index 5cd57588..ee02abcd 100644 --- a/include/etl/deque.h +++ b/include/etl/deque.h @@ -186,6 +186,15 @@ namespace etl return CAPACITY; } + //************************************************************************* + /// Returns the maximum possible size of the deque. + ///\return The maximum size of the deque. + //************************************************************************* + size_type capacity() const + { + return CAPACITY; + } + //************************************************************************* /// Returns the remaining capacity. ///\return The remaining capacity. @@ -2457,6 +2466,15 @@ namespace etl typename etl::aligned_storage::value>::type buffer[BUFFER_SIZE]; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + deque(T, Ts...) + ->deque && ...), T>, 1U + sizeof...(Ts)>; +#endif + //*************************************************************************** /// Equal operator. ///\param lhs Reference to the _begin deque. diff --git a/include/etl/flat_map.h b/include/etl/flat_map.h index 13c6988a..b5960133 100644 --- a/include/etl/flat_map.h +++ b/include/etl/flat_map.h @@ -1004,6 +1004,17 @@ namespace etl /// The vector that stores pointers to the nodes. etl::vector lookup; }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + flat_map(T, Ts...) + ->flat_map && ...), typename T::first_type>, + etl::enable_if_t<(etl::is_same_v && ...), typename T::second_type>, + 1U + sizeof...(Ts)>; +#endif } #undef ETL_FILE diff --git a/include/etl/flat_multimap.h b/include/etl/flat_multimap.h index d7761afb..e163ec67 100644 --- a/include/etl/flat_multimap.h +++ b/include/etl/flat_multimap.h @@ -907,6 +907,17 @@ namespace etl // The vector that stores pointers to the nodes. etl::vector lookup; }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + flat_multimap(T, Ts...) + ->flat_multimap && ...), typename T::first_type>, + etl::enable_if_t<(etl::is_same_v && ...), typename T::second_type>, + 1U + sizeof...(Ts)>; +#endif } #undef ETL_FILE diff --git a/include/etl/flat_multiset.h b/include/etl/flat_multiset.h index 3ffcfaf3..2e3ce7ae 100644 --- a/include/etl/flat_multiset.h +++ b/include/etl/flat_multiset.h @@ -857,6 +857,15 @@ namespace etl // The vector that stores pointers to the nodes. etl::vector lookup; }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + flat_multiset(T, Ts...) + ->flat_multiset && ...), T>, 1U + sizeof...(Ts)>; +#endif } #undef ETL_FILE diff --git a/include/etl/flat_set.h b/include/etl/flat_set.h index 9f73f099..baa19791 100644 --- a/include/etl/flat_set.h +++ b/include/etl/flat_set.h @@ -944,6 +944,15 @@ namespace etl // The vector that stores pointers to the nodes. etl::vector lookup; }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + flat_set(T, Ts...) + ->flat_set && ...), T>, 1U + sizeof...(Ts)>; +#endif } #undef ETL_FILE diff --git a/include/etl/forward_list.h b/include/etl/forward_list.h index 3e016567..4c6b9c22 100644 --- a/include/etl/forward_list.h +++ b/include/etl/forward_list.h @@ -180,6 +180,14 @@ namespace etl return MAX_SIZE; } + //************************************************************************* + /// Gets the maximum possible size of the forward_list. + //************************************************************************* + size_type capacity() const + { + return MAX_SIZE; + } + //************************************************************************* /// Gets the size of the forward_list. //************************************************************************* @@ -1726,6 +1734,15 @@ namespace etl etl::pool::data_node_t, MAX_SIZE> node_pool; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + forward_list(T, Ts...) + ->forward_list && ...), T>, 1U + sizeof...(Ts)>; +#endif + //************************************************************************* /// A templated forward_list implementation that uses a fixed size pool. ///\note 'merge' and 'splice_after' and are not supported. diff --git a/include/etl/indirect_vector.h b/include/etl/indirect_vector.h index f2e727dc..8d6b5442 100644 --- a/include/etl/indirect_vector.h +++ b/include/etl/indirect_vector.h @@ -1404,6 +1404,15 @@ namespace etl etl::pool storage_pool; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + indirect_vector(T, Ts...) + ->indirect_vector && ...), T>, 1U + sizeof...(Ts)>; +#endif + //*************************************************************************** /// A indirect_vector implementation that uses a fixed size buffer. /// The buffer is supplied on construction. diff --git a/include/etl/list.h b/include/etl/list.h index 1759db7f..c40a87ca 100644 --- a/include/etl/list.h +++ b/include/etl/list.h @@ -233,6 +233,14 @@ namespace etl return MAX_SIZE; } + //************************************************************************* + /// Gets the maximum possible size of the list. + //************************************************************************* + size_type capacity() const + { + return MAX_SIZE; + } + //************************************************************************* /// Gets the size of the list. //************************************************************************* @@ -2158,6 +2166,15 @@ namespace etl etl::pool::data_node_t, MAX_SIZE> node_pool; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + list(T, Ts...) + ->list && ...), T>, 1U + sizeof...(Ts)>; +#endif + //************************************************************************* /// A templated list implementation that uses a fixed size buffer. //************************************************************************* diff --git a/include/etl/map.h b/include/etl/map.h index b13fdf4f..0efc2ef6 100755 --- a/include/etl/map.h +++ b/include/etl/map.h @@ -2298,6 +2298,17 @@ namespace etl etl::pool::Data_Node, MAX_SIZE> node_pool; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + map(T, Ts...) + ->map && ...), typename T::first_type>, + typename T::second_type, + 1U + sizeof...(Ts)>; +#endif + //*************************************************************************** /// Equal operator. ///\param lhs Reference to the first lookup. diff --git a/include/etl/multimap.h b/include/etl/multimap.h index b54686d1..1cde7318 100644 --- a/include/etl/multimap.h +++ b/include/etl/multimap.h @@ -2033,7 +2033,6 @@ namespace etl { } #endif - }; //************************************************************************* @@ -2158,6 +2157,17 @@ namespace etl etl::pool::Data_Node, MAX_SIZE> node_pool; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + multimap(T, Ts...) + ->multimap && ...), typename T::first_type>, + typename T::second_type, + 1U + sizeof...(Ts)>; +#endif + //*************************************************************************** /// Equal operator. ///\param lhs Reference to the first lookup. diff --git a/include/etl/multiset.h b/include/etl/multiset.h index 3a43e3ed..dd950be1 100644 --- a/include/etl/multiset.h +++ b/include/etl/multiset.h @@ -2140,6 +2140,15 @@ namespace etl etl::pool::Data_Node, MAX_SIZE> node_pool; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + multiset(T, Ts...) + ->multiset && ...), T>, 1U + sizeof...(Ts)>; +#endif + //*************************************************************************** /// Equal operator. ///\param lhs Reference to the first lookup. diff --git a/include/etl/optional.h b/include/etl/optional.h index 25b4af0a..a909e031 100644 --- a/include/etl/optional.h +++ b/include/etl/optional.h @@ -507,6 +507,14 @@ namespace etl bool valid; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED + template + optional(T) -> optional; +#endif + //*************************************************************************** /// Equality operator. cppreference 1 //*************************************************************************** diff --git a/include/etl/pool.h b/include/etl/pool.h index 3aa79740..cb191bb6 100644 --- a/include/etl/pool.h +++ b/include/etl/pool.h @@ -256,7 +256,8 @@ namespace etl //************************************************************************* void release(const void* const p_object) { - release_item((char*)p_object); + const uintptr_t p = uintptr_t(p_object); + release_item((char*)p); } //************************************************************************* @@ -264,7 +265,7 @@ namespace etl //************************************************************************* void release_all() { - items_allocated = 0; + items_allocated = 0; items_initialised = 0; p_next = p_buffer; } @@ -274,10 +275,10 @@ namespace etl /// \param p_object A pointer to the object to be checked. /// \return true<\b> if it does, otherwise false //************************************************************************* - //template bool is_in_pool(const void* p_object) const { - return is_item_in_pool((const char*)p_object); + const uintptr_t p = uintptr_t(p_object); + return is_item_in_pool((const char*)p); } //************************************************************************* diff --git a/include/etl/set.h b/include/etl/set.h index ec16c784..63d3debc 100755 --- a/include/etl/set.h +++ b/include/etl/set.h @@ -2221,6 +2221,15 @@ namespace etl etl::pool::Data_Node, MAX_SIZE> node_pool; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + set(T, Ts...) + ->set && ...), T>, 1U + sizeof...(Ts)>; +#endif + //*************************************************************************** /// Equal operator. ///\param lhs Reference to the first lookup. diff --git a/include/etl/span.h b/include/etl/span.h index c66ab30d..89e4cf2f 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -309,6 +309,24 @@ namespace etl element_type* mend; }; + //************************************************************************* +/// Template deduction guides. +//************************************************************************* +#if ETL_CPP17_SUPPORTED + template + span(TArray& a) + ->span; + + template + span(const TIterator begin_, const TIterator end_) + ->span>; + + template + span(const TIterator begin_, const TSize size_) + ->span>; +#endif + //************************************************************************* /// Hash function. //************************************************************************* diff --git a/include/etl/unordered_map.h b/include/etl/unordered_map.h index 2b3c3cf1..45220ad1 100644 --- a/include/etl/unordered_map.h +++ b/include/etl/unordered_map.h @@ -54,6 +54,10 @@ SOFTWARE. #include "debug_count.h" #include "iterator.h" +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + #include +#endif + #undef ETL_FILE #define ETL_FILE "16" @@ -1229,6 +1233,14 @@ namespace etl return pnodepool->max_size(); } + //************************************************************************* + /// Gets the maximum possible size of the unordered_map. + //************************************************************************* + size_type capacity() const + { + return pnodepool->max_size(); + } + //************************************************************************* /// Checks to see if the unordered_map is empty. //************************************************************************* @@ -1579,6 +1591,17 @@ namespace etl base::assign(first_, last_); } +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + //************************************************************************* + /// Construct from initializer_list. + //************************************************************************* + unordered_map(std::initializer_list> init) + : base(node_pool, buckets, MAX_BUCKETS_) + { + base::assign(init.begin(), init.end()); + } +#endif + //************************************************************************* /// Destructor. //************************************************************************* @@ -1626,6 +1649,17 @@ namespace etl /// The buckets of node lists. etl::intrusive_forward_list buckets[MAX_BUCKETS_]; }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + unordered_map(T, Ts...) + ->unordered_map && ...), typename T::first_type>, + typename T::second_type, + 1U + sizeof...(Ts)>; +#endif } #undef ETL_FILE diff --git a/include/etl/unordered_multimap.h b/include/etl/unordered_multimap.h index 8810bc8a..e029593e 100644 --- a/include/etl/unordered_multimap.h +++ b/include/etl/unordered_multimap.h @@ -54,6 +54,10 @@ SOFTWARE. #include "debug_count.h" #include "iterator.h" +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + #include +#endif + #undef ETL_FILE #define ETL_FILE "25" @@ -1135,6 +1139,14 @@ namespace etl return pnodepool->max_size(); } + //************************************************************************* + /// Gets the maximum possible size of the unordered_multimap. + //************************************************************************* + size_type capacity() const + { + return pnodepool->max_size(); + } + //************************************************************************* /// Checks to see if the unordered_multimap is empty. //************************************************************************* @@ -1491,6 +1503,17 @@ namespace etl base::assign(first_, last_); } +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + //************************************************************************* + /// Construct from initializer_list. + //************************************************************************* + unordered_multimap(std::initializer_list> init) + : base(node_pool, buckets, MAX_BUCKETS_) + { + base::assign(init.begin(), init.end()); + } +#endif + //************************************************************************* /// Destructor. //************************************************************************* @@ -1538,6 +1561,17 @@ namespace etl /// The buckets of node lists. etl::intrusive_forward_list buckets[MAX_BUCKETS_]; }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + unordered_multimap(T, Ts...) + ->unordered_multimap && ...), typename T::first_type>, + typename T::second_type, + 1U + sizeof...(Ts)>; +#endif } #undef ETL_FILE diff --git a/include/etl/unordered_multiset.h b/include/etl/unordered_multiset.h index 677a5b1c..df7e5671 100644 --- a/include/etl/unordered_multiset.h +++ b/include/etl/unordered_multiset.h @@ -55,6 +55,10 @@ SOFTWARE. #include "debug_count.h" #include "iterator.h" +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + #include +#endif + #undef ETL_FILE #define ETL_FILE "26" @@ -1120,6 +1124,14 @@ namespace etl return pnodepool->max_size(); } + //************************************************************************* + /// Gets the maximum possible size of the unordered_multiset. + //************************************************************************* + size_type capacity() const + { + return pnodepool->max_size(); + } + //************************************************************************* /// Checks to see if the unordered_multiset is empty. //************************************************************************* @@ -1479,6 +1491,17 @@ namespace etl base::assign(first_, last_); } +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + //************************************************************************* + /// Construct from initializer_list. + //************************************************************************* + unordered_multiset(std::initializer_list init) + : base(node_pool, buckets, MAX_BUCKETS) + { + base::assign(init.begin(), init.end()); + } +#endif + //************************************************************************* /// Destructor. //************************************************************************* @@ -1526,6 +1549,15 @@ namespace etl /// The buckets of node lists. etl::intrusive_forward_list buckets[MAX_BUCKETS_]; }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + unordered_multiset(T, Ts...) + ->unordered_multiset && ...), T>, 1U + sizeof...(Ts)>; +#endif } #undef ETL_FILE diff --git a/include/etl/unordered_set.h b/include/etl/unordered_set.h index 4e4322c3..fd5b034e 100644 --- a/include/etl/unordered_set.h +++ b/include/etl/unordered_set.h @@ -54,6 +54,10 @@ SOFTWARE. #include "debug_count.h" #include "iterator.h" +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + #include +#endif + #undef ETL_FILE #define ETL_FILE "23" @@ -1112,6 +1116,14 @@ namespace etl return pnodepool->max_size(); } + //************************************************************************* + /// Gets the maximum possible size of the unordered_set. + //************************************************************************* + size_type capacity() const + { + return pnodepool->max_size(); + } + //************************************************************************* /// Checks to see if the unordered_set is empty. //************************************************************************* @@ -1475,6 +1487,17 @@ namespace etl base::assign(first_, last_); } +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + //************************************************************************* + /// Construct from initializer_list. + //************************************************************************* + unordered_set(std::initializer_list init) + : base(node_pool, buckets, MAX_BUCKETS) + { + base::assign(init.begin(), init.end()); + } +#endif + //************************************************************************* /// Destructor. //************************************************************************* @@ -1522,6 +1545,15 @@ namespace etl /// The buckets of node lists. etl::intrusive_forward_list buckets[MAX_BUCKETS_]; }; + + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + unordered_set(T, Ts...) + ->unordered_set && ...), T>, 1U + sizeof...(Ts)>; +#endif } #undef ETL_FILE diff --git a/include/etl/utility.h b/include/etl/utility.h index 03c2a37e..37155c95 100644 --- a/include/etl/utility.h +++ b/include/etl/utility.h @@ -230,6 +230,14 @@ namespace etl #endif }; +//************************************************************************* +/// Template deduction guides. +//************************************************************************* +#if ETL_CPP17_SUPPORTED + template + pair(T1, T2) ->pair; +#endif + //****************************************************************************** #if ETL_CPP11_SUPPORTED template diff --git a/include/etl/vector.h b/include/etl/vector.h index b154adee..087a5c65 100644 --- a/include/etl/vector.h +++ b/include/etl/vector.h @@ -1286,6 +1286,15 @@ namespace etl typename etl::aligned_storage::value>::type buffer; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + vector(T, Ts...) + ->vector && ...), T>, 1U + sizeof...(Ts)>; +#endif + //*************************************************************************** /// A vector implementation that uses a fixed size buffer. /// The buffer is supplied on construction. @@ -1569,6 +1578,15 @@ namespace etl typename etl::aligned_storage::value>::type buffer; }; + //************************************************************************* + /// Template deduction guides. + //************************************************************************* +#if ETL_CPP17_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + template + vector(T*, Ts*...) + ->vector && ...), T*>, 1U + sizeof...(Ts)>; +#endif + //*************************************************************************** /// A vector implementation that uses a fixed size buffer. /// The buffer is supplied on construction. diff --git a/include/etl/version.h b/include/etl/version.h index 31d47e3d..623aedce 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -38,8 +38,8 @@ SOFTWARE. ///\ingroup utilities #define ETL_VERSION_MAJOR 18 -#define ETL_VERSION_MINOR 15 -#define ETL_VERSION_PATCH 5 +#define ETL_VERSION_MINOR 16 +#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) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index 7c3ac2ec..5965c324 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.15.5", + "version": "18.16.0", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index fb402258..7e169f6d 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.15.5 +version=18.16.0 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 3aad4c64..909902e6 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +18.16.0 +Added template deduction guides for most containers. + =============================================================================== 18.15.5 Refactored empty(), full(), available() member functions for etl::list and etl::forward_list diff --git a/test/test_array_view.cpp b/test/test_array_view.cpp index bc172493..bc5e42a5 100644 --- a/test/test_array_view.cpp +++ b/test/test_array_view.cpp @@ -285,7 +285,7 @@ namespace //************************************************************************* #ifndef ETL_COMPILER_MICROSOFT // Temporarily disabled as Appveyor reports an "internal compiler error - TEST(test_cpp17_dedused_constructor) + TEST(test_cpp17_deduced_constructor) { etl::array data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; diff --git a/test/test_deque.cpp b/test/test_deque.cpp index 876aa4ea..e9bbe648 100644 --- a/test/test_deque.cpp +++ b/test/test_deque.cpp @@ -101,6 +101,24 @@ namespace CHECK_EQUAL(SIZE, data.max_size()); } +#if ETL_USING_STL + //************************************************************************* + 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) { diff --git a/test/test_flat_map.cpp b/test/test_flat_map.cpp index bc71c3c4..fe68b9b9 100644 --- a/test/test_flat_map.cpp +++ b/test/test_flat_map.cpp @@ -316,6 +316,26 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::flat_map data{ ElementNDC(0, N0), ElementNDC(1, N1), ElementNDC(2, N2), ElementNDC(3, N3), ElementNDC(4, N4), + ElementNDC(5, N5), ElementNDC(6, N6), ElementNDC(7, N7), ElementNDC(8, N8), ElementNDC(9, N9) }; + etl::flat_map check = { ElementNDC(0, N0), ElementNDC(1, N1), ElementNDC(2, N2), ElementNDC(3, N3), ElementNDC(4, N4), + ElementNDC(5, N5), ElementNDC(6, N6), ElementNDC(7, N7), ElementNDC(8, N8), ElementNDC(9, N9) }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST(test_destruct_via_iflat_map) { diff --git a/test/test_flat_multimap.cpp b/test/test_flat_multimap.cpp index 687e260d..213c8789 100644 --- a/test/test_flat_multimap.cpp +++ b/test/test_flat_multimap.cpp @@ -293,6 +293,26 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::flat_multimap data{ ElementNDC(0, N0), ElementNDC(1, N1), ElementNDC(2, N2), ElementNDC(3, N3), ElementNDC(4, N4), + ElementNDC(5, N5), ElementNDC(6, N6), ElementNDC(7, N7), ElementNDC(8, N8), ElementNDC(9, N9) }; + etl::flat_multimap check = { ElementNDC(0, N0), ElementNDC(1, N1), ElementNDC(2, N2), ElementNDC(3, N3), ElementNDC(4, N4), + ElementNDC(5, N5), ElementNDC(6, N6), ElementNDC(7, N7), ElementNDC(8, N8), ElementNDC(9, N9) }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST(test_destruct_via_iflat_multimap) { diff --git a/test/test_flat_multiset.cpp b/test/test_flat_multiset.cpp index 96c63bb4..ff6bebd1 100644 --- a/test/test_flat_multiset.cpp +++ b/test/test_flat_multiset.cpp @@ -262,6 +262,24 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::flat_multiset data{ N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; + etl::flat_multiset check = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST(test_destruct_via_iflat_multiset) { diff --git a/test/test_flat_set.cpp b/test/test_flat_set.cpp index 89be0a1f..c70bbe81 100644 --- a/test/test_flat_set.cpp +++ b/test/test_flat_set.cpp @@ -274,6 +274,24 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::flat_set data{ N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; + etl::flat_set check = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST(test_destruct_via_iflat_set) { diff --git a/test/test_forward_list.cpp b/test/test_forward_list.cpp index 2955720f..494e7155 100644 --- a/test/test_forward_list.cpp +++ b/test/test_forward_list.cpp @@ -95,6 +95,24 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::forward_list data{ ItemNDC("1", 1), ItemNDC("2", 2), ItemNDC("3", 3), ItemNDC("2", 4), ItemNDC("0", 5), ItemNDC("2", 6), ItemNDC("7", 7), ItemNDC("4", 8), ItemNDC("4", 9), ItemNDC("8", 10) }; + etl::forward_list< ItemNDC, 10> check = { ItemNDC("1", 1), ItemNDC("2", 2), ItemNDC("3", 3), ItemNDC("2", 4), ItemNDC("0", 5), ItemNDC("2", 6), ItemNDC("7", 7), ItemNDC("4", 8), ItemNDC("4", 9), ItemNDC("8", 10) }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size) { diff --git a/test/test_indirect_vector.cpp b/test/test_indirect_vector.cpp index 0415025a..b64a3fe1 100644 --- a/test/test_indirect_vector.cpp +++ b/test/test_indirect_vector.cpp @@ -136,6 +136,24 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } +#if ETL_USING_STL + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::indirect_vector data{ NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9") }; + etl::indirect_vector check = { NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9") }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_destruct_via_ivector) { diff --git a/test/test_list.cpp b/test/test_list.cpp index ad674793..a6fee7f4 100644 --- a/test/test_list.cpp +++ b/test/test_list.cpp @@ -106,6 +106,24 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::list data{ ItemNDC("1", 1), ItemNDC("2", 2), ItemNDC("3", 3), ItemNDC("2", 4), ItemNDC("0", 5), ItemNDC("2", 6), ItemNDC("7", 7), ItemNDC("4", 8), ItemNDC("4", 9), ItemNDC("8", 10) }; + etl::list< ItemNDC, 10> check = { ItemNDC("1", 1), ItemNDC("2", 2), ItemNDC("3", 3), ItemNDC("2", 4), ItemNDC("0", 5), ItemNDC("2", 6), ItemNDC("7", 7), ItemNDC("4", 8), ItemNDC("4", 9), ItemNDC("8", 10) }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST(test_destruct_via_ilist) { diff --git a/test/test_map.cpp b/test/test_map.cpp index d092c6af..c91a8416 100755 --- a/test/test_map.cpp +++ b/test/test_map.cpp @@ -225,6 +225,26 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::map data{ std::pair("0", 0), std::pair("1", 1), std::pair("2", 2), std::pair("3", 3), std::pair("4", 4), + std::pair("5", 5), std::pair("6", 6), std::pair("7", 7), std::pair("8", 8), std::pair("9", 9) }; + etl::map check = { std::pair("0", 0), std::pair("1", 1), std::pair("2", 2), std::pair("3", 3), std::pair("4", 4), + std::pair("5", 5), std::pair("6", 6), std::pair("7", 7), std::pair("8", 8), std::pair("9", 9) }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) { diff --git a/test/test_multimap.cpp b/test/test_multimap.cpp index 86aaa4cc..f94015ad 100755 --- a/test/test_multimap.cpp +++ b/test/test_multimap.cpp @@ -227,6 +227,26 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::multimap data{ std::pair("0", 0), std::pair("1", 1), std::pair("2", 2), std::pair("3", 3), std::pair("4", 4), + std::pair("5", 5), std::pair("6", 6), std::pair("7", 7), std::pair("8", 8), std::pair("9", 9) }; + etl::multimap check = { std::pair("0", 0), std::pair("1", 1), std::pair("2", 2), std::pair("3", 3), std::pair("4", 4), + std::pair("5", 5), std::pair("6", 6), std::pair("7", 7), std::pair("8", 8), std::pair("9", 9) }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) { diff --git a/test/test_multiset.cpp b/test/test_multiset.cpp index d28f37e0..6ecedcfa 100755 --- a/test/test_multiset.cpp +++ b/test/test_multiset.cpp @@ -234,6 +234,24 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::multiset data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + etl::multiset check = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) { diff --git a/test/test_optional.cpp b/test/test_optional.cpp index d0171411..3d996161 100644 --- a/test/test_optional.cpp +++ b/test/test_optional.cpp @@ -68,7 +68,6 @@ namespace CHECK(!data1.has_value()); CHECK(!data2.has_value()); - data1 = Data("Hello"); CHECK(bool(data1)); CHECK(data1.has_value()); @@ -97,7 +96,18 @@ namespace data4 = etl::nullopt; CHECK(!bool(data4)); CHECK(!data4.has_value()); + } + //************************************************************************* + TEST(test_deduced_initialisation) + { + Data data("Hello"); + + etl::optional opt{ data }; + + CHECK(opt.has_value()); + CHECK(bool(opt)); + CHECK_EQUAL(data, opt); } //************************************************************************* diff --git a/test/test_set.cpp b/test/test_set.cpp index 458c100e..1940ba4b 100755 --- a/test/test_set.cpp +++ b/test/test_set.cpp @@ -244,11 +244,30 @@ namespace CHECK_EQUAL(data.size(), size_t(0)); CHECK(data.empty()); - CHECK_EQUAL(data.capacity(), MAX_SIZE); - CHECK_EQUAL(data.max_size(), MAX_SIZE); + CHECK_EQUAL(MAX_SIZE, data.available()); + CHECK_EQUAL(MAX_SIZE, data.capacity()); + CHECK_EQUAL(MAX_SIZE, data.max_size()); CHECK(data.begin() == data.end()); } +#if ETL_USING_STL + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::set data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + etl::set check = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) { diff --git a/test/test_span.cpp b/test/test_span.cpp index cae33dd5..abf31310 100644 --- a/test/test_span.cpp +++ b/test/test_span.cpp @@ -247,6 +247,36 @@ namespace CHECK(isEqual); } + TEST(test_cpp17_deduced_constructor) + { + etl::array data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + etl::span span1{ data }; + etl::span span2{ data.begin(), data.end() }; + etl::span span3{ data.begin(), data.size() }; + etl::span span4{ span1 }; + + int c_array[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + etl::span span5{ c_array }; + + bool isEqual = false; + + isEqual = std::equal(span1.begin(), span1.end(), data.begin()); + CHECK(isEqual); + + isEqual = std::equal(span2.begin(), span2.end(), data.begin()); + CHECK(isEqual); + + isEqual = std::equal(span3.begin(), span3.end(), data.begin()); + CHECK(isEqual); + + isEqual = std::equal(span4.begin(), span4.end(), data.begin()); + CHECK(isEqual); + + isEqual = std::equal(span5.begin(), span5.end(), c_array); + CHECK(isEqual); + } + //************************************************************************* TEST(test_constructor_range) { diff --git a/test/test_unordered_map.cpp b/test/test_unordered_map.cpp index 72b36e51..8a7700f3 100644 --- a/test/test_unordered_map.cpp +++ b/test/test_unordered_map.cpp @@ -43,6 +43,7 @@ SOFTWARE. #include "data.h" #include "etl/unordered_map.h" +#include "etl/hash.h" namespace { @@ -73,19 +74,35 @@ namespace return true; } + typedef TestDataDC DC; + typedef TestDataNDC NDC; + + typedef ETL_OR_STD::pair ElementDC; + typedef ETL_OR_STD::pair ElementNDC; +} + +namespace etl +{ + template <> + struct hash + { + size_t operator ()(const std::string& e) const + { + size_t sum = 0U; + return std::accumulate(e.begin(), e.end(), sum); + } + }; +} + +namespace +{ SUITE(test_unordered_map) { static const size_t SIZE = 10; - typedef TestDataDC DC; - typedef TestDataNDC NDC; - using ItemM = TestDataM; using DataM = etl::unordered_map>; - typedef ETL_OR_STD::pair ElementDC; - typedef ETL_OR_STD::pair ElementNDC; - typedef etl::unordered_map DataDC; typedef etl::unordered_map DataNDC; typedef etl::iunordered_map IDataNDC; @@ -227,6 +244,26 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::unordered_map data{ ElementNDC(K0, N0), ElementNDC(K1, N1), ElementNDC(K2, N2), ElementNDC(K3, N3), ElementNDC(K4, N4), + ElementNDC(K5, N5), ElementNDC(K6, N6), ElementNDC(K7, N7), ElementNDC(K8, N8), ElementNDC(K9, N9) }; + etl::unordered_map check = { ElementNDC(K0, N0), ElementNDC(K1, N1), ElementNDC(K2, N2), ElementNDC(K3, N3), ElementNDC(K4, N4), + ElementNDC(K5, N5), ElementNDC(K6, N6), ElementNDC(K7, N7), ElementNDC(K8, N8), ElementNDC(K9, N9) }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { diff --git a/test/test_unordered_multimap.cpp b/test/test_unordered_multimap.cpp index 95d16f46..d8f9ea14 100644 --- a/test/test_unordered_multimap.cpp +++ b/test/test_unordered_multimap.cpp @@ -42,6 +42,19 @@ SOFTWARE. #include "etl/unordered_multimap.h" +namespace etl +{ + template <> + struct hash + { + size_t operator ()(const std::string& e) const + { + size_t sum = 0U; + return std::accumulate(e.begin(), e.end(), sum); + } + }; +} + namespace { //************************************************************************* @@ -71,6 +84,12 @@ namespace return true; } + typedef TestDataDC DC; + typedef TestDataNDC NDC; + + typedef ETL_OR_STD::pair ElementDC; + typedef ETL_OR_STD::pair ElementNDC; + SUITE(test_unordered_multimap) { static const size_t SIZE = 10; @@ -202,6 +221,26 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::unordered_multimap data{ ElementNDC(K0, N0), ElementNDC(K1, N1), ElementNDC(K2, N2), ElementNDC(K3, N3), ElementNDC(K4, N4), + ElementNDC(K5, N5), ElementNDC(K6, N6), ElementNDC(K7, N7), ElementNDC(K8, N8), ElementNDC(K9, N9) }; + etl::unordered_multimap check = { ElementNDC(K0, N0), ElementNDC(K1, N1), ElementNDC(K2, N2), ElementNDC(K3, N3), ElementNDC(K4, N4), + ElementNDC(K5, N5), ElementNDC(K6, N6), ElementNDC(K7, N7), ElementNDC(K8, N8), ElementNDC(K9, N9) }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { diff --git a/test/test_unordered_multiset.cpp b/test/test_unordered_multiset.cpp index 6dbb3dc7..ab501aac 100644 --- a/test/test_unordered_multiset.cpp +++ b/test/test_unordered_multiset.cpp @@ -42,15 +42,31 @@ SOFTWARE. #include "etl/unordered_multiset.h" #include "etl/checksum.h" +namespace +{ + typedef TestDataDC DC; + typedef TestDataNDC NDC; +} + +namespace etl +{ + template <> + struct hash + { + size_t operator ()(const NDC& e) const + { + size_t sum = 0U; + return std::accumulate(e.value.begin(), e.value.end(), sum); + } + }; +} + namespace { SUITE(test_unordered_multiset) { static const size_t SIZE = 10; - typedef TestDataDC DC; - typedef TestDataNDC NDC; - using ItemM = TestDataM; struct simple_hash @@ -146,6 +162,24 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::unordered_multiset data{ N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; + etl::unordered_multiset check = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { diff --git a/test/test_unordered_set.cpp b/test/test_unordered_set.cpp index 5d316dd0..7cb64474 100644 --- a/test/test_unordered_set.cpp +++ b/test/test_unordered_set.cpp @@ -40,6 +40,26 @@ SOFTWARE. #include "etl/unordered_set.h" #include "etl/checksum.h" +#include "etl/hash.h" + +namespace +{ + typedef TestDataDC DC; + typedef TestDataNDC NDC; +} + +namespace etl +{ + template <> + struct hash + { + size_t operator ()(const NDC& e) const + { + size_t sum = 0U; + return std::accumulate(e.value.begin(), e.value.end(), sum); + } + }; +} namespace { @@ -47,9 +67,6 @@ namespace { static const size_t SIZE = 10; - typedef TestDataDC DC; - typedef TestDataNDC NDC; - using ItemM = TestDataM; struct simple_hash @@ -138,6 +155,24 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::unordered_set data{ N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; + etl::unordered_set check = { N0, N1, N2, N3, N4, N5, N6, N7, N8, N9 }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { diff --git a/test/test_utility.cpp b/test/test_utility.cpp index ff39753a..30b78a75 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -60,7 +60,7 @@ namespace { etl::pair p1; - CHECK_EQUAL(int(), p1.first); + CHECK_EQUAL(int(), p1.first); CHECK_EQUAL(double(), p1.second); } @@ -69,7 +69,19 @@ namespace { etl::pair p1(1, 2.3); - CHECK_EQUAL(1, p1.first); + CHECK_EQUAL(1, p1.first); + CHECK_EQUAL(2.3, p1.second); + } + + //************************************************************************* + TEST(test_cpp17_deduced_pair_construct) + { + etl::pair p1{ 1, 2.3 }; + + CHECK((std::is_same_v)); + CHECK((std::is_same_v)); + + CHECK_EQUAL(1, p1.first); CHECK_EQUAL(2.3, p1.second); } @@ -78,7 +90,7 @@ namespace { etl::pair p1(1, 2.3); - CHECK_EQUAL(1, p1.first.value); + CHECK_EQUAL(1, p1.first.value); CHECK_EQUAL(2.3, p1.second.value); } @@ -88,7 +100,7 @@ namespace etl::pair p1(1, 2.3); etl::pair p2(p1); - CHECK_EQUAL(p1.first, p2.first); + CHECK_EQUAL(p1.first, p2.first); CHECK_EQUAL(p1.second, p2.second); } @@ -101,7 +113,7 @@ namespace CHECK(!bool(p1.first)); CHECK(!bool(p1.second)); - CHECK_EQUAL(1, p2.first.value); + CHECK_EQUAL(1, p2.first.value); CHECK_EQUAL(2.3, p2.second.value); } @@ -111,7 +123,7 @@ namespace etl::pair p1(1, 2.3f); etl::pair p2(p1); - CHECK_EQUAL(p1.first, p2.first); + CHECK_EQUAL(p1.first, p2.first); CHECK_EQUAL(p1.second, p2.second); } @@ -122,7 +134,7 @@ namespace etl::pair p2; p2 = etl::make_pair(1, 2.3); - CHECK_EQUAL(p1.first, p2.first); + CHECK_EQUAL(p1.first, p2.first); CHECK_EQUAL(p1.second, p2.second); } @@ -146,10 +158,10 @@ namespace p1.swap(p2); - CHECK_EQUAL(2, p1.first); + CHECK_EQUAL(2, p1.first); CHECK_EQUAL(3.4, p1.second); - CHECK_EQUAL(1, p2.first); + CHECK_EQUAL(1, p2.first); CHECK_EQUAL(2.3, p2.second); } @@ -161,10 +173,10 @@ namespace swap(p1, p2); - CHECK_EQUAL(2, p1.first); + CHECK_EQUAL(2, p1.first); CHECK_EQUAL(3.4, p1.second); - CHECK_EQUAL(1, p2.first); + CHECK_EQUAL(1, p2.first); CHECK_EQUAL(2.3, p2.second); } diff --git a/test/test_vector.cpp b/test/test_vector.cpp index ac4549ea..c0b1be91 100644 --- a/test/test_vector.cpp +++ b/test/test_vector.cpp @@ -83,6 +83,24 @@ namespace CHECK(data.begin() == data.end()); } +#if ETL_USING_STL + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::vector data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + etl::vector check = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST(test_iterator_comparison_empty) { diff --git a/test/test_vector_non_trivial.cpp b/test/test_vector_non_trivial.cpp index 82d533f6..b4c6f522 100644 --- a/test/test_vector_non_trivial.cpp +++ b/test/test_vector_non_trivial.cpp @@ -92,6 +92,24 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } +#if ETL_USING_STL + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::vector data{ NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9") }; + etl::vector check = { NDC("0"), NDC("1"), NDC("2"), NDC("3"), NDC("4"), NDC("5"), NDC("6"), NDC("7"), NDC("8"), NDC("9") }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_destruct_via_ivector) { diff --git a/test/test_vector_pointer.cpp b/test/test_vector_pointer.cpp index 9bbff8b3..d5fae547 100644 --- a/test/test_vector_pointer.cpp +++ b/test/test_vector_pointer.cpp @@ -55,26 +55,25 @@ namespace Compare_Data different_data; Compare_Data insert_data; + int n0 = 0; + int n1 = 1; + int n2 = 2; + int n3 = 3; + int n4 = 4; + int n5 = 5; + int n6 = 6; + int n7 = 7; + int n8 = 8; + int n9 = 9; + int n11 = 11; + int n12 = 12; + int n13 = 13; + //************************************************************************* struct SetupFixture { SetupFixture() { - int n0 = 0; - int n1 = 1; - int n2 = 2; - int n3 = 3; - int n4 = 4; - int n5 = 5; - int n6 = 6; - int n7 = 7; - int n8 = 8; - int n9 = 9; - int n11 = 11; - int n12 = 12; - int n13 = 13; - - int* n[] = { &n0, &n1, &n2, &n3, &n4, &n5, &n6, &n7, &n8, &n9 }; int* n_insert[] = { &n11, &n12, &n13 }; int* n_less[] = { &n0, &n1, &n2, &n3, &n3, &n5, &n6, &n7, &n8, &n9 }; @@ -100,6 +99,24 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } +#if ETL_USING_STL + //************************************************************************* + TEST(test_cpp17_deduced_constructor) + { + etl::vector data{ &n0, &n1, &n2, &n3, &n4, &n5, &n6, &n7, &n8, &n9 }; + etl::vector check = { &n0, &n1, &n2, &n3, &n4, &n5, &n6, &n7, &n8, &n9 }; + + CHECK(!data.empty()); + CHECK(data.full()); + CHECK(data.begin() != data.end()); + CHECK_EQUAL(0U, data.available()); + CHECK_EQUAL(10U, data.capacity()); + CHECK_EQUAL(10U, data.size()); + CHECK_EQUAL(10U, data.max_size()); + CHECK(data == check); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_default_constructor) { From f5290d896b814b5c912d12b0a7bb52248993b182 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 29 Sep 2020 09:58:04 +0100 Subject: [PATCH 59/71] Github CI update --- .github/workflows/main.yml | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d620336f..87101b69 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,47 +15,44 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Setup cmake - run: cmake -DBUILD_TESTS=ON ./ - - - name: Compile - run: make + - name: name: Build and run + run: | + cmake -DBUILD_TESTS=ON ./ + gcc --version + make - name: Run tests run: ./test/etl_tests - - - name: Save artifacts - uses: actions/upload-artifact@v2 - with: - name: Testfile - path: test/etl_tests build-clang-9-Linux: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 + - name: Build and run run: | export CC=clang-9 export CXX=clang++-9 cmake -D BUILD_TESTS=ON ./ + clang --version make - ./test/etl_tests - - name: Save artifacts - uses: actions/upload-artifact@v2 - with: - name: Testfile - path: test/etl_tests + - name: Run tests + run: ./test/etl_tests build-clang-10-osx: runs-on: macos-10.15 steps: - uses: actions/checkout@v2 + - name: Build and run run: | export CC=clang export CXX=clang++ cmake -D BUILD_TESTS=ON ./ + clang --version make - ./test/etl_tests + + - name: Run tests + run: ./test/etl_tests + From 17abf6326e6b2b6d7d84ec4ff997bf650ce0cf26 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 29 Sep 2020 09:58:04 +0100 Subject: [PATCH 60/71] Github CI update --- .github/workflows/main.yml | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d620336f..7fc4fe09 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,7 +1,7 @@ name: CI on: push: - branches: [ master ] + branches: [ hotfix/fix-ci-errors] pull_request: branches: [ master ] @@ -15,47 +15,44 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Setup cmake - run: cmake -DBUILD_TESTS=ON ./ - - - name: Compile - run: make + - name: name: Build and run + run: | + cmake -DBUILD_TESTS=ON ./ + gcc --version + make - name: Run tests run: ./test/etl_tests - - - name: Save artifacts - uses: actions/upload-artifact@v2 - with: - name: Testfile - path: test/etl_tests build-clang-9-Linux: runs-on: ubuntu-18.04 steps: - uses: actions/checkout@v2 + - name: Build and run run: | export CC=clang-9 export CXX=clang++-9 cmake -D BUILD_TESTS=ON ./ + clang --version make - ./test/etl_tests - - name: Save artifacts - uses: actions/upload-artifact@v2 - with: - name: Testfile - path: test/etl_tests + - name: Run tests + run: ./test/etl_tests build-clang-10-osx: runs-on: macos-10.15 steps: - uses: actions/checkout@v2 + - name: Build and run run: | export CC=clang export CXX=clang++ cmake -D BUILD_TESTS=ON ./ + clang --version make - ./test/etl_tests + + - name: Run tests + run: ./test/etl_tests + From 21d3f10542da32ace1aa94eef6a9427efc1d36fe Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 29 Sep 2020 10:00:38 +0100 Subject: [PATCH 61/71] Github CI update --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7fc4fe09..54b1988b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,7 @@ jobs: steps: - uses: actions/checkout@v2 - - name: name: Build and run + - name: Build and run run: | cmake -DBUILD_TESTS=ON ./ gcc --version From 5ad8cea9e0e01c51e186ed7e109344e0386e1991 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 29 Sep 2020 10:04:02 +0100 Subject: [PATCH 62/71] Github CI update --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 54b1988b..47c3ecfa 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-18.04, ubuntu-20.04] + os: [ubuntu-20.04] steps: - uses: actions/checkout@v2 From 18d8236f91b65f0a036e11377c2cf03096c4ac71 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 29 Sep 2020 11:23:10 +0100 Subject: [PATCH 63/71] Conditionally disable template deduction guide tests --- .github/workflows/main.yml | 12 +- test/test_array.cpp | 2 +- test/test_array_view.cpp | 2 +- test/test_deque.cpp | 2 +- test/test_flat_map.cpp | 2 +- test/test_flat_multimap.cpp | 2 +- test/test_flat_multiset.cpp | 2 +- test/test_flat_set.cpp | 2 +- test/test_forward_list.cpp | 2 +- test/test_indirect_vector.cpp | 2 +- test/test_list.cpp | 2 +- test/test_map.cpp | 2 +- test/test_multimap.cpp | 2 +- test/test_multiset.cpp | 2 +- test/test_optional.cpp | 2 + test/test_set.cpp | 2 +- test/test_span.cpp | 3 + test/test_unordered_map.cpp | 2 +- test/test_unordered_multimap.cpp | 2 +- test/test_unordered_multiset.cpp | 2 +- test/test_unordered_set.cpp | 2 +- test/test_utility.cpp | 2 + test/test_vector.cpp | 2 +- test/test_vector_non_trivial.cpp | 2 +- test/test_vector_pointer.cpp | 2 +- test/vs2019/etl.sln | 12 ++ test/vs2019/etl.vcxproj | 194 +++++++++++++++++++++++++++++++ 27 files changed, 244 insertions(+), 23 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 47c3ecfa..eca65b45 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,7 +25,11 @@ jobs: run: ./test/etl_tests build-clang-9-Linux: - runs-on: ubuntu-18.04 + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-18.04] + steps: - uses: actions/checkout@v2 @@ -41,7 +45,11 @@ jobs: run: ./test/etl_tests build-clang-10-osx: - runs-on: macos-10.15 + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-10.15] + steps: - uses: actions/checkout@v2 diff --git a/test/test_array.cpp b/test/test_array.cpp index 98368651..41fe82fb 100644 --- a/test/test_array.cpp +++ b/test/test_array.cpp @@ -57,7 +57,7 @@ namespace CHECK_EQUAL(data.max_size(), SIZE); } -#ifndef ETL_COMPILER_MICROSOFT // Temporarily disabled as Appveyor reports an "internal compiler error +#if !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_array_view.cpp b/test/test_array_view.cpp index bc5e42a5..7aafe9e6 100644 --- a/test/test_array_view.cpp +++ b/test/test_array_view.cpp @@ -284,7 +284,7 @@ namespace } //************************************************************************* -#ifndef ETL_COMPILER_MICROSOFT // Temporarily disabled as Appveyor reports an "internal compiler error +#if !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_deque.cpp b/test/test_deque.cpp index e9bbe648..9a312438 100644 --- a/test/test_deque.cpp +++ b/test/test_deque.cpp @@ -101,7 +101,7 @@ namespace CHECK_EQUAL(SIZE, data.max_size()); } -#if ETL_USING_STL +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_flat_map.cpp b/test/test_flat_map.cpp index fe68b9b9..278cd00a 100644 --- a/test/test_flat_map.cpp +++ b/test/test_flat_map.cpp @@ -316,7 +316,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_flat_multimap.cpp b/test/test_flat_multimap.cpp index 213c8789..d6cb90ee 100644 --- a/test/test_flat_multimap.cpp +++ b/test/test_flat_multimap.cpp @@ -293,7 +293,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_flat_multiset.cpp b/test/test_flat_multiset.cpp index ff6bebd1..10c52d64 100644 --- a/test/test_flat_multiset.cpp +++ b/test/test_flat_multiset.cpp @@ -262,7 +262,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_flat_set.cpp b/test/test_flat_set.cpp index c70bbe81..daf16013 100644 --- a/test/test_flat_set.cpp +++ b/test/test_flat_set.cpp @@ -274,7 +274,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_forward_list.cpp b/test/test_forward_list.cpp index 494e7155..9c3295bc 100644 --- a/test/test_forward_list.cpp +++ b/test/test_forward_list.cpp @@ -95,7 +95,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_indirect_vector.cpp b/test/test_indirect_vector.cpp index b64a3fe1..24bbb0f7 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 +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_list.cpp b/test/test_list.cpp index a6fee7f4..17f81e4b 100644 --- a/test/test_list.cpp +++ b/test/test_list.cpp @@ -106,7 +106,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_map.cpp b/test/test_map.cpp index c91a8416..08885eca 100755 --- a/test/test_map.cpp +++ b/test/test_map.cpp @@ -225,7 +225,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_multimap.cpp b/test/test_multimap.cpp index f94015ad..ca1c8f7b 100755 --- a/test/test_multimap.cpp +++ b/test/test_multimap.cpp @@ -227,7 +227,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_multiset.cpp b/test/test_multiset.cpp index 6ecedcfa..275b8daf 100755 --- a/test/test_multiset.cpp +++ b/test/test_multiset.cpp @@ -234,7 +234,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_optional.cpp b/test/test_optional.cpp index 3d996161..dfe3e386 100644 --- a/test/test_optional.cpp +++ b/test/test_optional.cpp @@ -98,6 +98,7 @@ namespace CHECK(!data4.has_value()); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_deduced_initialisation) { @@ -109,6 +110,7 @@ namespace CHECK(bool(opt)); CHECK_EQUAL(data, opt); } +#endif //************************************************************************* TEST(test_emplace) diff --git a/test/test_set.cpp b/test/test_set.cpp index 1940ba4b..118024ce 100755 --- a/test/test_set.cpp +++ b/test/test_set.cpp @@ -250,7 +250,7 @@ namespace CHECK(data.begin() == data.end()); } -#if ETL_USING_STL +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_span.cpp b/test/test_span.cpp index abf31310..6ebdaade 100644 --- a/test/test_span.cpp +++ b/test/test_span.cpp @@ -247,6 +247,8 @@ namespace CHECK(isEqual); } +#if ETL_USING_STL && !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 }; @@ -276,6 +278,7 @@ namespace isEqual = std::equal(span5.begin(), span5.end(), c_array); CHECK(isEqual); } +#endif //************************************************************************* TEST(test_constructor_range) diff --git a/test/test_unordered_map.cpp b/test/test_unordered_map.cpp index 8a7700f3..8fc0701d 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 +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_unordered_multimap.cpp b/test/test_unordered_multimap.cpp index d8f9ea14..efea060e 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 +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_unordered_multiset.cpp b/test/test_unordered_multiset.cpp index ab501aac..d60fe472 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 +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_unordered_set.cpp b/test/test_unordered_set.cpp index 7cb64474..cb6c7f19 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 +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_utility.cpp b/test/test_utility.cpp index 30b78a75..37048471 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -73,6 +73,7 @@ namespace CHECK_EQUAL(2.3, p1.second); } +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_pair_construct) { @@ -84,6 +85,7 @@ namespace CHECK_EQUAL(1, p1.first); CHECK_EQUAL(2.3, p1.second); } +#endif //************************************************************************* TEST(test_pair_move_parameter_construct) diff --git a/test/test_vector.cpp b/test/test_vector.cpp index c0b1be91..a7f9e999 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 +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/test_vector_non_trivial.cpp b/test/test_vector_non_trivial.cpp index b4c6f522..807a92d4 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 +#if ETL_USING_STL && !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 d5fae547..c056b8b5 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 +#if ETL_USING_STL && !defined(ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED) //************************************************************************* TEST(test_cpp17_deduced_constructor) { diff --git a/test/vs2019/etl.sln b/test/vs2019/etl.sln index 9f1b348f..ed4db4f9 100644 --- a/test/vs2019/etl.sln +++ b/test/vs2019/etl.sln @@ -27,6 +27,10 @@ Global Debug MSVC|x64 = Debug MSVC|x64 LLVM New|Win32 = LLVM New|Win32 LLVM New|x64 = LLVM New|x64 + MSVCDebugAppveyor|Win32 = MSVCDebugAppveyor|Win32 + MSVCDebugAppveyor|x64 = MSVCDebugAppveyor|x64 + MSVCDebugNoSTLAppveyor|Win32 = MSVCDebugNoSTLAppveyor|Win32 + MSVCDebugNoSTLAppveyor|x64 = MSVCDebugNoSTLAppveyor|x64 Release|Win32 = Release|Win32 Release|x64 = Release|x64 EndGlobalSection @@ -71,6 +75,14 @@ Global {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.LLVM New|Win32.Build.0 = LLVM New|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.LLVM New|x64.ActiveCfg = LLVM New|x64 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.LLVM New|x64.Build.0 = LLVM New|x64 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVCDebugAppveyor|Win32.ActiveCfg = MSVCDebugAppveyor|Win32 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVCDebugAppveyor|Win32.Build.0 = MSVCDebugAppveyor|Win32 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVCDebugAppveyor|x64.ActiveCfg = MSVCDebugAppveyor|x64 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVCDebugAppveyor|x64.Build.0 = MSVCDebugAppveyor|x64 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVCDebugNoSTLAppveyor|Win32.ActiveCfg = MSVCDebugNoSTLAppveyor|Win32 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVCDebugNoSTLAppveyor|Win32.Build.0 = MSVCDebugNoSTLAppveyor|Win32 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVCDebugNoSTLAppveyor|x64.ActiveCfg = MSVCDebugNoSTLAppveyor|x64 + {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.MSVCDebugNoSTLAppveyor|x64.Build.0 = MSVCDebugNoSTLAppveyor|x64 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Release|Win32.ActiveCfg = Release|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Release|Win32.Build.0 = Release|Win32 {C21DF78C-D8E0-46AB-9D6F-D38A3C1CB0FB}.Release|x64.ActiveCfg = Release|x64 diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 9b22a8df..20160357 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -89,6 +89,22 @@ LLVM New x64 + + MSVCDebugAppveyor + Win32 + + + MSVCDebugAppveyor + x64 + + + MSVCDebugNoSTLAppveyor + Win32 + + + MSVCDebugNoSTLAppveyor + x64 + Release Win32 @@ -112,6 +128,12 @@ v142 Unicode + + Application + true + v142 + Unicode + Application true @@ -136,6 +158,12 @@ v142 Unicode + + Application + true + v142 + Unicode + Application true @@ -166,6 +194,12 @@ v142 Unicode + + Application + true + v142 + Unicode + Application true @@ -190,6 +224,12 @@ v142 Unicode + + Application + true + v142 + Unicode + Application true @@ -258,6 +298,9 @@ + + + @@ -270,6 +313,9 @@ + + + @@ -285,6 +331,9 @@ + + + @@ -297,6 +346,9 @@ + + + @@ -333,6 +385,11 @@ true \$(IntDir) + + true + true + \$(IntDir) + true true @@ -353,6 +410,11 @@ true \$(IntDir) + + true + true + \$(IntDir) + true true @@ -377,6 +439,10 @@ true true + + true + true + true true @@ -393,6 +459,10 @@ true true + + true + true + true true @@ -455,6 +525,27 @@ $(OutDir)\etl.exe + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED;%(PreprocessorDefinitions) + ../../../unittest-cpp/;../../include;../../test + + + false + stdcpp17 + + + Console + true + + + $(OutDir)\etl.exe + + @@ -539,6 +630,27 @@ $(OutDir)\etl.exe + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;_SILENCE_CXX17_ADAPTOR_TYPEDEFS_DEPRECATION_WARNING;ETL_NO_STL;ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED;%(PreprocessorDefinitions) + ./;../../../unittest-cpp/;../../include;../../test + + + false + stdcpp17 + + + Console + true + + + $(OutDir)\etl.exe + + @@ -677,6 +789,27 @@ $(OutDir)\etl.exe + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ../../unittest-cpp/UnitTest++/;../../include/etl;../../test + + + false + stdcpp14 + + + Console + true + + + $(OutDir)\etl.exe + + @@ -761,6 +894,27 @@ $(OutDir)\etl.exe + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + ../../unittest-cpp/UnitTest++/;../../include/etl;../../test + + + false + stdcpp14 + + + Console + true + + + $(OutDir)\etl.exe + + @@ -1306,21 +1460,25 @@ false false false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1345,21 +1503,25 @@ false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1379,21 +1541,25 @@ false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1403,21 +1569,25 @@ false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1427,21 +1597,25 @@ false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1451,21 +1625,25 @@ false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1475,21 +1653,25 @@ false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1504,21 +1686,25 @@ false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1532,21 +1718,25 @@ true true false + false false false false false false + false false false false false false + false false false false false false + false false false false @@ -1565,21 +1755,25 @@ false + false false false false false false + false false false false false false + false false false false false false + false false false false From 94c826c6587c9f600135993bb758122d46c7afe0 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 29 Sep 2020 11:37:53 +0100 Subject: [PATCH 64/71] Conditionally disable template deduction guide tests --- appveyor.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index b4f4dc4c..53763baa 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,11 +1,11 @@ version: 1.0.{build} branches: only: - - master + - hotfix/fix-ci-errors image: Visual Studio 2017 configuration: -- Debug -- DebugNoSTL +- MSVCDebugAppveyor +- MSVCDebugNoSTLAppveyor clone_folder: c:\projects\etl install: - cmd: git submodule update --init --recursive @@ -20,4 +20,5 @@ notifications: method: POST on_build_success: true on_build_failure: true - on_build_status_changed: true \ No newline at end of file + on_build_status_changed: true + \ No newline at end of file From 253df1309c3d84eee5ad538336f5f698d508f5ac Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 29 Sep 2020 11:44:14 +0100 Subject: [PATCH 65/71] Conditionally disable template deduction guide tests --- appveyor.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 53763baa..d08eac59 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -2,17 +2,17 @@ version: 1.0.{build} branches: only: - hotfix/fix-ci-errors -image: Visual Studio 2017 +image: Visual Studio 2019 configuration: -- MSVCDebugAppveyor -- MSVCDebugNoSTLAppveyor +- Debug +- DebugNoSTL clone_folder: c:\projects\etl install: - cmd: git submodule update --init --recursive before_build: - cmd: git clone https://github.com/unittest-cpp/unittest-cpp.git c:\projects\unittest-cpp build: - project: test/vs2017/etl.vcxproj + project: test/vs2019/etl.vcxproj verbosity: minimal notifications: - provider: Webhook From a2812bd5a9420ab9628596e7630eed926c569720 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 29 Sep 2020 11:55:21 +0100 Subject: [PATCH 66/71] Conditionally disable template deduction guide tests --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index d08eac59..375e1e81 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ version: 1.0.{build} branches: only: - - hotfix/fix-ci-errors + - master image: Visual Studio 2019 configuration: - Debug From c6f327f4bfc0c85bd65c60622f032acc0227294a Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 29 Sep 2020 12:51:23 +0100 Subject: [PATCH 67/71] Conditionally disable template deduction guide tests --- test/vs2019/etl.vcxproj | 1 + test/vs2019/etl.vcxproj.filters | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 20160357..f3b511ab 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -1868,6 +1868,7 @@ + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index 5e960783..d4ddadfb 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -82,6 +82,9 @@ {586d2c92-e504-4dea-9b1f-42d725a5272c} + + {74399f00-a7a3-47e3-9b27-d01fb2b5ce87} + @@ -1456,6 +1459,9 @@ Resource Files\Make + + Resource Files\CI\Appveyor + From 57e6969f033b8fc27f016c20506e22f2a35ae89d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 29 Sep 2020 12:53:46 +0100 Subject: [PATCH 68/71] Conditionally disable template deduction guide tests --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index eca65b45..1da10f94 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,7 +1,7 @@ name: CI on: push: - branches: [ hotfix/fix-ci-errors] + branches: [ master ] pull_request: branches: [ master ] From 9c664eb484c1ead2d7efd2ab045a6eef664be789 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 29 Sep 2020 12:57:03 +0100 Subject: [PATCH 69/71] Conditionally disable template deduction guide tests --- .github/workflows/main.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1da10f94..63c0d4c3 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,11 +6,11 @@ on: branches: [ master ] jobs: - build: + build-gcc-linux: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04] + os: [ubuntu-18.04, ubuntu-20.04] steps: - uses: actions/checkout@v2 @@ -24,7 +24,7 @@ jobs: - name: Run tests run: ./test/etl_tests - build-clang-9-Linux: + build-clang-9-linux: runs-on: ${{ matrix.os }} strategy: matrix: From 9d45d7b867457565f0c0c17215f689c2ab5f9b1f Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 29 Sep 2020 13:00:51 +0100 Subject: [PATCH 70/71] Conditionally disable template deduction guide tests --- test/etl_profile.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/etl_profile.h b/test/etl_profile.h index 64f6f7d4..4b032bab 100644 --- a/test/etl_profile.h +++ b/test/etl_profile.h @@ -105,6 +105,10 @@ SOFTWARE. #include "../include/etl/profiles/determine_development_os.h" +#if defined(ETL_COMPILER_GCC) && (ETL_COMPILER_VERSION < 8) + #define ETL_TEMPLATE_DEDUCTION_GUIDE_TESTS_DISABLED +#endif + #if defined(ETL_DEVELOPMENT_OS_WINDOWS) #define ETL_TARGET_OS_WINDOWS #elif defined(ETL_DEVELOPMENT_OS_LINUX) From e337689ed0ebdb1bd282d5cdb2daaefe16a191d2 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 29 Sep 2020 13:15:37 +0100 Subject: [PATCH 71/71] Conditionally disable template deduction guide tests --- include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 4 ++++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/etl/version.h b/include/etl/version.h index 623aedce..183fbee5 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -39,7 +39,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 18 #define ETL_VERSION_MINOR 16 -#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) #define ETL_VERSION_U16 ETL_STRINGIFY(ETL_VERSION_MAJOR) u"." ETL_STRINGIFY(ETL_VERSION_MINOR) u"." ETL_STRINGIFY(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index 5965c324..c72f55bc 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "18.16.0", + "version": "18.16.1", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index 7e169f6d..444646b9 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=18.16.0 +version=18.16.1 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 909902e6..7fced63a 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,3 +1,7 @@ +=============================================================================== +18.16.1 +Updates to CI configuration files. + =============================================================================== 18.16.0 Added template deduction guides for most containers.