Updated etl::delgate to handle const functors correctly

Updated version info

Fixed functor delegate enable_if
This commit is contained in:
John Wellbelove 2022-12-16 18:05:24 +00:00
parent 8527d6864e
commit c9565d1fd9
11 changed files with 377 additions and 172 deletions

View File

@ -1,6 +1,6 @@
{
"name": "Embedded Template Library - Arduino",
"version": "20.35.6",
"version": "20.35.7",
"authors": {
"name": "John Wellbelove",
"email": "john.wellbelove@etlcpp.com"

View File

@ -1,5 +1,5 @@
name=Embedded Template Library - Arduino
version=20.35.6
version=20.35.7
author= John Wellbelove <john.wellbelove@etlcpp.com>
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
license=MIT

View File

@ -33,7 +33,7 @@ SOFTWARE.
#include "platform.h"
#if ETL_USING_CPP11 && !defined(ETL_CRC_FORCE_CPP03_IMPLEMENTATION)
#if ETL_USING_CPP11 && !defined(ETL_DELEGATE_FORCE_CPP03_IMPLEMENTATION)
#include "private/delegate_cpp11.h"
#else
#include "private/delegate_cpp03.h"

View File

@ -174,11 +174,13 @@ namespace etl
template <typename T>
class delegate;
template <typename TReturn, typename TParam>
class delegate<TReturn(TParam)> : public private_delegate::call_if_impl<delegate<TReturn(TParam)>, TReturn, TParam>
{
private:
typedef delegate<TReturn(TParam)> delegate_type;
public:
using private_delegate::call_if_impl<delegate<TReturn(TParam)>, TReturn, TParam>::call_if;
@ -202,11 +204,20 @@ namespace etl
// Construct from a functor.
//*************************************************************************
template <typename TFunctor>
delegate(const TFunctor& instance)
delegate(TFunctor& instance, typename etl::enable_if<etl::is_class<TFunctor>::value && !etl::is_same<delegate_type, TFunctor>::value, int>::type = 0)
{
assign((void*)(&instance), functor_stub<TFunctor>);
}
//*************************************************************************
// Construct from a const functor.
//*************************************************************************
template <typename TFunctor>
delegate(const TFunctor& instance, typename etl::enable_if<etl::is_class<TFunctor>::value && !etl::is_same<delegate_type, TFunctor>::value, int>::type = 0)
{
assign((void*)(&instance), const_functor_stub<TFunctor>);
}
//*************************************************************************
/// Create from function (Compile time).
//*************************************************************************
@ -221,12 +232,23 @@ namespace etl
//*************************************************************************
template <typename TFunctor>
static
typename etl::enable_if<etl::is_class<TFunctor>::value, delegate>::type
create(const TFunctor& instance)
typename etl::enable_if<etl::is_class<TFunctor>::value &&!etl::is_same<delegate_type, TFunctor>::value, delegate>::type
create(TFunctor& instance)
{
return delegate((void*)(&instance), functor_stub<TFunctor>);
}
//*************************************************************************
/// Create from a const Functor.
//*************************************************************************
template <typename TFunctor>
static
typename etl::enable_if<etl::is_class<TFunctor>::value && !etl::is_same<delegate_type, TFunctor>::value, delegate>::type
create(const TFunctor& instance)
{
return delegate((void*)(&instance), const_functor_stub<TFunctor>);
}
//*************************************************************************
/// Create from instance method (Run time).
//*************************************************************************
@ -273,15 +295,25 @@ namespace etl
}
//*************************************************************************
/// Set from Lambda or Functor.
/// Set from Functor.
//*************************************************************************
template <typename TFunctor>
typename etl::enable_if<etl::is_class<TFunctor>::value, void>::type
set(const TFunctor& instance)
typename etl::enable_if<etl::is_class<TFunctor>::value && !etl::is_same<delegate_type, TFunctor>::value, void>::type
set(TFunctor& instance)
{
assign((void*)(&instance), functor_stub<TFunctor>);
}
//*************************************************************************
/// Set from const Functor.
//*************************************************************************
template <typename TFunctor>
typename etl::enable_if<etl::is_class<TFunctor>::value && !etl::is_same<delegate_type, TFunctor>::value, void>::type
set(const TFunctor& instance)
{
assign((void*)(&instance), const_functor_stub<TFunctor>);
}
//*************************************************************************
/// Set from instance method (Run time).
//*************************************************************************
@ -384,16 +416,27 @@ namespace etl
}
//*************************************************************************
/// Create from Lambda or Functor.
/// Create from Functor.
//*************************************************************************
template <typename TFunctor>
typename etl::enable_if<etl::is_class<TFunctor>::value, delegate&>::type
operator =(const TFunctor& instance)
typename etl::enable_if<etl::is_class<TFunctor>::value && !etl::is_same<delegate_type, TFunctor>::value, delegate&>::type
operator =(TFunctor& instance)
{
assign((void*)(&instance), functor_stub<TFunctor>);
return *this;
}
//*************************************************************************
/// Create from const Functor.
//*************************************************************************
template <typename TFunctor>
typename etl::enable_if<etl::is_class<TFunctor>::value && !etl::is_same<delegate_type, TFunctor>::value, delegate&>::type
operator =(const TFunctor& instance)
{
assign((void*)(&instance), const_functor_stub<TFunctor>);
return *this;
}
//*************************************************************************
/// Checks equality.
//*************************************************************************
@ -549,7 +592,7 @@ namespace etl
}
//*************************************************************************
/// Stub call for a lambda or functor function.
/// Stub call for a functor function.
//*************************************************************************
template <typename TFunctor>
static TReturn functor_stub(void* object, TParam param)
@ -558,6 +601,16 @@ namespace etl
return (p->operator())(param);
}
//*************************************************************************
/// Stub call for a functor function.
//*************************************************************************
template <typename TFunctor>
static TReturn const_functor_stub(void* object, TParam param)
{
const TFunctor* p = static_cast<const TFunctor*>(object);
return (p->operator())(param);
}
//*************************************************************************
/// The invocation object.
//*************************************************************************
@ -568,9 +621,12 @@ namespace etl
/// Specialisation for void parameter.
//*************************************************************************
template <typename TReturn>
class delegate<TReturn(void)>
: public private_delegate::call_if_impl<delegate<TReturn(void)>, TReturn, void>
class delegate<TReturn(void)> : public private_delegate::call_if_impl<delegate<TReturn(void)>, TReturn, void>
{
private:
typedef delegate<TReturn(void)> delegate_type;
public:
using private_delegate::call_if_impl< delegate<TReturn(void)>, TReturn, void>::call_if;
@ -591,14 +647,23 @@ namespace etl
}
//*************************************************************************
// Construct from lambda or functor.
// Construct from functor.
//*************************************************************************
template <typename TFunctor>
delegate(const TFunctor& instance)
delegate(TFunctor& instance, typename etl::enable_if<etl::is_class<TFunctor>::value && !etl::is_same<delegate_type, TFunctor>::value, int>::type = 0)
{
assign((void*)(&instance), functor_stub<TFunctor>);
}
//*************************************************************************
// Construct from const functor.
//*************************************************************************
template <typename TFunctor>
delegate(const TFunctor& instance, typename etl::enable_if<etl::is_class<TFunctor>::value && !etl::is_same<delegate_type, TFunctor>::value, int>::type = 0)
{
assign((void*)(&instance), const_functor_stub<TFunctor>);
}
//*************************************************************************
/// Create from function (Compile time).
//*************************************************************************
@ -609,16 +674,27 @@ namespace etl
}
//*************************************************************************
/// Create from Lambda or Functor.
/// Create from Functor.
//*************************************************************************
template <typename TFunctor>
static
typename etl::enable_if<etl::is_class<TFunctor>::value, delegate>::type
create(const TFunctor& instance)
typename etl::enable_if<etl::is_class<TFunctor>::value && !etl::is_same<delegate_type, TFunctor>::value, delegate>::type
create(TFunctor& instance)
{
return delegate((void*)(&instance), functor_stub<TFunctor>);
}
//*************************************************************************
/// Create from const Functor.
//*************************************************************************
template <typename TFunctor>
static
typename etl::enable_if<etl::is_class<TFunctor>::value && !etl::is_same<delegate_type, TFunctor>::value, delegate>::type
create(const TFunctor& instance)
{
return delegate((void*)(&instance), const_functor_stub<TFunctor>);
}
//*************************************************************************
/// Create from instance method (Run time).
//*************************************************************************
@ -665,15 +741,25 @@ namespace etl
}
//*************************************************************************
/// Set from Lambda or Functor.
/// Set from Functor.
//*************************************************************************
template <typename TFunctor>
typename etl::enable_if<etl::is_class<TFunctor>::value, void>::type
set(const TFunctor& instance)
typename etl::enable_if<etl::is_class<TFunctor>::value && !etl::is_same<delegate_type, TFunctor>::value, void>::type
set(TFunctor& instance)
{
assign((void*)(&instance), functor_stub<TFunctor>);
}
//*************************************************************************
/// Set from const Functor.
//*************************************************************************
template <typename TFunctor>
typename etl::enable_if<etl::is_class<TFunctor>::value && !etl::is_same<delegate_type, TFunctor>::value, void>::type
set(const TFunctor& instance)
{
assign((void*)(&instance), const_functor_stub<TFunctor>);
}
//*************************************************************************
/// Set from instance method (Run time).
//*************************************************************************
@ -776,16 +862,27 @@ namespace etl
}
//*************************************************************************
/// Create from Lambda or Functor.
/// Create from Functor.
//*************************************************************************
template <typename TFunctor>
typename etl::enable_if<etl::is_class<TFunctor>::value, delegate&>::type
operator =(const TFunctor& instance)
typename etl::enable_if<etl::is_class<TFunctor>::value && !etl::is_same<delegate_type, TFunctor>::value, delegate&>::type
operator =(TFunctor& instance)
{
assign((void*)(&instance), functor_stub<TFunctor>);
return *this;
}
//*************************************************************************
/// Create from const Functor.
//*************************************************************************
template <typename TFunctor>
typename etl::enable_if<etl::is_class<TFunctor>::value && !etl::is_same<delegate_type, TFunctor>::value, delegate&>::type
operator =(const TFunctor& instance)
{
assign((void*)(&instance), const_functor_stub<TFunctor>);
return *this;
}
//*************************************************************************
/// Checks equality.
//*************************************************************************
@ -941,7 +1038,7 @@ namespace etl
}
//*************************************************************************
/// Stub call for a lambda or functor function.
/// Stub call for a functor function.
//*************************************************************************
template <typename TFunctor>
static TReturn functor_stub(void* object)
@ -950,6 +1047,16 @@ namespace etl
return (p->operator())();
}
//*************************************************************************
/// Stub call for a const functor function.
//*************************************************************************
template <typename TFunctor>
static TReturn const_functor_stub(void* object)
{
const TFunctor* p = static_cast<const TFunctor*>(object);
return (p->operator())();
}
//*************************************************************************
/// The invocation object.
//*************************************************************************

