From 22fc884d4516de51dc87cede0d3e657c4b0266b4 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sat, 22 Aug 2026 17:47:16 +0200 Subject: [PATCH] Various cleanup (#1562) * Fix wrong templating * Fix stray double parens * Documentation cleanup: Some key/value actually are value only --- docs/containers/maps/flat-map.md | 2 +- docs/containers/maps/flat-multimap.md | 2 +- docs/containers/sets/const-multiset.md | 2 +- docs/containers/sets/const-set.md | 2 +- docs/containers/sets/flat-multiset.md | 37 ++++++++------- docs/containers/sets/flat-set.md | 40 +++++++++------- docs/strings/to-arithmetic.md | 2 +- include/etl/const_map.h | 1 - include/etl/const_multimap.h | 1 - include/etl/const_multiset.h | 1 - include/etl/const_set.h | 1 - include/etl/flat_multiset.h | 1 - include/etl/format.h | 2 +- include/etl/signal.h | 4 +- include/etl/to_arithmetic.h | 4 +- test/test_to_arithmetic.cpp | 65 ++++++++++++++++++++++++++ 16 files changed, 120 insertions(+), 47 deletions(-) diff --git a/docs/containers/maps/flat-map.md b/docs/containers/maps/flat-map.md index cc3ea886..0231aac5 100644 --- a/docs/containers/maps/flat-map.md +++ b/docs/containers/maps/flat-map.md @@ -239,7 +239,7 @@ The return type is either `std::pair` (default) or `etl::pair` (`ETL_NO_STL`) --- ```cpp -pair emplace((const value_type& value)) +pair emplace(const value_type& value) pair emplace(const key_type& key, const mapped_type& value) ``` **Description** diff --git a/docs/containers/maps/flat-multimap.md b/docs/containers/maps/flat-multimap.md index 58bda46b..4fede72c 100644 --- a/docs/containers/maps/flat-multimap.md +++ b/docs/containers/maps/flat-multimap.md @@ -239,7 +239,7 @@ The return type is either `std::pair` (default) or `etl::pair` (`ETL_NO_STL`) --- ```cpp -pair emplace((const value_type& value)) +pair emplace(const value_type& value) pair emplace(const key_type& key, const mapped_type& value) ``` **Description** diff --git a/docs/containers/sets/const-multiset.md b/docs/containers/sets/const-multiset.md index f4200dad..13add134 100644 --- a/docs/containers/sets/const-multiset.md +++ b/docs/containers/sets/const-multiset.md @@ -333,4 +333,4 @@ operator >= ## Technical stuff -The const set is implemented as a sorted array key/value pairs. +The const set is implemented as a sorted array of values. diff --git a/docs/containers/sets/const-set.md b/docs/containers/sets/const-set.md index 100549f7..dbb3b3ad 100644 --- a/docs/containers/sets/const-set.md +++ b/docs/containers/sets/const-set.md @@ -333,4 +333,4 @@ operator >= ## Technical stuff -The const set is implemented as a sorted array key/value pairs. +The const set is implemented as a sorted array of values. diff --git a/docs/containers/sets/flat-multiset.md b/docs/containers/sets/flat-multiset.md index d88e4a17..29bd454d 100644 --- a/docs/containers/sets/flat-multiset.md +++ b/docs/containers/sets/flat-multiset.md @@ -235,55 +235,60 @@ The return type is either `std::pair` (default) or `etl::pair` (`ETL_NO_STL`) --- ```cpp -pair emplace((const_reference value)) -pair emplace(const key_type& key, const mapped_type& value) +pair emplace(const_reference value) ``` **Description** -Inserts key/value pairs into the set by constructing directly into storage. +Inserts a value into the set by constructing directly into storage. The return type is either `std::pair` (default) or `etl::pair` (`ETL_NO_STL`) --- **C++03** -The emplace functions differ from that of std::set in that, due to C++03 not supporting 'perfect forwarding'. +The emplace functions differ from that of std::multiset in that, due to C++03 not supporting 'perfect forwarding'. + +```cpp +pair emplace() +``` +**Description** +Emplaces a default constructed value into the set. ```cpp template -pair emplace(const key_type& key, const T1& value1) +pair emplace(const T1& value1) ``` **Description** -Emplaces a value constructed from `key` and 1 argument into the set. +Emplaces a value constructed from 1 argument into the set. ```cpp template -pair emplace(const key_type& key, const T1& value1, const T2& value2) +pair emplace(const T1& value1, const T2& value2) ``` **Description** -Emplaces a value constructed from `key` and 2 arguments into the set. +Emplaces a value constructed from 2 arguments into the set. ```cpp template -pair emplace(const key_type& key, const T1& value1, const T2& value2, const T3& value3) +pair emplace(const T1& value1, const T2& value2, const T3& value3) ``` **Description** -Emplaces a value constructed from `key` and 3 arguments into the set. +Emplaces a value constructed from 3 arguments into the set. ```cpp template -pair emplace(const key_type& key, const T1& value1, const T2& value2, const T3& value3, const T4& value4) +pair emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4) ``` **Description** -Emplaces a value constructed from `key` and 4 arguments into the set. +Emplaces a value constructed from 4 arguments into the set. --- **C++11** ```cpp template -pair emplace(const key_type& key, Args&& ... args) +pair emplace(Args&& ... args) ``` **Description** -Emplaces a value constructed from the `key` and arguments into the set. +Emplaces a value constructed from the arguments into the set. --- @@ -493,9 +498,9 @@ operator != ## Technical stuff -Flat maps are usually implemented internally as a sorted vector of key/value pairs. Whilst this makes searching fast, it can have a detrimental effect when items are inserted into a container that stores complex, non-trivial keys or values. +Flat sets are usually implemented internally as a sorted vector of values. Whilst this makes searching fast, it can have a detrimental effect when items are inserted into a container that stores complex, non-trivial values. As inserting requires that all of the items to the right of the insert position must be shifted this can become an expensive operation for larger containers. -To improve insertion performance ETL flat maps are implemented as vectors of pointers to key/value pairs, sorted by key value. An insertion will involve a copy of a range of pointers; an operation that can be very fast. +To improve insertion performance ETL flat sets are implemented as vectors of pointers to values, sorted by value. An insertion will involve a copy of a range of pointers; an operation that can be very fast. The downside is that access to an item via an iterator will involve one indirection and the overhead of the container will be one pointer per item. A normal flat set implementation does not have this overhead. diff --git a/docs/containers/sets/flat-set.md b/docs/containers/sets/flat-set.md index e5c08610..4216b30b 100644 --- a/docs/containers/sets/flat-set.md +++ b/docs/containers/sets/flat-set.md @@ -235,11 +235,10 @@ The return type is either `std::pair` (default) or `etl::pair` (`ETL_NO_STL`) --- ```cpp -pair emplace((const_reference value)) -pair emplace(const key_type& key, const mapped_type& value) +pair emplace(const_reference value) ``` **Description** -Inserts key/value pairs into the set by constructing directly into storage. +Inserts a value into the set by constructing directly into storage. The return type is either `std::pair` (default) or `etl::pair` (`ETL_NO_STL`) --- @@ -248,39 +247,48 @@ The return type is either `std::pair` (default) or `etl::pair` (`ETL_NO_STL`) The emplace functions differ from that of `std::set` due to C++03 not supporting 'perfect forwarding'. ```cpp -template -pair emplace(const key_type& key, const T1& value1) +pair emplace() ``` **Description** -Emplaces a value constructed from `key` and 1 argument into the set. +Emplaces a default constructed value into the set. + +--- + +```cpp +template +pair emplace(const T1& value1) +``` +**Description** + +Emplaces a value constructed from 1 argument into the set. --- ```cpp template -pair emplace(const key_type& key, const T1& value1, const T2& value2) +pair emplace(const T1& value1, const T2& value2) ``` **Description** -Emplaces a value constructed from `key` and 2 arguments into the set. +Emplaces a value constructed from 2 arguments into the set. --- ```cpp template -pair emplace(const key_type& key, const T1& value1, const T2& value2, const T3& value3) +pair emplace(const T1& value1, const T2& value2, const T3& value3) ``` **Description** -Emplaces a value constructed from `key` and 3 arguments into the set. +Emplaces a value constructed from 3 arguments into the set. --- ```cpp template -pair emplace(const key_type& key, const T1& value1, const T2& value2, const T3& value3, const T4& value4) +pair emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4) ``` **Description** -Emplaces a value constructed from `key` and 4 arguments into the set. +Emplaces a value constructed from 4 arguments into the set. --- @@ -288,10 +296,10 @@ Emplaces a value constructed from `key` and 4 arguments into the set. ```cpp template -pair emplace(const key_type& key, Args&& ... args) +pair emplace(Args&& ... args) ``` **Description** -Emplaces a value constructed from the `key` and arguments into the set. +Emplaces a value constructed from the arguments into the set. --- @@ -509,9 +517,9 @@ operator != ## Technical stuff -Flat maps are usually implemented internally as a sorted vector of key/value pairs. Whilst this makes searching fast, it can have a detrimental effect when items are inserted into a container that stores complex, non-trivial keys or values. +Flat sets are usually implemented internally as a sorted vector of values. Whilst this makes searching fast, it can have a detrimental effect when items are inserted into a container that stores complex, non-trivial values. As inserting requires that all of the items to the right of the insert position must be shifted this can become an expensive operation for larger containers. -To improve insertion performance ETL flat maps are implemented as vectors of pointers to key/value pairs, sorted by key value. An insertion will involve a copy of a range of pointers; an operation that can be very fast. +To improve insertion performance ETL flat sets are implemented as vectors of pointers to values, sorted by value. An insertion will involve a copy of a range of pointers; an operation that can be very fast. The downside is that access to an item via an iterator will involve one indirection and the overhead of the container will be one pointer per item. A normal flat set implementation does not have this overhead. diff --git a/docs/strings/to-arithmetic.md b/docs/strings/to-arithmetic.md index be571377..297ae45d 100644 --- a/docs/strings/to-arithmetic.md +++ b/docs/strings/to-arithmetic.md @@ -327,7 +327,7 @@ Inequality test for etl::to_arithmetic_result ```cpp template ETL_CONSTEXPR14 bool operator !=(const T& lhs, - const etl::to_arithmetic_result& rhs) + const etl::to_arithmetic_result& rhs) ``` Inequality test for etl::to_arithmetic_result diff --git a/include/etl/const_map.h b/include/etl/const_map.h index 051e6303..747cc5ed 100644 --- a/include/etl/const_map.h +++ b/include/etl/const_map.h @@ -449,7 +449,6 @@ namespace etl //************************************************************************* /// Constructor //************************************************************************* - template ETL_CONSTEXPR14 explicit iconst_map(const value_type* element_list_, size_type size_, size_type max_elements_) ETL_NOEXCEPT : element_list(element_list_) , element_list_end{element_list_ + size_} diff --git a/include/etl/const_multimap.h b/include/etl/const_multimap.h index 589fe331..824abf77 100644 --- a/include/etl/const_multimap.h +++ b/include/etl/const_multimap.h @@ -398,7 +398,6 @@ namespace etl //************************************************************************* /// Constructor //************************************************************************* - template ETL_CONSTEXPR14 explicit iconst_multimap(const value_type* element_list_, size_type size_, size_type max_elements_) ETL_NOEXCEPT : element_list(element_list_) , element_list_end{element_list_ + size_} diff --git a/include/etl/const_multiset.h b/include/etl/const_multiset.h index 6184f9e7..28e9567d 100644 --- a/include/etl/const_multiset.h +++ b/include/etl/const_multiset.h @@ -354,7 +354,6 @@ namespace etl //************************************************************************* /// Constructor //************************************************************************* - template ETL_CONSTEXPR14 explicit iconst_multiset(const value_type* element_list_, size_type size_, size_type max_elements_) ETL_NOEXCEPT : element_list(element_list_) , element_list_end{element_list_ + size_} diff --git a/include/etl/const_set.h b/include/etl/const_set.h index df7f0989..e734de43 100644 --- a/include/etl/const_set.h +++ b/include/etl/const_set.h @@ -345,7 +345,6 @@ namespace etl //************************************************************************* /// Constructor //************************************************************************* - template ETL_CONSTEXPR14 explicit iconst_set(const value_type* element_list_, size_type size_, size_type max_elements_) ETL_NOEXCEPT : element_list(element_list_) , element_list_end{element_list_ + size_} diff --git a/include/etl/flat_multiset.h b/include/etl/flat_multiset.h index a3d5b048..e0d13220 100644 --- a/include/etl/flat_multiset.h +++ b/include/etl/flat_multiset.h @@ -321,7 +321,6 @@ namespace etl //************************************************************************* /// Emplaces a value to the set. //************************************************************************* - template ETL_OR_STD::pair emplace(const_reference value) { return insert(value); diff --git a/include/etl/format.h b/include/etl/format.h index 30152dc9..8820ac6f 100644 --- a/include/etl/format.h +++ b/include/etl/format.h @@ -1516,7 +1516,7 @@ namespace etl } // for integers - template + template void format_num(OutputIt& it, T value, const format_spec_t& spec) { size_t width = 0; diff --git a/include/etl/signal.h b/include/etl/signal.h index 695bd0c1..eda5dff5 100644 --- a/include/etl/signal.h +++ b/include/etl/signal.h @@ -384,7 +384,7 @@ namespace etl //************************************************************************* /// For a delegate slot type. //************************************************************************* - template + template static typename etl::enable_if_t::value, bool> slot_is_valid(const TSlotType& s) ETL_NOEXCEPT { return s.is_valid(); @@ -393,7 +393,7 @@ namespace etl //************************************************************************* /// For a non-delegate slot type. //************************************************************************* - template + template static typename etl::enable_if_t::value, bool> slot_is_valid(const TSlotType&) ETL_NOEXCEPT { return true; diff --git a/include/etl/to_arithmetic.h b/include/etl/to_arithmetic.h index 090ec110..941fc09b 100644 --- a/include/etl/to_arithmetic.h +++ b/include/etl/to_arithmetic.h @@ -908,7 +908,7 @@ ETL_CONSTEXPR14 bool operator==(const etl::to_arithmetic_result& lhs, const e } else { - return (lhs.status() == rhs.status()); + return (lhs.error() == rhs.error()); } } @@ -952,7 +952,7 @@ ETL_CONSTEXPR14 bool operator!=(const etl::to_arithmetic_result& lhs, const U /// Inequality test for etl::to_arithmetic_result //*************************************************************************** template -ETL_CONSTEXPR14 bool operator!=(const T& lhs, const etl::to_arithmetic_result& rhs) +ETL_CONSTEXPR14 bool operator!=(const T& lhs, const etl::to_arithmetic_result& rhs) { return !(lhs == rhs); } diff --git a/test/test_to_arithmetic.cpp b/test/test_to_arithmetic.cpp index 1dadabae..f78895b4 100644 --- a/test/test_to_arithmetic.cpp +++ b/test/test_to_arithmetic.cpp @@ -1039,6 +1039,71 @@ namespace CHECK_EQUAL(83, int(etl::to_arithmetic(ETLText(text.c_str(), text.size()), etl::radix::decimal).value())); } + //************************************************************************* + TEST(test_comparison_operators) + { + const Text text(STR("123")); + const Text bad_text(STR("1X3")); + const Text other_bad_text(STR("2X3")); + const Text overflow_text(STR("99999999999999999999")); + + const etl::to_arithmetic_result result = etl::to_arithmetic(text.c_str(), text.size()); + const etl::to_arithmetic_result same = etl::to_arithmetic(text.c_str(), text.size()); + const etl::to_arithmetic_result bad_result = etl::to_arithmetic(bad_text.c_str(), bad_text.size()); + const etl::to_arithmetic_result same_bad_result = etl::to_arithmetic(other_bad_text.c_str(), other_bad_text.size()); + const etl::to_arithmetic_result overflow_result = etl::to_arithmetic(overflow_text.c_str(), overflow_text.size()); + + // result <-> result + CHECK_TRUE(result == same); + CHECK_FALSE(result != same); + CHECK_TRUE(result != bad_result); + CHECK_FALSE(result == bad_result); + + // Two errored results with the same status compare equal. + CHECK_EQUAL(bad_result.error(), same_bad_result.error()); + CHECK_TRUE(bad_result == same_bad_result); + CHECK_FALSE(bad_result != same_bad_result); + + // Two errored results with different statuses do not compare equal. + CHECK(bad_result.error() != overflow_result.error()); + CHECK_TRUE(bad_result != overflow_result); + CHECK_FALSE(bad_result == overflow_result); + + // result <-> value + CHECK_TRUE(result == 123); + CHECK_FALSE(result != 123); + CHECK_TRUE(result != 124); + CHECK_FALSE(result == 124); + + // value <-> result + CHECK_TRUE(123 == result); + CHECK_FALSE(123 != result); + CHECK_TRUE(124 != result); + CHECK_FALSE(124 == result); + + // An errored result never compares equal to a value. + CHECK_FALSE(bad_result == 123); + CHECK_TRUE(bad_result != 123); + CHECK_FALSE(123 == bad_result); + CHECK_TRUE(123 != bad_result); + + // Heterogeneous result <-> value, using a different result value type. + const etl::to_arithmetic_result long_result = etl::to_arithmetic(text.c_str(), text.size()); + const etl::to_arithmetic_result small_result = etl::to_arithmetic(text.c_str(), text.size()); + + CHECK_TRUE(long_result == 123); + CHECK_FALSE(long_result != 123); + CHECK_TRUE(123 == long_result); + CHECK_TRUE(long_result != 124); + CHECK_FALSE(123 != long_result); + CHECK_TRUE(124 != long_result); + + CHECK_TRUE(small_result == 123); + CHECK_FALSE(small_result != 123); + CHECK_TRUE(123 == small_result); + CHECK_TRUE(small_result != 124); + } + //************************************************************************* #if ETL_USING_CPP14 TEST(test_constexpr_integral)