diff --git a/include/etl/private/delegate_cpp11.h b/include/etl/private/delegate_cpp11.h index 0770e0f0..d373325f 100644 --- a/include/etl/private/delegate_cpp11.h +++ b/include/etl/private/delegate_cpp11.h @@ -413,32 +413,23 @@ namespace etl //************************************************************************* /// Execute the delegate. //************************************************************************* - template - ETL_CONSTEXPR14 return_type operator()(TCallArgs&&... args) const + ETL_CONSTEXPR14 return_type operator()(TArgs... args) const { - ETL_STATIC_ASSERT((sizeof...(TCallArgs) == sizeof...(TArgs)), "Incorrect number of parameters passed to delegate"); - ETL_STATIC_ASSERT((etl::type_lists_are_convertible, argument_types>::value), - "Incompatible parameter types passed to delegate"); - ETL_ASSERT(is_valid(), ETL_ERROR(delegate_uninitialised)); - return (*invocation.stub)(invocation, etl::forward(args)...); + return (*invocation.stub)(invocation, etl::forward(args)...); } //************************************************************************* /// Execute the delegate if valid. /// 'void' return delegate. //************************************************************************* - template - ETL_CONSTEXPR14 typename etl::enable_if_t::value, bool> call_if(TCallArgs&&... args) const + template + ETL_CONSTEXPR14 typename etl::enable_if_t::value, bool> call_if(TArgs... args) const { - ETL_STATIC_ASSERT((sizeof...(TCallArgs) == sizeof...(TArgs)), "Incorrect number of parameters passed to delegate"); - ETL_STATIC_ASSERT((etl::type_lists_are_convertible, argument_types>::value), - "Incompatible parameter types passed to delegate"); - if (is_valid()) { - (*invocation.stub)(invocation, etl::forward(args)...); + (*invocation.stub)(invocation, etl::forward(args)...); return true; } else @@ -451,18 +442,14 @@ namespace etl /// Execute the delegate if valid. /// Non 'void' return delegate. //************************************************************************* - template - ETL_CONSTEXPR14 typename etl::enable_if_t::value, etl::optional> call_if(TCallArgs&&... args) const + template + ETL_CONSTEXPR14 typename etl::enable_if_t::value, etl::optional> call_if(TArgs... args) const { - ETL_STATIC_ASSERT((sizeof...(TCallArgs) == sizeof...(TArgs)), "Incorrect number of parameters passed to delegate"); - ETL_STATIC_ASSERT((etl::type_lists_are_convertible, argument_types>::value), - "Incompatible parameter types passed to delegate"); - etl::optional result; if (is_valid()) { - result = (*invocation.stub)(invocation, etl::forward(args)...); + result = (*invocation.stub)(invocation, etl::forward(args)...); } return result; @@ -472,20 +459,16 @@ namespace etl /// Execute the delegate if valid or call alternative. /// Run time alternative. //************************************************************************* - template - ETL_CONSTEXPR14 TReturn call_or(TAlternative&& alternative, TCallArgs&&... args) const + template + ETL_CONSTEXPR14 TReturn call_or(TAlternative&& alternative, TArgs... args) const { - ETL_STATIC_ASSERT((sizeof...(TCallArgs) == sizeof...(TArgs)), "Incorrect number of parameters passed to delegate"); - ETL_STATIC_ASSERT((etl::type_lists_are_convertible, argument_types>::value), - "Incompatible parameter types passed to delegate"); - if (is_valid()) { - return (*invocation.stub)(invocation, etl::forward(args)...); + return (*invocation.stub)(invocation, etl::forward(args)...); } else { - return etl::forward(alternative)(etl::forward(args)...); + return etl::forward(alternative)(etl::forward(args)...); } } @@ -493,20 +476,16 @@ namespace etl /// Execute the delegate if valid or call alternative. /// Compile time alternative. //************************************************************************* - template - ETL_CONSTEXPR14 TReturn call_or(TCallArgs&&... args) const + template + ETL_CONSTEXPR14 TReturn call_or(TArgs... args) const { - ETL_STATIC_ASSERT((sizeof...(TCallArgs) == sizeof...(TArgs)), "Incorrect number of parameters passed to delegate"); - ETL_STATIC_ASSERT((etl::type_lists_are_convertible, argument_types>::value), - "Incompatible parameter types passed to delegate"); - if (is_valid()) { - return (*invocation.stub)(invocation, etl::forward(args)...); + return (*invocation.stub)(invocation, etl::forward(args)...); } else { - return (Method)(etl::forward(args)...); + return (Method)(etl::forward(args)...); } } diff --git a/test/test_delegate.cpp b/test/test_delegate.cpp index f990e115..6d07d2a1 100644 --- a/test/test_delegate.cpp +++ b/test/test_delegate.cpp @@ -96,7 +96,11 @@ namespace MoveableOnlyData& operator=(const MoveableOnlyData&) = delete; MoveableOnlyData(MoveableOnlyData&&) = default; MoveableOnlyData& operator=(MoveableOnlyData&&) = default; - int d; + MoveableOnlyData(int _d) + : d{_d} + { + } + int d; }; //***************************************************************************** @@ -583,6 +587,17 @@ namespace CHECK(parameter_correct); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_free_moveableonly_deduced_type) + { + auto d = etl::delegate::create(); + + d({VALUE1}); // deduce argument type from braced initializer list + + CHECK(function_called == FunctionCalled::Free_Moveableonly_Called); + CHECK(parameter_correct); + } + //************************************************************************* #if ETL_USING_CPP17 TEST_FIXTURE(SetupFixture, test_make_delegate_free_moveableonly)