View File

@ -111,12 +111,21 @@ namespace etl
//*************************************************************************
// Construct from lambda or functor.
//*************************************************************************
template <typename TLambda, typename = etl::enable_if_t<etl::is_class<TLambda>::value, void>>
ETL_CONSTEXPR14 delegate(const TLambda& instance)
template <typename TLambda, typename = etl::enable_if_t<etl::is_class<TLambda>::value && !etl::is_same<etl::delegate<TReturn(TParams...)>, TLambda>::value, void>>
ETL_CONSTEXPR14 delegate(TLambda& instance)
{
assign((void*)(&instance), lambda_stub<TLambda>);
}
//*************************************************************************
// Construct from const lambda or functor.
//*************************************************************************
template <typename TLambda, typename = etl::enable_if_t<etl::is_class<TLambda>::value && !etl::is_same<etl::delegate<TReturn(TParams...)>, TLambda>::value, void>>
ETL_CONSTEXPR14 delegate(const TLambda& instance)
{
assign((void*)(&instance), const_lambda_stub<TLambda>);
}
//*************************************************************************
/// Create from function (Compile time).
//*************************************************************************
@ -130,13 +139,23 @@ namespace etl
//*************************************************************************
/// Create from Lambda or Functor.
//*************************************************************************
template <typename TLambda, typename = etl::enable_if_t<etl::is_class<TLambda>::value, void>>
template <typename TLambda, typename = etl::enable_if_t<etl::is_class<TLambda>::value && !etl::is_same<etl::delegate<TReturn(TParams...)>, TLambda>::value, void>>
ETL_NODISCARD
static ETL_CONSTEXPR14 delegate create(const TLambda& instance)
static ETL_CONSTEXPR14 delegate create(TLambda& instance)
{
return delegate((void*)(&instance), lambda_stub<TLambda>);
}
//*************************************************************************
/// Create from const Lambda or Functor.
//*************************************************************************
template <typename TLambda, typename = etl::enable_if_t<etl::is_class<TLambda>::value && !etl::is_same<etl::delegate<TReturn(TParams...)>, TLambda>::value, void>>
ETL_NODISCARD
static ETL_CONSTEXPR14 delegate create(const TLambda& instance)
{
return delegate((void*)(&instance), const_lambda_stub<TLambda>);
}
//*************************************************************************
/// Create from instance method (Run time).
//*************************************************************************
@ -203,12 +222,21 @@ namespace etl
//*************************************************************************
/// Set from Lambda or Functor.
//*************************************************************************
template <typename TLambda, typename = etl::enable_if_t<etl::is_class<TLambda>::value, void>>
ETL_CONSTEXPR14 void set(const TLambda& instance)
template <typename TLambda, typename = etl::enable_if_t<etl::is_class<TLambda>::value && !etl::is_same<etl::delegate<TReturn(TParams...)>, TLambda>::value, void>>
ETL_CONSTEXPR14 void set(TLambda& instance)
{
assign((void*)(&instance), lambda_stub<TLambda>);
}
//*************************************************************************
/// Set from const Lambda or Functor.
//*************************************************************************
template <typename TLambda, typename = etl::enable_if_t<etl::is_class<TLambda>::value && !etl::is_same<etl::delegate<TReturn(TParams...)>, TLambda>::value, void>>
ETL_CONSTEXPR14 void set(const TLambda& instance)
{
assign((void*)(&instance), const_lambda_stub<TLambda>);
}
//*************************************************************************
/// Set from instance method (Run time).
//*************************************************************************
@ -347,13 +375,23 @@ namespace etl
//*************************************************************************
/// Create from Lambda or Functor.
//*************************************************************************
template <typename TLambda, typename = etl::enable_if_t<etl::is_class<TLambda>::value, void>>
ETL_CONSTEXPR14 delegate& operator =(const TLambda& instance)
template <typename TLambda, typename = etl::enable_if_t<etl::is_class<TLambda>::value && !etl::is_same<etl::delegate<TReturn(TParams...)>, TLambda>::value, void>>
ETL_CONSTEXPR14 delegate& operator =(TLambda& instance)
{
assign((void*)(&instance), lambda_stub<TLambda>);
return *this;
}
//*************************************************************************
/// Create from const Lambda or Functor.
//*************************************************************************
template <typename TLambda, typename = etl::enable_if_t<etl::is_class<TLambda>::value && !etl::is_same<etl::delegate<TReturn(TParams...)>, TLambda>::value, void>>
ETL_CONSTEXPR14 delegate& operator =(const TLambda& instance)
{
assign((void*)(&instance), const_lambda_stub<TLambda>);
return *this;
}
//*************************************************************************
/// Checks equality.
//*************************************************************************
@ -517,6 +555,16 @@ namespace etl
return (p->operator())(etl::forward<TParams>(arg)...);
}
//*************************************************************************
/// Stub call for a const lambda or functor function.
//*************************************************************************
template <typename TLambda>
static ETL_CONSTEXPR14 TReturn const_lambda_stub(void* object, TParams... arg)
{
const TLambda* p = static_cast<const TLambda*>(object);
return (p->operator())(etl::forward<TParams>(arg)...);
}
//*************************************************************************
/// The invocation object.
//*************************************************************************

