From c9565d1fd92f030bdc205a14f9d6a2b783c19ad5 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 16 Dec 2022 18:05:24 +0000 Subject: [PATCH] Updated etl::delgate to handle const functors correctly Updated version info Fixed functor delegate enable_if --- arduino/library-arduino.json | 2 +- arduino/library-arduino.properties | 2 +- include/etl/delegate.h | 2 +- include/etl/private/delegate_cpp03.h | 159 +++++++++++++++++++---- include/etl/private/delegate_cpp11.h | 64 +++++++-- include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- test/test_delegate.cpp | 187 +++++++++++++++------------ test/test_delegate_cpp03.cpp | 125 +++++++++++------- version.txt | 2 +- 11 files changed, 377 insertions(+), 172 deletions(-) diff --git a/arduino/library-arduino.json b/arduino/library-arduino.json index e2d4a0d9c..706d8b408 100644 --- a/arduino/library-arduino.json +++ b/arduino/library-arduino.json @@ -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" diff --git a/arduino/library-arduino.properties b/arduino/library-arduino.properties index 5c372eebf..fe39a17cc 100644 --- a/arduino/library-arduino.properties +++ b/arduino/library-arduino.properties @@ -1,5 +1,5 @@ name=Embedded Template Library - Arduino -version=20.35.6 +version=20.35.7 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/include/etl/delegate.h b/include/etl/delegate.h index 4220b65f4..d03119279 100644 --- a/include/etl/delegate.h +++ b/include/etl/delegate.h @@ -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" diff --git a/include/etl/private/delegate_cpp03.h b/include/etl/private/delegate_cpp03.h index 8afb09c9a..1116d8007 100644 --- a/include/etl/private/delegate_cpp03.h +++ b/include/etl/private/delegate_cpp03.h @@ -174,11 +174,13 @@ namespace etl template class delegate; - - template class delegate : public private_delegate::call_if_impl, TReturn, TParam> { + private: + + typedef delegate delegate_type; + public: using private_delegate::call_if_impl, TReturn, TParam>::call_if; @@ -202,11 +204,20 @@ namespace etl // Construct from a functor. //************************************************************************* template - delegate(const TFunctor& instance) + delegate(TFunctor& instance, typename etl::enable_if::value && !etl::is_same::value, int>::type = 0) { assign((void*)(&instance), functor_stub); } + //************************************************************************* + // Construct from a const functor. + //************************************************************************* + template + delegate(const TFunctor& instance, typename etl::enable_if::value && !etl::is_same::value, int>::type = 0) + { + assign((void*)(&instance), const_functor_stub); + } + //************************************************************************* /// Create from function (Compile time). //************************************************************************* @@ -221,12 +232,23 @@ namespace etl //************************************************************************* template static - typename etl::enable_if::value, delegate>::type - create(const TFunctor& instance) + typename etl::enable_if::value &&!etl::is_same::value, delegate>::type + create(TFunctor& instance) { return delegate((void*)(&instance), functor_stub); } + //************************************************************************* + /// Create from a const Functor. + //************************************************************************* + template + static + typename etl::enable_if::value && !etl::is_same::value, delegate>::type + create(const TFunctor& instance) + { + return delegate((void*)(&instance), const_functor_stub); + } + //************************************************************************* /// Create from instance method (Run time). //************************************************************************* @@ -273,15 +295,25 @@ namespace etl } //************************************************************************* - /// Set from Lambda or Functor. + /// Set from Functor. //************************************************************************* template - typename etl::enable_if::value, void>::type - set(const TFunctor& instance) + typename etl::enable_if::value && !etl::is_same::value, void>::type + set(TFunctor& instance) { assign((void*)(&instance), functor_stub); } + //************************************************************************* + /// Set from const Functor. + //************************************************************************* + template + typename etl::enable_if::value && !etl::is_same::value, void>::type + set(const TFunctor& instance) + { + assign((void*)(&instance), const_functor_stub); + } + //************************************************************************* /// Set from instance method (Run time). //************************************************************************* @@ -384,16 +416,27 @@ namespace etl } //************************************************************************* - /// Create from Lambda or Functor. + /// Create from Functor. //************************************************************************* template - typename etl::enable_if::value, delegate&>::type - operator =(const TFunctor& instance) + typename etl::enable_if::value && !etl::is_same::value, delegate&>::type + operator =(TFunctor& instance) { assign((void*)(&instance), functor_stub); return *this; } + //************************************************************************* + /// Create from const Functor. + //************************************************************************* + template + typename etl::enable_if::value && !etl::is_same::value, delegate&>::type + operator =(const TFunctor& instance) + { + assign((void*)(&instance), const_functor_stub); + 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 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 + static TReturn const_functor_stub(void* object, TParam param) + { + const TFunctor* p = static_cast(object); + return (p->operator())(param); + } + //************************************************************************* /// The invocation object. //************************************************************************* @@ -568,9 +621,12 @@ namespace etl /// Specialisation for void parameter. //************************************************************************* template - class delegate - : public private_delegate::call_if_impl, TReturn, void> + class delegate : public private_delegate::call_if_impl, TReturn, void> { + private: + + typedef delegate delegate_type; + public: using private_delegate::call_if_impl< delegate, TReturn, void>::call_if; @@ -591,14 +647,23 @@ namespace etl } //************************************************************************* - // Construct from lambda or functor. + // Construct from functor. //************************************************************************* template - delegate(const TFunctor& instance) + delegate(TFunctor& instance, typename etl::enable_if::value && !etl::is_same::value, int>::type = 0) { assign((void*)(&instance), functor_stub); } + //************************************************************************* + // Construct from const functor. + //************************************************************************* + template + delegate(const TFunctor& instance, typename etl::enable_if::value && !etl::is_same::value, int>::type = 0) + { + assign((void*)(&instance), const_functor_stub); + } + //************************************************************************* /// Create from function (Compile time). //************************************************************************* @@ -609,16 +674,27 @@ namespace etl } //************************************************************************* - /// Create from Lambda or Functor. + /// Create from Functor. //************************************************************************* template static - typename etl::enable_if::value, delegate>::type - create(const TFunctor& instance) + typename etl::enable_if::value && !etl::is_same::value, delegate>::type + create(TFunctor& instance) { return delegate((void*)(&instance), functor_stub); } + //************************************************************************* + /// Create from const Functor. + //************************************************************************* + template + static + typename etl::enable_if::value && !etl::is_same::value, delegate>::type + create(const TFunctor& instance) + { + return delegate((void*)(&instance), const_functor_stub); + } + //************************************************************************* /// Create from instance method (Run time). //************************************************************************* @@ -665,15 +741,25 @@ namespace etl } //************************************************************************* - /// Set from Lambda or Functor. + /// Set from Functor. //************************************************************************* template - typename etl::enable_if::value, void>::type - set(const TFunctor& instance) + typename etl::enable_if::value && !etl::is_same::value, void>::type + set(TFunctor& instance) { assign((void*)(&instance), functor_stub); } + //************************************************************************* + /// Set from const Functor. + //************************************************************************* + template + typename etl::enable_if::value && !etl::is_same::value, void>::type + set(const TFunctor& instance) + { + assign((void*)(&instance), const_functor_stub); + } + //************************************************************************* /// Set from instance method (Run time). //************************************************************************* @@ -776,16 +862,27 @@ namespace etl } //************************************************************************* - /// Create from Lambda or Functor. + /// Create from Functor. //************************************************************************* template - typename etl::enable_if::value, delegate&>::type - operator =(const TFunctor& instance) + typename etl::enable_if::value && !etl::is_same::value, delegate&>::type + operator =(TFunctor& instance) { assign((void*)(&instance), functor_stub); return *this; } + //************************************************************************* + /// Create from const Functor. + //************************************************************************* + template + typename etl::enable_if::value && !etl::is_same::value, delegate&>::type + operator =(const TFunctor& instance) + { + assign((void*)(&instance), const_functor_stub); + 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 static TReturn functor_stub(void* object) @@ -950,6 +1047,16 @@ namespace etl return (p->operator())(); } + //************************************************************************* + /// Stub call for a const functor function. + //************************************************************************* + template + static TReturn const_functor_stub(void* object) + { + const TFunctor* p = static_cast(object); + return (p->operator())(); + } + //************************************************************************* /// The invocation object. //************************************************************************* diff --git a/include/etl/private/delegate_cpp11.h b/include/etl/private/delegate_cpp11.h index 0b2102f16..e85cd8953 100644 --- a/include/etl/private/delegate_cpp11.h +++ b/include/etl/private/delegate_cpp11.h @@ -111,12 +111,21 @@ namespace etl //************************************************************************* // Construct from lambda or functor. //************************************************************************* - template ::value, void>> - ETL_CONSTEXPR14 delegate(const TLambda& instance) + template ::value && !etl::is_same, TLambda>::value, void>> + ETL_CONSTEXPR14 delegate(TLambda& instance) { assign((void*)(&instance), lambda_stub); } + //************************************************************************* + // Construct from const lambda or functor. + //************************************************************************* + template ::value && !etl::is_same, TLambda>::value, void>> + ETL_CONSTEXPR14 delegate(const TLambda& instance) + { + assign((void*)(&instance), const_lambda_stub); + } + //************************************************************************* /// Create from function (Compile time). //************************************************************************* @@ -130,13 +139,23 @@ namespace etl //************************************************************************* /// Create from Lambda or Functor. //************************************************************************* - template ::value, void>> + template ::value && !etl::is_same, 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); } + //************************************************************************* + /// Create from const Lambda or Functor. + //************************************************************************* + template ::value && !etl::is_same, TLambda>::value, void>> + ETL_NODISCARD + static ETL_CONSTEXPR14 delegate create(const TLambda& instance) + { + return delegate((void*)(&instance), const_lambda_stub); + } + //************************************************************************* /// Create from instance method (Run time). //************************************************************************* @@ -203,12 +222,21 @@ namespace etl //************************************************************************* /// Set from Lambda or Functor. //************************************************************************* - template ::value, void>> - ETL_CONSTEXPR14 void set(const TLambda& instance) + template ::value && !etl::is_same, TLambda>::value, void>> + ETL_CONSTEXPR14 void set(TLambda& instance) { assign((void*)(&instance), lambda_stub); } + //************************************************************************* + /// Set from const Lambda or Functor. + //************************************************************************* + template ::value && !etl::is_same, TLambda>::value, void>> + ETL_CONSTEXPR14 void set(const TLambda& instance) + { + assign((void*)(&instance), const_lambda_stub); + } + //************************************************************************* /// Set from instance method (Run time). //************************************************************************* @@ -347,13 +375,23 @@ namespace etl //************************************************************************* /// Create from Lambda or Functor. //************************************************************************* - template ::value, void>> - ETL_CONSTEXPR14 delegate& operator =(const TLambda& instance) + template ::value && !etl::is_same, TLambda>::value, void>> + ETL_CONSTEXPR14 delegate& operator =(TLambda& instance) { assign((void*)(&instance), lambda_stub); return *this; } + //************************************************************************* + /// Create from const Lambda or Functor. + //************************************************************************* + template ::value && !etl::is_same, TLambda>::value, void>> + ETL_CONSTEXPR14 delegate& operator =(const TLambda& instance) + { + assign((void*)(&instance), const_lambda_stub); + return *this; + } + //************************************************************************* /// Checks equality. //************************************************************************* @@ -517,6 +555,16 @@ namespace etl return (p->operator())(etl::forward(arg)...); } + //************************************************************************* + /// Stub call for a const lambda or functor function. + //************************************************************************* + template + static ETL_CONSTEXPR14 TReturn const_lambda_stub(void* object, TParams... arg) + { + const TLambda* p = static_cast(object); + return (p->operator())(etl::forward(arg)...); + } + //************************************************************************* /// The invocation object. //************************************************************************* diff --git a/include/etl/version.h b/include/etl/version.h index 3b1de873e..6d4305630 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -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) diff --git a/library.json b/library.json index 336a91a03..91a73e494 100644 --- a/library.json +++ b/library.json @@ -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" diff --git a/library.properties b/library.properties index 3ce3ec249..4228e3ca3 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=20.35.6 +version=20.35.7 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/test/test_delegate.cpp b/test/test_delegate.cpp index ce0e10305..1a8509410 100644 --- a/test/test_delegate.cpp +++ b/test/test_delegate.cpp @@ -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 d([](int i, int j) { function_called = true; parameter_correct = (i == VALUE1) && (j == VALUE2); }); + etl::delegate 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 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 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); } }; diff --git a/test/test_delegate_cpp03.cpp b/test/test_delegate_cpp03.cpp index 36b291367..c6e19aa7f 100644 --- a/test/test_delegate_cpp03.cpp +++ b/test/test_delegate_cpp03.cpp @@ -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 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); } }; diff --git a/version.txt b/version.txt index 584d82f2e..7be2f0c01 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -20.35.6 +20.35.7