mirror of
https://github.com/ETLCPP/etl.git
synced 2026-07-30 08:16:19 +08:00
Squashed commit of the following:
commit c5dc331004b4d9611ab996935bedada203676c71
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date: Sat Jul 11 12:32:20 2026 +0100
Updated release notes
commit 4bf6ed6ce8d79857658d763e368ee56617542b2c
Author: vcoselev <145198867+vcoselev@users.noreply.github.com>
Date: Sat Jul 11 12:05:39 2026 +0100
Fix for 1405: etl::exchange doesn't work with unique_ptr (#1477)
* Separate bit order and endianness in bit_stream.h (#1495)
* Factor out ranges tests from test_algorithm.cpp to test_algorithm_ranges.cpp (#1497)
* Fix exchange to use forwarding reference (U&&) and move
- etl::exchange was using the copy constructor. Changed for etl::move.
- The assignment to the new object is now done with forward.
- Added a test with unique_ptr.
---------
Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>
Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
commit 2ed9019df04d470530c41c1f27d35adc30b9a32d
Author: Moritz Pflanzer <moritz@pflanzer.eu>
Date: Fri Jul 10 11:42:32 2026 +0200
Update operator[] docs for map class (#1499)
* Separate bit order and endianness in bit_stream.h (#1495)
* Update operator[] docs for map class
No const variant is implemented for the operator[].
---------
Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>
commit 423e18d96dc645f1c733cb0d8ae6b675b9eb7e83
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Fri Jul 10 11:14:08 2026 +0200
Factor out ranges tests from test_algorithm.cpp to test_algorithm_ranges.cpp (#1497)
commit 338bfdbb1f4df3c5c08a68a9038f13b8dae1c28b
Author: John Wellbelove <jwellbelove@users.noreply.github.com>
Date: Fri Jul 10 10:12:04 2026 +0100
Add coverage report to docs (#1498)
* Updated release notes
* Added link to coverage report
---------
Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.com>
commit 269025424f4c6f61cebac090f4df82985fb3b239
Merge: c004cc9d faa4c15b
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date: Thu Jul 9 14:18:32 2026 +0100
Merge branch 'development' of https://github.com/ETLCPP/etl into development
commit c004cc9d508efcf398630758a47aae95b37a7eb8
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date: Thu Jul 9 10:06:17 2026 +0100
Updated release notes
commit faa4c15b49c8ad15475c83ae23e00f5a46f803ca
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date: Thu Jul 9 10:06:17 2026 +0100
Updated release notes
commit 1523e63e35a15cfd1fa72d230a3c79efa7b9c3e0
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Wed Jul 8 20:48:33 2026 +0200
Support non-assignable alternatives in variant (#1496)
commit 878a0ba5a28f6b0dcae9f472a6a6a1f107de0a74
Author: John Wellbelove <john.wellbelove@etlcpp.com>
Date: Wed Jul 8 11:07:01 2026 +0100
Updated version and release notes
commit 5287fe4b3b9f58330881d2a62abf6ce8e1159b8d
Author: John Wellbelove <jwellbelove@users.noreply.github.com>
Date: Wed Jul 8 09:06:50 2026 +0100
Allow etl::vector to store pointers to functions and member functions (#1492)
* Refactored vector.h
Deleted ivectorpointer.h
* Minor changes
* Fixed code incompatible with C++03
* Clang-format changes
* Removed redundant double-qualified name
* Fixed is_is_object_pointer_v to is_object_pointer_v
* Added new test files to meson.build
* Added overflow checks to vector_ext copy and move constructors and assignments
Added assert throw tests.
* Added diagnostic pushes to eliminate GCC warning false positives
* Changed the GCC C++23 Github action to use GCC14
* Applied clang-format
* Added guard to pop_heap
* Added guard to adjust_heap
* Attempt to fix GCC diagnostic
* Attempt to fix GCC diagnostic
Re-enable ranges algorithm tests
* Attempt to fix GCC diagnostic
Re-enable ranges algorithm tests
* clang-format
* Attempt to fix GCC diagnostic
Re-enable ranges algorithm tests
* Attempt to fix GCC diagnostic
Re-enable ranges algorithm tests
* Attempt to fix GCC diagnostic
Re-enable ranges algorithm tests
* Missing newline at end of file
* Attempt to fix GCC diagnostic
Re-enable ranges algorithm tests
* Attempt to fix GCC diagnostic
Re-enable ranges algorithm tests
* Attempt to fix GCC diagnostic
Re-enable ranges algorithm tests
* Attempt to fix GCC diagnostic
Re-enable ranges algorithm tests
* Attempt to fix GCC diagnostic
* clang-format
* Changed gcc --version to gcc-14 --version
---------
Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.com>
Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>
commit 40dddd7f9601985ae7350e60a404af9028bc9fe9
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Tue Jul 7 23:41:17 2026 +0200
Add optional etl_profile label_flag for Bazel profile injection (#1491)
Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
commit 84fca4cd62f72c382c062376ca934803116a20d5
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Tue Jul 7 21:45:47 2026 +0200
Add missing memory functions, according the standard (#1490)
Adding:
- etl::align
- etl::assume_aligned
- etl::is_sufficiently_aligned
- etl::launder
- etl::pointer_traits
- etl::start_lifetime_as
Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
commit dca6653b3759b2cdc79307fec7425589feea478d
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Tue Jul 7 21:00:09 2026 +0200
Add missing interfaces to etl::chrono (#1489)
Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
commit c52b2ac7b1f675e6b1d34052239423b7f3634033
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Tue Jul 7 18:06:05 2026 +0200
Fix etl::mem_cast cross-size copy constructor and assignment (#1488)
The templated cross-size copy constructor and assignment operator were
broken in two ways:
- They accessed other.buffer / rhs.buffer, which is private in a
different mem_cast instantiation, so the cross-size overloads failed
to compile whenever they were actually instantiated.
- They copied Size_ (the destination size) bytes from a source buffer
that is only Other_Size bytes large, reading past the end of the
source when the destination was larger.
Use the public data() accessor and copy Other_Size bytes. The existing
static_assert(Size >= Other_Size) guarantees the destination is big
enough.
Add test_mem_cast_copy_and_assign_from_smaller regression test.
Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
commit 165674cb23dda1fd4f7e5a1182f49554a796bfe8
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Tue Jul 7 16:41:50 2026 +0200
Fix etl::pearson::reset() not resetting the first-byte flag (#1487)
reset() cleared the hash array but left the `first` flag false, so a
calculator reused after reset() took the XOR update path on its next
add() instead of the initialisation path. This produced an incorrect
hash for any pearson object that was reset and reused.
Reset `first` to true in reset() so a reset calculator behaves like a
freshly constructed one.
Add test_pearson_reset regression test.
Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
commit 032ec4cc80f1c0f1baa0383bdbc5f9239b68f268
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Tue Jul 7 13:40:04 2026 +0200
Fix etl::bitset single-element from_string shift on empty string (#1486)
The single-element from_string overloads (char, wchar_t, char16_t,
char32_t) computed element_type(1) << (string_length - 1U) before the
copy loop. For an empty string, or when active_bits is 0, string_length
is 0, so the shift count underflows to SIZE_MAX. Shifting by more than
the element width is undefined behaviour, which also breaks constexpr
evaluation.
Guard the mask with a zero-length check so the shift is only performed
when string_length > 0. The multi-element from_string overloads were
already safe.
Add test_construct_from_empty_string regression test.
Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
commit 98cb365d4c28e7b72f8547b734a03a4068acd3f5
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Tue Jul 7 12:32:56 2026 +0200
Fix etl::histogram copy/move not preserving start_index (#1485)
The run-time-offset specialization of etl::histogram stores a start_index
member used to map keys to bins (accumulator[key - start_index]). Its copy
constructor, move constructor, copy assignment, and move assignment copied
only the accumulator and left start_index uninitialized, so a copied or
moved histogram indexed the wrong bin in operator[]/add(), causing
out-of-bounds access (undefined behavior).
All four special member functions now also copy start_index. The
compile-time-offset specialization is unaffected, as its start index is a
template constant rather than a data member.
Add regression tests covering copy/move construction and assignment.
Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
commit 5cd2f28cd54e4019f7be126bcf7394a6a8318eb9
Author: Drew Rife <darife@jlg.com>
Date: Tue Jul 7 03:14:48 2026 -0400
Refactor variant::emplace to perfect forward args instead of copy/move construct (#1494)
* refactor: emplace logic to use do_emplace for in-place construction with forwarded arguments #1493
* Add test for variant_variadic
---------
Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de>
commit a47c0aae81b886259918961d5fcee20faa06fdd0
Author: Roland Reichwein <Roland.Reichwein@bmw.de>
Date: Mon Jul 6 17:32:26 2026 +0200
Fix etl::message_timer firing following timers early on unregister (#1484)
active_list.remove(id, has_expired) adjusts the next timer's delta only
when has_expired is false. When unregistering an active, non-expired timer,
unregister_timer() incorrectly passed true, skipping that adjustment, so
every timer after the removed one in the active list fired early by the
removed timer's delta.
Pass false instead, matching the etl::callback_timer family. tick() still
passes true, since the timer has genuinely expired there. The bug affected
all four variants: message_timer, message_timer_interrupt,
message_timer_atomic and message_timer_locked. Existing tests missed it
because they only ever unregistered the tail timer, where the delta
adjustment is a no-op.
Add a regression test that unregisters a non-tail active timer and checks
the following timer still fires at its original absolute time.
This commit is contained in:
parent
c707428cc4
commit
afa17c5042
24
.github/workflows/gcc-c++23.yml
vendored
24
.github/workflows/gcc-c++23.yml
vendored
@ -21,10 +21,10 @@ jobs:
|
||||
- name: Build
|
||||
run: |
|
||||
export ASAN_OPTIONS=alloc_dealloc_mismatch=0,detect_leaks=0
|
||||
export CC=gcc
|
||||
export CXX=g++
|
||||
export CC=gcc-14
|
||||
export CXX=g++-14
|
||||
cmake -DBUILD_TESTS=ON -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=23 -DETL_OPTIMISATION=-O3 ./
|
||||
gcc --version
|
||||
gcc-14 --version
|
||||
make -j "$(getconf _NPROCESSORS_ONLN)"
|
||||
|
||||
- name: Run tests
|
||||
@ -43,10 +43,10 @@ jobs:
|
||||
- name: Build
|
||||
run: |
|
||||
export ASAN_OPTIONS=alloc_dealloc_mismatch=0,detect_leaks=0
|
||||
export CC=gcc
|
||||
export CXX=g++
|
||||
export CC=gcc-14
|
||||
export CXX=g++-14
|
||||
cmake -DBUILD_TESTS=ON -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=23 -DETL_OPTIMISATION=-O3 ./
|
||||
gcc --version
|
||||
gcc-14 --version
|
||||
make -j "$(getconf _NPROCESSORS_ONLN)"
|
||||
|
||||
- name: Run tests
|
||||
@ -65,10 +65,10 @@ jobs:
|
||||
- name: Build
|
||||
run: |
|
||||
export ASAN_OPTIONS=alloc_dealloc_mismatch=0,detect_leaks=0
|
||||
export CC=gcc
|
||||
export CXX=g++
|
||||
export CC=gcc-14
|
||||
export CXX=g++-14
|
||||
cmake -DBUILD_TESTS=ON -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=23 -DETL_OPTIMISATION=-O3 ./
|
||||
gcc --version
|
||||
gcc-14 --version
|
||||
make -j "$(getconf _NPROCESSORS_ONLN)"
|
||||
|
||||
- name: Run tests
|
||||
@ -87,10 +87,10 @@ jobs:
|
||||
- name: Build
|
||||
run: |
|
||||
export ASAN_OPTIONS=alloc_dealloc_mismatch=0,detect_leaks=0
|
||||
export CC=gcc
|
||||
export CXX=g++
|
||||
export CC=gcc-14
|
||||
export CXX=g++-14
|
||||
cmake -DBUILD_TESTS=ON -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=23 -DETL_OPTIMISATION=-O3 ./
|
||||
gcc --version
|
||||
gcc-14 --version
|
||||
make -j "$(getconf _NPROCESSORS_ONLN)"
|
||||
|
||||
- name: Run tests
|
||||
|
||||
27
BUILD.bazel
27
BUILD.bazel
@ -2,8 +2,35 @@ load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
# ETL can be tailored to a project through an `etl_profile.h` header (see
|
||||
# `include/etl/platform.h`). When no such header is on the include path, ETL
|
||||
# falls back to its built-in defaults via `ETL_NO_PROFILE_HEADER`.
|
||||
#
|
||||
# This label_flag lets a consumer inject that profile as a Bazel target, without
|
||||
# patching this BUILD file:
|
||||
#
|
||||
# bazel build @etl//:etl --@etl//:etl_profile=//path/to:my_etl_profile
|
||||
#
|
||||
# The injected target is a cc_library that exposes a single `etl_profile.h` on
|
||||
# its include path, for example:
|
||||
#
|
||||
# cc_library(
|
||||
# name = "my_etl_profile",
|
||||
# hdrs = ["etl_profile.h"],
|
||||
# strip_include_prefix = ".",
|
||||
# )
|
||||
#
|
||||
# The default is empty, so ETL's built-in defaults are used unless overridden.
|
||||
label_flag(
|
||||
name = "etl_profile",
|
||||
build_setting_default = ":no_profile",
|
||||
)
|
||||
|
||||
cc_library(name = "no_profile")
|
||||
|
||||
cc_library(
|
||||
name = "etl",
|
||||
hdrs = glob(["include/**/*.h"]),
|
||||
includes = ["include"],
|
||||
deps = [":etl_profile"],
|
||||
)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Embedded Template Library ETL",
|
||||
"version": "20.48.0",
|
||||
"version": "20.48.1",
|
||||
"authors": {
|
||||
"name": "John Wellbelove",
|
||||
"email": "john.wellbelove@etlcpp.com"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name=Embedded Template Library ETL
|
||||
version=20.48.0
|
||||
version=20.48.1
|
||||
author= John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
license=MIT
|
||||
|
||||
@ -39,14 +39,13 @@ type: hextra-home
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<a href="https://github.com/ETLCPP/etl/actions/workflows/coverage.yml"><img src="https://github.com/ETLCPP/etl/actions/workflows/coverage.yml/badge.svg" alt="coverage"></a>
|
||||
<a href="https://etlcpp.github.io/etl/"><img src="https://github.com/ETLCPP/etl/actions/workflows/coverage.yml/badge.svg" alt="coverage"">
|
||||
<a href="https://www.codacy.com/manual/jwellbelove/etl"><img src="https://api.codacy.com/project/badge/Grade/3c14cd918ccf40008d0bcd7b083d5946" alt="Codacy"></a>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<a href="https://www.etlcpp.com/sponsor.html"><img src="https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86" alt="Sponsor"></a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
## Version
|
||||
|
||||
@ -136,3 +136,48 @@ ETL_NOEXCEPT
|
||||
A specialisation of absolute for `etl::chrono::duration`.
|
||||
**Return**
|
||||
The absolute duration value.
|
||||
|
||||
## 12/24 hour functions
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
inline ETL_CONSTEXPR14
|
||||
bool is_am(const etl::chrono::hours& h)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Returns `true` if `h` is in the range [0h, 11h] (an am hour).
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
inline ETL_CONSTEXPR14
|
||||
bool is_pm(const etl::chrono::hours& h)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Returns `true` if `h` is in the range [12h, 23h] (a pm hour).
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
inline ETL_CONSTEXPR14
|
||||
etl::chrono::hours make12(const etl::chrono::hours& h)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Returns the 12-hour equivalent of `h` in the range [1h, 12h].
|
||||
If `h` is not in the range [0h, 23h], the value returned is unspecified.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
inline ETL_CONSTEXPR14
|
||||
etl::chrono::hours make24(const etl::chrono::hours& h, bool is_pm)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Returns the 24-hour equivalent of `h`, which is assumed to represent the hour with the indicated am/pm.
|
||||
If `h` is not in the range [1h, 12h], the value returned is unspecified.
|
||||
@ -100,6 +100,41 @@ ETL_NOEXCEPT
|
||||
**Description**
|
||||
Subtracts a duration.
|
||||
|
||||
## Increment/decrement
|
||||
```cpp
|
||||
ETL_CONSTEXPR14 time_point& operator ++()
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Pre-increments the stored duration by one tick.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR14 time_point operator ++(int)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Post-increments the stored duration by one tick.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR14 time_point& operator --()
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Pre-decrements the stored duration by one tick.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR14 time_point operator --(int)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Post-decrements the stored duration by one tick.
|
||||
|
||||
## Constants
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
@ -180,6 +215,65 @@ If time_point < other, returns -1
|
||||
else if time_point > other, returns 1
|
||||
else returns 0
|
||||
|
||||
## Non-member mathematical operators
|
||||
```cpp
|
||||
template <typename TClock, typename TDuration1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::time_point<TClock, typename etl::common_type<TDuration1, etl::chrono::duration<TRep2, TPeriod2> >::type>
|
||||
operator +(const time_point<TClock, TDuration1>& lhs,
|
||||
const etl::chrono::duration<TRep2, TPeriod2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Adds a duration to a time_point.
|
||||
**Return**
|
||||
A time_point whose duration is the common type of the two.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TRep1, typename TPeriod1, typename TClock, typename TDuration2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::time_point<TClock, typename etl::common_type<etl::chrono::duration<TRep1, TPeriod1>, TDuration2>::type>
|
||||
operator +(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
|
||||
const time_point<TClock, TDuration2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Adds a duration to a time_point.
|
||||
**Return**
|
||||
A time_point whose duration is the common type of the two.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TClock, typename TDuration1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::time_point<TClock, typename etl::common_type<TDuration1, etl::chrono::duration<TRep2, TPeriod2> >::type>
|
||||
operator -(const time_point<TClock, TDuration1>& lhs,
|
||||
const etl::chrono::duration<TRep2, TPeriod2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Subtracts a duration from a time_point.
|
||||
**Return**
|
||||
A time_point whose duration is the common type of the two.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TClock, typename TDuration1, typename TDuration2>
|
||||
ETL_CONSTEXPR14
|
||||
typename etl::common_type<TDuration1, TDuration2>::type
|
||||
operator -(const time_point<TClock, TDuration1>& lhs,
|
||||
const time_point<TClock, TDuration2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Subtracts one time_point from another.
|
||||
**Return**
|
||||
The duration between them as the common type of the two durations.
|
||||
|
||||
## Non-member comparison operators
|
||||
```cpp
|
||||
template <typename TClock, typename TDuration1, typename TDuration2>
|
||||
|
||||
@ -96,10 +96,9 @@ If assert or exceptions are not enabled then undefined behaviour occurs.
|
||||
|
||||
```cpp
|
||||
TMapped& operator[](key_parameter_t key)
|
||||
const TMapped& operator[](key_parameter_t key) const
|
||||
```
|
||||
**Description**
|
||||
Returns a reference or const reference to the indexed element.
|
||||
Returns a reference to the indexed element.
|
||||
If the key does not exist then one is created using the default constructor.
|
||||
If the map is full then asserts an `etl::map_full`. If asserts or exceptions are not enabled then undefined behaviour occurs.
|
||||
|
||||
|
||||
@ -5,6 +5,24 @@ weight: 2002
|
||||
|
||||
Click on the links to see the original Github page.
|
||||
|
||||
## 20.48.1
|
||||
|
||||
**Pull requests:**
|
||||
|
||||
[#1477](https://github.com/ETLCPP/etl/pull/1477) Fix for 1405: etl::exchange doesn't work with unique_ptr
|
||||
[#1484](https://github.com/ETLCPP/etl/pull/1484) Fix `etl::message_timer` firing following timers early on unregister
|
||||
[#1485](https://github.com/ETLCPP/etl/pull/1485) Fix `etl::histogram` copy/move not preserving start_index
|
||||
[#1486](https://github.com/ETLCPP/etl/pull/1486) Fix `etl::bitset` single-element `from_string` shift on empty string
|
||||
[#1487](https://github.com/ETLCPP/etl/pull/1487) Fix `etl::pearson::reset()` not resetting the first-byte flag
|
||||
[#1488](https://github.com/ETLCPP/etl/pull/1488) Fix `etl::mem_cast` cross-size copy constructor and assignment
|
||||
[#1489](https://github.com/ETLCPP/etl/pull/1489) Add missing interfaces to `etl::chrono`
|
||||
[#1490](https://github.com/ETLCPP/etl/pull/1490) Add missing memory functions, according the standard
|
||||
[#1491](https://github.com/ETLCPP/etl/pull/1491) Add optional `etl_profile` `label_flag` for Bazel profile injection
|
||||
[#1492](https://github.com/ETLCPP/etl/pull/1492) Allow `etl::vector` to store pointers to functions and member functions
|
||||
[#1494](https://github.com/ETLCPP/etl/pull/1494) Refactor `variant::emplace` to perfect forward args instead of copy/move construct
|
||||
[#1495](https://github.com/ETLCPP/etl/pull/1495) Separate bit order and endianness in `bit_stream.h`
|
||||
[#1496](https://github.com/ETLCPP/etl/pull/1496) Fix non-assignable alternatives in variant
|
||||
|
||||
## 20.48.0
|
||||
|
||||
**Pull requests:**
|
||||
|
||||
@ -296,3 +296,37 @@ Then use them with `--config`:
|
||||
```sh
|
||||
bazel test //test:etl_tests --config=clang --config=c++20 --config=release
|
||||
```
|
||||
|
||||
### Injecting a Custom Profile Header
|
||||
|
||||
Instead of passing many individual `--copt=-D...` flags, ETL can be configured in bulk through a user-provided `etl_profile.h` header. When such a header is reachable on the include path, `include/etl/platform.h` includes it automatically; otherwise ETL falls back to its built-in defaults (`ETL_NO_PROFILE_HEADER`).
|
||||
|
||||
Because the header must sit on ETL's include path, `BUILD.bazel` exposes an `etl_profile` [`label_flag`](https://bazel.build/extending/config) so you can inject it as a Bazel target — without patching ETL's `BUILD.bazel`.
|
||||
|
||||
First, wrap your profile header in a `cc_library` that places `etl_profile.h` on its include path:
|
||||
|
||||
```python
|
||||
# path/to/BUILD.bazel
|
||||
cc_library(
|
||||
name = "my_etl_profile",
|
||||
hdrs = ["etl_profile.h"],
|
||||
strip_include_prefix = ".",
|
||||
)
|
||||
```
|
||||
|
||||
Then point the `etl_profile` flag at that target when building:
|
||||
|
||||
```sh
|
||||
bazel build @etl//:etl --@etl//:etl_profile=//path/to:my_etl_profile
|
||||
```
|
||||
|
||||
The flag defaults to an empty library (`:no_profile`), so ETL uses its built-in defaults unless you override it. As with any flag, the override can be made permanent in `.bazelrc`:
|
||||
|
||||
```
|
||||
# .bazelrc
|
||||
build --@etl//:etl_profile=//path/to:my_etl_profile
|
||||
```
|
||||
|
||||
> **Note:** Use the repository-qualified form `--@etl//:etl_profile=...` when consuming ETL as an
|
||||
> external dependency. When building from within the ETL repository itself, drop the repository
|
||||
> prefix: `--//:etl_profile=...`.
|
||||
|
||||
@ -3,7 +3,7 @@ title: "type_traits"
|
||||
---
|
||||
|
||||
Reverse engineered types traits classes from C++11 plus several ETL extensions.
|
||||
This file is generated from type_traits_generator.h. See Generators
|
||||
This file is generated from `type_traits_generator.h`. See Generators
|
||||
Not all traits have been defined as some rely on compiler intrinsics that are not available on all compiler platforms.
|
||||
|
||||
`integral_constant`
|
||||
@ -459,3 +459,20 @@ template <typename T, template <typename...> class Template>
|
||||
inline constexpr bool is_specialization_v = etl::is_specialization<T, Template>::value;
|
||||
```
|
||||
C++17
|
||||
|
||||
## is_object_pointer
|
||||
From: `20.49.0`
|
||||
|
||||
```cpp
|
||||
template <typename T>
|
||||
struct is_object_pointer
|
||||
```
|
||||
Checks if `T` is a pointer to an object.
|
||||
Pointers to functions and member functions return `false`.
|
||||
The result is found in the member `value`.
|
||||
|
||||
```cpp
|
||||
template <typename T>
|
||||
inline constexpr bool is_object_pointer_v = etl::is_object_pointer<T>::value;
|
||||
```
|
||||
C++17
|
||||
|
||||
@ -1 +1 @@
|
||||
20.48.0
|
||||
20.48.1
|
||||
|
||||
@ -914,6 +914,7 @@ namespace etl
|
||||
TDistance top_index = value_index;
|
||||
TDistance child2nd = (2 * value_index) + 2;
|
||||
|
||||
#include "etl/private/diagnostic_array_bounds_push.h"
|
||||
while (child2nd < length)
|
||||
{
|
||||
if (compare(*(first + child2nd), *(first + (child2nd - 1))))
|
||||
@ -931,6 +932,7 @@ namespace etl
|
||||
*(first + value_index) = ETL_MOVE(*(first + (child2nd - 1)));
|
||||
value_index = child2nd - 1;
|
||||
}
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
|
||||
push_heap(first, value_index, top_index, ETL_MOVE(value), compare);
|
||||
}
|
||||
@ -965,6 +967,12 @@ namespace etl
|
||||
typedef typename etl::iterator_traits<TIterator>::value_type value_t;
|
||||
typedef typename etl::iterator_traits<TIterator>::difference_type distance_t;
|
||||
|
||||
const distance_t n = last - first;
|
||||
if (n <= 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
value_t value = ETL_MOVE(*(last - 1));
|
||||
*(last - 1) = ETL_MOVE(*first);
|
||||
|
||||
@ -5844,6 +5852,8 @@ namespace etl
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_random_access_iterator<I>::value, "partial_sort requires random access iterators");
|
||||
|
||||
#include "etl/private/diagnostic_array_bounds_push.h"
|
||||
|
||||
I last_it = ranges::next(first, last);
|
||||
|
||||
if (first == middle || first == last_it)
|
||||
@ -5880,6 +5890,8 @@ namespace etl
|
||||
}
|
||||
|
||||
return last_it;
|
||||
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
}
|
||||
|
||||
template <class R, class Comp = ranges::less, class Proj = etl::identity, typename = etl::enable_if_t<etl::is_range_v<R>>>
|
||||
@ -5933,6 +5945,8 @@ namespace etl
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_random_access_iterator<I2>::value, "partial_sort_copy requires the output to be random access iterators");
|
||||
|
||||
#include "etl/private/diagnostic_array_bounds_push.h"
|
||||
|
||||
I1 in_last = ranges::next(first, last);
|
||||
I2 out_last = ranges::next(result_first, result_last);
|
||||
|
||||
@ -5970,7 +5984,6 @@ namespace etl
|
||||
}
|
||||
}
|
||||
|
||||
#include "etl/private/diagnostic_array_bounds_push.h"
|
||||
// Sort the heap to produce a sorted output range
|
||||
for (auto heap_end = heap_size - 1; heap_end > 0; --heap_end)
|
||||
{
|
||||
@ -7025,6 +7038,8 @@ namespace etl
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_random_access_iterator<I>::value, "pop_heap requires random access iterators");
|
||||
|
||||
#include "etl/private/diagnostic_array_bounds_push.h"
|
||||
|
||||
I last_it = ranges::next(first, last);
|
||||
|
||||
auto length = etl::distance(first, last_it);
|
||||
@ -7041,6 +7056,8 @@ namespace etl
|
||||
sift_down(first, decltype(length)(0), etl::distance(first, last_it), comp, proj);
|
||||
|
||||
return ranges::next(first, last);
|
||||
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
}
|
||||
|
||||
template <class R, class Comp = ranges::less, class Proj = etl::identity, typename = etl::enable_if_t<etl::is_range_v<R>>>
|
||||
|
||||
@ -296,6 +296,7 @@ namespace etl
|
||||
histogram(const histogram& other)
|
||||
{
|
||||
this->accumulator = other.accumulator;
|
||||
start_index = other.start_index;
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
@ -305,6 +306,7 @@ namespace etl
|
||||
histogram(histogram&& other)
|
||||
{
|
||||
this->accumulator = etl::move(other.accumulator);
|
||||
start_index = other.start_index;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -314,6 +316,7 @@ namespace etl
|
||||
histogram& operator=(const histogram& rhs)
|
||||
{
|
||||
this->accumulator = rhs.accumulator;
|
||||
start_index = rhs.start_index;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -325,6 +328,7 @@ namespace etl
|
||||
histogram& operator=(histogram&& rhs)
|
||||
{
|
||||
this->accumulator = etl::move(rhs.accumulator);
|
||||
start_index = rhs.start_index;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -227,11 +227,13 @@ namespace etl
|
||||
return ETL_NULLPTR == base::etl_parent;
|
||||
}
|
||||
|
||||
#include "private/diagnostic_null_dereference_push.h"
|
||||
ETL_NODISCARD
|
||||
link_type* get_parent()
|
||||
{
|
||||
return static_cast<link_type*>(base::etl_parent);
|
||||
}
|
||||
#include "private/diagnostic_pop.h"
|
||||
|
||||
ETL_NODISCARD
|
||||
const link_type* get_parent() const
|
||||
|
||||
@ -115,7 +115,7 @@ namespace etl
|
||||
{
|
||||
ETL_STATIC_ASSERT(Size >= Other_Size, "Other size is too large");
|
||||
|
||||
memcpy(buffer, other.buffer, Size_);
|
||||
memcpy(buffer, other.data(), Other_Size);
|
||||
}
|
||||
|
||||
//***********************************
|
||||
@ -126,7 +126,7 @@ namespace etl
|
||||
{
|
||||
ETL_STATIC_ASSERT(Size >= Other_Size, "RHS size is too large");
|
||||
|
||||
memcpy(buffer, rhs.buffer, Size_);
|
||||
memcpy(buffer, rhs.data(), Other_Size);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -74,6 +74,323 @@ namespace etl
|
||||
return etl::to_address(itr.operator->());
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP17 && defined(__cpp_lib_launder)
|
||||
using std::launder;
|
||||
#else
|
||||
//*****************************************************************************
|
||||
/// Obtains a pointer to the object created in the storage pointed to by p.
|
||||
/// Prevents the compiler from making invalid assumptions when the lifetime of
|
||||
/// an object has ended and a new object has been created in the same storage.
|
||||
/// T must not be a function type nor a (possibly cv-qualified) void type.
|
||||
/// https://en.cppreference.com/w/cpp/utility/launder
|
||||
///\ingroup memory
|
||||
//*****************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR17 T* launder(T* p) ETL_NOEXCEPT
|
||||
{
|
||||
#if ETL_USING_CPP11
|
||||
// etl::is_function is only defined for C++11 and later.
|
||||
ETL_STATIC_ASSERT(!etl::is_function<T>::value, "etl::launder argument must not be a function type");
|
||||
#endif
|
||||
ETL_STATIC_ASSERT(!etl::is_void<T>::value, "etl::launder argument must not be a void type");
|
||||
|
||||
#if defined(__has_builtin) && !defined(ETL_COMPILER_MICROSOFT)
|
||||
#if __has_builtin(__builtin_launder)
|
||||
return __builtin_launder(p);
|
||||
#else
|
||||
return p;
|
||||
#endif
|
||||
#elif ETL_USING_GCC_COMPILER && (ETL_COMPILER_FULL_VERSION >= 70000)
|
||||
// GCC 7, 8 and 9 provide __builtin_launder but not __has_builtin.
|
||||
return __builtin_launder(p);
|
||||
#else
|
||||
return p;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP23 && defined(__cpp_lib_start_lifetime_as)
|
||||
using std::start_lifetime_as;
|
||||
using std::start_lifetime_as_array;
|
||||
#else
|
||||
namespace private_memory
|
||||
{
|
||||
//*************************************************************************
|
||||
/// Implicitly create the objects in [p, p + n) and return a usable pointer
|
||||
/// to the first one. Used by start_lifetime_as / start_lifetime_as_array.
|
||||
//*************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
inline T* start_lifetime_as_impl(void* p, size_t n) ETL_NOEXCEPT
|
||||
{
|
||||
if (n == 0U)
|
||||
{
|
||||
// No objects are created, so there is nothing to launder.
|
||||
// Return the original pointer to preserve pointer identity.
|
||||
return static_cast<T*>(p);
|
||||
}
|
||||
|
||||
#if ETL_USING_BUILTIN_MEMMOVE
|
||||
void* const q = __builtin_memmove(p, p, sizeof(T) * n);
|
||||
#else
|
||||
void* const q = ::memmove(p, p, sizeof(T) * n);
|
||||
#endif
|
||||
|
||||
return etl::launder(static_cast<T*>(q));
|
||||
}
|
||||
} // namespace private_memory
|
||||
|
||||
//*****************************************************************************
|
||||
/// Implicitly creates an object of type T in the storage pointed to by p and
|
||||
/// starts its lifetime. T must be a trivially copyable (implicit-lifetime)
|
||||
/// type. The storage must be suitably sized and aligned for T.
|
||||
/// https://en.cppreference.com/w/cpp/memory/start_lifetime_as
|
||||
///\ingroup memory
|
||||
//*****************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
T* start_lifetime_as(void* p) ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
||||
return etl::private_memory::start_lifetime_as_impl<T>(p, 1U);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
const T* start_lifetime_as(const void* p) ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
||||
return etl::private_memory::start_lifetime_as_impl<const T>(const_cast<void*>(p), 1U);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
volatile T* start_lifetime_as(volatile void* p) ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
||||
return etl::private_memory::start_lifetime_as_impl<volatile T>(const_cast<void*>(p), 1U);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
const volatile T* start_lifetime_as(const volatile void* p) ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
||||
return etl::private_memory::start_lifetime_as_impl<const volatile T>(const_cast<void*>(p), 1U);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
/// Implicitly creates an array of n objects of type T in the storage pointed
|
||||
/// to by p and starts their lifetimes. T must be a trivially copyable
|
||||
/// (implicit-lifetime) type. Returns a pointer to the first element, or a
|
||||
/// pointer comparing equal to p when n is zero.
|
||||
/// https://en.cppreference.com/w/cpp/memory/start_lifetime_as
|
||||
///\ingroup memory
|
||||
//*****************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
T* start_lifetime_as_array(void* p, size_t n) ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
||||
return etl::private_memory::start_lifetime_as_impl<T>(p, n);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
const T* start_lifetime_as_array(const void* p, size_t n) ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
||||
return etl::private_memory::start_lifetime_as_impl<const T>(const_cast<void*>(p), n);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
volatile T* start_lifetime_as_array(volatile void* p, size_t n) ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
||||
return etl::private_memory::start_lifetime_as_impl<volatile T>(const_cast<void*>(p), n);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
const volatile T* start_lifetime_as_array(const volatile void* p, size_t n) ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
||||
return etl::private_memory::start_lifetime_as_impl<const volatile T>(const_cast<void*>(p), n);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP11
|
||||
using std::pointer_traits;
|
||||
#else
|
||||
#if ETL_USING_CPP11
|
||||
namespace private_memory
|
||||
{
|
||||
//*************************************************************************
|
||||
/// Decomposes a pointer-like class template of the form
|
||||
/// Pointer<Element, Args...> to recover its first template parameter and
|
||||
/// to rebind it to a different first parameter. Left undefined for types
|
||||
/// that are not such a template instantiation.
|
||||
//*************************************************************************
|
||||
template <typename T>
|
||||
struct pointer_traits_template;
|
||||
|
||||
template <template <typename, typename...> class Pointer, typename Element, typename... Args>
|
||||
struct pointer_traits_template<Pointer<Element, Args...> >
|
||||
{
|
||||
typedef Element type;
|
||||
|
||||
template <typename U>
|
||||
struct rebind
|
||||
{
|
||||
typedef Pointer<U, Args...> type;
|
||||
};
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Deduces the element_type of a pointer-like type. Prefers a nested
|
||||
/// T::element_type, otherwise falls back to the first template parameter.
|
||||
//*************************************************************************
|
||||
template <typename T, typename = void>
|
||||
struct pointer_traits_element_type
|
||||
{
|
||||
typedef typename pointer_traits_template<T>::type type;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pointer_traits_element_type<T, etl::void_t<typename T::element_type> >
|
||||
{
|
||||
typedef typename T::element_type type;
|
||||
};
|
||||
} // namespace private_memory
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
/// Provides information about pointer-like types. General case where the
|
||||
/// type itself models the pointer (fancy / smart pointers).
|
||||
/// https://en.cppreference.com/w/cpp/memory/pointer_traits
|
||||
///\ingroup memory
|
||||
//*****************************************************************************
|
||||
template <typename T>
|
||||
struct pointer_traits
|
||||
{
|
||||
typedef T pointer;
|
||||
#if ETL_USING_CPP11
|
||||
typedef typename private_memory::pointer_traits_element_type<T>::type element_type;
|
||||
#else
|
||||
typedef typename T::element_type element_type;
|
||||
#endif
|
||||
typedef ptrdiff_t difference_type;
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
template <typename U>
|
||||
using rebind = typename private_memory::pointer_traits_template<T>::template rebind<U>::type;
|
||||
#endif
|
||||
|
||||
ETL_NODISCARD
|
||||
static ETL_CONSTEXPR pointer pointer_to(element_type& r) ETL_NOEXCEPT
|
||||
{
|
||||
return T::pointer_to(r);
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
/// Provides information about pointer-like types. Raw pointer specialisation.
|
||||
/// https://en.cppreference.com/w/cpp/memory/pointer_traits
|
||||
///\ingroup memory
|
||||
//*****************************************************************************
|
||||
template <typename T>
|
||||
struct pointer_traits<T*>
|
||||
{
|
||||
typedef T* pointer;
|
||||
typedef T element_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
template <typename U>
|
||||
using rebind = U*;
|
||||
#endif
|
||||
|
||||
ETL_NODISCARD
|
||||
static ETL_CONSTEXPR pointer pointer_to(element_type& r) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::addressof(r);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP11
|
||||
using std::align;
|
||||
#else
|
||||
//*****************************************************************************
|
||||
/// Aligns a pointer within a buffer. Advances 'ptr' to the next address with
|
||||
/// the given 'alignment' that can hold 'size' bytes within 'space' bytes,
|
||||
/// shrinking 'space' by the consumed padding. Returns the aligned pointer, or
|
||||
/// ETL_NULLPTR when the buffer is too small. 'alignment' must be a power of 2;
|
||||
/// the behaviour is undefined if it is not.
|
||||
/// https://en.cppreference.com/w/cpp/memory/align
|
||||
///\ingroup memory
|
||||
//*****************************************************************************
|
||||
inline void* align(size_t alignment, size_t size, void*& ptr, size_t& space) ETL_NOEXCEPT
|
||||
{
|
||||
const uintptr_t p = reinterpret_cast<uintptr_t>(ptr);
|
||||
const uintptr_t aligned = (p + (alignment - 1U)) & ~(static_cast<uintptr_t>(alignment) - 1U);
|
||||
const size_t padding = static_cast<size_t>(aligned - p);
|
||||
|
||||
if ((padding > space) || (size > (space - padding)))
|
||||
{
|
||||
return ETL_NULLPTR;
|
||||
}
|
||||
|
||||
space -= padding;
|
||||
ptr = reinterpret_cast<void*>(aligned);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP20 && defined(__cpp_lib_assume_aligned)
|
||||
using std::assume_aligned;
|
||||
#else
|
||||
//*****************************************************************************
|
||||
/// Informs the compiler that the pointer 'ptr' is aligned to at least N bytes
|
||||
/// and returns it. N must be a power of 2. Behaviour is undefined if 'ptr' is
|
||||
/// not actually aligned to N.
|
||||
/// https://en.cppreference.com/w/cpp/memory/assume_aligned
|
||||
///\ingroup memory
|
||||
//*****************************************************************************
|
||||
template <size_t N, typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR T* assume_aligned(T* ptr) ETL_NOEXCEPT
|
||||
{
|
||||
#if defined(__has_builtin) && !defined(ETL_COMPILER_MICROSOFT)
|
||||
#if __has_builtin(__builtin_assume_aligned)
|
||||
return static_cast<T*>(__builtin_assume_aligned(ptr, N));
|
||||
#else
|
||||
return ptr;
|
||||
#endif
|
||||
#else
|
||||
return ptr;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP26 && defined(__cpp_lib_is_sufficiently_aligned)
|
||||
using std::is_sufficiently_aligned;
|
||||
#else
|
||||
//*****************************************************************************
|
||||
/// Checks whether 'ptr' is aligned to at least Alignment bytes.
|
||||
/// Alignment must be a power of 2.
|
||||
/// https://en.cppreference.com/w/cpp/memory/is_sufficiently_aligned
|
||||
///\ingroup memory
|
||||
//*****************************************************************************
|
||||
template <size_t Alignment, typename T>
|
||||
ETL_NODISCARD
|
||||
bool is_sufficiently_aligned(T* ptr) ETL_NOEXCEPT
|
||||
{
|
||||
return (reinterpret_cast<uintptr_t>(ptr) % Alignment) == 0U;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ETL_USING_STL
|
||||
//*****************************************************************************
|
||||
/// Fills uninitialised memory range with a value.
|
||||
|
||||
@ -379,7 +379,7 @@ namespace etl
|
||||
if (timer.is_active())
|
||||
{
|
||||
ETL_DISABLE_TIMER_UPDATES;
|
||||
active_list.remove(timer.id, true);
|
||||
active_list.remove(timer.id, false);
|
||||
remove_callback.call_if(timer.id);
|
||||
ETL_ENABLE_TIMER_UPDATES;
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ namespace etl
|
||||
if (timer.is_active())
|
||||
{
|
||||
++process_semaphore;
|
||||
active_list.remove(timer.id, true);
|
||||
active_list.remove(timer.id, false);
|
||||
remove_callback.call_if(timer.id);
|
||||
--process_semaphore;
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ namespace etl
|
||||
TInterruptGuard guard;
|
||||
(void)guard; // Silence 'unused variable warnings.
|
||||
|
||||
active_list.remove(timer.id, true);
|
||||
active_list.remove(timer.id, false);
|
||||
remove_callback.call_if(timer.id);
|
||||
}
|
||||
|
||||
|
||||
@ -111,7 +111,7 @@ namespace etl
|
||||
if (timer.is_active())
|
||||
{
|
||||
lock();
|
||||
active_list.remove(timer.id, true);
|
||||
active_list.remove(timer.id, false);
|
||||
remove_callback.call_if(timer.id);
|
||||
unlock();
|
||||
}
|
||||
|
||||
@ -93,6 +93,7 @@ namespace etl
|
||||
void reset()
|
||||
{
|
||||
hash.fill(0);
|
||||
first = true;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -311,6 +311,11 @@ namespace etl
|
||||
// Build from the string.
|
||||
string_length = etl::min(active_bits, string_length);
|
||||
|
||||
if (string_length == 0U)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
element_type mask = element_type(element_type(1) << (string_length - 1U));
|
||||
|
||||
for (size_t i = 0U; i < string_length; ++i)
|
||||
@ -339,6 +344,11 @@ namespace etl
|
||||
// Build from the string.
|
||||
string_length = etl::min(active_bits, string_length);
|
||||
|
||||
if (string_length == 0U)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
element_type mask = element_type(element_type(1) << (string_length - 1U));
|
||||
|
||||
for (size_t i = 0U; i < string_length; ++i)
|
||||
@ -367,6 +377,11 @@ namespace etl
|
||||
// Build from the string.
|
||||
string_length = etl::min(active_bits, string_length);
|
||||
|
||||
if (string_length == 0U)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
element_type mask = element_type(element_type(1) << (string_length - 1U));
|
||||
|
||||
for (size_t i = 0U; i < string_length; ++i)
|
||||
@ -395,6 +410,11 @@ namespace etl
|
||||
// Build from the string.
|
||||
string_length = etl::min(active_bits, string_length);
|
||||
|
||||
if (string_length == 0U)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
element_type mask = element_type(element_type(1) << (string_length - 1U));
|
||||
|
||||
for (size_t i = 0U; i < string_length; ++i)
|
||||
|
||||
@ -184,5 +184,64 @@ namespace etl
|
||||
|
||||
template <typename TDuration>
|
||||
constexpr int etl::chrono::hh_mm_ss<TDuration>::fractional_width;
|
||||
|
||||
//***********************************************************************
|
||||
/// 12/24 hours functions
|
||||
//***********************************************************************
|
||||
|
||||
//***********************************************************************
|
||||
/// Returns true if h is in the range [0h, 11h] (an am hour).
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD
|
||||
inline ETL_CONSTEXPR14 bool is_am(const etl::chrono::hours& h) ETL_NOEXCEPT
|
||||
{
|
||||
return (h >= etl::chrono::hours(0)) && (h <= etl::chrono::hours(11));
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Returns true if h is in the range [12h, 23h] (a pm hour).
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD
|
||||
inline ETL_CONSTEXPR14 bool is_pm(const etl::chrono::hours& h) ETL_NOEXCEPT
|
||||
{
|
||||
return (h >= etl::chrono::hours(12)) && (h <= etl::chrono::hours(23));
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Returns the 12-hour equivalent of h in the range [1h, 12h].
|
||||
/// If h is not in the range [0h, 23h], the value returned is unspecified.
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD
|
||||
inline ETL_CONSTEXPR14 etl::chrono::hours make12(const etl::chrono::hours& h) ETL_NOEXCEPT
|
||||
{
|
||||
if (h == etl::chrono::hours(0))
|
||||
{
|
||||
return etl::chrono::hours(12);
|
||||
}
|
||||
else if (h > etl::chrono::hours(12))
|
||||
{
|
||||
return h - etl::chrono::hours(12);
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Returns the 24-hour equivalent of h, which is assumed to represent the
|
||||
/// hour with the indicated am/pm.
|
||||
/// If h is not in the range [1h, 12h], the value returned is unspecified.
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD
|
||||
inline ETL_CONSTEXPR14 etl::chrono::hours make24(const etl::chrono::hours& h, bool is_pm) ETL_NOEXCEPT
|
||||
{
|
||||
if (is_pm)
|
||||
{
|
||||
return (h == etl::chrono::hours(12)) ? h : (h + etl::chrono::hours(12));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (h == etl::chrono::hours(12)) ? etl::chrono::hours(0) : h;
|
||||
}
|
||||
}
|
||||
} // namespace chrono
|
||||
} // namespace etl
|
||||
|
||||
@ -122,6 +122,48 @@ namespace etl
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Pre-increments the stored duration by one tick.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 time_point& operator++() ETL_NOEXCEPT
|
||||
{
|
||||
++dur;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Post-increments the stored duration by one tick.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 time_point operator++(int) ETL_NOEXCEPT
|
||||
{
|
||||
time_point temp(*this);
|
||||
++dur;
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Pre-decrements the stored duration by one tick.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 time_point& operator--() ETL_NOEXCEPT
|
||||
{
|
||||
--dur;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Post-decrements the stored duration by one tick.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 time_point operator--(int) ETL_NOEXCEPT
|
||||
{
|
||||
time_point temp(*this);
|
||||
--dur;
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Returns a time_point with the smallest possible duration.
|
||||
//***************************************************************************
|
||||
@ -200,6 +242,59 @@ namespace etl
|
||||
return etl::chrono::time_point<TClock, TToDuration>(dur);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Adds a duration to a time_point.
|
||||
/// Returns a time_point whose duration is the common type of the two.
|
||||
//***************************************************************************
|
||||
template <typename TClock, typename TDuration1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14 etl::chrono::time_point<TClock, typename etl::common_type<TDuration1, etl::chrono::duration<TRep2, TPeriod2> >::type>
|
||||
operator+(const time_point<TClock, TDuration1>& lhs, const etl::chrono::duration<TRep2, TPeriod2>& rhs) ETL_NOEXCEPT
|
||||
{
|
||||
using common_duration = typename etl::common_type<TDuration1, etl::chrono::duration<TRep2, TPeriod2> >::type;
|
||||
using result_time_point = etl::chrono::time_point<TClock, common_duration>;
|
||||
|
||||
return result_time_point(lhs.time_since_epoch() + rhs);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Adds a time_point to a duration.
|
||||
/// Returns a time_point whose duration is the common type of the two.
|
||||
//***************************************************************************
|
||||
template <typename TRep1, typename TPeriod1, typename TClock, typename TDuration2>
|
||||
ETL_CONSTEXPR14 etl::chrono::time_point<TClock, typename etl::common_type<etl::chrono::duration<TRep1, TPeriod1>, TDuration2>::type>
|
||||
operator+(const etl::chrono::duration<TRep1, TPeriod1>& lhs, const time_point<TClock, TDuration2>& rhs) ETL_NOEXCEPT
|
||||
{
|
||||
using common_duration = typename etl::common_type<etl::chrono::duration<TRep1, TPeriod1>, TDuration2>::type;
|
||||
using result_time_point = etl::chrono::time_point<TClock, common_duration>;
|
||||
|
||||
return result_time_point(lhs + rhs.time_since_epoch());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Subtracts a duration from a time_point.
|
||||
/// Returns a time_point whose duration is the common type of the two.
|
||||
//***************************************************************************
|
||||
template <typename TClock, typename TDuration1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14 etl::chrono::time_point<TClock, typename etl::common_type<TDuration1, etl::chrono::duration<TRep2, TPeriod2> >::type>
|
||||
operator-(const time_point<TClock, TDuration1>& lhs, const etl::chrono::duration<TRep2, TPeriod2>& rhs) ETL_NOEXCEPT
|
||||
{
|
||||
using common_duration = typename etl::common_type<TDuration1, etl::chrono::duration<TRep2, TPeriod2> >::type;
|
||||
using result_time_point = etl::chrono::time_point<TClock, common_duration>;
|
||||
|
||||
return result_time_point(lhs.time_since_epoch() - rhs);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Subtracts one time_point from another.
|
||||
/// Returns the duration between them as the common type of the two durations.
|
||||
//***************************************************************************
|
||||
template <typename TClock, typename TDuration1, typename TDuration2>
|
||||
ETL_CONSTEXPR14 typename etl::common_type<TDuration1, TDuration2>::type operator-(const time_point<TClock, TDuration1>& lhs,
|
||||
const time_point<TClock, TDuration2>& rhs) ETL_NOEXCEPT
|
||||
{
|
||||
return lhs.time_since_epoch() - rhs.time_since_epoch();
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Equality operator
|
||||
//***************************************************************************
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -715,7 +715,7 @@ namespace etl
|
||||
using type = etl::remove_cvref_t<T>;
|
||||
|
||||
do_destroy();
|
||||
do_construct<type>(type(etl::forward<TArgs>(args)...));
|
||||
do_emplace<type>(etl::forward<TArgs>(args)...);
|
||||
|
||||
type_id = index_of_type<T>::value;
|
||||
|
||||
@ -735,7 +735,7 @@ namespace etl
|
||||
using type = etl::remove_cvref_t<T>;
|
||||
|
||||
do_destroy();
|
||||
do_construct<type>(type(il, etl::forward<TArgs>(args)...));
|
||||
do_emplace<type>(il, etl::forward<TArgs>(args)...);
|
||||
|
||||
type_id = index_of_type<T>::value;
|
||||
|
||||
@ -755,7 +755,7 @@ namespace etl
|
||||
using type = type_from_index<Index>;
|
||||
|
||||
do_destroy();
|
||||
do_construct<type>(type(etl::forward<TArgs>(args)...));
|
||||
do_emplace<type>(etl::forward<TArgs>(args)...);
|
||||
|
||||
type_id = Index;
|
||||
|
||||
@ -775,7 +775,7 @@ namespace etl
|
||||
using type = type_from_index<Index>;
|
||||
|
||||
do_destroy();
|
||||
do_construct<type>(type(il, etl::forward<TArgs>(args)...));
|
||||
do_emplace<type>(il, etl::forward<TArgs>(args)...);
|
||||
|
||||
type_id = Index;
|
||||
|
||||
@ -1096,6 +1096,32 @@ namespace etl
|
||||
private_variant::variant_operations<0, TTypes...>::destroy(data, type_id);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Emplace-construct the alternative in place from forwarded args.
|
||||
/// No temporary, so no move/copy is required (works for move-hostile types).
|
||||
//***************************************************************************
|
||||
template <typename T, typename... TArgs>
|
||||
void do_emplace(TArgs&&... args)
|
||||
{
|
||||
do_emplace_impl<T>(etl::integral_constant<bool, Is_Trivially_Destructible_Suite>{}, etl::forward<TArgs>(args)...);
|
||||
}
|
||||
|
||||
// Trivially destructible suite: storage is a variadic_union. The old member is
|
||||
// trivially destructible, so placement-new of the new member is well-defined at
|
||||
// runtime (emplace is not constexpr, so placement-new is permitted here).
|
||||
template <typename T, typename... TArgs>
|
||||
void do_emplace_impl(etl::integral_constant<bool, true>, TArgs&&... args)
|
||||
{
|
||||
::new (static_cast<void*>(etl::addressof(private_variant::variadic_union_get<index_of_type<T>::value>(data)))) T(etl::forward<TArgs>(args)...);
|
||||
}
|
||||
|
||||
// Non-trivially destructible suite: storage is an uninitialized_buffer.
|
||||
template <typename T, typename... TArgs>
|
||||
void do_emplace_impl(etl::integral_constant<bool, false>, TArgs&&... args)
|
||||
{
|
||||
::new (static_cast<char*>(data)) T(etl::forward<TArgs>(args)...);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Construct a value in the union or buffer storage.
|
||||
//***************************************************************************
|
||||
@ -1108,8 +1134,12 @@ namespace etl
|
||||
template <typename T, typename U>
|
||||
void do_construct_impl(U&& value, etl::integral_constant<bool, true>)
|
||||
{
|
||||
// Trivially destructible: assign directly into the variadic_union.
|
||||
private_variant::variadic_union_get<index_of_type<T>::value>(data) = etl::forward<U>(value);
|
||||
// Begin the lifetime of the new alternative via placement new. The target
|
||||
// union member is not alive after do_destroy(), and the alternative may be
|
||||
// non-assignable (e.g. reference or const members), so assignment would be
|
||||
// both undefined behaviour and ill-formed for such types. Use etl::addressof
|
||||
// so the raw storage address is used even for types that overload operator&.
|
||||
::new (static_cast<void*>(etl::addressof(private_variant::variadic_union_get<index_of_type<T>::value>(data)))) T(etl::forward<U>(value));
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
|
||||
@ -167,6 +167,15 @@ SOFTWARE.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(ETL_COMPILER_MICROSOFT) // The Microsoft compiler supports the __is_trivially_copyable
|
||||
// intrinsic directly. __has_builtin is not used for Microsoft
|
||||
// (see above) to avoid a VS2022 intellisense issue, so the
|
||||
// intrinsic is enabled here for the no-STL configuration.
|
||||
#if !defined(ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE)
|
||||
#define ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// The default. Set to 0, if not already set.
|
||||
#if !defined(ETL_USING_BUILTIN_IS_ASSIGNABLE)
|
||||
#define ETL_USING_BUILTIN_IS_ASSIGNABLE 0
|
||||
|
||||
@ -1491,14 +1491,14 @@ namespace etl
|
||||
span(const etl::array<T, Size>&) -> span<const T, Size>;
|
||||
|
||||
// Forward declaration of etl::ivector
|
||||
template <typename T>
|
||||
template <typename T, typename Enable>
|
||||
class ivector;
|
||||
|
||||
template <typename T>
|
||||
span(etl::ivector<T>&) -> span<T>;
|
||||
template <typename T, typename Enable>
|
||||
span(etl::ivector<T, Enable>&) -> span<T>;
|
||||
|
||||
template <typename T>
|
||||
span(const etl::ivector<T>&) -> span<const T>;
|
||||
template <typename T, typename Enable>
|
||||
span(const etl::ivector<T, Enable>&) -> span<const T>;
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP11
|
||||
template <typename T, size_t Size>
|
||||
|
||||
@ -3909,6 +3909,32 @@ namespace etl
|
||||
#endif
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Is T a member pointer
|
||||
//***************************************************************************
|
||||
namespace private_type_traits
|
||||
{
|
||||
template <typename T>
|
||||
struct is_member_pointer_helper : etl::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <typename T, typename TObject>
|
||||
struct is_member_pointer_helper<T TObject::*> : etl::true_type
|
||||
{
|
||||
};
|
||||
} // namespace private_type_traits
|
||||
|
||||
template <typename T>
|
||||
struct is_member_pointer : private_type_traits::is_member_pointer_helper< typename etl::remove_cv<T>::type>
|
||||
{
|
||||
};
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
template <typename T>
|
||||
inline constexpr bool is_member_pointer_v = etl::is_member_pointer<T>::value;
|
||||
#endif
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
//*********************************
|
||||
/// Check if T is a function type
|
||||
@ -4008,6 +4034,15 @@ namespace etl
|
||||
inline constexpr bool is_function_v = etl::is_function<T>::value;
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
template <typename T>
|
||||
struct is_function : etl::bool_constant<!etl::is_member_pointer<T>::value && !etl::is_const<const T>::value && !etl::is_reference<T>::value>
|
||||
{
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// is_object
|
||||
//***************************************************************************
|
||||
@ -4016,10 +4051,22 @@ namespace etl
|
||||
{
|
||||
};
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
#if ETL_USING_CPP17
|
||||
template <typename T>
|
||||
inline constexpr bool is_object_v = etl::is_object<T>::value;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// is_object_pointer
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
struct is_object_pointer : etl::bool_constant<etl::is_pointer<T>::value && etl::is_object<typename etl::remove_pointer<T>::type>::value>
|
||||
{
|
||||
};
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
template <typename T>
|
||||
inline constexpr bool is_object_pointer_v = etl::is_object_pointer<T>::value;
|
||||
#endif
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
@ -4075,32 +4122,6 @@ namespace etl
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Is T a member pointer
|
||||
//***************************************************************************
|
||||
namespace private_type_traits
|
||||
{
|
||||
template <typename T>
|
||||
struct is_member_pointer_helper : etl::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <typename T, typename TObject>
|
||||
struct is_member_pointer_helper<T TObject::*> : etl::true_type
|
||||
{
|
||||
};
|
||||
} // namespace private_type_traits
|
||||
|
||||
template <typename T>
|
||||
struct is_member_pointer : private_type_traits::is_member_pointer_helper< typename etl::remove_cv<T>::type>
|
||||
{
|
||||
};
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
template <typename T>
|
||||
inline constexpr bool is_member_pointer_v = etl::is_member_pointer<T>::value;
|
||||
#endif
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
//***************************************************************************
|
||||
/// Is T a member function pointer
|
||||
|
||||
@ -490,6 +490,7 @@ namespace etl
|
||||
};
|
||||
|
||||
#if ETL_NOT_USING_STL || ETL_CPP14_NOT_SUPPORTED
|
||||
#if ETL_CPP11_NOT_SUPPORTED
|
||||
//***************************************************************************
|
||||
/// exchange (const)
|
||||
//***************************************************************************
|
||||
@ -500,7 +501,6 @@ namespace etl
|
||||
object = new_value;
|
||||
return old_value;
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
T exchange(T& object, const U& new_value)
|
||||
{
|
||||
@ -508,16 +508,30 @@ namespace etl
|
||||
object = new_value;
|
||||
return old_value;
|
||||
}
|
||||
#else
|
||||
#else
|
||||
//***************************************************************************
|
||||
/// exchange (const)
|
||||
/// exchange
|
||||
//***************************************************************************
|
||||
template <typename T, typename U = T>
|
||||
T exchange(T& object, const U& new_value)
|
||||
ETL_CONSTEXPR14 T exchange(T& object, U&& new_value)
|
||||
ETL_NOEXCEPT_IF((etl::is_nothrow_move_constructible<T>::value && etl::is_nothrow_assignable<T&, U>::value))
|
||||
{
|
||||
return std::exchange(object, new_value);
|
||||
T old_value = etl::move(object);
|
||||
object = etl::forward<U>(new_value);
|
||||
return old_value;
|
||||
}
|
||||
#endif
|
||||
#endif // ETL_CPP11_NOT_SUPPORTED
|
||||
#else
|
||||
//***************************************************************************
|
||||
/// exchange
|
||||
//***************************************************************************
|
||||
template <typename T, typename U = T>
|
||||
ETL_CONSTEXPR14 T exchange(T& object, U&& new_value)
|
||||
ETL_NOEXCEPT_IF((etl::is_nothrow_move_constructible<T>::value && etl::is_nothrow_assignable<T&, U>::value))
|
||||
{
|
||||
return std::exchange(object, etl::forward<U>(new_value));
|
||||
}
|
||||
#endif // ETL_NOT_USING_STL || ETL_CPP14_NOT_SUPPORTED
|
||||
|
||||
//***************************************************************************
|
||||
/// as_const
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -40,7 +40,7 @@ SOFTWARE.
|
||||
|
||||
#define ETL_VERSION_MAJOR 20
|
||||
#define ETL_VERSION_MINOR 48
|
||||
#define ETL_VERSION_PATCH 0
|
||||
#define ETL_VERSION_PATCH 1
|
||||
|
||||
#define ETL_VERSION \
|
||||
ETL_STRING(ETL_VERSION_MAJOR) \
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Embedded Template Library",
|
||||
"version": "20.48.0",
|
||||
"version": "20.48.1",
|
||||
"authors": {
|
||||
"name": "John Wellbelove",
|
||||
"email": "john.wellbelove@etlcpp.com"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name=Embedded Template Library
|
||||
version=20.48.0
|
||||
version=20.48.1
|
||||
author= John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
license=MIT
|
||||
|
||||
@ -1,4 +1,21 @@
|
||||
===============================================================================
|
||||
20.48.1
|
||||
|
||||
#1477 Fix for 1405: etl::exchange doesn't work with unique_ptr
|
||||
#1484 Fix etl::message_timer firing following timers early on unregister
|
||||
#1485 Fix etl::histogram copy/move not preserving start_index
|
||||
#1486 Fix etl::bitset single-element from_string shift on empty string
|
||||
#1487 Fix etl::pearson::reset() not resetting the first-byte flag
|
||||
#1488 Fix etl::mem_cast cross-size copy constructor and assignment
|
||||
#1489 Add missing interfaces to etl::chrono
|
||||
#1490 Add missing memory functions, according the standard
|
||||
#1491 Add optional etl_profile label_flag for Bazel profile injection
|
||||
#1492 Allow etl::vector to store pointers to functions and member functions
|
||||
#1494 Refactor variant::emplace to perfect forward args instead of copy/move construct
|
||||
#1495 Separate bit order and endianness in bit_stream.h
|
||||
#1496 Fix non-assignable alternatives in variant
|
||||
|
||||
===============================================================================
|
||||
20.48.0
|
||||
|
||||
#1375 Support for C++26
|
||||
|
||||
@ -375,6 +375,10 @@ add_executable(etl_tests
|
||||
test_vector_non_trivial.cpp
|
||||
test_vector_pointer.cpp
|
||||
test_vector_pointer_external_buffer.cpp
|
||||
test_vector_function_pointer.cpp
|
||||
test_vector_function_pointer_external_buffer.cpp
|
||||
test_vector_member_function_pointer.cpp
|
||||
test_vector_member_function_pointer_external_buffer.cpp
|
||||
test_visitor.cpp
|
||||
test_xor_checksum.cpp
|
||||
test_xor_rotate_checksum.cpp
|
||||
|
||||
@ -363,6 +363,10 @@ etl_test_sources = files(
|
||||
'test_vector_non_trivial.cpp',
|
||||
'test_vector_pointer.cpp',
|
||||
'test_vector_pointer_external_buffer.cpp',
|
||||
'test_vector_function_pointer.cpp',
|
||||
'test_vector_function_pointer_external_buffer.cpp',
|
||||
'test_vector_member_function_pointer.cpp',
|
||||
'test_vector_member_function_pointer_external_buffer.cpp',
|
||||
'test_visitor.cpp',
|
||||
'test_xor_checksum.cpp',
|
||||
'test_xor_rotate_checksum.cpp'
|
||||
|
||||
@ -398,6 +398,22 @@ namespace
|
||||
CHECK_EQUAL(0, data.count());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Empty strings exercise the string_length == 0 path in from_string,
|
||||
// which must not shift by (0 - 1U).
|
||||
TEST(test_construct_from_empty_string)
|
||||
{
|
||||
etl::bitset<64, uint64_t> data_char("");
|
||||
etl::bitset<64, uint64_t> data_wchar(L"");
|
||||
etl::bitset<64, uint64_t> data_u16(u"");
|
||||
etl::bitset<64, uint64_t> data_u32(U"");
|
||||
|
||||
CHECK_EQUAL(0U, data_char.count());
|
||||
CHECK_EQUAL(0U, data_wchar.count());
|
||||
CHECK_EQUAL(0U, data_u16.count());
|
||||
CHECK_EQUAL(0U, data_u32.count());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_excess_string)
|
||||
{
|
||||
|
||||
@ -286,5 +286,86 @@ namespace
|
||||
CHECK_EQUAL(0, time.fractional_width);
|
||||
CHECK_TRUE((std::is_same<duration_type, Chrono::hh_mm_ss<duration_type>::precision>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_is_am)
|
||||
{
|
||||
for (int h = 0; h <= 11; ++h)
|
||||
{
|
||||
CHECK_TRUE(Chrono::is_am(Chrono::hours(h)));
|
||||
}
|
||||
|
||||
for (int h = 12; h <= 23; ++h)
|
||||
{
|
||||
CHECK_FALSE(Chrono::is_am(Chrono::hours(h)));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_is_pm)
|
||||
{
|
||||
for (int h = 0; h <= 11; ++h)
|
||||
{
|
||||
CHECK_FALSE(Chrono::is_pm(Chrono::hours(h)));
|
||||
}
|
||||
|
||||
for (int h = 12; h <= 23; ++h)
|
||||
{
|
||||
CHECK_TRUE(Chrono::is_pm(Chrono::hours(h)));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_make12)
|
||||
{
|
||||
// Midnight (0h) maps to 12h.
|
||||
CHECK_EQUAL(12, Chrono::make12(Chrono::hours(0)).count());
|
||||
|
||||
// 1h..12h are unchanged.
|
||||
for (int h = 1; h <= 12; ++h)
|
||||
{
|
||||
CHECK_EQUAL(h, Chrono::make12(Chrono::hours(h)).count());
|
||||
}
|
||||
|
||||
// 13h..23h map to 1h..11h.
|
||||
for (int h = 13; h <= 23; ++h)
|
||||
{
|
||||
CHECK_EQUAL(h - 12, Chrono::make12(Chrono::hours(h)).count());
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_make24)
|
||||
{
|
||||
// am: 12h maps to 0h, 1h..11h are unchanged.
|
||||
CHECK_EQUAL(0, Chrono::make24(Chrono::hours(12), false).count());
|
||||
|
||||
for (int h = 1; h <= 11; ++h)
|
||||
{
|
||||
CHECK_EQUAL(h, Chrono::make24(Chrono::hours(h), false).count());
|
||||
}
|
||||
|
||||
// pm: 12h stays 12h, 1h..11h map to 13h..23h.
|
||||
CHECK_EQUAL(12, Chrono::make24(Chrono::hours(12), true).count());
|
||||
|
||||
for (int h = 1; h <= 11; ++h)
|
||||
{
|
||||
CHECK_EQUAL(h + 12, Chrono::make24(Chrono::hours(h), true).count());
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_make12_make24_round_trip)
|
||||
{
|
||||
// For every 24-hour value, make12 plus its am/pm flag round-trips via make24.
|
||||
for (int h = 0; h <= 23; ++h)
|
||||
{
|
||||
Chrono::hours h24(h);
|
||||
bool pm = Chrono::is_pm(h24);
|
||||
Chrono::hours h12 = Chrono::make12(h24);
|
||||
|
||||
CHECK_EQUAL(h, Chrono::make24(h12, pm).count());
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -185,6 +185,99 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_operator_plus_time_point_duration)
|
||||
{
|
||||
TimePoint tp{Chrono::hours(10)};
|
||||
|
||||
// Same duration type.
|
||||
auto result = tp + Chrono::hours(5);
|
||||
CHECK_EQUAL(15, result.time_since_epoch().count());
|
||||
|
||||
// Mixed duration types resolve to the common (finer) type.
|
||||
auto result_mixed = tp + Chrono::days(1); // 10 hours + 24 hours
|
||||
CHECK_EQUAL(34, result_mixed.time_since_epoch().count());
|
||||
CHECK_TRUE((std::is_same<decltype(result_mixed)::duration, Chrono::hours>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_operator_plus_duration_time_point)
|
||||
{
|
||||
TimePoint tp{Chrono::hours(10)};
|
||||
|
||||
// Same duration type.
|
||||
auto result = Chrono::hours(5) + tp;
|
||||
CHECK_EQUAL(15, result.time_since_epoch().count());
|
||||
|
||||
// Mixed duration types resolve to the common (finer) type.
|
||||
auto result_mixed = Chrono::days(1) + tp; // 24 hours + 10 hours
|
||||
CHECK_EQUAL(34, result_mixed.time_since_epoch().count());
|
||||
CHECK_TRUE((std::is_same<decltype(result_mixed)::duration, Chrono::hours>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_operator_minus_time_point_duration)
|
||||
{
|
||||
TimePoint tp{Chrono::hours(50)};
|
||||
|
||||
// Same duration type.
|
||||
auto result = tp - Chrono::hours(5);
|
||||
CHECK_EQUAL(45, result.time_since_epoch().count());
|
||||
|
||||
// Mixed duration types resolve to the common (finer) type.
|
||||
auto result_mixed = tp - Chrono::days(1); // 50 hours - 24 hours
|
||||
CHECK_EQUAL(26, result_mixed.time_since_epoch().count());
|
||||
CHECK_TRUE((std::is_same<decltype(result_mixed)::duration, Chrono::hours>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_operator_minus_time_point_time_point)
|
||||
{
|
||||
TimePoint tp1{Chrono::hours(50)};
|
||||
TimePoint tp2{Chrono::hours(20)};
|
||||
|
||||
// Subtracting two time_points yields the duration between them.
|
||||
auto diff = tp1 - tp2;
|
||||
CHECK_EQUAL(30, diff.count());
|
||||
CHECK_TRUE((std::is_same<decltype(diff), Chrono::hours>::value));
|
||||
|
||||
// Mixed duration types resolve to the common (finer) duration.
|
||||
Chrono::time_point<test_clock, Chrono::days> tp_days{Chrono::days(2)}; // 48 hours
|
||||
auto diff_mixed = tp1 - tp_days; // 50 hours - 48 hours
|
||||
CHECK_EQUAL(2, diff_mixed.count());
|
||||
CHECK_TRUE((std::is_same<decltype(diff_mixed), Chrono::hours>::value));
|
||||
|
||||
// The reverse difference is negative.
|
||||
auto diff_negative = tp2 - tp1;
|
||||
CHECK_EQUAL(-30, diff_negative.count());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_increment_decrement_operators)
|
||||
{
|
||||
TimePoint tp{Chrono::hours(10)};
|
||||
|
||||
// Pre-increment.
|
||||
auto& pre_inc = ++tp;
|
||||
CHECK_EQUAL(11, tp.time_since_epoch().count());
|
||||
CHECK_EQUAL(11, pre_inc.time_since_epoch().count());
|
||||
|
||||
// Post-increment returns the previous value.
|
||||
TimePoint post_inc = tp++;
|
||||
CHECK_EQUAL(11, post_inc.time_since_epoch().count());
|
||||
CHECK_EQUAL(12, tp.time_since_epoch().count());
|
||||
|
||||
// Pre-decrement.
|
||||
auto& pre_dec = --tp;
|
||||
CHECK_EQUAL(11, tp.time_since_epoch().count());
|
||||
CHECK_EQUAL(11, pre_dec.time_since_epoch().count());
|
||||
|
||||
// Post-decrement returns the previous value.
|
||||
TimePoint post_dec = tp--;
|
||||
CHECK_EQUAL(11, post_dec.time_since_epoch().count());
|
||||
CHECK_EQUAL(10, tp.time_since_epoch().count());
|
||||
}
|
||||
|
||||
#if ETL_USING_ETL_CHRONO
|
||||
//*************************************************************************
|
||||
TEST(test_min_max_time_point)
|
||||
|
||||
@ -593,6 +593,7 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_conversion_operator_for_forward_iterator)
|
||||
{
|
||||
#include "etl/private/diagnostic_null_dereference_push.h"
|
||||
DataF data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
|
||||
etl::circular_iterator<DataF::const_iterator> ci(std::begin(data), std::end(data));
|
||||
@ -607,6 +608,7 @@ namespace
|
||||
++itr;
|
||||
++ci;
|
||||
CHECK(itr == ci.current());
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -2306,7 +2306,9 @@ namespace
|
||||
|
||||
data.fill(N999);
|
||||
|
||||
#include "etl/private/diagnostic_uninitialized_push.h"
|
||||
CHECK(std::equal(blank_data.begin(), blank_data.end(), data.begin()));
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -2319,6 +2321,7 @@ namespace
|
||||
// Access via const_iterator operator[]
|
||||
DataNDC::const_iterator cit = cdata.begin();
|
||||
|
||||
#include "etl/private/diagnostic_uninitialized_push.h"
|
||||
// Verify operator[] returns values matching sequential access
|
||||
for (size_t i = 0; i < cdata.size(); ++i)
|
||||
{
|
||||
@ -2330,6 +2333,7 @@ namespace
|
||||
// the type would be non-const reference which is incorrect for const_iterator)
|
||||
const NDC& ref = cit[0];
|
||||
CHECK(ref == cdata[0]);
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -248,6 +248,68 @@ namespace
|
||||
CHECK_EQUAL(0U, histogram2.count());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// operator[] of the run time offset histogram uses the stored start index,
|
||||
// so copying/moving must preserve it. Regression test: the copy/move
|
||||
// constructors and assignment operators used to forget to copy start_index.
|
||||
//*************************************************************************
|
||||
TEST(test_int_runtime_offset_copy_constructor_preserves_start_index)
|
||||
{
|
||||
IntRuntimeOffsetHistogram histogram1(Start, input2.begin(), input2.end());
|
||||
|
||||
IntRuntimeOffsetHistogram histogram2(histogram1);
|
||||
|
||||
for (int key = Start; key < Start + static_cast<int>(Size); ++key)
|
||||
{
|
||||
CHECK_EQUAL(static_cast<int>(histogram1[key]), static_cast<int>(histogram2[key]));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_int_runtime_offset_copy_assignment_preserves_start_index)
|
||||
{
|
||||
IntRuntimeOffsetHistogram histogram1(Start, input2.begin(), input2.end());
|
||||
|
||||
IntRuntimeOffsetHistogram histogram2(Start);
|
||||
histogram2 = histogram1;
|
||||
|
||||
for (int key = Start; key < Start + static_cast<int>(Size); ++key)
|
||||
{
|
||||
CHECK_EQUAL(static_cast<int>(histogram1[key]), static_cast<int>(histogram2[key]));
|
||||
}
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
//*************************************************************************
|
||||
TEST(test_int_runtime_offset_move_constructor_preserves_start_index)
|
||||
{
|
||||
IntRuntimeOffsetHistogram histogram1(Start, input2.begin(), input2.end());
|
||||
IntRuntimeOffsetHistogram histogram_source(Start, input2.begin(), input2.end());
|
||||
|
||||
IntRuntimeOffsetHistogram histogram2(etl::move(histogram_source));
|
||||
|
||||
for (int key = Start; key < Start + static_cast<int>(Size); ++key)
|
||||
{
|
||||
CHECK_EQUAL(static_cast<int>(histogram1[key]), static_cast<int>(histogram2[key]));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_int_runtime_offset_move_assignment_preserves_start_index)
|
||||
{
|
||||
IntRuntimeOffsetHistogram histogram1(Start, input2.begin(), input2.end());
|
||||
IntRuntimeOffsetHistogram histogram_source(Start, input2.begin(), input2.end());
|
||||
|
||||
IntRuntimeOffsetHistogram histogram2(Start);
|
||||
histogram2 = etl::move(histogram_source);
|
||||
|
||||
for (int key = Start; key < Start + static_cast<int>(Size); ++key)
|
||||
{
|
||||
CHECK_EQUAL(static_cast<int>(histogram1[key]), static_cast<int>(histogram2[key]));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_string_histogram_constructor)
|
||||
{
|
||||
|
||||
@ -1720,6 +1720,7 @@ namespace
|
||||
{
|
||||
using Pair = std::pair<const std::string, int>;
|
||||
|
||||
#include "etl/private/diagnostic_null_dereference_push.h"
|
||||
etl::map data{Pair{"0", 0}, Pair{"1", 1}, Pair{"2", 2}, Pair{"3", 3}, Pair{"4", 4}, Pair{"5", 5}};
|
||||
|
||||
auto v = *data.begin();
|
||||
@ -1732,6 +1733,7 @@ namespace
|
||||
CHECK_EQUAL(3, data.at("3"));
|
||||
CHECK_EQUAL(4, data.at("4"));
|
||||
CHECK_EQUAL(5, data.at("5"));
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
|
||||
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
||||
}
|
||||
@ -1743,6 +1745,7 @@ namespace
|
||||
{
|
||||
using Pair = ETL_OR_STD::pair<const std::string, int>;
|
||||
|
||||
#include "etl/private/diagnostic_null_dereference_push.h"
|
||||
auto data = etl::make_map<const std::string, int, std::less<std::string>>(Pair{"0", 0}, Pair{"1", 1}, Pair{"2", 2}, Pair{"3", 3}, Pair{"4", 4},
|
||||
Pair{"5", 5});
|
||||
|
||||
@ -1756,6 +1759,7 @@ namespace
|
||||
CHECK_EQUAL(3, data.at("3"));
|
||||
CHECK_EQUAL(4, data.at("4"));
|
||||
CHECK_EQUAL(5, data.at("5"));
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
|
||||
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
||||
}
|
||||
|
||||
@ -152,6 +152,24 @@ namespace
|
||||
CHECK_EQUAL(3, memCast.ref<Data>().a[2]);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Cross-size copy/assignment must copy only the source's bytes and must
|
||||
// not read past the end of the (smaller) source buffer.
|
||||
TEST(test_mem_cast_copy_and_assign_from_smaller)
|
||||
{
|
||||
etl::mem_cast<sizeof(uint32_t), alignof(uint32_t)> smaller;
|
||||
smaller.assign<uint32_t>(0x12345678UL);
|
||||
|
||||
// Cross-size copy construct (destination larger than source).
|
||||
etl::mem_cast<sizeof(uint32_t) * 2U, alignof(uint32_t)> larger_copy(smaller);
|
||||
CHECK_EQUAL(0x12345678UL, larger_copy.ref<uint32_t>());
|
||||
|
||||
// Cross-size assignment (destination larger than source).
|
||||
etl::mem_cast<sizeof(uint32_t) * 2U, alignof(uint32_t)> larger_assign;
|
||||
larger_assign = smaller;
|
||||
CHECK_EQUAL(0x12345678UL, larger_assign.ref<uint32_t>());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_mem_cast_assign_type_at_dynamic_offset)
|
||||
{
|
||||
|
||||
@ -158,6 +158,33 @@ namespace
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***********************************
|
||||
// A minimal fancy pointer with a nested element_type and a static
|
||||
// pointer_to. Used to exercise etl::pointer_traits' primary template.
|
||||
template <typename T>
|
||||
struct fancy_pointer
|
||||
{
|
||||
typedef T element_type;
|
||||
|
||||
T* raw;
|
||||
|
||||
static fancy_pointer pointer_to(T& r)
|
||||
{
|
||||
fancy_pointer p;
|
||||
p.raw = etl::addressof(r);
|
||||
return p;
|
||||
}
|
||||
};
|
||||
|
||||
//***********************************
|
||||
// A fancy pointer without a nested element_type, so pointer_traits must
|
||||
// deduce the element type from the first template parameter.
|
||||
template <typename T>
|
||||
struct bare_pointer
|
||||
{
|
||||
T* raw;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace
|
||||
@ -1808,6 +1835,157 @@ namespace
|
||||
CHECK_EQUAL(plist_item, etl::to_address(itr));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_launder)
|
||||
{
|
||||
int i = 42;
|
||||
int* p = etl::launder(&i);
|
||||
CHECK_EQUAL(&i, p);
|
||||
CHECK_EQUAL(42, *p);
|
||||
|
||||
// Launder a new object created in reused storage.
|
||||
struct quad_t
|
||||
{
|
||||
uint8_t a;
|
||||
uint8_t b;
|
||||
uint8_t c;
|
||||
uint8_t d;
|
||||
};
|
||||
|
||||
alignas(quad_t) unsigned char buffer[sizeof(quad_t)];
|
||||
quad_t* q = ::new (buffer) quad_t{1, 2, 3, 4};
|
||||
quad_t* lq = etl::launder(q);
|
||||
CHECK(reinterpret_cast<unsigned char*>(lq) == buffer);
|
||||
CHECK_EQUAL(1, lq->a);
|
||||
CHECK_EQUAL(2, lq->b);
|
||||
CHECK_EQUAL(3, lq->c);
|
||||
CHECK_EQUAL(4, lq->d);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_start_lifetime_as)
|
||||
{
|
||||
struct quad_t
|
||||
{
|
||||
uint8_t a;
|
||||
uint8_t b;
|
||||
uint8_t c;
|
||||
uint8_t d;
|
||||
};
|
||||
|
||||
alignas(quad_t) unsigned char buffer[sizeof(quad_t)] = {1, 2, 3, 4};
|
||||
|
||||
quad_t* p = etl::start_lifetime_as<quad_t>(buffer);
|
||||
CHECK(reinterpret_cast<unsigned char*>(p) == buffer);
|
||||
CHECK_EQUAL(1, p->a);
|
||||
CHECK_EQUAL(2, p->b);
|
||||
CHECK_EQUAL(3, p->c);
|
||||
CHECK_EQUAL(4, p->d);
|
||||
|
||||
const void* cbuffer = buffer;
|
||||
const quad_t* cp = etl::start_lifetime_as<quad_t>(cbuffer);
|
||||
CHECK(reinterpret_cast<const unsigned char*>(cp) == buffer);
|
||||
CHECK_EQUAL(1, cp->a);
|
||||
CHECK_EQUAL(4, cp->d);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_start_lifetime_as_array)
|
||||
{
|
||||
alignas(uint16_t) unsigned char buffer[sizeof(uint16_t) * 3] = {0, 0, 0, 0, 0, 0};
|
||||
|
||||
uint16_t* p = etl::start_lifetime_as_array<uint16_t>(buffer, 3);
|
||||
CHECK(reinterpret_cast<unsigned char*>(p) == buffer);
|
||||
p[0] = 1;
|
||||
p[2] = 2;
|
||||
CHECK_EQUAL(1, p[0]);
|
||||
CHECK_EQUAL(2, p[2]);
|
||||
|
||||
// n == 0 returns a pointer comparing equal to p.
|
||||
uint16_t* p0 = etl::start_lifetime_as_array<uint16_t>(buffer, 0);
|
||||
CHECK(reinterpret_cast<unsigned char*>(p0) == buffer);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pointer_traits)
|
||||
{
|
||||
typedef etl::pointer_traits<int*> traits;
|
||||
|
||||
CHECK((std::is_same<int*, traits::pointer>::value));
|
||||
CHECK((std::is_same<int, traits::element_type>::value));
|
||||
CHECK((std::is_same<ptrdiff_t, traits::difference_type>::value));
|
||||
#if ETL_USING_CPP11
|
||||
CHECK((std::is_same<char*, traits::rebind<char> >::value));
|
||||
#endif
|
||||
|
||||
int i = 42;
|
||||
int* p = traits::pointer_to(i);
|
||||
CHECK_EQUAL(&i, p);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pointer_traits_fancy_pointer)
|
||||
{
|
||||
typedef etl::pointer_traits<fancy_pointer<int> > traits;
|
||||
|
||||
CHECK((std::is_same<fancy_pointer<int>, traits::pointer>::value));
|
||||
CHECK((std::is_same<int, traits::element_type>::value));
|
||||
CHECK((std::is_same<ptrdiff_t, traits::difference_type>::value));
|
||||
CHECK((std::is_same<fancy_pointer<char>, traits::rebind<char> >::value));
|
||||
|
||||
int i = 42;
|
||||
fancy_pointer<int> p = traits::pointer_to(i);
|
||||
CHECK_EQUAL(&i, p.raw);
|
||||
|
||||
// element_type and rebind are deduced from the first template parameter
|
||||
// when there is no nested element_type.
|
||||
CHECK((std::is_same<int, etl::pointer_traits<bare_pointer<int> >::element_type>::value));
|
||||
CHECK((std::is_same<bare_pointer<char>, etl::pointer_traits<bare_pointer<int> >::rebind<char> >::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_align)
|
||||
{
|
||||
alignas(16) unsigned char buffer[64];
|
||||
|
||||
void* ptr = buffer + 1; // Deliberately misaligned.
|
||||
size_t space = sizeof(buffer) - 1;
|
||||
|
||||
void* aligned = etl::align(16, 8, ptr, space);
|
||||
|
||||
// 'buffer' is 16-aligned, so aligning 'buffer + 1' to 16 skips 15 bytes of
|
||||
// padding, landing on 'buffer + 16' and shrinking 'space' by that padding.
|
||||
CHECK(aligned != ETL_NULLPTR);
|
||||
CHECK(reinterpret_cast<unsigned char*>(aligned) == buffer + 16);
|
||||
CHECK(reinterpret_cast<unsigned char*>(ptr) == buffer + 16);
|
||||
CHECK_EQUAL(sizeof(buffer) - 1 - 15, space);
|
||||
|
||||
// Not enough space returns nullptr.
|
||||
void* small_ptr = buffer + 1;
|
||||
size_t small_space = 2;
|
||||
CHECK(etl::align(16, 8, small_ptr, small_space) == ETL_NULLPTR);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_assume_aligned)
|
||||
{
|
||||
alignas(16) int data[4] = {1, 2, 3, 4};
|
||||
|
||||
int* p = etl::assume_aligned<16>(&data[0]);
|
||||
CHECK_EQUAL(&data[0], p);
|
||||
CHECK_EQUAL(1, *p);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_is_sufficiently_aligned)
|
||||
{
|
||||
alignas(16) unsigned char buffer[32];
|
||||
|
||||
CHECK(etl::is_sufficiently_aligned<16>(buffer));
|
||||
CHECK(etl::is_sufficiently_aligned<8>(buffer));
|
||||
CHECK(!etl::is_sufficiently_aligned<16>(buffer + 1));
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
//*************************************************************************
|
||||
TEST(test_ranges_uninitialized_copy_iterator_trivial)
|
||||
|
||||
@ -433,6 +433,52 @@ namespace
|
||||
CHECK_ARRAY_EQUAL(compare3.data(), router1.message3.data(), compare3.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Unregistering an active timer that is not at the tail of the active list
|
||||
// must preserve the absolute timeout of the timers that follow it.
|
||||
// Regression test: unregister_timer used to pass has_expired = true, which
|
||||
// skipped the delta adjustment of the next timer, making it fire early.
|
||||
//*************************************************************************
|
||||
TEST(message_timer_unregister_active_timer_preserves_following_timer_timing)
|
||||
{
|
||||
etl::message_timer<2> timer_controller;
|
||||
|
||||
// id1 (period 10) becomes the active list head, id2 (period 20) follows it.
|
||||
etl::timer::id::type id1 = timer_controller.register_timer(message1, router1, 10, etl::timer::mode::Single_Shot);
|
||||
etl::timer::id::type id2 = timer_controller.register_timer(message2, router1, 20, etl::timer::mode::Single_Shot);
|
||||
|
||||
router1.clear();
|
||||
|
||||
timer_controller.start(id1);
|
||||
timer_controller.start(id2);
|
||||
|
||||
timer_controller.enable(true);
|
||||
|
||||
ticks = 0;
|
||||
|
||||
const uint32_t step = 1UL;
|
||||
|
||||
while (ticks <= 30U)
|
||||
{
|
||||
if (ticks == 5U)
|
||||
{
|
||||
// id1 is the active head and still has a 'next' (id2).
|
||||
timer_controller.unregister_timer(id1);
|
||||
}
|
||||
|
||||
ticks += step;
|
||||
timer_controller.tick(step);
|
||||
}
|
||||
|
||||
// id1 was unregistered before it could fire.
|
||||
CHECK_EQUAL(0U, router1.message1.size());
|
||||
|
||||
// id2 must still fire at its original absolute time of 20, not earlier.
|
||||
std::vector<uint64_t> compare2 = {20ULL};
|
||||
CHECK_EQUAL(compare2.size(), router1.message2.size());
|
||||
CHECK_ARRAY_EQUAL(compare2.data(), router1.message2.data(), compare2.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(message_timer_repeating_clear)
|
||||
{
|
||||
|
||||
@ -144,6 +144,25 @@ namespace
|
||||
CHECK(compare == hash);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pearson_reset)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
etl::pearson<HASH_SIZE> pearson_calculator;
|
||||
|
||||
// Use the calculator, then reset it and reuse it for the same data.
|
||||
pearson_calculator.add(data.begin(), data.end());
|
||||
pearson_calculator.reset();
|
||||
pearson_calculator.add(data.begin(), data.end());
|
||||
|
||||
hash_t compare = Pearson_Compare(data);
|
||||
hash_t hash = pearson_calculator.value();
|
||||
|
||||
// A reset calculator must produce the same hash as a fresh one.
|
||||
CHECK(compare == hash);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pearson_add_range_endian)
|
||||
{
|
||||
|
||||
@ -28,6 +28,7 @@ SOFTWARE.
|
||||
|
||||
#include "unit_test_framework.h"
|
||||
|
||||
#include "etl/memory.h"
|
||||
#include "etl/utility.h"
|
||||
|
||||
#include <algorithm>
|
||||
@ -315,6 +316,32 @@ namespace
|
||||
CHECK_EQUAL(1, c);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_exchange_unique_ptr)
|
||||
{
|
||||
etl::unique_ptr<int> p1(new int(1));
|
||||
etl::unique_ptr<int> p2 = etl::exchange(p1, nullptr);
|
||||
|
||||
CHECK_FALSE(p1);
|
||||
CHECK_TRUE(p2);
|
||||
CHECK_EQUAL(*p2, 1);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_exchange_unique_ptr_move_in)
|
||||
{
|
||||
etl::unique_ptr<int> a(new int(10));
|
||||
etl::unique_ptr<int> b(new int(20));
|
||||
|
||||
etl::unique_ptr<int> old = etl::exchange(a, etl::move(b));
|
||||
|
||||
CHECK_TRUE(old);
|
||||
CHECK_EQUAL(*old, 10);
|
||||
CHECK_TRUE(a);
|
||||
CHECK_EQUAL(*a, 20);
|
||||
CHECK_FALSE(b);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_as_const)
|
||||
{
|
||||
|
||||
@ -320,6 +320,106 @@ namespace
|
||||
bool moved_to;
|
||||
bool copied_to;
|
||||
};
|
||||
|
||||
//*********************************************
|
||||
// Trivially destructible, but non-copyable and non-movable.
|
||||
// Exercises the trivially-destructible (variadic_union) emplace path.
|
||||
struct TrivialNonMovable
|
||||
{
|
||||
TrivialNonMovable(int a_, int b_)
|
||||
: a(a_)
|
||||
, b(b_)
|
||||
{
|
||||
}
|
||||
|
||||
TrivialNonMovable(const TrivialNonMovable&) = delete;
|
||||
TrivialNonMovable(TrivialNonMovable&&) = delete;
|
||||
TrivialNonMovable& operator=(const TrivialNonMovable&) = delete;
|
||||
TrivialNonMovable& operator=(TrivialNonMovable&&) = delete;
|
||||
|
||||
int a;
|
||||
int b;
|
||||
};
|
||||
|
||||
//*********************************************
|
||||
// Non-trivially destructible, non-copyable and non-movable.
|
||||
// Exercises the non-trivially-destructible (uninitialized_buffer) emplace path,
|
||||
// including the initializer_list overload.
|
||||
struct NonTrivialNonMovable
|
||||
{
|
||||
NonTrivialNonMovable(int a_, int b_)
|
||||
: a(a_)
|
||||
, b(b_)
|
||||
, sum_of_list(0)
|
||||
{
|
||||
}
|
||||
|
||||
NonTrivialNonMovable(std::initializer_list<int> il, int b_)
|
||||
: a(0)
|
||||
, b(b_)
|
||||
, sum_of_list(0)
|
||||
{
|
||||
for (int value : il)
|
||||
{
|
||||
sum_of_list += value;
|
||||
}
|
||||
}
|
||||
|
||||
~NonTrivialNonMovable() // Makes it non-trivially destructible.
|
||||
{
|
||||
}
|
||||
|
||||
NonTrivialNonMovable(const NonTrivialNonMovable&) = delete;
|
||||
NonTrivialNonMovable(NonTrivialNonMovable&&) = delete;
|
||||
NonTrivialNonMovable& operator=(const NonTrivialNonMovable&) = delete;
|
||||
NonTrivialNonMovable& operator=(NonTrivialNonMovable&&) = delete;
|
||||
|
||||
int a;
|
||||
int b;
|
||||
int sum_of_list;
|
||||
};
|
||||
|
||||
// Trivially destructible but not assignable (deleted copy and move
|
||||
// assignment). Constructing an alternative of this type exercises the
|
||||
// trivially-destructible-suite path, which must begin the alternative's
|
||||
// lifetime with placement new rather than assigning into the union member.
|
||||
struct NonAssignable
|
||||
{
|
||||
explicit NonAssignable(int value_)
|
||||
: value(value_)
|
||||
{
|
||||
}
|
||||
|
||||
NonAssignable(const NonAssignable&) = default;
|
||||
NonAssignable(NonAssignable&&) = default;
|
||||
NonAssignable& operator=(const NonAssignable&) = delete;
|
||||
NonAssignable& operator=(NonAssignable&&) = delete;
|
||||
|
||||
int value;
|
||||
};
|
||||
|
||||
//*********************************************
|
||||
// Trivially destructible type that overloads operator& (here by deleting it).
|
||||
// Constructing an alternative of this type must obtain the placement-new
|
||||
// target with etl::addressof, not the built-in unary operator&: taking the
|
||||
// address with & would be ill-formed (deleted) or, for an operator& that
|
||||
// returns something other than the object's address, would construct into the
|
||||
// wrong storage.
|
||||
struct NonAddressable
|
||||
{
|
||||
explicit NonAddressable(int value_)
|
||||
: value(value_)
|
||||
{
|
||||
}
|
||||
|
||||
NonAddressable(const NonAddressable&) = default;
|
||||
NonAddressable(NonAddressable&&) = default;
|
||||
|
||||
NonAddressable* operator&() = delete;
|
||||
const NonAddressable* operator&() const = delete;
|
||||
|
||||
int value;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
// Moved from the top of the file otherwise clang has issues with
|
||||
@ -418,6 +518,48 @@ struct etl::is_copy_constructible<MoveableCopyable> : public etl::true_type
|
||||
template <>
|
||||
struct etl::is_move_constructible<MoveableCopyable> : public etl::true_type
|
||||
{
|
||||
};
|
||||
|
||||
//*************************
|
||||
template <>
|
||||
struct etl::is_copy_constructible<TrivialNonMovable> : public etl::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <>
|
||||
struct etl::is_copy_constructible<NonAssignable> : public etl::true_type
|
||||
{
|
||||
};
|
||||
|
||||
template <>
|
||||
struct etl::is_move_constructible<TrivialNonMovable> : public etl::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <>
|
||||
struct etl::is_move_constructible<NonAssignable> : public etl::true_type
|
||||
{
|
||||
};
|
||||
|
||||
//*************************
|
||||
template <>
|
||||
struct etl::is_copy_constructible<NonTrivialNonMovable> : public etl::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <>
|
||||
struct etl::is_copy_constructible<NonAddressable> : public etl::true_type
|
||||
{
|
||||
};
|
||||
|
||||
template <>
|
||||
struct etl::is_move_constructible<NonTrivialNonMovable> : public etl::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <>
|
||||
struct etl::is_move_constructible<NonAddressable> : public etl::true_type
|
||||
{
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -732,6 +874,86 @@ namespace
|
||||
CHECK_EQUAL(text, etl::get<std::string>(variant_text_etl));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// emplace must construct the alternative in place from the forwarded
|
||||
// arguments, without requiring the alternative to be copyable or movable
|
||||
// (see issue #1493).
|
||||
TEST(test_emplace_non_movable_type)
|
||||
{
|
||||
// Trivially destructible suite (variadic_union storage).
|
||||
{
|
||||
etl::variant<int, TrivialNonMovable> v;
|
||||
|
||||
TrivialNonMovable& r1 = v.emplace<TrivialNonMovable>(3, 4);
|
||||
CHECK(etl::holds_alternative<TrivialNonMovable>(v));
|
||||
CHECK_EQUAL(3, r1.a);
|
||||
CHECK_EQUAL(4, r1.b);
|
||||
CHECK_EQUAL(&r1, &etl::get<TrivialNonMovable>(v));
|
||||
|
||||
// Emplace by index over the existing alternative.
|
||||
TrivialNonMovable& r2 = v.emplace<1>(5, 6);
|
||||
CHECK_EQUAL(5, r2.a);
|
||||
CHECK_EQUAL(6, r2.b);
|
||||
|
||||
// Switch to the trivial alternative and back again.
|
||||
v.emplace<int>(42);
|
||||
CHECK(etl::holds_alternative<int>(v));
|
||||
CHECK_EQUAL(42, etl::get<int>(v));
|
||||
|
||||
TrivialNonMovable& r3 = v.emplace<TrivialNonMovable>(7, 8);
|
||||
CHECK(etl::holds_alternative<TrivialNonMovable>(v));
|
||||
CHECK_EQUAL(7, r3.a);
|
||||
CHECK_EQUAL(8, r3.b);
|
||||
}
|
||||
|
||||
// Non-trivially destructible suite (uninitialized_buffer storage).
|
||||
{
|
||||
etl::variant<std::string, NonTrivialNonMovable> v;
|
||||
|
||||
NonTrivialNonMovable& r1 = v.emplace<NonTrivialNonMovable>(1, 2);
|
||||
CHECK(etl::holds_alternative<NonTrivialNonMovable>(v));
|
||||
CHECK_EQUAL(1, r1.a);
|
||||
CHECK_EQUAL(2, r1.b);
|
||||
CHECK_EQUAL(&r1, &etl::get<NonTrivialNonMovable>(v));
|
||||
|
||||
// Emplace by index over the existing alternative.
|
||||
NonTrivialNonMovable& r2 = v.emplace<1>(9, 10);
|
||||
CHECK_EQUAL(9, r2.a);
|
||||
CHECK_EQUAL(10, r2.b);
|
||||
|
||||
// Switch to the std::string alternative and back again.
|
||||
v.emplace<std::string>("Some Text");
|
||||
CHECK(etl::holds_alternative<std::string>(v));
|
||||
CHECK_EQUAL(std::string("Some Text"), etl::get<std::string>(v));
|
||||
|
||||
NonTrivialNonMovable& r3 = v.emplace<NonTrivialNonMovable>(11, 12);
|
||||
CHECK(etl::holds_alternative<NonTrivialNonMovable>(v));
|
||||
CHECK_EQUAL(11, r3.a);
|
||||
CHECK_EQUAL(12, r3.b);
|
||||
}
|
||||
}
|
||||
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
//*************************************************************************
|
||||
// The initializer_list emplace overloads must also construct in place,
|
||||
// without requiring the alternative to be copyable or movable (#1493).
|
||||
TEST(test_emplace_non_movable_type_with_initializer_list)
|
||||
{
|
||||
etl::variant<std::string, NonTrivialNonMovable> v;
|
||||
|
||||
// By type.
|
||||
NonTrivialNonMovable& r1 = v.emplace<NonTrivialNonMovable>({10, 20, 30}, 99);
|
||||
CHECK(etl::holds_alternative<NonTrivialNonMovable>(v));
|
||||
CHECK_EQUAL(60, r1.sum_of_list);
|
||||
CHECK_EQUAL(99, r1.b);
|
||||
|
||||
// By index.
|
||||
NonTrivialNonMovable& r2 = v.emplace<1>({1, 2, 3, 4}, 7);
|
||||
CHECK_EQUAL(10, r2.sum_of_list);
|
||||
CHECK_EQUAL(7, r2.b);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_copy_constructor)
|
||||
{
|
||||
@ -896,6 +1118,81 @@ namespace
|
||||
CHECK_EQUAL(D4("1", "2", "3", "4"), etl::get<D4>(variant_etl));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Constructing an alternative must begin the object's lifetime with
|
||||
// placement new, not assign into the (inactive) union member. A trivially
|
||||
// destructible but non-assignable type would fail to compile (deleted
|
||||
// assignment) or invoke undefined behaviour if assignment were used.
|
||||
// (The trivially-destructible-suite union path is taken when the STL or the
|
||||
// compiler type-trait built-ins are available; otherwise construction goes
|
||||
// through the buffer path, which is exercised here just the same.)
|
||||
TEST(test_construct_trivially_destructible_non_assignable_type)
|
||||
{
|
||||
using variant_type = etl::variant<int, NonAssignable>;
|
||||
|
||||
// Emplace by type.
|
||||
variant_type variant_by_type;
|
||||
variant_by_type.emplace<NonAssignable>(42);
|
||||
CHECK(etl::holds_alternative<NonAssignable>(variant_by_type));
|
||||
CHECK_EQUAL(42, etl::get<NonAssignable>(variant_by_type).value);
|
||||
|
||||
// Emplace by index.
|
||||
variant_type variant_by_index;
|
||||
variant_by_index.emplace<1>(43);
|
||||
CHECK(etl::holds_alternative<NonAssignable>(variant_by_index));
|
||||
CHECK_EQUAL(43, etl::get<NonAssignable>(variant_by_index).value);
|
||||
|
||||
// Assignment from a value (operator=(T&&)).
|
||||
variant_type variant_by_assignment;
|
||||
variant_by_assignment = NonAssignable(44);
|
||||
CHECK(etl::holds_alternative<NonAssignable>(variant_by_assignment));
|
||||
CHECK_EQUAL(44, etl::get<NonAssignable>(variant_by_assignment).value);
|
||||
|
||||
// Re-emplace over an already-active alternative (do_destroy then
|
||||
// placement new into the same union member).
|
||||
variant_by_assignment.emplace<NonAssignable>(45);
|
||||
CHECK(etl::holds_alternative<NonAssignable>(variant_by_assignment));
|
||||
CHECK_EQUAL(45, etl::get<NonAssignable>(variant_by_assignment).value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Constructing an alternative must take the raw storage address for
|
||||
// placement new via etl::addressof, not the built-in unary operator&.
|
||||
// NonAddressable deletes operator&, so the old `&variadic_union_get(...)`
|
||||
// form would be ill-formed. Read-back uses by-index etl::get (which returns
|
||||
// a reference) and the reference returned by emplace, so it never invokes
|
||||
// operator&. (The trivially-destructible-suite union path is taken when the
|
||||
// STL or the compiler built-ins are available; otherwise construction goes
|
||||
// through the buffer path, which is exercised here just the same.)
|
||||
TEST(test_construct_type_with_overloaded_address_of_operator)
|
||||
{
|
||||
using variant_type = etl::variant<int, NonAddressable>;
|
||||
|
||||
// Emplace by type (returns a reference, so no operator& on read-back).
|
||||
variant_type variant_by_type;
|
||||
NonAddressable& by_type = variant_by_type.emplace<NonAddressable>(42);
|
||||
CHECK(etl::holds_alternative<NonAddressable>(variant_by_type));
|
||||
CHECK_EQUAL(42, by_type.value);
|
||||
CHECK_EQUAL(42, etl::get<1>(variant_by_type).value);
|
||||
|
||||
// Emplace by index.
|
||||
variant_type variant_by_index;
|
||||
variant_by_index.emplace<1>(43);
|
||||
CHECK(etl::holds_alternative<NonAddressable>(variant_by_index));
|
||||
CHECK_EQUAL(43, etl::get<1>(variant_by_index).value);
|
||||
|
||||
// Assignment from a value (operator=(T&&)).
|
||||
variant_type variant_by_assignment;
|
||||
variant_by_assignment = NonAddressable(44);
|
||||
CHECK(etl::holds_alternative<NonAddressable>(variant_by_assignment));
|
||||
CHECK_EQUAL(44, etl::get<1>(variant_by_assignment).value);
|
||||
|
||||
// Re-emplace over an already-active alternative.
|
||||
variant_by_assignment.emplace<1>(45);
|
||||
CHECK(etl::holds_alternative<NonAddressable>(variant_by_assignment));
|
||||
CHECK_EQUAL(45, etl::get<1>(variant_by_assignment).value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_variant_accept_visitor)
|
||||
{
|
||||
@ -1007,6 +1304,7 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
#include "etl/private/diagnostic_uninitialized_push.h"
|
||||
TEST(test_const_variant_accept_visitor)
|
||||
{
|
||||
struct Visitor : public etl::visitor<const char&, const int&, const std::string&>
|
||||
@ -1057,8 +1355,10 @@ namespace
|
||||
const_variant_etl3.accept(visitor);
|
||||
CHECK_EQUAL("3", visitor.result_s);
|
||||
}
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
|
||||
//*************************************************************************
|
||||
#include "etl/private/diagnostic_uninitialized_push.h"
|
||||
TEST(test_const_variant_accept_visitor_deprecated)
|
||||
{
|
||||
struct Visitor : public etl::visitor<char, int, const std::string&>
|
||||
@ -1111,6 +1411,7 @@ namespace
|
||||
const_variant_etl3.accept(visitor);
|
||||
CHECK_EQUAL("3", visitor.result_s);
|
||||
}
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_variant_accept_functor_with_functor_class)
|
||||
@ -1218,6 +1519,7 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
#include "etl/private/diagnostic_uninitialized_push.h"
|
||||
TEST(test_const_variant_accept_functor_with_functor_class)
|
||||
{
|
||||
struct Visitor
|
||||
@ -1268,8 +1570,10 @@ namespace
|
||||
const_variant_etl3.accept(visitor);
|
||||
CHECK_EQUAL("3", visitor.result_s);
|
||||
}
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
|
||||
//*************************************************************************
|
||||
#include "etl/private/diagnostic_uninitialized_push.h"
|
||||
TEST(test_const_variant_accept_functor_with_functor_class_deprecated)
|
||||
{
|
||||
struct Visitor
|
||||
@ -1320,6 +1624,7 @@ namespace
|
||||
const_variant_etl3.accept(visitor);
|
||||
CHECK_EQUAL("3", visitor.result_s);
|
||||
}
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_USING_CPP17
|
||||
@ -1390,6 +1695,7 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
#include "etl/private/diagnostic_uninitialized_push.h"
|
||||
TEST(test_const_variant_accept_functor_with_overload)
|
||||
{
|
||||
char result_c;
|
||||
@ -1416,8 +1722,10 @@ namespace
|
||||
const_variant_etl3.accept(visitor);
|
||||
CHECK_EQUAL("3", result_s);
|
||||
}
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
|
||||
//*************************************************************************
|
||||
#include "etl/private/diagnostic_uninitialized_push.h"
|
||||
TEST(test_const_variant_accept_functor_with_overload_deprecated)
|
||||
{
|
||||
char result_c;
|
||||
@ -1444,6 +1752,7 @@ namespace
|
||||
const_variant_etl3.accept(visitor);
|
||||
CHECK_EQUAL("3", result_s);
|
||||
}
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -1078,12 +1078,14 @@ namespace
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Compare_Data::iterator const_cdi = compare_data.begin() + 2U;
|
||||
int compare_value = *(const_cdi + 1U);
|
||||
#include "etl/private/diagnostic_null_dereference_push.h"
|
||||
int compare_value = compare_data[3];
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
Compare_Data::iterator cdi = compare_data.erase(const_cdi);
|
||||
CHECK_EQUAL(compare_value, *cdi);
|
||||
|
||||
Data::iterator const_di = data.begin() + 2U;
|
||||
int data_value = *(const_di + 1U);
|
||||
int data_value = data[3];
|
||||
Data::iterator di = data.erase(const_di);
|
||||
CHECK_EQUAL(data_value, *di);
|
||||
|
||||
@ -1109,12 +1111,14 @@ namespace
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Compare_Data::const_iterator const_cdi = compare_data.cbegin() + 2U;
|
||||
int compare_value = *(const_cdi + 1U);
|
||||
#include "etl/private/diagnostic_null_dereference_push.h"
|
||||
int compare_value = compare_data[3];
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
Compare_Data::iterator cdi = compare_data.erase(const_cdi);
|
||||
CHECK_EQUAL(compare_value, *cdi);
|
||||
|
||||
Data::const_iterator const_di = data.cbegin() + 2U;
|
||||
int data_value = *(const_di + 1U);
|
||||
int data_value = data[3];
|
||||
Data::iterator di = data.erase(const_di);
|
||||
CHECK_EQUAL(data_value, *di);
|
||||
|
||||
@ -1139,15 +1143,9 @@ namespace
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Compare_Data::const_iterator const_cdi = compare_data.cbegin() + 2U;
|
||||
int compare_value = *(const_cdi + 2U);
|
||||
Compare_Data::iterator cdi = compare_data.erase(const_cdi, const_cdi + 2U);
|
||||
CHECK_EQUAL(compare_value, *cdi);
|
||||
compare_data.erase(compare_data.begin() + 2, compare_data.begin() + 4);
|
||||
|
||||
Data::const_iterator const_di = data.cbegin() + 2U;
|
||||
int data_value = *(const_di + 2U);
|
||||
Data::iterator di = data.erase(const_di, const_di + 2U);
|
||||
CHECK_EQUAL(data_value, *di);
|
||||
data.erase(data.begin() + 2, data.begin() + 4);
|
||||
|
||||
CHECK_EQUAL(compare_data.size(), data.size());
|
||||
|
||||
|
||||
@ -46,6 +46,8 @@ namespace
|
||||
int buffer4[SIZE];
|
||||
int buffer5[SIZE];
|
||||
|
||||
int bufferLarger[SIZE + 1];
|
||||
|
||||
SUITE(test_vector_external_buffer)
|
||||
{
|
||||
typedef etl::vector_ext<int> Data;
|
||||
@ -183,6 +185,14 @@ namespace
|
||||
CHECK(data2 != data);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_copy_construct_from_larger_vector_ext)
|
||||
{
|
||||
Data data(initial_data.begin(), initial_data.end(), bufferLarger, SIZE + 1);
|
||||
data.resize(SIZE + 1, 0);
|
||||
CHECK_THROW(Data data2(data, buffer1, SIZE), etl::vector_full);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_move_constructor)
|
||||
{
|
||||
@ -193,6 +203,14 @@ namespace
|
||||
CHECK(data2 != data);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_move_construct_from_larger_vector_ext)
|
||||
{
|
||||
Data data(initial_data.begin(), initial_data.end(), bufferLarger, SIZE + 1);
|
||||
data.resize(SIZE + 1, 0);
|
||||
CHECK_THROW(Data data2(etl::move(data), buffer1, SIZE), etl::vector_full);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_assignment)
|
||||
{
|
||||
|
||||
1321
test/test_vector_function_pointer.cpp
Normal file
1321
test/test_vector_function_pointer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1301
test/test_vector_function_pointer_external_buffer.cpp
Normal file
1301
test/test_vector_function_pointer_external_buffer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1330
test/test_vector_member_function_pointer.cpp
Normal file
1330
test/test_vector_member_function_pointer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1329
test/test_vector_member_function_pointer_external_buffer.cpp
Normal file
1329
test/test_vector_member_function_pointer_external_buffer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -3700,7 +3700,6 @@
|
||||
<ClInclude Include="..\..\include\etl\mutex\mutex_std.h" />
|
||||
<ClInclude Include="..\..\include\etl\packet.h" />
|
||||
<ClInclude Include="..\..\include\etl\permutations.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\ivectorpointer.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\minmax_pop.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\minmax_push.h" />
|
||||
<ClInclude Include="..\..\include\etl\profiles\arduino_arm.h" />
|
||||
@ -11463,6 +11462,10 @@
|
||||
<ClCompile Include="..\test_variant_pool.cpp" />
|
||||
<ClCompile Include="..\test_vector.cpp" />
|
||||
<ClCompile Include="..\test_vector_external_buffer.cpp" />
|
||||
<ClCompile Include="..\test_vector_function_pointer.cpp" />
|
||||
<ClCompile Include="..\test_vector_function_pointer_external_buffer.cpp" />
|
||||
<ClCompile Include="..\test_vector_member_function_pointer.cpp" />
|
||||
<ClCompile Include="..\test_vector_member_function_pointer_external_buffer.cpp" />
|
||||
<ClCompile Include="..\test_vector_non_trivial.cpp" />
|
||||
<ClCompile Include="..\test_vector_pointer.cpp" />
|
||||
<ClCompile Include="..\test_vector_pointer_external_buffer.cpp" />
|
||||
@ -11498,19 +11501,32 @@
|
||||
<None Include="..\..\.clang-format" />
|
||||
<None Include="..\..\.coderabbit.yaml" />
|
||||
<None Include="..\..\.gitattributes" />
|
||||
<None Include="..\..\.github\workflows\bazel-gcc-c++23-no-stl.yml" />
|
||||
<None Include="..\..\.github\workflows\clang-c++11.yml" />
|
||||
<None Include="..\..\.github\workflows\clang-c++14.yml" />
|
||||
<None Include="..\..\.github\workflows\clang-c++17.yml" />
|
||||
<None Include="..\..\.github\workflows\clang-c++20.yml" />
|
||||
<None Include="..\..\.github\workflows\clang-c++23.yml" />
|
||||
<None Include="..\..\.github\workflows\clang-c++26.yml" />
|
||||
<None Include="..\..\.github\workflows\clang-format.yaml" />
|
||||
<None Include="..\..\.github\workflows\clang-format_update.yaml" />
|
||||
<None Include="..\..\.github\workflows\clang-syntax-checks.yml" />
|
||||
<None Include="..\..\.github\workflows\clang-tidy.yaml" />
|
||||
<None Include="..\..\.github\workflows\coverage.yml" />
|
||||
<None Include="..\..\.github\workflows\deploy-etl-documentation.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++11.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++14.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++17.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++20.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-armhf.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-i386.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-powerpc.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-riscv64.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-s390x.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++23.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++26.yml" />
|
||||
<None Include="..\..\.github\workflows\generator.yml" />
|
||||
<None Include="..\..\.github\workflows\meson-gcc-c++23-no-stl.yml" />
|
||||
<None Include="..\..\.github\workflows\msvc.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-syntax-checks.yml" />
|
||||
<None Include="..\..\.github\workflows\platformio-update.yml" />
|
||||
|
||||
@ -597,9 +597,6 @@
|
||||
<ClInclude Include="..\..\include\etl\bit_stream.h">
|
||||
<Filter>ETL\Utilities</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\private\ivectorpointer.h">
|
||||
<Filter>ETL\Private</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\private\minmax_pop.h">
|
||||
<Filter>ETL\Private</Filter>
|
||||
</ClInclude>
|
||||
@ -1569,6 +1566,9 @@
|
||||
<ClInclude Include="..\..\include\etl\generators\message_router_cpp03_generator.h">
|
||||
<Filter>ETL\Messaging\Generators</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\format.h">
|
||||
<Filter>UnitTest++\Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\test_string_char.cpp">
|
||||
@ -3818,6 +3818,18 @@
|
||||
<ClCompile Include="..\test_closure_with_inplace_function.cpp">
|
||||
<Filter>Tests\Callbacks & Delegates</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_vector_function_pointer.cpp">
|
||||
<Filter>Tests\Containers</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_vector_member_function_pointer.cpp">
|
||||
<Filter>Tests\Containers</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_vector_function_pointer_external_buffer.cpp">
|
||||
<Filter>Tests\Containers</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_vector_member_function_pointer_external_buffer.cpp">
|
||||
<Filter>Tests\Containers</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\library.properties">
|
||||
@ -4002,6 +4014,45 @@
|
||||
<None Include="..\run-coverage.sh">
|
||||
<Filter>Tests\Scripts</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\bazel-gcc-c++23-no-stl.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\clang-c++26.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\clang-tidy.yaml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\coverage.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\deploy-etl-documentation.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-armhf.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-i386.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-powerpc.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-riscv64.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-s390x.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\gcc-c++26.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\generator.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\meson-gcc-c++23-no-stl.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="..\..\support\Release notes.txt">
|
||||
|
||||
@ -1 +1 @@
|
||||
20.48.0
|
||||
20.48.1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user