View File

@ -40,7 +40,7 @@ SOFTWARE.
#define ETL_VERSION_MAJOR 20
#define ETL_VERSION_MINOR 35
#define ETL_VERSION_PATCH 6
#define ETL_VERSION_PATCH 7
#define ETL_VERSION ETL_STRING(ETL_VERSION_MAJOR) "." ETL_STRING(ETL_VERSION_MINOR) "." ETL_STRING(ETL_VERSION_PATCH)
#define ETL_VERSION_W ETL_WIDE_STRING(ETL_VERSION_MAJOR) L"." ETL_WIDE_STRING(ETL_VERSION_MINOR) L"." ETL_WIDE_STRING(ETL_VERSION_PATCH)

View File

@ -1,6 +1,6 @@
{
"name": "Embedded Template Library",
"version": "20.35.6",
"version": "20.35.7",
"authors": {
"name": "John Wellbelove",
"email": "john.wellbelove@etlcpp.com"

View File

@ -1,5 +1,5 @@
name=Embedded Template Library
version=20.35.6
version=20.35.7
author= John Wellbelove <john.wellbelove@etlcpp.com>
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
license=MIT

View File

@ -37,10 +37,35 @@ SOFTWARE.
namespace
{
//*****************************************************************************
enum class FunctionCalled : int
{
Not_Called,
Free_Void_Called,
Free_Int_Called,
Free_Reference_Called,
Free_Moveableonly_Called,
Normal_Called,
Normal_Returning_Void_Called,
Alternative_Called,
Member_Void_Called,
Member_Void_Const_Called,
Member_Int_Called,
Member_Int_Const_Called,
Member_Reference_Called,
Member_Reference_Const_Called,
Member_Moveableonly_Called,
Member_Static_Called,
Operator_Called,
Operator_Const_Called,
Lambda_Called
};
FunctionCalled function_called = FunctionCalled::Not_Called;
//*****************************************************************************
const int VALUE1 = 1;
const int VALUE2 = 2;
bool function_called = false;
bool parameter_correct = false;
//*****************************************************************************
@ -70,7 +95,7 @@ namespace
//*****************************************************************************
void free_void()
{
function_called = true;
function_called = FunctionCalled::Free_Void_Called;
}
//*****************************************************************************
@ -78,7 +103,7 @@ namespace
//*****************************************************************************
void free_int(int i, int j)
{
function_called = true;
function_called = FunctionCalled::Free_Int_Called;;
parameter_correct = (i == VALUE1) && (j == VALUE2);
}
@ -87,7 +112,7 @@ namespace
//*****************************************************************************
void free_reference(const Data& data, int j)
{
function_called = true;
function_called = FunctionCalled::Free_Reference_Called;
parameter_correct = (data.d == VALUE1) && (j == VALUE2);
}
@ -96,7 +121,7 @@ namespace
//*****************************************************************************
void free_moveableonly(MoveableOnlyData&& data)
{
function_called = true;
function_called = FunctionCalled::Free_Moveableonly_Called;
parameter_correct = (data.d == VALUE1);
}
@ -105,7 +130,7 @@ namespace
//*****************************************************************************
int normal(int i, int j)
{
function_called = true;
function_called = FunctionCalled::Normal_Called;
parameter_correct = (i == VALUE1) && (j == VALUE2);
return i + j;
@ -116,7 +141,7 @@ namespace
//*****************************************************************************
void normal_returning_void(int i, int j)
{
function_called = true;
function_called = FunctionCalled::Normal_Returning_Void_Called;
parameter_correct = (i == VALUE1) && (j == VALUE2);
}
@ -125,7 +150,7 @@ namespace
//*****************************************************************************
int alternative(int i, int j)
{
function_called = true;
function_called = FunctionCalled::Alternative_Called;
parameter_correct = (i == VALUE1) && (j == VALUE2);
return i + j + 1;
@ -142,25 +167,25 @@ namespace
// void
void member_void()
{
function_called = true;
function_called = FunctionCalled::Member_Void_Called;
}
void member_void_const() const
{
function_called = true;
function_called = FunctionCalled::Member_Void_Const_Called;
}
//*******************************************
// int
void member_int(int i, int j)
{
function_called = true;
function_called = FunctionCalled::Member_Int_Called;
parameter_correct = (i == VALUE1) && (j == VALUE2);
}
void member_int_const(int i, int j) const
{
function_called = true;
function_called = FunctionCalled::Member_Int_Const_Called;
parameter_correct = (i == VALUE1) && (j == VALUE2);
}
@ -168,13 +193,13 @@ namespace
// reference
void member_reference(const Data& data, int j)
{
function_called = true;
function_called = FunctionCalled::Member_Reference_Called;
parameter_correct = (data.d == VALUE1) && (j == VALUE2);
}
void member_reference_const(const Data& data, int j) const
{
function_called = true;
function_called = FunctionCalled::Member_Reference_Const_Called;
parameter_correct = (data.d == VALUE1) && (j == VALUE2);
}
@ -182,7 +207,7 @@ namespace
// moveable only data
void member_moveableonly(MoveableOnlyData&& data)
{
function_called = true;
function_called = FunctionCalled::Member_Moveableonly_Called;
parameter_correct = (data.d == VALUE1);
}
@ -190,7 +215,7 @@ namespace
// static
static void member_static(const Data& data, int j)
{
function_called = true;
function_called = FunctionCalled::Member_Static_Called;
parameter_correct = (data.d == VALUE1) && (j == VALUE2);
}
@ -198,12 +223,12 @@ namespace
// operator()
void operator()()
{
function_called = true;
function_called = FunctionCalled::Operator_Called;
}
void operator()() const
{
function_called = true;
function_called = FunctionCalled::Operator_Const_Called;
}
};
@ -226,7 +251,7 @@ namespace
{
SetupFixture()
{
function_called = false;
function_called = FunctionCalled::Not_Called;
parameter_correct = false;
}
};
@ -272,7 +297,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Free_Void_Called);
}
//*************************************************************************
@ -282,7 +307,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Free_Void_Called);
}
//*************************************************************************
@ -292,7 +317,7 @@ namespace
d(VALUE1, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Free_Int_Called);
CHECK(parameter_correct);
}
@ -303,7 +328,7 @@ namespace
d(VALUE1, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Free_Int_Called);
CHECK(parameter_correct);
}
@ -317,7 +342,7 @@ namespace
d(data, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Free_Reference_Called);
CHECK(parameter_correct);
}
@ -331,7 +356,7 @@ namespace
d(data, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Free_Reference_Called);
CHECK(parameter_correct);
}
@ -345,7 +370,7 @@ namespace
d(std::move(data));
CHECK(function_called);
CHECK(function_called == FunctionCalled::Free_Moveableonly_Called);
CHECK(parameter_correct);
}
@ -359,31 +384,31 @@ namespace
d(std::move(data));
CHECK(function_called);
CHECK(function_called == FunctionCalled::Free_Moveableonly_Called);
CHECK(parameter_correct);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_lambda_int)
{
etl::delegate<void(int, int)> d([](int i, int j) { function_called = true; parameter_correct = (i == VALUE1) && (j == VALUE2); });
etl::delegate<void(int, int)> d([](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); });
d(VALUE1, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Lambda_Called);
CHECK(parameter_correct);
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_lambda_int_create)
{
auto lambda = [](int i, int j) { function_called = true; parameter_correct = (i == VALUE1) && (j == VALUE2); };
auto lambda = [](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); };
etl::delegate<void(int, int)> d(lambda);
d(VALUE1, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Lambda_Called);
CHECK(parameter_correct);
}
@ -396,7 +421,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Operator_Called);
}
//*************************************************************************
@ -408,7 +433,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Operator_Called);
}
//*************************************************************************
@ -420,7 +445,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Operator_Called);
}
//*************************************************************************
@ -432,7 +457,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Operator_Const_Called);
}
#if !defined(ETL_COMPILER_GCC)
@ -443,7 +468,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Operator_Called);
}
//*************************************************************************
@ -453,7 +478,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Operator_Called);
}
//*************************************************************************
@ -463,7 +488,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Operator_Const_Called);
}
//*************************************************************************
@ -473,7 +498,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Operator_Const_Called);
}
#endif
@ -488,7 +513,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Operator_Called);
}
//*************************************************************************
@ -500,7 +525,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Void_Called);
}
//*************************************************************************
@ -512,7 +537,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Void_Called);
}
//*************************************************************************
@ -524,7 +549,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Void_Const_Called);
}
//*************************************************************************
@ -536,7 +561,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Void_Const_Called);
}
//*************************************************************************
@ -548,7 +573,7 @@ namespace
d(VALUE1, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Int_Called);
CHECK(parameter_correct);
}
@ -561,7 +586,7 @@ namespace
d(VALUE1, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Int_Called);
CHECK(parameter_correct);
}
@ -574,7 +599,7 @@ namespace
d(VALUE1, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Int_Const_Called);
CHECK(parameter_correct);
}
@ -587,7 +612,7 @@ namespace
d(VALUE1, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Int_Const_Called);
CHECK(parameter_correct);
}
@ -602,7 +627,7 @@ namespace
d(data, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Called);
CHECK(parameter_correct);
}
@ -617,7 +642,7 @@ namespace
d(data, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Called);
CHECK(parameter_correct);
}
@ -632,7 +657,7 @@ namespace
d(data, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Const_Called);
CHECK(parameter_correct);
}
@ -647,7 +672,7 @@ namespace
d(data, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Const_Called);
CHECK(parameter_correct);
}
@ -662,7 +687,7 @@ namespace
d(std::move(data));
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Moveableonly_Called);
CHECK(parameter_correct);
}
@ -677,7 +702,7 @@ namespace
d(std::move(data));
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Moveableonly_Called);
CHECK(parameter_correct);
}
@ -691,7 +716,7 @@ namespace
d(data, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Static_Called);
CHECK(parameter_correct);
}
@ -705,7 +730,7 @@ namespace
d(data, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Static_Called);
CHECK(parameter_correct);
}
@ -717,7 +742,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Void_Called);
}
//*************************************************************************
@ -727,7 +752,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Void_Called);
}
//*************************************************************************
@ -737,7 +762,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Void_Const_Called);
}
//*************************************************************************
@ -747,7 +772,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Void_Const_Called);
}
//*************************************************************************
@ -757,7 +782,7 @@ namespace
d(VALUE1, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Int_Called);
CHECK(parameter_correct);
}
@ -768,7 +793,7 @@ namespace
d(VALUE1, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Int_Called);
CHECK(parameter_correct);
}
@ -779,7 +804,7 @@ namespace
d(VALUE1, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Int_Const_Called);
CHECK(parameter_correct);
}
@ -790,7 +815,7 @@ namespace
d(VALUE1, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Int_Const_Called);
CHECK(parameter_correct);
}
@ -804,7 +829,7 @@ namespace
d(data, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Called);
CHECK(parameter_correct);
}
@ -818,7 +843,7 @@ namespace
d(data, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Called);
CHECK(parameter_correct);
}
@ -832,7 +857,7 @@ namespace
d(data, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Const_Called);
CHECK(parameter_correct);
}
@ -846,7 +871,7 @@ namespace
d(data, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Const_Called);
CHECK(parameter_correct);
}
@ -859,7 +884,7 @@ namespace
d(VALUE1, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Free_Int_Called);
CHECK(parameter_correct);
}
@ -868,11 +893,11 @@ namespace
{
etl::delegate<void(int, int)> d;
d.set([](int i, int j) { function_called = true; 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);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Lambda_Called);
CHECK(parameter_correct);
}
@ -889,7 +914,7 @@ namespace
d(data, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Called);
CHECK(parameter_correct);
}
@ -906,7 +931,7 @@ namespace
d(data, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Const_Called);
CHECK(parameter_correct);
}
@ -922,7 +947,7 @@ namespace
d(data, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Called);
CHECK(parameter_correct);
}
@ -938,7 +963,7 @@ namespace
d(data, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Const_Called);
CHECK(parameter_correct);
}
#endif
@ -953,7 +978,7 @@ namespace
d2(VALUE1, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Int_Called);
CHECK(parameter_correct);
}
@ -967,7 +992,7 @@ namespace
d2(VALUE1, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Int_Called);
CHECK(parameter_correct);
}
@ -983,7 +1008,7 @@ namespace
d2(VALUE1, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Int_Called);
CHECK(parameter_correct);
}
@ -1090,7 +1115,7 @@ namespace
bool was_called = d.call_if(VALUE1, VALUE2);
CHECK(was_called);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Normal_Returning_Void_Called);
CHECK(parameter_correct);
}
@ -1102,7 +1127,7 @@ namespace
bool was_called = d.call_if(VALUE1, VALUE2);
CHECK(!was_called);
CHECK(!function_called);
CHECK(function_called == FunctionCalled::Not_Called);
CHECK(!parameter_correct);
}
@ -1115,7 +1140,7 @@ namespace
d(VALUE1, VALUE2);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Free_Int_Called);
CHECK(parameter_correct);
}
};

