From 576b03f38db24bc7c1284667b4790296d6670dbe Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 4 Apr 2026 00:14:49 +0100 Subject: [PATCH] Merged from local copy of PR1295 --- include/etl/intrusive_links.h | 70 ++++++++++------------------ include/etl/private/delegate_cpp11.h | 27 ++++++----- test/test_delegate.cpp | 46 +++++++++++++----- 3 files changed, 73 insertions(+), 70 deletions(-) diff --git a/include/etl/intrusive_links.h b/include/etl/intrusive_links.h index 22bdc7d2..6355ee0a 100644 --- a/include/etl/intrusive_links.h +++ b/include/etl/intrusive_links.h @@ -1141,18 +1141,16 @@ namespace etl //*************************************************************************** // Reference, Reference template - typename etl::enable_if >::value, void>::type - link_left(TLink& parent, TLink& child) + typename etl::enable_if >::value, void>::type link_left(TLink& parent, TLink& child) { - parent.etl_left = &child; + parent.etl_left = &child; child.etl_parent = &parent; } //*********************************** // Pointer, Pointer template - typename etl::enable_if >::value, void>::type - link_left(TLink* parent, TLink* child) + typename etl::enable_if >::value, void>::type link_left(TLink* parent, TLink* child) { if (parent != ETL_NULLPTR) { @@ -1168,8 +1166,7 @@ namespace etl //*********************************** // Reference, Pointer template - typename etl::enable_if >::value, void>::type - link_left(TLink& parent, TLink* child) + typename etl::enable_if >::value, void>::type link_left(TLink& parent, TLink* child) { parent.etl_left = child; @@ -1182,8 +1179,7 @@ namespace etl //*********************************** // Pointer, Reference template - typename etl::enable_if >::value, void>::type - link_left(TLink* parent, TLink& child) + typename etl::enable_if >::value, void>::type link_left(TLink* parent, TLink& child) { if (parent != ETL_NULLPTR) { @@ -1198,8 +1194,7 @@ namespace etl // Sets the right link. //*************************************************************************** template - typename etl::enable_if >::value, void>::type - link_right(TLink& parent, TLink& child) + typename etl::enable_if >::value, void>::type link_right(TLink& parent, TLink& child) { parent.etl_right = &child; child.etl_parent = &parent; @@ -1207,8 +1202,7 @@ namespace etl //*********************************** template - typename etl::enable_if >::value, void>::type - link_right(TLink* parent, TLink* child) + typename etl::enable_if >::value, void>::type link_right(TLink* parent, TLink* child) { if (parent != ETL_NULLPTR) { @@ -1223,8 +1217,7 @@ namespace etl //*********************************** template - typename etl::enable_if >::value, void>::type - link_right(TLink& parent, TLink* child) + typename etl::enable_if >::value, void>::type link_right(TLink& parent, TLink* child) { parent.etl_right = child; @@ -1236,8 +1229,7 @@ namespace etl //*********************************** template - typename etl::enable_if >::value, void>::type - link_right(TLink* parent, TLink& child) + typename etl::enable_if >::value, void>::type link_right(TLink* parent, TLink& child) { if (parent != ETL_NULLPTR) { @@ -1252,8 +1244,7 @@ namespace etl //*************************************************************************** // Reference, Reference template - typename etl::enable_if >::value, void>::type - link_rotate_left(TLink& parent, TLink& child) + typename etl::enable_if >::value, void>::type link_rotate_left(TLink& parent, TLink& child) { TLink* grandparent = parent.etl_parent; @@ -1264,9 +1255,9 @@ namespace etl parent.etl_right->etl_parent = &parent; } - child.etl_parent = grandparent; + child.etl_parent = grandparent; parent.etl_parent = &child; - child.etl_left = &parent; + child.etl_left = &parent; if (grandparent != ETL_NULLPTR) { @@ -1284,8 +1275,7 @@ namespace etl //*********************************** // Pointer, Pointer template - typename etl::enable_if >::value, void>::type - link_rotate_left(TLink* parent, TLink* child) + typename etl::enable_if >::value, void>::type link_rotate_left(TLink* parent, TLink* child) { if ((parent != ETL_NULLPTR) && (child != ETL_NULLPTR)) { @@ -1296,8 +1286,7 @@ namespace etl //*********************************** // Reference, Pointer template - typename etl::enable_if >::value, void>::type - link_rotate_left(TLink& parent, TLink* child) + typename etl::enable_if >::value, void>::type link_rotate_left(TLink& parent, TLink* child) { if (child != ETL_NULLPTR) { @@ -1308,8 +1297,7 @@ namespace etl //*********************************** // Pointer, Reference template - typename etl::enable_if >::value, void>::type - link_rotate_left(TLink* parent, TLink& child) + typename etl::enable_if >::value, void>::type link_rotate_left(TLink* parent, TLink& child) { if (parent != ETL_NULLPTR) { @@ -1321,8 +1309,7 @@ namespace etl // link_rotate_right //*************************************************************************** template - typename etl::enable_if >::value, void>::type - link_rotate_right(TLink& parent, TLink& child) + typename etl::enable_if >::value, void>::type link_rotate_right(TLink& parent, TLink& child) { TLink* grandparent = parent.etl_parent; @@ -1333,9 +1320,9 @@ namespace etl parent.etl_left->etl_parent = &parent; } - child.etl_parent = grandparent; + child.etl_parent = grandparent; parent.etl_parent = &child; - child.etl_right = &parent; + child.etl_right = &parent; if (grandparent != ETL_NULLPTR) { @@ -1351,8 +1338,7 @@ namespace etl } template - typename etl::enable_if >::value, void>::type - link_rotate_right(TLink* parent, TLink* child) + typename etl::enable_if >::value, void>::type link_rotate_right(TLink* parent, TLink* child) { if ((parent != ETL_NULLPTR) && (child != ETL_NULLPTR)) { @@ -1361,8 +1347,7 @@ namespace etl } template - typename etl::enable_if >::value, void>::type - link_rotate_right(TLink& parent, TLink* child) + typename etl::enable_if >::value, void>::type link_rotate_right(TLink& parent, TLink* child) { if (child != ETL_NULLPTR) { @@ -1372,8 +1357,7 @@ namespace etl //*********************************** template - typename etl::enable_if >::value, void>::type - link_rotate_right(TLink* parent, TLink& child) + typename etl::enable_if >::value, void>::type link_rotate_right(TLink* parent, TLink& child) { if (parent != ETL_NULLPTR) { @@ -1387,8 +1371,7 @@ namespace etl // Reference, Reference /// Automatically detects whether a left or right rotate is expected. template - typename etl::enable_if >::value, void>::type - link_rotate(TLink& parent, TLink& child) + typename etl::enable_if >::value, void>::type link_rotate(TLink& parent, TLink& child) { if (parent.etl_left == &child) { @@ -1404,8 +1387,7 @@ namespace etl // Pointer, Pointer /// Automatically detects whether a left or right rotate is expected. template - typename etl::enable_if >::value, void>::type - link_rotate(TLink* parent, TLink* child) + typename etl::enable_if >::value, void>::type link_rotate(TLink* parent, TLink* child) { if ((parent != ETL_NULLPTR) && (child != ETL_NULLPTR)) { @@ -1424,8 +1406,7 @@ namespace etl // Reference, Pointer /// Automatically detects whether a left or right rotate is expected. template - typename etl::enable_if >::value, void>::type - link_rotate(TLink& parent, TLink* child) + typename etl::enable_if >::value, void>::type link_rotate(TLink& parent, TLink* child) { if (child != ETL_NULLPTR) { @@ -1444,8 +1425,7 @@ namespace etl // Pointer, Reference /// Automatically detects whether a left or right rotate is expected. template - typename etl::enable_if >::value, void>::type - link_rotate(TLink* parent, TLink& child) + typename etl::enable_if >::value, void>::type link_rotate(TLink* parent, TLink& child) { if (parent != ETL_NULLPTR) { diff --git a/include/etl/private/delegate_cpp11.h b/include/etl/private/delegate_cpp11.h index ba1e074d..33d993e2 100644 --- a/include/etl/private/delegate_cpp11.h +++ b/include/etl/private/delegate_cpp11.h @@ -122,7 +122,7 @@ namespace etl private: using object_ptr = void*; - using function_ptr = TReturn(*)(TArgs...); + using function_ptr = TReturn (*)(TArgs...); public: @@ -163,9 +163,10 @@ namespace etl // Delete construction from rvalue reference lambda or functor. // Excludes non-capturing lambdas convertible to a function pointer. //************************************************************************* - template ::value && - !etl::is_same, TLambda>::value && - !etl::is_convertible::value, void>> + template ::value && !etl::is_same, TLambda>::value + && !etl::is_convertible::value, + void>> ETL_CONSTEXPR14 delegate(TLambda&& instance) = delete; //************************************************************************* @@ -531,7 +532,7 @@ namespace etl //************************************************************************* // Create from a function pointer. //************************************************************************* - delegate& operator =(function_ptr fp) ETL_NOEXCEPT + delegate& operator=(function_ptr fp) ETL_NOEXCEPT { assign(fp, function_ptr_stub); return *this; @@ -607,7 +608,7 @@ namespace etl //************************************************************************* struct invocation_element { - using stub_type = TReturn(*)(const invocation_element&, TArgs...); + using stub_type = TReturn (*)(const invocation_element&, TArgs...); //*********************************************************************** ETL_CONSTEXPR14 invocation_element() ETL_NOEXCEPT @@ -640,9 +641,7 @@ namespace etl //*********************************************************************** ETL_CONSTEXPR14 bool operator==(const invocation_element& rhs) const ETL_NOEXCEPT { - return (rhs.stub == stub) && - ((stub == function_ptr_stub) ? (rhs.ptr.fp == ptr.fp) - : (rhs.ptr.object == ptr.object)); + return (rhs.stub == stub) && ((stub == function_ptr_stub) ? (rhs.ptr.fp == ptr.fp) : (rhs.ptr.object == ptr.object)); } //*********************************************************************** @@ -739,7 +738,7 @@ namespace etl //************************************************************************* /// Stub call for a member function. Run time instance. //************************************************************************* - template + template static ETL_CONSTEXPR14 TReturn method_stub(const invocation_element& invocation, TArgs... args) { T* p = static_cast(invocation.ptr.object); @@ -749,7 +748,7 @@ namespace etl //************************************************************************* /// Stub call for a const member function. Run time instance. //************************************************************************* - template + template static ETL_CONSTEXPR14 TReturn const_method_stub(const invocation_element& invocation, TArgs... args) { T* const p = static_cast(invocation.ptr.object); @@ -759,7 +758,7 @@ namespace etl //************************************************************************* /// Stub call for a member function. Compile time instance. //************************************************************************* - template + template static ETL_CONSTEXPR14 TReturn method_instance_stub(const invocation_element&, TArgs... args) { return (Instance.*Method)(etl::forward(args)...); @@ -768,7 +767,7 @@ namespace etl //************************************************************************* /// Stub call for a const member function. Compile time instance. //************************************************************************* - template + template static ETL_CONSTEXPR14 TReturn const_method_instance_stub(const invocation_element&, TArgs... args) { return (Instance.*Method)(etl::forward(args)...); @@ -788,7 +787,7 @@ namespace etl //************************************************************************* /// Stub call for a free function. //************************************************************************* - template + template static ETL_CONSTEXPR14 TReturn function_stub(const invocation_element&, TArgs... args) { return (Method)(etl::forward(args)...); diff --git a/test/test_delegate.cpp b/test/test_delegate.cpp index bad8afe5..b8445166 100644 --- a/test/test_delegate.cpp +++ b/test/test_delegate.cpp @@ -644,7 +644,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_from_rvalue_non_capturing_lambda) { - etl::delegate d(+[](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); return i + j; }); + etl::delegate d(+[](int i, int j) + { + function_called = FunctionCalled::Lambda_Called; + parameter_correct = (i == VALUE1) && (j == VALUE2); + return i + j; + }); int result = d(VALUE1, VALUE2); @@ -658,7 +663,12 @@ namespace { etl::delegate d; - d = +[](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); return i + j + 2; }; + d = +[](int i, int j) + { + function_called = FunctionCalled::Lambda_Called; + parameter_correct = (i == VALUE1) && (j == VALUE2); + return i + j + 2; + }; int result = d(VALUE1, VALUE2); @@ -670,7 +680,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_create_from_rvalue_non_capturing_lambda) { - auto d = etl::delegate::create(+[](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); return i + j + 5; }); + auto d = etl::delegate::create(+[](int i, int j) + { + function_called = FunctionCalled::Lambda_Called; + parameter_correct = (i == VALUE1) && (j == VALUE2); + return i + j + 5; + }); int result = d(VALUE1, VALUE2); @@ -685,7 +700,11 @@ namespace etl::delegate d; d.set(+[](int i, int j) - { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); return i + j + 6; }); + { + function_called = FunctionCalled::Lambda_Called; + parameter_correct = (i == VALUE1) && (j == VALUE2); + return i + j + 6; + }); int result = d(VALUE1, VALUE2); @@ -1234,7 +1253,7 @@ namespace } //************************************************************************* -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 TEST_FIXTURE(SetupFixture, test_make_delegate_member_static) { auto d = etl::make_delegate(); @@ -1247,7 +1266,7 @@ namespace CHECK(function_called == FunctionCalled::Member_Static_Called); CHECK(parameter_correct); } -#endif + #endif //************************************************************************* #if ETL_USING_CPP14 @@ -1266,7 +1285,7 @@ namespace #endif //************************************************************************* -#if ETL_USING_CPP17 + #if ETL_USING_CPP17 TEST_FIXTURE(SetupFixture, test_make_delegate_member_static_constexpr) { constexpr auto d = etl::make_delegate(); @@ -1279,7 +1298,7 @@ namespace CHECK(function_called == FunctionCalled::Member_Static_Called); CHECK(parameter_correct); } -#endif + #endif #if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 5)) //************************************************************************* @@ -1704,7 +1723,12 @@ namespace { etl::delegate d; - d.set([](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); }); + d.set( + [](int i, int j) + { + function_called = FunctionCalled::Lambda_Called; + parameter_correct = (i == VALUE1) && (j == VALUE2); + }); d(VALUE1, VALUE2); @@ -1864,7 +1888,7 @@ namespace auto d1 = etl::delegate::create(object); auto d2 = d1; - auto d3 = etl::delegate::create(+[](int, int) { }); + auto d3 = etl::delegate::create(+[](int, int) {}); auto d4 = d3; CHECK(d1 == d2); @@ -1878,7 +1902,7 @@ namespace auto d1 = etl::delegate::create(object); auto d2 = etl::delegate::create(object); - auto d3 = etl::delegate::create(+[](int, int) { }); + auto d3 = etl::delegate::create(+[](int, int) {}); CHECK(d1 != d2); CHECK(d1 != d3);