Merge branch 'development' into fix-absolute-ub

This commit is contained in:
John Wellbelove 2026-03-12 16:11:46 +00:00 committed by GitHub
commit c82e122968
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 3240 additions and 180 deletions

6
docs/_config.yml Normal file
View File

@ -0,0 +1,6 @@
plugins:
- jekyll-relative-links
relative_links:
enabled: true
include:
- manchester.md

7
docs/index.md Normal file
View File

@ -0,0 +1,7 @@
---
title: ETL documentation
---
## Pages
* [Manchester](manchester.md)

258
docs/manchester.md Normal file
View File

@ -0,0 +1,258 @@
---
title: Manchester encoding and decoding
---
Efficient Manchester encoding and decoding of data. The Manchester code represents a data bit as a sequence of a 'high' and a 'low' value. In software this translates to a conversion from one to two bits, or in a practical situation, from `n` bytes to `n*2` bytes.
## See also
[Manchester code](https://en.wikipedia.org/wiki/Manchester_code)
## Features
- Normal and inverted Manchester encoding
- Support for multiple encoding chunk sizes: 8-bit, 16-bit and 32-bit
- Span-based operations or chunk-based operations
- Constexpr functions for compile-time encoding/decoding (8-bit chunk size only)
- Validation of encoded data
## Algorithm background
To encode the value `0b11001100` we must first duplicate all bits to create the value `0b1111000011110000`. We then perform an XOR of this value with the constant `0b1010101010101010` (`0xAAAA`) to obtain the Manchester coded value of `0b1010010110100101`. We have now replaced each `1` bit with the sequence `10` and each `0` bit with the sequence `01`.
### 2. Bit duplication
Bit duplication is achieved with the following steps. This is also called binary interleaving. The example shows encoding of an 8-bit value.
| Step | High Byte | Low Byte | Operation |
|------|--------------------|--------------------|----------------------------|
| 0 | `_ _ _ _ _ _ _ _` | `A B C D E F G H` | input value (i) |
| 1 | `_ _ _ _ A B C D` | `_ _ _ _ E F G H` | `(i \| (i << 4)) & 0x0F0F` |
| 2 | `_ _ A B _ _ C D` | `_ _ E F _ _ G H` | `(i \| (i << 2)) & 0x3333` |
| 3 | `_ A _ B _ C _ D` | `_ E _ F _ G _ H` | `(i \| (i << 1)) & 0x5555` |
| 4 | `A A B B C C D D` | `E E F F G G H H` | `(i \| (i << 1))` |
This process can be easily extended to 16-bit or 32-bit values by adding additional steps to the bit duplication.
### 3. Manchester Decoding
Manchester decoding is done in a similar, but reversed way.
### 4. Error Detection
Error detection in Manchester coded data is done by comparing 2 neighboring bits. If they are
equal, then there is an error in the encoded input data.
Comparing all 8 bit pairs in a 16-bit word is done as follows.
| Step | Binary Value | Operation | Description |
|------|--------------|-------------------|-----------------------------------------------------------------------------------------------|
| 1 | `11011000` | Original | First bit pair (lsb, 00) is invalid. Last bit pair is also invalid. Other bit pairs are valid |
| 2 | `01101100` | Shift right by 1 | Shift the original value right by one bit |
| 3 | `10110100` | XOR | XOR the original with the shifted value |
| 4 | `01010101` | Mask with 0x55 | Apply mask to isolate bit pairs |
| 5 | `00010100` | Result | If result is not equal to 0x55, there was an error in the input |
## Analysis
Most traditional ways to Manchester encode data consist of a loop over all bits and a nested if-statement to check the value of the current bit. This approach does not scale well to increasing number of bits. The algorithm implemented here contains no conditional code and scales well. Doubling the number of processed bits per step (the chunk size) adds a single row to the bit duplication table. Because of the lack of loops and conditional code, this algorithm is likely to perform better than traditional ones on simple processors or when compiler optimization is disabled. On modern, powerful processors with caches and advanced optimization possibilities this algorithm may not show much benefit. In any case, the performance of the algorithm depends heavily on the processor type, compiler and compiler (optimization) settings.
## API Reference
### Classes
Classes `etl::manchester` and `etl::manchester_inverted` contain static functions for encoding, decoding and validity checking. It is not necessary to instantiate objects of these classes.
#### etl::manchester
```cpp
typedef manchester_base<private_manchester::manchester_type_normal> manchester;
```
Manchester encoder using normal encoding (no inversion).
#### etl::manchester_inverted
```cpp
typedef manchester_base<private_manchester::manchester_type_inverted> manchester_inverted;
```
Manchester encoder using inverted encoding.
### Encoding Functions
#### Encode single value
```cpp
template <typename TDecoded>
static ETL_CONSTEXPR14 typename encoded<TDecoded>::type encode(TDecoded decoded)
```
Encodes a single value using Manchester encoding.
**Parameters:**
- `decoded`: The value to encode (`uint8_t`, `uint16_t`, or `uint32_t`)
**Returns:**
- The Manchester encoded value (twice the bit width of input)
**Example:**
```cpp
uint16_t encoded = etl::manchester::encode(0x55);
```
#### Encode range
```cpp
template <typename TChunk = uint_least8_t>
static ETL_CONSTEXPR14 void encode(etl::span<const uint_least8_t> decoded,
etl::span<uint_least8_t> encoded)
```
Encodes a span of data using the specified chunk size.
**Parameters:**
- `decoded`: Source data to encode
- `encoded`: Destination for encoded data (must be twice the size of `decoded`)
**Template Parameters:**
- `TChunk`: Chunk size for encoding (`uint8_t`, `uint16_t` or `uint32_t`)
**Example:**
```cpp
std::array<uint8_t, 4> data = {0x12, 0x34, 0x56, 0x78};
std::array<uint8_t, 8> encoded_data1{};
std::array<uint8_t, 8> encoded_data2{};
// Encode with TChunk == uint8_t
etl::manchester::encode(data, encoded_data1);
// Encode with TChunk == uint32_t
etl::manchester::encode<uint32_t>(data, encoded_data2);
```
### Decoding Functions
#### Decode single value
```cpp
template <typename TEncoded>
static ETL_CONSTEXPR14 typename decoded<TEncoded>::type decode(TEncoded encoded)
```
Decodes a single Manchester encoded value.
**Parameters:**
- `encoded`: The encoded value to decode (`uint16_t`, `uint32_t`, or `uint64_t`)
**Returns:**
- The Manchester decoded value (half the bit width of input)
**Example:**
```cpp
uint8_t decoded = etl::manchester::decode(0x5A5A);
```
#### Decode range
```cpp
template <typename TChunk = typename private_manchester::encoded<uint_least8_t>::type>
static ETL_CONSTEXPR14 void decode(etl::span<const uint_least8_t> encoded,
etl::span<uint_least8_t> decoded)
```
Decodes a span of Manchester encoded data.
**Parameters:**
- `encoded`: Source data to decode
- `decoded`: Destination for decoded data (must be half the size of `encoded`)
**Template Parameters:**
- `TChunk`: Chunk type for decoding (`uint16_t`, `uint32_t`, or `uint64_t`)
**Example:**
```cpp
std::array<uint8_t, 8> encoded = {/* ... */};
std::array<uint8_t, 4> decoded1 {};
std::array<uint8_t, 4> decoded2 {};
// Decode with TChunk == uint16_t
etl::manchester::decode(encoded, decoded1);
// Decode with TChunk == uint64_t
etl::manchester::decode<uint64_t>(encoded, decoded2);
```
### Validation Functions
#### Single value
```cpp
template <typename TChunk>
static ETL_CONSTEXPR14 bool is_valid(TChunk encoded)
```
Validates that a single value contains valid Manchester encoded data.
**Parameters:**
- `encoded`: The encoded value to validate
**Returns:**
- `true` if the value contains valid Manchester encoded data, `false` otherwise
**Example:**
```cpp
bool valid = etl::manchester::is_valid(0x5A5A);
```
#### Range
```cpp
static ETL_CONSTEXPR14 bool is_valid(etl::span<const uint_least8_t> encoded)
```
Validates that a range contains valid Manchester encoded data.
**Parameters:**
- `encoded`: The range of encoded data to validate
**Returns:**
- `true` if all data is valid Manchester encoding, `false` otherwise
**Example:**
```cpp
std::array<uint8_t, 8> encoded_data = {/* ... */};
bool valid = etl::manchester::is_valid(encoded_data);
```
## Supported Types
### Input/chunk types for encoding
- `uint8_t``uint16_t` (if 8-bit types are supported)
- `uint16_t``uint32_t`
- `uint32_t``uint64_t` (if 64-bit types are supported)
### Input/chunk types for decoding
- `uint16_t``uint8_t` (if 8-bit types are supported)
- `uint32_t``uint16_t`
- `uint64_t``uint32_t` (if 64-bit types are supported)

View File

@ -34,7 +34,7 @@ SOFTWARE.
#define ETL_ALGORITHM_INCLUDED
///\defgroup algorithm algorithm
/// Including reverse engineered algorithms from C++ 0x11, 0x14, 0x17
/// Including reverse engineered algorithms from C++11, 14, 17
/// Additional new variants of certain algorithms.
///\ingroup utilities
@ -507,6 +507,7 @@ namespace etl
//***************************************************************************
template <typename TIterator, typename T, typename Compare>
ETL_NODISCARD
ETL_CONSTEXPR14
bool binary_search(TIterator first, TIterator last, const T& value, Compare compare)
{
first = etl::lower_bound(first, last, value, compare);
@ -516,6 +517,7 @@ namespace etl
template <typename TIterator, typename T>
ETL_NODISCARD
ETL_CONSTEXPR14
bool binary_search(TIterator first, TIterator last, const T& value)
{
typedef etl::less<typename etl::iterator_traits<TIterator>::value_type> compare;
@ -949,7 +951,7 @@ namespace etl
{
// Push Heap Helper
template <typename TIterator, typename TDistance, typename TValue, typename TCompare>
void push_heap(TIterator first, TDistance value_index, TDistance top_index, TValue value, TCompare compare)
ETL_CONSTEXPR14 void push_heap(TIterator first, TDistance value_index, TDistance top_index, TValue value, TCompare compare)
{
TDistance parent = (value_index - 1) / 2;
@ -965,7 +967,7 @@ namespace etl
// Adjust Heap Helper
template <typename TIterator, typename TDistance, typename TValue, typename TCompare>
void adjust_heap(TIterator first, TDistance value_index, TDistance length, TValue value, TCompare compare)
ETL_CONSTEXPR14 void adjust_heap(TIterator first, TDistance value_index, TDistance length, TValue value, TCompare compare)
{
TDistance top_index = value_index;
TDistance child2nd = (2 * value_index) + 2;
@ -993,7 +995,7 @@ namespace etl
// Is Heap Helper
template <typename TIterator, typename TDistance, typename TCompare>
bool is_heap(const TIterator first, const TDistance n, TCompare compare)
ETL_CONSTEXPR14 bool is_heap(const TIterator first, const TDistance n, TCompare compare)
{
TDistance parent = 0;
@ -1016,6 +1018,7 @@ namespace etl
// Pop Heap
template <typename TIterator, typename TCompare>
ETL_CONSTEXPR14
void pop_heap(TIterator first, TIterator last, TCompare compare)
{
typedef typename etl::iterator_traits<TIterator>::value_type value_t;
@ -1029,6 +1032,7 @@ namespace etl
// Pop Heap
template <typename TIterator>
ETL_CONSTEXPR14
void pop_heap(TIterator first, TIterator last)
{
typedef etl::less<typename etl::iterator_traits<TIterator>::value_type> compare;
@ -1038,6 +1042,7 @@ namespace etl
// Push Heap
template <typename TIterator, typename TCompare>
ETL_CONSTEXPR14
void push_heap(TIterator first, TIterator last, TCompare compare)
{
typedef typename etl::iterator_traits<TIterator>::difference_type difference_t;
@ -1048,6 +1053,7 @@ namespace etl
// Push Heap
template <typename TIterator>
ETL_CONSTEXPR14
void push_heap(TIterator first, TIterator last)
{
typedef etl::less<typename etl::iterator_traits<TIterator>::value_type> compare;
@ -1057,6 +1063,7 @@ namespace etl
// Make Heap
template <typename TIterator, typename TCompare>
ETL_CONSTEXPR14
void make_heap(TIterator first, TIterator last, TCompare compare)
{
typedef typename etl::iterator_traits<TIterator>::difference_type difference_t;
@ -1084,6 +1091,7 @@ namespace etl
// Make Heap
template <typename TIterator>
ETL_CONSTEXPR14
void make_heap(TIterator first, TIterator last)
{
typedef etl::less<typename etl::iterator_traits<TIterator>::value_type> compare;
@ -1094,6 +1102,7 @@ namespace etl
// Is Heap
template <typename TIterator>
ETL_NODISCARD
ETL_CONSTEXPR14
bool is_heap(TIterator first, TIterator last)
{
typedef etl::less<typename etl::iterator_traits<TIterator>::value_type> compare;
@ -1104,6 +1113,7 @@ namespace etl
// Is Heap
template <typename TIterator, typename TCompare>
ETL_NODISCARD
ETL_CONSTEXPR14
bool is_heap(TIterator first, TIterator last, TCompare compare)
{
return private_heap::is_heap(first, last - first, compare);
@ -1111,6 +1121,7 @@ namespace etl
// Sort Heap
template <typename TIterator>
ETL_CONSTEXPR14
void sort_heap(TIterator first, TIterator last)
{
while (first != last)
@ -1122,6 +1133,7 @@ namespace etl
// Sort Heap
template <typename TIterator, typename TCompare>
ETL_CONSTEXPR14
void sort_heap(TIterator first, TIterator last, TCompare compare)
{
while (first != last)
@ -1131,6 +1143,119 @@ namespace etl
}
}
//***************************************************************************
/// partial_sort
///\ingroup algorithm
///<a href="http://en.cppreference.com/w/cpp/algorithm/partial_sort"></a>
//***************************************************************************
template <typename TIterator, typename TCompare>
ETL_CONSTEXPR14
void partial_sort(TIterator first, TIterator middle, TIterator last, TCompare compare)
{
if (first == middle)
{
return;
}
typedef typename etl::iterator_traits<TIterator>::value_type value_t;
typedef typename etl::iterator_traits<TIterator>::difference_type difference_t;
etl::make_heap(first, middle, compare);
for (TIterator i = middle; i != last; ++i)
{
if (compare(*i, *first))
{
value_t value = ETL_MOVE(*i);
*i = ETL_MOVE(*first);
private_heap::adjust_heap(first, difference_t(0), difference_t(middle - first), ETL_MOVE(value), compare);
}
}
etl::sort_heap(first, middle, compare);
}
//***************************************************************************
/// partial_sort
///\ingroup algorithm
///<a href="http://en.cppreference.com/w/cpp/algorithm/partial_sort"></a>
//***************************************************************************
template <typename TIterator>
ETL_CONSTEXPR14
void partial_sort(TIterator first, TIterator middle, TIterator last)
{
typedef etl::less<typename etl::iterator_traits<TIterator>::value_type> compare;
etl::partial_sort(first, middle, last, compare());
}
//***************************************************************************
/// partial_sort_copy
///\ingroup algorithm
///<a href="http://en.cppreference.com/w/cpp/algorithm/partial_sort_copy"></a>
//***************************************************************************
template <typename TInputIterator, typename TRandomAccessIterator, typename TCompare>
ETL_CONSTEXPR14
TRandomAccessIterator partial_sort_copy(TInputIterator first,
TInputIterator last,
TRandomAccessIterator d_first,
TRandomAccessIterator d_last,
TCompare compare)
{
typedef typename etl::iterator_traits<TRandomAccessIterator>::value_type value_t;
typedef typename etl::iterator_traits<TRandomAccessIterator>::difference_type difference_t;
TRandomAccessIterator result = d_first;
// Fill the destination range
while ((first != last) && (result != d_last))
{
*result = *first;
++result;
++first;
}
if (result == d_first)
{
return result;
}
// Build a max-heap over the destination range
etl::make_heap(d_first, result, compare);
// Process remaining input elements
for (TInputIterator i = first; i != last; ++i)
{
if (compare(*i, *d_first))
{
value_t value = *i;
private_heap::adjust_heap(d_first, difference_t(0), difference_t(result - d_first), ETL_MOVE(value), compare);
}
}
etl::sort_heap(d_first, result, compare);
return result;
}
//***************************************************************************
/// partial_sort_copy
///\ingroup algorithm
///<a href="http://en.cppreference.com/w/cpp/algorithm/partial_sort_copy"></a>
//***************************************************************************
template <typename TInputIterator, typename TRandomAccessIterator>
ETL_CONSTEXPR14
TRandomAccessIterator partial_sort_copy(TInputIterator first,
TInputIterator last,
TRandomAccessIterator d_first,
TRandomAccessIterator d_last)
{
typedef etl::less<typename etl::iterator_traits<TRandomAccessIterator>::value_type> compare;
return etl::partial_sort_copy(first, last, d_first, d_last, compare());
}
//***************************************************************************
// Search
//***************************************************************************
@ -1185,7 +1310,6 @@ namespace etl
//***************************************************************************
namespace private_algorithm
{
#if ETL_USING_CPP11
//*********************************
// For random access iterators
template <typename TIterator>
@ -1193,27 +1317,32 @@ namespace etl
typename etl::enable_if<etl::is_random_access_iterator<TIterator>::value, TIterator>::type
rotate_general(TIterator first, TIterator middle, TIterator last)
{
if (first == middle || middle == last)
if (first == middle)
{
return last;
}
if (middle == last)
{
return first;
}
typedef typename etl::iterator_traits<TIterator>::value_type value_type;
typedef typename etl::iterator_traits<TIterator>::difference_type difference_type;
int n = last - first;
int m = middle - first;
int gcd_nm = (n == 0 || m == 0) ? n + m : etl::gcd(n, m);
difference_type n = last - first;
difference_type m = middle - first;
difference_type gcd_nm = (n == 0 || m == 0) ? n + m : etl::gcd(n, m);
TIterator result = first + (last - middle);
for (int i = 0; i < gcd_nm; i++)
for (difference_type i = 0; i < gcd_nm; i++)
{
value_type temp = ETL_MOVE(*(first + i));
int j = i;
difference_type j = i;
while (true)
{
int k = j + m;
difference_type k = j + m;
if (k >= n)
{
@ -1234,56 +1363,6 @@ namespace etl
return result;
}
#else
//*********************************
// For random access iterators
template <typename TIterator>
ETL_CONSTEXPR14
typename etl::enable_if<etl::is_random_access_iterator<TIterator>::value, TIterator>::type
rotate_general(TIterator first, TIterator middle, TIterator last)
{
if (first == middle || middle == last)
{
return first;
}
typedef typename etl::iterator_traits<TIterator>::value_type value_type;
int n = last - first;
int m = middle - first;
int gcd_nm = (n == 0 || m == 0) ? n + m : etl::gcd(n, m);
TIterator result = first + (last - middle);
for (int i = 0; i < gcd_nm; i++)
{
value_type temp = *(first + i);
int j = i;
while (true)
{
int k = j + m;
if (k >= n)
{
k = k - n;
}
if (k == i)
{
break;
}
*(first + j) = *(first + k);
j = k;
}
*(first + j) = temp;
}
return result;
}
#endif
//*********************************
// For bidirectional iterators
@ -1292,7 +1371,12 @@ namespace etl
typename etl::enable_if<etl::is_bidirectional_iterator<TIterator>::value, TIterator>::type
rotate_general(TIterator first, TIterator middle, TIterator last)
{
if (first == middle || middle == last)
if (first == middle)
{
return last;
}
if (middle == last)
{
return first;
}
@ -1314,7 +1398,12 @@ namespace etl
typename etl::enable_if<etl::is_forward_iterator<TIterator>::value, TIterator>::type
rotate_general(TIterator first, TIterator middle, TIterator last)
{
if (first == middle || middle == last)
if (first == middle)
{
return last;
}
if (middle == last)
{
return first;
}
@ -1390,26 +1479,29 @@ namespace etl
ETL_CONSTEXPR14
TIterator rotate(TIterator first, TIterator middle, TIterator last)
{
if (first == middle)
{
return last;
}
if (middle == last)
{
return first;
}
if (etl::next(first) == middle)
{
return private_algorithm::rotate_left_by_one(first, last);
}
#if ETL_USING_CPP20
if (etl::next(middle) == last)
{
#if ETL_USING_CPP20
if ETL_IF_CONSTEXPR(etl::is_forward_iterator<TIterator>::value)
{
return private_algorithm::rotate_general(first, middle, last);
}
else
if ETL_IF_CONSTEXPR(etl::is_bidirectional_iterator_concept<TIterator>::value)
{
return private_algorithm::rotate_right_by_one(first, last);
}
#else
return private_algorithm::rotate_general(first, middle, last);
#endif
}
#endif
return private_algorithm::rotate_general(first, middle, last);
}
@ -1641,35 +1733,6 @@ namespace etl
return compare(b, a) ? ETL_OR_STD::pair<const T&, const T&>(b, a) : ETL_OR_STD::pair<const T&, const T&>(a, b);
}
//***************************************************************************
/// is_sorted_until
///\ingroup algorithm
///<a href="http://en.cppreference.com/w/cpp/algorithm/is_sorted_until"></a>
//***************************************************************************
template <typename TIterator>
ETL_NODISCARD
ETL_CONSTEXPR14
TIterator is_sorted_until(TIterator begin,
TIterator end)
{
if (begin != end)
{
TIterator next = begin;
while (++next != end)
{
if (*next < *begin)
{
return next;
}
++begin;
}
}
return end;
}
//***************************************************************************
/// is_sorted_until
///\ingroup algorithm
@ -1700,6 +1763,22 @@ namespace etl
return end;
}
//***************************************************************************
/// is_sorted_until
///\ingroup algorithm
///<a href="http://en.cppreference.com/w/cpp/algorithm/is_sorted_until"></a>
//***************************************************************************
template <typename TIterator>
ETL_NODISCARD
ETL_CONSTEXPR14
TIterator is_sorted_until(TIterator begin,
TIterator end)
{
typedef etl::less<typename etl::iterator_traits<TIterator>::value_type> compare;
return etl::is_sorted_until(begin, end, compare());
}
//***************************************************************************
/// is_sorted
///\ingroup algorithm
@ -1768,22 +1847,9 @@ namespace etl
TIterator is_unique_sorted_until(TIterator begin,
TIterator end)
{
if (begin != end)
{
TIterator next = begin;
typedef etl::less<typename etl::iterator_traits<TIterator>::value_type> compare;
while (++next != end)
{
if (!(*begin < *next))
{
return next;
}
++begin;
}
}
return end;
return etl::is_unique_sorted_until(begin, end, compare());
}
//***************************************************************************
@ -1838,6 +1904,51 @@ namespace etl
return end;
}
//***************************************************************************
/// adjacent_find
///\ingroup algorithm
///<a href="http://en.cppreference.com/w/cpp/algorithm/adjacent_find"></a>
//***************************************************************************
template <typename TIterator, typename TBinaryPredicate>
ETL_NODISCARD
ETL_CONSTEXPR14
TIterator adjacent_find(TIterator first, TIterator last, TBinaryPredicate predicate)
{
if (first != last)
{
TIterator next = first;
++next;
while (next != last)
{
if (predicate(*first, *next))
{
return first;
}
++first;
++next;
}
}
return last;
}
//***************************************************************************
/// adjacent_find
///\ingroup algorithm
///<a href="http://en.cppreference.com/w/cpp/algorithm/adjacent_find"></a>
//***************************************************************************
template <typename TIterator>
ETL_NODISCARD
ETL_CONSTEXPR14
TIterator adjacent_find(TIterator first, TIterator last)
{
typedef etl::equal_to<typename etl::iterator_traits<TIterator>::value_type> predicate;
return etl::adjacent_find(first, last, predicate());
}
//***************************************************************************
/// is_permutation
///\ingroup algorithm
@ -1896,9 +2007,9 @@ namespace etl
{
if (i == etl::find_if(begin1, i, etl::bind1st(predicate, *i)))
{
size_t n = etl::count(begin2, end2, *i);
size_t n = etl::count_if(begin2, end2, etl::bind1st(predicate, *i));
if (n == 0 || size_t(etl::count(i, end1, *i)) != n)
if (n == 0 || size_t(etl::count_if(i, end1, etl::bind1st(predicate, *i))) != n)
{
return false;
}
@ -1922,18 +2033,20 @@ namespace etl
TIterator2 begin2,
TIterator2 end2)
{
if (begin1 != end1)
if (etl::distance(begin1, end1) != etl::distance(begin2, end2))
{
for (TIterator1 i = begin1; i != end1; ++i)
{
if (i == etl::find(begin1, i, *i))
{
size_t n = etl::count(begin2, end2, *i);
return false;
}
if (n == 0 || size_t(etl::count(i, end1, *i)) != n)
{
return false;
}
for (TIterator1 i = begin1; i != end1; ++i)
{
if (i == etl::find(begin1, i, *i))
{
size_t n = etl::count(begin2, end2, *i);
if (n == 0 || size_t(etl::count(i, end1, *i)) != n)
{
return false;
}
}
}
@ -1948,24 +2061,27 @@ namespace etl
//***************************************************************************
template <typename TIterator1, typename TIterator2, typename TBinaryPredicate>
ETL_NODISCARD
ETL_CONSTEXPR14
bool is_permutation(TIterator1 begin1,
TIterator1 end1,
TIterator2 begin2,
TIterator2 end2,
TBinaryPredicate predicate)
{
if (begin1 != end1)
if (etl::distance(begin1, end1) != etl::distance(begin2, end2))
{
for (TIterator1 i = begin1; i != end1; ++i)
{
if (i == etl::find_if(begin1, i, etl::bind1st(predicate, *i)))
{
size_t n = etl::count(begin2, end2, *i);
return false;
}
if (n == 0 || size_t(etl::count(i, end1, *i)) != n)
{
return false;
}
for (TIterator1 i = begin1; i != end1; ++i)
{
if (i == etl::find_if(begin1, i, etl::bind1st(predicate, *i)))
{
size_t n = etl::count_if(begin2, end2, etl::bind1st(predicate, *i));
if (n == 0 || size_t(etl::count_if(i, end1, etl::bind1st(predicate, *i))) != n)
{
return false;
}
}
}
@ -2020,14 +2136,22 @@ namespace etl
TIterator end,
TUnaryPredicate predicate)
{
while (begin != end)
{
if (!predicate(*begin))
{
return begin;
}
typedef typename etl::iterator_traits<TIterator>::difference_type difference_t;
++begin;
// binary search on a partitioned range
for (difference_t length = etl::distance(begin, end); 0 < length; )
{
difference_t half = length / 2;
TIterator middle = etl::next(begin, half);
if (predicate(*middle))
{
begin = etl::next(middle);
length -= (half + 1);
}
else
{
length = half;
}
}
return begin;
@ -2344,6 +2468,253 @@ namespace etl
return first;
}
//***************************************************************************
/// unique
/// see https://en.cppreference.com/w/cpp/algorithm/unique
///\ingroup algorithm
//***************************************************************************
template <typename TIterator>
ETL_CONSTEXPR14
TIterator unique(TIterator first, TIterator last)
{
if (first == last)
{
return last;
}
TIterator result = first;
while (++first != last)
{
if (!(*result == *first) && (++result != first))
{
*result = ETL_MOVE(*first);
}
}
return ++result;
}
//***************************************************************************
/// unique
/// see https://en.cppreference.com/w/cpp/algorithm/unique
/// predicate overload to determine equality.
///\ingroup algorithm
//***************************************************************************
template <typename TIterator, typename TBinaryPredicate>
ETL_CONSTEXPR14
TIterator unique(TIterator first, TIterator last, TBinaryPredicate predicate)
{
if (first == last)
{
return last;
}
TIterator result = first;
while (++first != last)
{
if (!predicate(*result, *first) && (++result != first))
{
*result = ETL_MOVE(*first);
}
}
return ++result;
}
//***************************************************************************
/// unique_copy
/// see https://en.cppreference.com/w/cpp/algorithm/unique_copy
///\ingroup algorithm
//***************************************************************************
template <typename TInputIterator, typename TOutputIterator>
ETL_CONSTEXPR14
TOutputIterator unique_copy(TInputIterator first,
TInputIterator last,
TOutputIterator d_first)
{
if (first == last)
{
return d_first;
}
typename etl::iterator_traits<TInputIterator>::value_type prev = *first;
*d_first = prev;
while (++first != last)
{
if (!(prev == *first))
{
prev = *first;
*(++d_first) = prev;
}
}
return ++d_first;
}
//***************************************************************************
/// unique_copy
/// see https://en.cppreference.com/w/cpp/algorithm/unique_copy
/// predicate overload to determine equality.
///\ingroup algorithm
//***************************************************************************
template <typename TInputIterator, typename TOutputIterator, typename TBinaryPredicate>
ETL_CONSTEXPR14
TOutputIterator unique_copy(TInputIterator first,
TInputIterator last,
TOutputIterator d_first,
TBinaryPredicate predicate)
{
if (first == last)
{
return d_first;
}
typename etl::iterator_traits<TInputIterator>::value_type prev = *first;
*d_first = prev;
while (++first != last)
{
if (!predicate(prev, *first))
{
prev = *first;
*(++d_first) = prev;
}
}
return ++d_first;
}
//***************************************************************************
/// merge
/// Merges two sorted ranges into one sorted range.
/// see https://en.cppreference.com/w/cpp/algorithm/merge
///\ingroup algorithm
//***************************************************************************
template <typename TInputIterator1, typename TInputIterator2, typename TOutputIterator, typename TCompare>
ETL_CONSTEXPR14
TOutputIterator merge(TInputIterator1 first1, TInputIterator1 last1,
TInputIterator2 first2, TInputIterator2 last2,
TOutputIterator d_first,
TCompare compare)
{
while ((first1 != last1) && (first2 != last2))
{
if (compare(*first2, *first1))
{
*d_first = *first2;
++first2;
}
else
{
*d_first = *first1;
++first1;
}
++d_first;
}
d_first = etl::copy(first1, last1, d_first);
d_first = etl::copy(first2, last2, d_first);
return d_first;
}
//***************************************************************************
/// merge
/// Merges two sorted ranges into one sorted range.
/// Uses operator< for comparison.
/// see https://en.cppreference.com/w/cpp/algorithm/merge
///\ingroup algorithm
//***************************************************************************
template <typename TInputIterator1, typename TInputIterator2, typename TOutputIterator>
ETL_CONSTEXPR14
TOutputIterator merge(TInputIterator1 first1, TInputIterator1 last1,
TInputIterator2 first2, TInputIterator2 last2,
TOutputIterator d_first)
{
typedef etl::less<typename etl::iterator_traits<TInputIterator1>::value_type> compare;
return etl::merge(first1, last1, first2, last2, d_first, compare());
}
//***************************************************************************
/// inplace_merge
/// Merges two consecutive sorted ranges [first, middle) and [middle, last)
/// into one sorted range [first, last) in-place.
/// Uses an iterative rotate-based algorithm that requires no additional
/// memory, no recursion and no explicit stack, making it safe for deeply
/// embedded targets with constrained stack sizes.
/// Complexity: O(N log N) comparisons, O(N log N) element moves.
/// see https://en.cppreference.com/w/cpp/algorithm/inplace_merge
///\ingroup algorithm
//***************************************************************************
template <typename TBidirectionalIterator, typename TCompare>
void inplace_merge(TBidirectionalIterator first,
TBidirectionalIterator middle,
TBidirectionalIterator last,
TCompare compare)
{
typedef typename etl::iterator_traits<TBidirectionalIterator>::difference_type difference_type;
difference_type len1 = etl::distance(first, middle);
difference_type len2 = etl::distance(middle, last);
while ((len1 != 0) && (len2 != 0))
{
// Find where the first element of the right half belongs in the left half.
// All elements in [first, cut1) are <= *middle, so they are already in place.
TBidirectionalIterator cut1 = etl::upper_bound(first, middle, *middle, compare);
difference_type prefix = etl::distance(first, cut1);
len1 -= prefix;
// If the entire left half is <= *middle, we are done.
if (len1 == 0)
{
return;
}
// Advance first past the already-placed prefix.
first = cut1;
// Find where the first element of the (remaining) left half belongs in
// the right half. All elements in [middle, cut2) are < *first, so they
// need to be moved before *first.
TBidirectionalIterator cut2 = etl::lower_bound(middle, last, *first, compare);
difference_type run = etl::distance(middle, cut2);
len2 -= run;
// Rotate the block [first, middle, cut2) so that [middle, cut2) moves
// before [first, middle). After the rotate the elements from
// [middle, cut2) (length = run) now occupy [first, first + run) and
// are in their final position.
etl::rotate(first, middle, cut2);
// Advance past the block we just placed.
etl::advance(first, run);
middle = cut2;
}
}
//***************************************************************************
/// inplace_merge
/// Merges two consecutive sorted ranges [first, middle) and [middle, last)
/// into one sorted range [first, last) in-place.
/// Uses operator< for comparison.
/// see https://en.cppreference.com/w/cpp/algorithm/inplace_merge
///\ingroup algorithm
//***************************************************************************
template <typename TBidirectionalIterator>
void inplace_merge(TBidirectionalIterator first,
TBidirectionalIterator middle,
TBidirectionalIterator last)
{
typedef etl::less<typename etl::iterator_traits<TBidirectionalIterator>::value_type> compare;
etl::inplace_merge(first, middle, last, compare());
}
}
//*****************************************************************************
@ -3140,6 +3511,11 @@ namespace etl
ETL_CONSTEXPR20
void selection_sort(TIterator first, TIterator last, TCompare compare)
{
if (first == last)
{
return;
}
TIterator min;
const TIterator ilast = private_algorithm::get_before_last(first, last);
const TIterator jlast = last;
@ -3160,7 +3536,10 @@ namespace etl
}
using ETL_OR_STD::swap; // Allow ADL
swap(*i, *min);
if (min != i)
{
swap(*i, *min);
}
}
}
@ -3184,11 +3563,7 @@ namespace etl
ETL_CONSTEXPR14
void heap_sort(TIterator first, TIterator last, TCompare compare)
{
if (!etl::is_heap(first, last, compare))
{
etl::make_heap(first, last, compare);
}
etl::make_heap(first, last, compare);
etl::sort_heap(first, last, compare);
}
@ -3200,11 +3575,7 @@ namespace etl
ETL_CONSTEXPR14
void heap_sort(TIterator first, TIterator last)
{
if (!etl::is_heap(first, last))
{
etl::make_heap(first, last);
}
etl::make_heap(first, last);
etl::sort_heap(first, last);
}
@ -3248,7 +3619,7 @@ namespace etl
#endif
//***************************************************************************
/// Returns the maximum value.
/// Returns the minimum value.
//***************************************************************************
#if ETL_USING_CPP11
template <typename T>
@ -3444,14 +3815,7 @@ namespace etl
{
typedef typename etl::iterator_traits<TIterator>::value_type value_type;
TIterator pivot = last; // Maybe find a better pivot choice?
value_type pivot_value = *pivot;
// Swap the pivot with the last, if necessary.
if (pivot != last)
{
swap(*pivot, *last);
}
value_type pivot_value = ETL_MOVE(*last);
TIterator i = first;
@ -3550,7 +3914,7 @@ namespace etl
{
typedef etl::less<typename etl::iterator_traits<TIterator>::value_type> compare_t;
nth_element(first, last, compare_t());
nth_element(first, nth, last, compare_t());
}
#endif
}

View File

@ -46,7 +46,7 @@ SOFTWARE.
#include <stddef.h>
///\defgroup array array
/// A replacement for std::array if you haven't got C++0x11.
/// A replacement for std::array if you haven't got C++11.
///\ingroup containers
namespace etl
@ -81,7 +81,7 @@ namespace etl
//***************************************************************************
///\ingroup array
/// A replacement for std::array if you haven't got C++0x11.
/// A replacement for std::array if you haven't got C++11.
//***************************************************************************
template <typename T, size_t SIZE_>
class array
@ -646,7 +646,7 @@ namespace etl
//***************************************************************************
///\ingroup array
/// A replacement for std::array if you haven't got C++0x11.
/// A replacement for std::array if you haven't got C++11.
/// Specialisation for zero sized array.
//***************************************************************************
template <typename T>

View File

@ -48,7 +48,9 @@ SOFTWARE.
#include "variant.h"
#include "visitor.h"
#if ETL_USING_FORMAT_FLOATING_POINT
#include <cmath>
#endif
#if ETL_USING_CPP11
@ -138,9 +140,11 @@ namespace etl
unsigned int,
long long int,
unsigned long long int,
#if ETL_USING_FORMAT_FLOATING_POINT
float,
double,
long double,
#endif
const char*,
etl::string_view,
const void*
@ -302,6 +306,7 @@ namespace etl
{
}
#if ETL_USING_FORMAT_FLOATING_POINT
basic_format_arg(const float v)
: data(v)
{
@ -316,6 +321,7 @@ namespace etl
: data(v)
{
}
#endif
basic_format_arg(const etl::string_view v)
: data(v)
@ -1039,6 +1045,7 @@ namespace etl
format_plain_num(it, value, spec, width);
}
#if ETL_USING_FORMAT_FLOATING_POINT
template<typename OutputIt, typename T>
void format_floating_default(OutputIt& it, T value, const format_spec_t& spec)
{
@ -1214,6 +1221,7 @@ namespace etl
private_format::format_sequence<OutputIt>(it, ".");
private_format::format_plain_num<OutputIt, unsigned long long int>(it, fractional_int, spec, fractional_decimals);
}
#endif
class dummy_assign_to
{
@ -1336,6 +1344,7 @@ namespace etl
size_t count;
};
#if ETL_USING_FORMAT_FLOATING_POINT
template<typename OutputIt, typename T>
void format_floating_g(OutputIt& it, T value, const format_spec_t& spec)
{
@ -1409,6 +1418,7 @@ namespace etl
}
}
}
#endif
template<class OutputIt>
struct format_visitor
@ -1490,6 +1500,7 @@ namespace etl
return it;
}
#if ETL_USING_FORMAT_FLOATING_POINT
template<typename OutputIt, typename Float>
typename format_context<OutputIt>::iterator format_aligned_floating(Float arg, format_context<OutputIt>& fmt_ctx)
{
@ -1534,6 +1545,7 @@ namespace etl
private_format::fill<OutputIt>(it, suffix_size, fmt_ctx.format_spec.fill);
return it;
}
#endif
template<typename OutputIt>
void format_string_view(OutputIt& it, etl::string_view arg, const format_spec_t& spec)
@ -2072,6 +2084,7 @@ namespace etl
}
};
#if ETL_USING_FORMAT_FLOATING_POINT
template<>
struct formatter<float>
{
@ -2119,6 +2132,7 @@ namespace etl
return private_format::format_aligned_floating<OutputIt, long double>(arg, fmt_ctx);
}
};
#endif
template<>
struct formatter<etl::string_view>

View File

@ -43,7 +43,7 @@ SOFTWARE.
namespace etl
{
//***************************************************************************
/// A definition of reference_wrapper for those that don't have C++ 0x11 support.
/// A definition of reference_wrapper for those that don't have C++11 support.
///\ingroup reference
//***************************************************************************
template <typename T>
@ -224,9 +224,9 @@ namespace etl
typedef int is_transparent;
template <typename T1, typename T2>
constexpr auto operator()(T1&& lhs, T2&& rhs) const -> decltype(static_cast<T1&&>(lhs) < static_cast<T2&&>(rhs))
constexpr auto operator()(T1&& lhs, T2&& rhs) const -> decltype(!(static_cast<T2&&>(rhs) < static_cast<T1&&>(lhs)))
{
return !(static_cast<T1&&>(lhs) < static_cast<T2&&>(rhs));
return !(static_cast<T2&&>(rhs) < static_cast<T1&&>(lhs));
}
};
#endif
@ -250,7 +250,7 @@ namespace etl
typedef int is_transparent;
template <typename T1, typename T2>
constexpr auto operator()(T1&& lhs, T2&& rhs) const -> decltype(static_cast<T1&&>(lhs) < static_cast<T2&&>(rhs))
constexpr auto operator()(T1&& lhs, T2&& rhs) const -> decltype(static_cast<T2&&>(rhs) < static_cast<T1&&>(lhs))
{
return static_cast<T2&&>(rhs) < static_cast<T1&&>(lhs);
}
@ -276,9 +276,9 @@ namespace etl
typedef int is_transparent;
template <typename T1, typename T2>
constexpr auto operator()(T1&& lhs, T2&& rhs) const -> decltype(static_cast<T1&&>(lhs) < static_cast<T2&&>(rhs))
constexpr auto operator()(T1&& lhs, T2&& rhs) const -> decltype(!(static_cast<T1&&>(lhs) < static_cast<T2&&>(rhs)))
{
return static_cast<T1&&>(rhs) < static_cast<T2&&>(lhs);
return !(static_cast<T1&&>(lhs) < static_cast<T2&&>(rhs));
}
};
#endif
@ -303,7 +303,7 @@ namespace etl
typedef int is_transparent;
template <typename T1, typename T2>
constexpr auto operator()(T1&& lhs, T2&& rhs) const -> decltype(static_cast<T1&&>(lhs) < static_cast<T2&&>(rhs))
constexpr auto operator()(T1&& lhs, T2&& rhs) const -> decltype(static_cast<T1&&>(lhs) == static_cast<T2&&>(rhs))
{
return static_cast<T1&&>(lhs) == static_cast<T2&&>(rhs);
}
@ -329,7 +329,7 @@ namespace etl
typedef int is_transparent;
template <typename T1, typename T2>
constexpr auto operator()(T1&& lhs, T2&& rhs) const -> decltype(static_cast<T1&&>(lhs) < static_cast<T2&&>(rhs))
constexpr auto operator()(T1&& lhs, T2&& rhs) const -> decltype(!(static_cast<T1&&>(lhs) == static_cast<T2&&>(rhs)))
{
return !(static_cast<T1&&>(lhs) == static_cast<T2&&>(rhs));
}

View File

@ -47,7 +47,7 @@ namespace etl
{
//***************************************************************************
/// iota
/// Reverse engineered version of std::iota for non C++ 0x11 compilers.
/// Reverse engineered version of std::iota for non C++11 compilers.
/// Fills a range of elements with sequentially increasing values starting with <b>value</b>.
///\param first An iterator to the first position to fill.
///\param last An iterator to the last + 1 position.

View File

@ -154,6 +154,16 @@ SOFTWARE.
#define ETL_NOT_USING_WIDE_CHARACTERS 0
#endif
//*************************************
// Helper macro for ETL_FORMAT_NO_FLOATING_POINT.
#if defined(ETL_FORMAT_NO_FLOATING_POINT)
#define ETL_USING_FORMAT_FLOATING_POINT 0
#define ETL_NOT_USING_FORMAT_FLOATING_POINT 1
#else
#define ETL_USING_FORMAT_FLOATING_POINT 1
#define ETL_NOT_USING_FORMAT_FLOATING_POINT 0
#endif
//*************************************
// Figure out things about the compiler, if haven't already done so in etl_profile.h
#include "profiles/determine_compiler_version.h"
@ -651,6 +661,7 @@ namespace etl
static ETL_CONSTANT bool using_exceptions = (ETL_USING_EXCEPTIONS == 1);
static ETL_CONSTANT bool using_libc_wchar_h = (ETL_USING_LIBC_WCHAR_H == 1);
static ETL_CONSTANT bool using_std_exception = (ETL_USING_STD_EXCEPTION == 1);
static ETL_CONSTANT bool using_format_floating_point = (ETL_USING_FORMAT_FLOATING_POINT == 1);
// Has...
static ETL_CONSTANT bool has_initializer_list = (ETL_HAS_INITIALIZER_LIST == 1);

View File

@ -86,6 +86,7 @@ add_executable(etl_tests
test_closure.cpp
test_closure_constexpr.cpp
test_compare.cpp
test_concepts.cpp
test_constant.cpp
test_const_map.cpp
test_const_map_constexpr.cpp
@ -172,6 +173,7 @@ add_executable(etl_tests
test_endian.cpp
test_enum_type.cpp
test_error_handler.cpp
test_etl_assert.cpp
test_etl_traits.cpp
test_exception.cpp
test_expected.cpp
@ -183,6 +185,7 @@ add_executable(etl_tests
test_flat_multiset.cpp
test_flat_set.cpp
test_fnv_1.cpp
test_format.cpp
test_format_spec.cpp
test_forward_list.cpp
test_forward_list_shared_pool.cpp
@ -194,10 +197,12 @@ add_executable(etl_tests
test_hash.cpp
test_hfsm.cpp
test_hfsm_recurse_to_inner_state_on_start.cpp
test_hfsm_transition_on_enter.cpp
test_histogram.cpp
test_index_of_type.cpp
test_indirect_vector.cpp
test_indirect_vector_external_buffer.cpp
test_inplace_function.cpp
test_instance_count.cpp
test_integral_limits.cpp
test_intrusive_forward_list.cpp
@ -206,7 +211,9 @@ add_executable(etl_tests
test_intrusive_queue.cpp
test_intrusive_stack.cpp
test_invert.cpp
test_invoke.cpp
test_io_port.cpp
test_is_invocable.cpp
test_iterator.cpp
test_jenkins.cpp
test_largest.cpp
@ -259,6 +266,7 @@ add_executable(etl_tests
test_pool.cpp
test_pool_external_buffer.cpp
test_priority_queue.cpp
test_print.cpp
test_pseudo_moving_average.cpp
test_quantize.cpp
test_queue.cpp
@ -286,6 +294,7 @@ add_executable(etl_tests
test_scaled_rounding.cpp
test_set.cpp
test_shared_message.cpp
test_signal.cpp
test_singleton.cpp
test_singleton_base.cpp
test_smallest.cpp

View File

@ -113,6 +113,12 @@ struct non_random_iterator : public etl::iterator<ETL_OR_STD::bidirectional_iter
T* ptr;
};
template <typename T>
bool operator ==(const non_random_iterator<T>& lhs, const non_random_iterator<T>& rhs)
{
return lhs.ptr == rhs.ptr;
}
template <typename T>
bool operator !=(const non_random_iterator<T>& lhs, const non_random_iterator<T>& rhs)
{

0
test/run-syntax-checks.sh Normal file → Executable file
View File

File diff suppressed because it is too large Load Diff

View File

@ -34,6 +34,8 @@ SOFTWARE.
#include "etl/error_handler.h"
#include "etl/exception.h"
#include <cstring>
namespace
{
class TestException1 : public etl::exception

View File

@ -197,6 +197,7 @@ namespace
CHECK_EQUAL("-6759414", test_format(s, "{}", static_cast<int32_t>(-6759414)));
}
#if ETL_USING_FORMAT_FLOATING_POINT
//*************************************************************************
TEST(test_format_float)
{
@ -266,6 +267,7 @@ namespace
CHECK_EQUAL("0x1.92a738p-5", test_format(s, "{:a}", 0.0000015f));
CHECK_EQUAL("0x1.6345785d8ap+e", test_format(s, "{:a}", 100000000000000000.l));
}
#endif
//*************************************************************************
TEST(test_format_char_array)

View File

@ -85,6 +85,24 @@ namespace
mutable std::string result;
};
#if ETL_USING_CPP11
// Lightweight type used to verify transparent heterogeneous comparison.
// Only operator<(int, Wrapper) is defined; operator<(Wrapper, int) is
// intentionally absent. less_equal<void> is implemented as
// !(rhs < lhs), so less_equal<void>{}(Wrapper, int) needs
// operator<(int, Wrapper) which IS provided.
struct Wrapper
{
int value;
constexpr explicit Wrapper(int v) : value(v) {}
};
// int < Wrapper -- defined
constexpr bool operator<(int lhs, const Wrapper& rhs) { return lhs < rhs.value; }
// Wrapper < int -- intentionally NOT defined
#endif
SUITE(test_functional)
{
//*************************************************************************
@ -101,6 +119,32 @@ namespace
CHECK((compare<etl::less_equal<int>>(1, 2)));
CHECK(!(compare<etl::less_equal<int>>(2, 1)));
CHECK((compare<etl::less_equal<int>>(1, 1)));
#if ETL_USING_CPP11
CHECK((compare<etl::less_equal<void>>(1, 2)));
CHECK(!(compare<etl::less_equal<void>>(2, 1)));
CHECK((compare<etl::less_equal<void>>(1, 1)));
#endif
}
//*************************************************************************
TEST(test_less_equal_void_heterogeneous)
{
#if ETL_USING_CPP11
// less_equal<void>{}(lhs, rhs) is !(rhs < lhs).
// With only operator<(int, Wrapper) defined, we can call
// less_equal<void>{}(Wrapper, int) because the implementation
// evaluates !(int < Wrapper).
// Wrapper(1) <= 2 → !(2 < Wrapper(1)) → !(2 < 1) → !false → true
CHECK((etl::less_equal<void>{}(Wrapper(1), 2)));
// Wrapper(2) <= 1 → !(1 < Wrapper(2)) → !(1 < 2) → !true → false
CHECK(!(etl::less_equal<void>{}(Wrapper(2), 1)));
// Wrapper(3) <= 3 → !(3 < Wrapper(3)) → !(3 < 3) → !false → true
CHECK((etl::less_equal<void>{}(Wrapper(3), 3)));
#endif
}
//*************************************************************************
@ -117,6 +161,32 @@ namespace
CHECK(!(compare<etl::greater_equal<int>>(1, 2)));
CHECK((compare<etl::greater_equal<int>>(2, 1)));
CHECK((compare<etl::greater_equal<int>>(1, 1)));
#if ETL_USING_CPP11
CHECK(!(compare<etl::greater_equal<void>>(1, 2)));
CHECK((compare<etl::greater_equal<void>>(2, 1)));
CHECK((compare<etl::greater_equal<void>>(1, 1)));
#endif
}
//*************************************************************************
TEST(test_greater_equal_void_heterogeneous)
{
#if ETL_USING_CPP11
// greater_equal<void>{}(lhs, rhs) is !(lhs < rhs).
// With only operator<(int, Wrapper) defined, we can call
// greater_equal<void>{}(int, Wrapper) because the implementation
// evaluates !(int < Wrapper).
// 2 >= Wrapper(1) → !(2 < Wrapper(1)) → !(2 < 1) → !false → true
CHECK((etl::greater_equal<void>{}(2, Wrapper(1))));
// 1 >= Wrapper(2) → !(1 < Wrapper(2)) → !(1 < 2) → !true → false
CHECK(!(etl::greater_equal<void>{}(1, Wrapper(2))));
// 3 >= Wrapper(3) → !(3 < Wrapper(3)) → !(3 < 3) → !false → true
CHECK((etl::greater_equal<void>{}(3, Wrapper(3))));
#endif
}
//*************************************************************************

View File

@ -3552,6 +3552,7 @@
<ClInclude Include="..\..\include\etl\monostate.h" />
<ClInclude Include="..\..\include\etl\not_null.h" />
<ClInclude Include="..\..\include\etl\poly_span.h" />
<ClInclude Include="..\..\include\etl\print.h" />
<ClInclude Include="..\..\include\etl\private\bitset_legacy.h" />
<ClInclude Include="..\..\include\etl\private\bitset_new.h" />
<ClInclude Include="..\..\include\etl\private\chrono\day.h" />
@ -10362,6 +10363,7 @@
<ClCompile Include="..\test_not_null_unique_pointer.cpp" />
<ClCompile Include="..\test_poly_span_dynamic_extent.cpp" />
<ClCompile Include="..\test_poly_span_fixed_extent.cpp" />
<ClCompile Include="..\test_print.cpp" />
<ClCompile Include="..\test_pseudo_moving_average.cpp" />
<ClCompile Include="..\test_delegate.cpp" />
<ClCompile Include="..\test_delegate_cpp03.cpp" />