View File

@ -35,9 +35,34 @@ SOFTWARE.
namespace
{
//*****************************************************************************
enum class FunctionCalled : int
{
Not_Called,
Free_Void_Called,
Free_Int_Called,
Free_Reference_Called,
Free_Moveableonly_Called,
Normal_Called,
Normal_Returning_Void_Called,
Alternative_Called,
Member_Void_Called,
Member_Void_Const_Called,
Member_Int_Called,
Member_Int_Const_Called,
Member_Reference_Called,
Member_Reference_Const_Called,
Member_Moveableonly_Called,
Member_Static_Called,
Operator_Called,
Operator_Const_Called,
Lambda_Called
};
FunctionCalled function_called = FunctionCalled::Not_Called;
//*****************************************************************************
const int VALUE1 = 1;
bool function_called = false;
bool parameter_correct = false;
//*****************************************************************************
@ -53,7 +78,7 @@ namespace
//*****************************************************************************
void free_void()
{
function_called = true;
function_called = FunctionCalled::Free_Void_Called;
}
//*****************************************************************************
@ -61,7 +86,7 @@ namespace
//*****************************************************************************
void free_int(int i)
{
function_called = true;
function_called = FunctionCalled::Free_Int_Called;
parameter_correct = (i == VALUE1);
}
@ -70,7 +95,7 @@ namespace
//*****************************************************************************
void free_reference(const Data& data)
{
function_called = true;
function_called = FunctionCalled::Free_Reference_Called;
parameter_correct = (data.d == VALUE1);
}
@ -79,7 +104,7 @@ namespace
//*****************************************************************************
int normal(int i)
{
function_called = true;
function_called = FunctionCalled::Normal_Called;
parameter_correct = (i == VALUE1);
return i;
@ -90,7 +115,7 @@ namespace
//*****************************************************************************
void normal_returning_void(int i)
{
function_called = true;
function_called = FunctionCalled::Normal_Returning_Void_Called;
parameter_correct = (i == VALUE1);
}
@ -99,7 +124,7 @@ namespace
//*****************************************************************************
int alternative(int i)
{
function_called = true;
function_called = FunctionCalled::Alternative_Called;
parameter_correct = (i == VALUE1);
return i + 1;
@ -116,25 +141,25 @@ namespace
// void
void member_void()
{
function_called = true;
function_called = FunctionCalled::Member_Void_Called;
}
void member_void_const() const
{
function_called = true;
function_called = FunctionCalled::Member_Void_Const_Called;
}
//*******************************************
// int
void member_int(int i)
{
function_called = true;
function_called = FunctionCalled::Member_Int_Called;
parameter_correct = (i == VALUE1);
}
void member_int_const(int i) const
{
function_called = true;
function_called = FunctionCalled::Member_Int_Const_Called;
parameter_correct = (i == VALUE1);
}
@ -142,13 +167,13 @@ namespace
// reference
void member_reference(const Data& data)
{
function_called = true;
function_called = FunctionCalled::Member_Reference_Called;
parameter_correct = (data.d == VALUE1);
}
void member_reference_const(const Data& data) const
{
function_called = true;
function_called = FunctionCalled::Member_Reference_Const_Called;
parameter_correct = (data.d == VALUE1);
}
@ -156,7 +181,7 @@ namespace
// static
static void member_static(const Data& data)
{
function_called = true;
function_called = FunctionCalled::Member_Static_Called;
parameter_correct = (data.d == VALUE1);
}
@ -164,12 +189,12 @@ namespace
// operator()
void operator()()
{
function_called = true;
function_called = FunctionCalled::Operator_Called;
}
void operator()() const
{
function_called = true;
function_called = FunctionCalled::Operator_Const_Called;
}
};
@ -192,7 +217,7 @@ namespace
{
SetupFixture()
{
function_called = false;
function_called = FunctionCalled::Not_Called;
parameter_correct = false;
}
};
@ -217,7 +242,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Free_Void_Called);
}
//*************************************************************************
@ -227,7 +252,7 @@ namespace
d(VALUE1);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Free_Int_Called);
CHECK(parameter_correct);
}
@ -241,7 +266,7 @@ namespace
d(data);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Free_Reference_Called);
CHECK(parameter_correct);
}
@ -254,7 +279,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Operator_Called);
}
//*************************************************************************
@ -266,7 +291,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Operator_Called);
}
//*************************************************************************
@ -278,7 +303,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Operator_Const_Called);
}
#if !defined(ETL_COMPILER_GCC)
@ -289,7 +314,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Operator_Called);
}
//*************************************************************************
@ -299,7 +324,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Operator_Const_Called);
}
#endif
@ -314,7 +339,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Operator_Called);
}
//*************************************************************************
@ -326,7 +351,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Void_Called);
}
//*************************************************************************
@ -338,7 +363,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Void_Const_Called);
}
//*************************************************************************
@ -350,7 +375,7 @@ namespace
d(VALUE1);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Int_Called);
CHECK(parameter_correct);
}
@ -363,7 +388,7 @@ namespace
d(VALUE1);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Int_Const_Called);
CHECK(parameter_correct);
}
@ -378,7 +403,7 @@ namespace
d(data);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Called);
CHECK(parameter_correct);
}
@ -393,7 +418,7 @@ namespace
d(data);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Const_Called);
CHECK(parameter_correct);
}
@ -407,7 +432,7 @@ namespace
d(data);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Static_Called);
CHECK(parameter_correct);
}
@ -419,7 +444,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Void_Called);
}
//*************************************************************************
@ -429,7 +454,7 @@ namespace
d();
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Void_Const_Called);
}
//*************************************************************************
@ -439,7 +464,7 @@ namespace
d(VALUE1);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Int_Called);
CHECK(parameter_correct);
}
@ -450,7 +475,7 @@ namespace
d(VALUE1);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Int_Const_Called);
CHECK(parameter_correct);
}
@ -464,7 +489,7 @@ namespace
d(data);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Called);
CHECK(parameter_correct);
}
@ -478,7 +503,7 @@ namespace
d(data);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Const_Called);
CHECK(parameter_correct);
}
@ -491,7 +516,7 @@ namespace
d(VALUE1);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Free_Int_Called);
CHECK(parameter_correct);
}
@ -500,11 +525,11 @@ namespace
{
etl_cpp03::delegate<void(int)> d;
d.set([](int i) { function_called = true; parameter_correct = (i == VALUE1); });
d.set([](int i) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1); });
d(VALUE1);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Lambda_Called);
CHECK(parameter_correct);
}
@ -521,7 +546,7 @@ namespace
d(data);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Called);
CHECK(parameter_correct);
}
@ -538,7 +563,7 @@ namespace
d(data);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Const_Called);
CHECK(parameter_correct);
}
@ -554,7 +579,7 @@ namespace
d(data);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Called);
CHECK(parameter_correct);
}
@ -570,7 +595,7 @@ namespace
d(data);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Reference_Const_Called);
CHECK(parameter_correct);
}
#endif
@ -585,7 +610,7 @@ namespace
d2(VALUE1);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Int_Called);
CHECK(parameter_correct);
}
@ -601,7 +626,7 @@ namespace
d2(VALUE1);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Member_Int_Called);
CHECK(parameter_correct);
}
@ -708,7 +733,7 @@ namespace
bool was_called = d.call_if(VALUE1);
CHECK(was_called);
CHECK(function_called);
CHECK(function_called == FunctionCalled::Normal_Returning_Void_Called);
CHECK(parameter_correct);
}
@ -720,7 +745,7 @@ namespace
bool was_called = d.call_if(VALUE1);
CHECK(!was_called);
CHECK(!function_called);
CHECK(function_called == FunctionCalled::Not_Called);
CHECK(!parameter_correct);
}
};

View File

@ -1 +1 @@
20.35.6
20.35.7