From a47c0aae81b886259918961d5fcee20faa06fdd0 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Mon, 6 Jul 2026 17:32:26 +0200 Subject: [PATCH 01/19] 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. --- include/etl/message_timer.h | 2 +- include/etl/message_timer_atomic.h | 2 +- include/etl/message_timer_interrupt.h | 2 +- include/etl/message_timer_locked.h | 2 +- test/test_message_timer.cpp | 46 +++++++++++++++++++++++++++ 5 files changed, 50 insertions(+), 4 deletions(-) diff --git a/include/etl/message_timer.h b/include/etl/message_timer.h index eaf506c8..a9c0ce31 100644 --- a/include/etl/message_timer.h +++ b/include/etl/message_timer.h @@ -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; } diff --git a/include/etl/message_timer_atomic.h b/include/etl/message_timer_atomic.h index 93e328c3..8d716d8b 100644 --- a/include/etl/message_timer_atomic.h +++ b/include/etl/message_timer_atomic.h @@ -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; } diff --git a/include/etl/message_timer_interrupt.h b/include/etl/message_timer_interrupt.h index 5aaeb424..33ac248c 100644 --- a/include/etl/message_timer_interrupt.h +++ b/include/etl/message_timer_interrupt.h @@ -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); } diff --git a/include/etl/message_timer_locked.h b/include/etl/message_timer_locked.h index 4eb689ee..92b41488 100644 --- a/include/etl/message_timer_locked.h +++ b/include/etl/message_timer_locked.h @@ -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(); } diff --git a/test/test_message_timer.cpp b/test/test_message_timer.cpp index 712d13c1..4b05f74b 100644 --- a/test/test_message_timer.cpp +++ b/test/test_message_timer.cpp @@ -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 compare2 = {20ULL}; + CHECK_EQUAL(compare2.size(), router1.message2.size()); + CHECK_ARRAY_EQUAL(compare2.data(), router1.message2.data(), compare2.size()); + } + //************************************************************************* TEST(message_timer_repeating_clear) { From 5cd2f28cd54e4019f7be126bcf7394a6a8318eb9 Mon Sep 17 00:00:00 2001 From: Drew Rife Date: Tue, 7 Jul 2026 03:14:48 -0400 Subject: [PATCH 02/19] 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 --- include/etl/private/variant_variadic.h | 34 +++++- test/test_variant_variadic.cpp | 160 +++++++++++++++++++++++++ 2 files changed, 190 insertions(+), 4 deletions(-) diff --git a/include/etl/private/variant_variadic.h b/include/etl/private/variant_variadic.h index 3b621582..f3d3dee7 100644 --- a/include/etl/private/variant_variadic.h +++ b/include/etl/private/variant_variadic.h @@ -715,7 +715,7 @@ namespace etl using type = etl::remove_cvref_t; do_destroy(); - do_construct(type(etl::forward(args)...)); + do_emplace(etl::forward(args)...); type_id = index_of_type::value; @@ -735,7 +735,7 @@ namespace etl using type = etl::remove_cvref_t; do_destroy(); - do_construct(type(il, etl::forward(args)...)); + do_emplace(il, etl::forward(args)...); type_id = index_of_type::value; @@ -755,7 +755,7 @@ namespace etl using type = type_from_index; do_destroy(); - do_construct(type(etl::forward(args)...)); + do_emplace(etl::forward(args)...); type_id = Index; @@ -775,7 +775,7 @@ namespace etl using type = type_from_index; do_destroy(); - do_construct(type(il, etl::forward(args)...)); + do_emplace(il, etl::forward(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 + void do_emplace(TArgs&&... args) + { + do_emplace_impl(etl::integral_constant{}, etl::forward(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 + void do_emplace_impl(etl::integral_constant, TArgs&&... args) + { + ::new (static_cast(etl::addressof(private_variant::variadic_union_get::value>(data)))) T(etl::forward(args)...); + } + + // Non-trivially destructible suite: storage is an uninitialized_buffer. + template + void do_emplace_impl(etl::integral_constant, TArgs&&... args) + { + ::new (static_cast(data)) T(etl::forward(args)...); + } + //*************************************************************************** /// Construct a value in the union or buffer storage. //*************************************************************************** diff --git a/test/test_variant_variadic.cpp b/test/test_variant_variadic.cpp index 01ff7ded..b9f7a04b 100644 --- a/test/test_variant_variadic.cpp +++ b/test/test_variant_variadic.cpp @@ -320,6 +320,64 @@ 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 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; + }; } // namespace // Moved from the top of the file otherwise clang has issues with @@ -418,6 +476,28 @@ struct etl::is_copy_constructible : public etl::true_type template <> struct etl::is_move_constructible : public etl::true_type { +}; + +//************************* +template <> +struct etl::is_copy_constructible : public etl::false_type +{ +}; + +template <> +struct etl::is_move_constructible : public etl::false_type +{ +}; + +//************************* +template <> +struct etl::is_copy_constructible : public etl::false_type +{ +}; + +template <> +struct etl::is_move_constructible : public etl::false_type +{ }; #endif @@ -732,6 +812,86 @@ namespace CHECK_EQUAL(text, etl::get(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 v; + + TrivialNonMovable& r1 = v.emplace(3, 4); + CHECK(etl::holds_alternative(v)); + CHECK_EQUAL(3, r1.a); + CHECK_EQUAL(4, r1.b); + CHECK_EQUAL(&r1, &etl::get(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(42); + CHECK(etl::holds_alternative(v)); + CHECK_EQUAL(42, etl::get(v)); + + TrivialNonMovable& r3 = v.emplace(7, 8); + CHECK(etl::holds_alternative(v)); + CHECK_EQUAL(7, r3.a); + CHECK_EQUAL(8, r3.b); + } + + // Non-trivially destructible suite (uninitialized_buffer storage). + { + etl::variant v; + + NonTrivialNonMovable& r1 = v.emplace(1, 2); + CHECK(etl::holds_alternative(v)); + CHECK_EQUAL(1, r1.a); + CHECK_EQUAL(2, r1.b); + CHECK_EQUAL(&r1, &etl::get(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("Some Text"); + CHECK(etl::holds_alternative(v)); + CHECK_EQUAL(std::string("Some Text"), etl::get(v)); + + NonTrivialNonMovable& r3 = v.emplace(11, 12); + CHECK(etl::holds_alternative(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 v; + + // By type. + NonTrivialNonMovable& r1 = v.emplace({10, 20, 30}, 99); + CHECK(etl::holds_alternative(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) { From 98cb365d4c28e7b72f8547b734a03a4068acd3f5 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 7 Jul 2026 12:32:56 +0200 Subject: [PATCH 03/19] 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 --- include/etl/histogram.h | 4 +++ test/test_histogram.cpp | 62 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/include/etl/histogram.h b/include/etl/histogram.h index 95943b76..aad21b18 100644 --- a/include/etl/histogram.h +++ b/include/etl/histogram.h @@ -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; } diff --git a/test/test_histogram.cpp b/test/test_histogram.cpp index 624c0e68..40f5de20 100644 --- a/test/test_histogram.cpp +++ b/test/test_histogram.cpp @@ -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(Size); ++key) + { + CHECK_EQUAL(static_cast(histogram1[key]), static_cast(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(Size); ++key) + { + CHECK_EQUAL(static_cast(histogram1[key]), static_cast(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(Size); ++key) + { + CHECK_EQUAL(static_cast(histogram1[key]), static_cast(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(Size); ++key) + { + CHECK_EQUAL(static_cast(histogram1[key]), static_cast(histogram2[key])); + } + } +#endif + //************************************************************************* TEST(test_string_histogram_constructor) { From 032ec4cc80f1c0f1baa0383bdbc5f9239b68f268 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 7 Jul 2026 13:40:04 +0200 Subject: [PATCH 04/19] 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 --- include/etl/private/bitset_new.h | 20 +++++++++++++++++++ ...itset_new_explicit_single_element_type.cpp | 16 +++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/etl/private/bitset_new.h b/include/etl/private/bitset_new.h index e33f3b10..ef1152cd 100644 --- a/include/etl/private/bitset_new.h +++ b/include/etl/private/bitset_new.h @@ -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) diff --git a/test/test_bitset_new_explicit_single_element_type.cpp b/test/test_bitset_new_explicit_single_element_type.cpp index de9bd2fe..3a44690b 100644 --- a/test/test_bitset_new_explicit_single_element_type.cpp +++ b/test/test_bitset_new_explicit_single_element_type.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) { From 165674cb23dda1fd4f7e5a1182f49554a796bfe8 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 7 Jul 2026 16:41:50 +0200 Subject: [PATCH 05/19] 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 --- include/etl/pearson.h | 1 + test/test_pearson.cpp | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/etl/pearson.h b/include/etl/pearson.h index fffae1d8..2b1d0ab2 100644 --- a/include/etl/pearson.h +++ b/include/etl/pearson.h @@ -93,6 +93,7 @@ namespace etl void reset() { hash.fill(0); + first = true; } //************************************************************************* diff --git a/test/test_pearson.cpp b/test/test_pearson.cpp index 4b5e5609..aa3eea30 100644 --- a/test/test_pearson.cpp +++ b/test/test_pearson.cpp @@ -144,6 +144,25 @@ namespace CHECK(compare == hash); } + //************************************************************************* + TEST(test_pearson_reset) + { + std::string data("123456789"); + + etl::pearson 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) { From c52b2ac7b1f675e6b1d34052239423b7f3634033 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 7 Jul 2026 18:06:05 +0200 Subject: [PATCH 06/19] 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 --- include/etl/mem_cast.h | 4 ++-- test/test_mem_cast.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/etl/mem_cast.h b/include/etl/mem_cast.h index 853aa18c..35980787 100644 --- a/include/etl/mem_cast.h +++ b/include/etl/mem_cast.h @@ -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; } diff --git a/test/test_mem_cast.cpp b/test/test_mem_cast.cpp index 85bdae8f..717fe1d9 100644 --- a/test/test_mem_cast.cpp +++ b/test/test_mem_cast.cpp @@ -152,6 +152,24 @@ namespace CHECK_EQUAL(3, memCast.ref().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 smaller; + smaller.assign(0x12345678UL); + + // Cross-size copy construct (destination larger than source). + etl::mem_cast larger_copy(smaller); + CHECK_EQUAL(0x12345678UL, larger_copy.ref()); + + // Cross-size assignment (destination larger than source). + etl::mem_cast larger_assign; + larger_assign = smaller; + CHECK_EQUAL(0x12345678UL, larger_assign.ref()); + } + //************************************************************************* TEST(test_mem_cast_assign_type_at_dynamic_offset) { From dca6653b3759b2cdc79307fec7425589feea478d Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 7 Jul 2026 21:00:09 +0200 Subject: [PATCH 07/19] Add missing interfaces to etl::chrono (#1489) Co-authored-by: John Wellbelove --- docs/chrono/hh_mm_ss.md | 47 +++++++++++- docs/chrono/time_point.md | 94 ++++++++++++++++++++++++ include/etl/private/chrono/hh_mm_ss.h | 59 +++++++++++++++ include/etl/private/chrono/time_point.h | 95 +++++++++++++++++++++++++ test/test_chrono_hh_mm_ss.cpp | 81 +++++++++++++++++++++ test/test_chrono_time_point.cpp | 93 ++++++++++++++++++++++++ 6 files changed, 468 insertions(+), 1 deletion(-) diff --git a/docs/chrono/hh_mm_ss.md b/docs/chrono/hh_mm_ss.md index f7744ff1..583e2cba 100644 --- a/docs/chrono/hh_mm_ss.md +++ b/docs/chrono/hh_mm_ss.md @@ -135,4 +135,49 @@ ETL_NOEXCEPT ``` A specialisation of absolute for `etl::chrono::duration`. **Return** -The absolute duration value. \ No newline at end of file +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. \ No newline at end of file diff --git a/docs/chrono/time_point.md b/docs/chrono/time_point.md index dd0bd674..4b9680f8 100644 --- a/docs/chrono/time_point.md +++ b/docs/chrono/time_point.md @@ -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 +ETL_CONSTEXPR14 +etl::chrono::time_point >::type> + operator +(const time_point& lhs, + const etl::chrono::duration& 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 +ETL_CONSTEXPR14 +etl::chrono::time_point, TDuration2>::type> + operator +(const etl::chrono::duration& lhs, + const time_point& 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 +ETL_CONSTEXPR14 +etl::chrono::time_point >::type> + operator -(const time_point& lhs, + const etl::chrono::duration& 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 +ETL_CONSTEXPR14 +typename etl::common_type::type + operator -(const time_point& lhs, + const time_point& 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 diff --git a/include/etl/private/chrono/hh_mm_ss.h b/include/etl/private/chrono/hh_mm_ss.h index 2777551d..d60b3829 100644 --- a/include/etl/private/chrono/hh_mm_ss.h +++ b/include/etl/private/chrono/hh_mm_ss.h @@ -184,5 +184,64 @@ namespace etl template constexpr int etl::chrono::hh_mm_ss::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 diff --git a/include/etl/private/chrono/time_point.h b/include/etl/private/chrono/time_point.h index 1d122f12..f90f1c61 100644 --- a/include/etl/private/chrono/time_point.h +++ b/include/etl/private/chrono/time_point.h @@ -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(dur); } + //*************************************************************************** + /// Adds a duration to a time_point. + /// Returns a time_point whose duration is the common type of the two. + //*************************************************************************** + template + ETL_CONSTEXPR14 etl::chrono::time_point >::type> + operator+(const time_point& lhs, const etl::chrono::duration& rhs) ETL_NOEXCEPT + { + using common_duration = typename etl::common_type >::type; + using result_time_point = etl::chrono::time_point; + + 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 + ETL_CONSTEXPR14 etl::chrono::time_point, TDuration2>::type> + operator+(const etl::chrono::duration& lhs, const time_point& rhs) ETL_NOEXCEPT + { + using common_duration = typename etl::common_type, TDuration2>::type; + using result_time_point = etl::chrono::time_point; + + 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 + ETL_CONSTEXPR14 etl::chrono::time_point >::type> + operator-(const time_point& lhs, const etl::chrono::duration& rhs) ETL_NOEXCEPT + { + using common_duration = typename etl::common_type >::type; + using result_time_point = etl::chrono::time_point; + + 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 + ETL_CONSTEXPR14 typename etl::common_type::type operator-(const time_point& lhs, + const time_point& rhs) ETL_NOEXCEPT + { + return lhs.time_since_epoch() - rhs.time_since_epoch(); + } + //*************************************************************************** /// Equality operator //*************************************************************************** diff --git a/test/test_chrono_hh_mm_ss.cpp b/test/test_chrono_hh_mm_ss.cpp index 9e770024..7342964d 100644 --- a/test/test_chrono_hh_mm_ss.cpp +++ b/test/test_chrono_hh_mm_ss.cpp @@ -286,5 +286,86 @@ namespace CHECK_EQUAL(0, time.fractional_width); CHECK_TRUE((std::is_same::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 diff --git a/test/test_chrono_time_point.cpp b/test/test_chrono_time_point.cpp index e49c3791..0bbea37f 100644 --- a/test/test_chrono_time_point.cpp +++ b/test/test_chrono_time_point.cpp @@ -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::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::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::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::value)); + + // Mixed duration types resolve to the common (finer) duration. + Chrono::time_point 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::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) From 84fca4cd62f72c382c062376ca934803116a20d5 Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Tue, 7 Jul 2026 21:45:47 +0200 Subject: [PATCH 08/19] 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 --- include/etl/memory.h | 317 ++++++++++++++++++ .../etl/profiles/determine_builtin_support.h | 9 + test/test_memory.cpp | 178 ++++++++++ 3 files changed, 504 insertions(+) diff --git a/include/etl/memory.h b/include/etl/memory.h index 40dd1183..f923a6ce 100644 --- a/include/etl/memory.h +++ b/include/etl/memory.h @@ -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 + 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::value, "etl::launder argument must not be a function type"); + #endif + ETL_STATIC_ASSERT(!etl::is_void::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 + 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(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(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 + ETL_NODISCARD + T* start_lifetime_as(void* p) ETL_NOEXCEPT + { + ETL_STATIC_ASSERT(etl::is_trivially_copyable::value, "T must be trivially copyable"); + return etl::private_memory::start_lifetime_as_impl(p, 1U); + } + + template + ETL_NODISCARD + const T* start_lifetime_as(const void* p) ETL_NOEXCEPT + { + ETL_STATIC_ASSERT(etl::is_trivially_copyable::value, "T must be trivially copyable"); + return etl::private_memory::start_lifetime_as_impl(const_cast(p), 1U); + } + + template + ETL_NODISCARD + volatile T* start_lifetime_as(volatile void* p) ETL_NOEXCEPT + { + ETL_STATIC_ASSERT(etl::is_trivially_copyable::value, "T must be trivially copyable"); + return etl::private_memory::start_lifetime_as_impl(const_cast(p), 1U); + } + + template + ETL_NODISCARD + const volatile T* start_lifetime_as(const volatile void* p) ETL_NOEXCEPT + { + ETL_STATIC_ASSERT(etl::is_trivially_copyable::value, "T must be trivially copyable"); + return etl::private_memory::start_lifetime_as_impl(const_cast(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 + ETL_NODISCARD + T* start_lifetime_as_array(void* p, size_t n) ETL_NOEXCEPT + { + ETL_STATIC_ASSERT(etl::is_trivially_copyable::value, "T must be trivially copyable"); + return etl::private_memory::start_lifetime_as_impl(p, n); + } + + template + ETL_NODISCARD + const T* start_lifetime_as_array(const void* p, size_t n) ETL_NOEXCEPT + { + ETL_STATIC_ASSERT(etl::is_trivially_copyable::value, "T must be trivially copyable"); + return etl::private_memory::start_lifetime_as_impl(const_cast(p), n); + } + + template + ETL_NODISCARD + volatile T* start_lifetime_as_array(volatile void* p, size_t n) ETL_NOEXCEPT + { + ETL_STATIC_ASSERT(etl::is_trivially_copyable::value, "T must be trivially copyable"); + return etl::private_memory::start_lifetime_as_impl(const_cast(p), n); + } + + template + 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::value, "T must be trivially copyable"); + return etl::private_memory::start_lifetime_as_impl(const_cast(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 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 + struct pointer_traits_template; + + template