mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
Various cleanup (#1562)
* Fix wrong templating * Fix stray double parens * Documentation cleanup: Some key/value actually are value only
This commit is contained in:
parent
9b1890e00c
commit
22fc884d45
@ -239,7 +239,7 @@ The return type is either `std::pair` (default) or `etl::pair` (`ETL_NO_STL`)
|
||||
---
|
||||
|
||||
```cpp
|
||||
pair<iterator, bool> emplace((const value_type& value))
|
||||
pair<iterator, bool> emplace(const value_type& value)
|
||||
pair<iterator, bool> emplace(const key_type& key, const mapped_type& value)
|
||||
```
|
||||
**Description**
|
||||
|
||||
@ -239,7 +239,7 @@ The return type is either `std::pair` (default) or `etl::pair` (`ETL_NO_STL`)
|
||||
---
|
||||
|
||||
```cpp
|
||||
pair<iterator, bool> emplace((const value_type& value))
|
||||
pair<iterator, bool> emplace(const value_type& value)
|
||||
pair<iterator, bool> emplace(const key_type& key, const mapped_type& value)
|
||||
```
|
||||
**Description**
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -235,55 +235,60 @@ The return type is either `std::pair` (default) or `etl::pair` (`ETL_NO_STL`)
|
||||
---
|
||||
|
||||
```cpp
|
||||
pair<iterator, bool> emplace((const_reference value))
|
||||
pair<iterator, bool> emplace(const key_type& key, const mapped_type& value)
|
||||
pair<iterator, bool> 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<iterator, bool> emplace()
|
||||
```
|
||||
**Description**
|
||||
Emplaces a default constructed value into the set.
|
||||
|
||||
```cpp
|
||||
template <typename T1>
|
||||
pair<iterator, bool> emplace(const key_type& key, const T1& value1)
|
||||
pair<iterator, bool> 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 <typename T1, typename T2>
|
||||
pair<iterator, bool> emplace(const key_type& key, const T1& value1, const T2& value2)
|
||||
pair<iterator, bool> 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 <typename T1, typename T2, typename T3>
|
||||
pair<iterator, bool> emplace(const key_type& key, const T1& value1, const T2& value2, const T3& value3)
|
||||
pair<iterator, bool> 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 <typename T1, typename T2, typename T3, typename T4>
|
||||
pair<iterator, bool> emplace(const key_type& key, const T1& value1, const T2& value2, const T3& value3, const T4& value4)
|
||||
pair<iterator, bool> 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 <typename ... Args>
|
||||
pair<iterator, bool> emplace(const key_type& key, Args&& ... args)
|
||||
pair<iterator, bool> 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.
|
||||
|
||||
@ -235,11 +235,10 @@ The return type is either `std::pair` (default) or `etl::pair` (`ETL_NO_STL`)
|
||||
---
|
||||
|
||||
```cpp
|
||||
pair<iterator, bool> emplace((const_reference value))
|
||||
pair<iterator, bool> emplace(const key_type& key, const mapped_type& value)
|
||||
pair<iterator, bool> 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 <typename T1>
|
||||
pair<iterator, bool> emplace(const key_type& key, const T1& value1)
|
||||
pair<iterator, bool> emplace()
|
||||
```
|
||||
**Description**
|
||||
|
||||
Emplaces a value constructed from `key` and 1 argument into the set.
|
||||
Emplaces a default constructed value into the set.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename T1>
|
||||
pair<iterator, bool> emplace(const T1& value1)
|
||||
```
|
||||
**Description**
|
||||
|
||||
Emplaces a value constructed from 1 argument into the set.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename T1, typename T2>
|
||||
pair<iterator, bool> emplace(const key_type& key, const T1& value1, const T2& value2)
|
||||
pair<iterator, bool> 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 <typename T1, typename T2, typename T3>
|
||||
pair<iterator, bool> emplace(const key_type& key, const T1& value1, const T2& value2, const T3& value3)
|
||||
pair<iterator, bool> 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 <typename T1, typename T2, typename T3, typename T4>
|
||||
pair<iterator, bool> emplace(const key_type& key, const T1& value1, const T2& value2, const T3& value3, const T4& value4)
|
||||
pair<iterator, bool> 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 <typename ... Args>
|
||||
pair<iterator, bool> emplace(const key_type& key, Args&& ... args)
|
||||
pair<iterator, bool> 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.
|
||||
|
||||
@ -327,7 +327,7 @@ Inequality test for etl::to_arithmetic_result
|
||||
```cpp
|
||||
template <typename T, typename U>
|
||||
ETL_CONSTEXPR14 bool operator !=(const T& lhs,
|
||||
const etl::to_arithmetic_result<T>& rhs)
|
||||
const etl::to_arithmetic_result<U>& rhs)
|
||||
```
|
||||
Inequality test for etl::to_arithmetic_result
|
||||
|
||||
|
||||
@ -449,7 +449,6 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Constructor
|
||||
//*************************************************************************
|
||||
template <typename... TElements>
|
||||
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_}
|
||||
|
||||
@ -398,7 +398,6 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Constructor
|
||||
//*************************************************************************
|
||||
template <typename... TElements>
|
||||
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_}
|
||||
|
||||
@ -354,7 +354,6 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Constructor
|
||||
//*************************************************************************
|
||||
template <typename... TElements>
|
||||
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_}
|
||||
|
||||
@ -345,7 +345,6 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Constructor
|
||||
//*************************************************************************
|
||||
template <typename... TElements>
|
||||
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_}
|
||||
|
||||
@ -321,7 +321,6 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Emplaces a value to the set.
|
||||
//*************************************************************************
|
||||
template <typename T1>
|
||||
ETL_OR_STD::pair<iterator, bool> emplace(const_reference value)
|
||||
{
|
||||
return insert(value);
|
||||
|
||||
@ -1516,7 +1516,7 @@ namespace etl
|
||||
}
|
||||
|
||||
// for integers
|
||||
template <typename OutputIt, typename T, bool skip_last_zeros = false>
|
||||
template <typename OutputIt, typename T>
|
||||
void format_num(OutputIt& it, T value, const format_spec_t& spec)
|
||||
{
|
||||
size_t width = 0;
|
||||
|
||||
@ -384,7 +384,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// For a delegate slot type.
|
||||
//*************************************************************************
|
||||
template <typename TSlotType, typename... TArgs>
|
||||
template <typename TSlotType>
|
||||
static typename etl::enable_if_t<etl::is_delegate<TSlotType>::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 <typename TSlotType, typename... TArgs>
|
||||
template <typename TSlotType>
|
||||
static typename etl::enable_if_t<!etl::is_delegate<TSlotType>::value, bool> slot_is_valid(const TSlotType&) ETL_NOEXCEPT
|
||||
{
|
||||
return true;
|
||||
|
||||
@ -908,7 +908,7 @@ ETL_CONSTEXPR14 bool operator==(const etl::to_arithmetic_result<T>& 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<T>& lhs, const U
|
||||
/// Inequality test for etl::to_arithmetic_result
|
||||
//***************************************************************************
|
||||
template <typename T, typename U>
|
||||
ETL_CONSTEXPR14 bool operator!=(const T& lhs, const etl::to_arithmetic_result<T>& rhs)
|
||||
ETL_CONSTEXPR14 bool operator!=(const T& lhs, const etl::to_arithmetic_result<U>& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
@ -1039,6 +1039,71 @@ namespace
|
||||
CHECK_EQUAL(83, int(etl::to_arithmetic<int8_t>(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<int> result = etl::to_arithmetic<int>(text.c_str(), text.size());
|
||||
const etl::to_arithmetic_result<int> same = etl::to_arithmetic<int>(text.c_str(), text.size());
|
||||
const etl::to_arithmetic_result<int> bad_result = etl::to_arithmetic<int>(bad_text.c_str(), bad_text.size());
|
||||
const etl::to_arithmetic_result<int> same_bad_result = etl::to_arithmetic<int>(other_bad_text.c_str(), other_bad_text.size());
|
||||
const etl::to_arithmetic_result<int> overflow_result = etl::to_arithmetic<int>(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> long_result = etl::to_arithmetic<long>(text.c_str(), text.size());
|
||||
const etl::to_arithmetic_result<int8_t> small_result = etl::to_arithmetic<int8_t>(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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user