diff --git a/include/etl/private/delegate_cpp11.h b/include/etl/private/delegate_cpp11.h index 79182656..4aa0244b 100644 --- a/include/etl/private/delegate_cpp11.h +++ b/include/etl/private/delegate_cpp11.h @@ -372,25 +372,33 @@ namespace etl //************************************************************************* /// Execute the delegate. //************************************************************************* - ETL_CONSTEXPR14 TReturn operator()(TParams... args) const + template + ETL_CONSTEXPR14 + return_type operator()(TArgs&&... args) const { + ETL_STATIC_ASSERT((sizeof...(TArgs) == sizeof...(TParams)), "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.object, etl::forward(args)...); + return (*invocation.stub)(invocation.object, etl::forward(args)...); } //************************************************************************* /// Execute the delegate if valid. /// 'void' return delegate. //************************************************************************* - template + template ETL_CONSTEXPR14 typename etl::enable_if_t::value, bool> - call_if(TParams... args) const + call_if(TArgs&&... args) const { + ETL_STATIC_ASSERT((sizeof...(TArgs) == sizeof...(TParams)), "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.object, etl::forward(args)...); + (*invocation.stub)(invocation.object, etl::forward(args)...); return true; } else @@ -403,16 +411,19 @@ namespace etl /// Execute the delegate if valid. /// Non 'void' return delegate. //************************************************************************* - template + template ETL_CONSTEXPR14 typename etl::enable_if_t::value, etl::optional> - call_if(TParams... args) const + call_if(TArgs&&... args) const { + ETL_STATIC_ASSERT((sizeof...(TArgs) == sizeof...(TParams)), "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.object, etl::forward(args)...); + result = (*invocation.stub)(invocation.object, etl::forward(args)...); } return result; @@ -422,16 +433,19 @@ namespace etl /// Execute the delegate if valid or call alternative. /// Run time alternative. //************************************************************************* - template - ETL_CONSTEXPR14 TReturn call_or(TAlternative alternative, TParams... args) const + template + ETL_CONSTEXPR14 TReturn call_or(TAlternative alternative, TArgs&&... args) const { + ETL_STATIC_ASSERT((sizeof...(TArgs) == sizeof...(TParams)), "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.object, etl::forward(args)...); + return (*invocation.stub)(invocation.object, etl::forward(args)...); } else { - return alternative(etl::forward(args)...); + return alternative(etl::forward(args)...); } } @@ -439,16 +453,19 @@ namespace etl /// Execute the delegate if valid or call alternative. /// Compile time alternative. //************************************************************************* - template - ETL_CONSTEXPR14 TReturn call_or(TParams... args) const + template + ETL_CONSTEXPR14 TReturn call_or(TArgs&&... args) const { + ETL_STATIC_ASSERT((sizeof...(TArgs) == sizeof...(TParams)), "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.object, etl::forward(args)...); + return (*invocation.stub)(invocation.object, etl::forward(args)...); } else { - return (Method)(etl::forward(args)...); + return (Method)(etl::forward(args)...); } }