Merged from local copy of PR1295

This commit is contained in:
John Wellbelove 2026-04-04 00:14:49 +01:00
parent f7e1384a70
commit 576b03f38d
3 changed files with 73 additions and 70 deletions

View File

@ -1141,18 +1141,16 @@ namespace etl
//***************************************************************************
// Reference, Reference
template <typename TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_left(TLink& parent, TLink& child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::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 TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_left(TLink* parent, TLink* child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type link_left(TLink* parent, TLink* child)
{
if (parent != ETL_NULLPTR)
{
@ -1168,8 +1166,7 @@ namespace etl
//***********************************
// Reference, Pointer
template <typename TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_left(TLink& parent, TLink* child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type link_left(TLink& parent, TLink* child)
{
parent.etl_left = child;
@ -1182,8 +1179,7 @@ namespace etl
//***********************************
// Pointer, Reference
template <typename TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_left(TLink* parent, TLink& child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::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 TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_right(TLink& parent, TLink& child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::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 TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_right(TLink* parent, TLink* child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type link_right(TLink* parent, TLink* child)
{
if (parent != ETL_NULLPTR)
{
@ -1223,8 +1217,7 @@ namespace etl
//***********************************
template <typename TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_right(TLink& parent, TLink* child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type link_right(TLink& parent, TLink* child)
{
parent.etl_right = child;
@ -1236,8 +1229,7 @@ namespace etl
//***********************************
template <typename TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_right(TLink* parent, TLink& child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type link_right(TLink* parent, TLink& child)
{
if (parent != ETL_NULLPTR)
{
@ -1252,8 +1244,7 @@ namespace etl
//***************************************************************************
// Reference, Reference
template <typename TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_rotate_left(TLink& parent, TLink& child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::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 TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_rotate_left(TLink* parent, TLink* child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::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 TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_rotate_left(TLink& parent, TLink* child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type link_rotate_left(TLink& parent, TLink* child)
{
if (child != ETL_NULLPTR)
{
@ -1308,8 +1297,7 @@ namespace etl
//***********************************
// Pointer, Reference
template <typename TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_rotate_left(TLink* parent, TLink& child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::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 TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_rotate_right(TLink& parent, TLink& child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::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 TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_rotate_right(TLink* parent, TLink* child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::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 TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_rotate_right(TLink& parent, TLink* child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type link_rotate_right(TLink& parent, TLink* child)
{
if (child != ETL_NULLPTR)
{
@ -1372,8 +1357,7 @@ namespace etl
//***********************************
template <typename TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_rotate_right(TLink* parent, TLink& child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::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 TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_rotate(TLink& parent, TLink& child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::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 TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_rotate(TLink* parent, TLink* child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::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 TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_rotate(TLink& parent, TLink* child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::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 TLink>
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type
link_rotate(TLink* parent, TLink& child)
typename etl::enable_if<etl::is_same<TLink, etl::tree_link<TLink::ID> >::value, void>::type link_rotate(TLink* parent, TLink& child)
{
if (parent != ETL_NULLPTR)
{

View File

@ -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 <typename TLambda, typename = etl::enable_if_t<etl::is_class<TLambda>::value &&
!etl::is_same<etl::delegate<TReturn(TArgs...)>, TLambda>::value &&
!etl::is_convertible<TLambda, function_ptr>::value, void>>
template <typename TLambda,
typename = etl::enable_if_t<etl::is_class<TLambda>::value && !etl::is_same<etl::delegate<TReturn(TArgs...)>, TLambda>::value
&& !etl::is_convertible<TLambda, function_ptr>::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 <typename T, TReturn(T::*Method)(TArgs...)>
template <typename T, TReturn (T::*Method)(TArgs...)>
static ETL_CONSTEXPR14 TReturn method_stub(const invocation_element& invocation, TArgs... args)
{
T* p = static_cast<T*>(invocation.ptr.object);
@ -749,7 +748,7 @@ namespace etl
//*************************************************************************
/// Stub call for a const member function. Run time instance.
//*************************************************************************
template <typename T, TReturn(T::*Method)(TArgs...) const>
template <typename T, TReturn (T::*Method)(TArgs...) const>
static ETL_CONSTEXPR14 TReturn const_method_stub(const invocation_element& invocation, TArgs... args)
{
T* const p = static_cast<T*>(invocation.ptr.object);
@ -759,7 +758,7 @@ namespace etl
//*************************************************************************
/// Stub call for a member function. Compile time instance.
//*************************************************************************
template <typename T, TReturn(T::*Method)(TArgs...), T& Instance>
template <typename T, TReturn (T::*Method)(TArgs...), T& Instance>
static ETL_CONSTEXPR14 TReturn method_instance_stub(const invocation_element&, TArgs... args)
{
return (Instance.*Method)(etl::forward<TArgs>(args)...);
@ -768,7 +767,7 @@ namespace etl
//*************************************************************************
/// Stub call for a const member function. Compile time instance.
//*************************************************************************
template <typename T, TReturn(T::*Method)(TArgs...) const, const T& Instance>
template <typename T, TReturn (T::*Method)(TArgs...) const, const T& Instance>
static ETL_CONSTEXPR14 TReturn const_method_instance_stub(const invocation_element&, TArgs... args)
{
return (Instance.*Method)(etl::forward<TArgs>(args)...);
@ -788,7 +787,7 @@ namespace etl
//*************************************************************************
/// Stub call for a free function.
//*************************************************************************
template <TReturn(*Method)(TArgs...)>
template <TReturn (*Method)(TArgs...)>
static ETL_CONSTEXPR14 TReturn function_stub(const invocation_element&, TArgs... args)
{
return (Method)(etl::forward<TArgs>(args)...);

View File

@ -644,7 +644,12 @@ namespace
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_construct_from_rvalue_non_capturing_lambda)
{
etl::delegate<int(int, int)> d(+[](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); return i + j; });
etl::delegate<int(int, int)> 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<int(int, int)> 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<int(int, int)>::create(+[](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); return i + j + 5; });
auto d = etl::delegate<int(int, int)>::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<int(int, int)> 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<Object::member_static>();
@ -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<Object::member_static>();
@ -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<void(int, int)> 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<void(int, int)>::create<Object, &Object::member_int>(object);
auto d2 = d1;
auto d3 = etl::delegate<void(int, int)>::create(+[](int, int) { });
auto d3 = etl::delegate<void(int, int)>::create(+[](int, int) {});
auto d4 = d3;
CHECK(d1 == d2);
@ -1878,7 +1902,7 @@ namespace
auto d1 = etl::delegate<void(int, int)>::create<Object, &Object::member_int>(object);
auto d2 = etl::delegate<void(int, int)>::create<Object, &Object::member_int_const>(object);
auto d3 = etl::delegate<void(int, int)>::create(+[](int, int) { });
auto d3 = etl::delegate<void(int, int)>::create(+[](int, int) {});
CHECK(d1 != d2);
CHECK(d1 != d3);