Skip to content

Commit

Permalink
Added the option of more logical ordering for template parameters for…
Browse files Browse the repository at this point in the history
… compile time member functions
  • Loading branch information
John Wellbelove committed Aug 11, 2024
1 parent e6653d3 commit af9b3de
Show file tree
Hide file tree
Showing 4 changed files with 427 additions and 19 deletions.
104 changes: 92 additions & 12 deletions include/etl/private/delegate_cpp03.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,17 @@ namespace etl
template <typename T, T& Instance, TReturn(T::*Method)(TParam)>
static delegate create()
{
return delegate(method_instance_stub<T, Instance, Method>);
return delegate(method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
/// Create from instance method (Compile time).
/// New API
//*************************************************************************
template <typename T, TReturn(T::* Method)(TParam), T& Instance>
static delegate create()
{
return delegate(method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
Expand All @@ -282,7 +292,17 @@ namespace etl
template <typename T, T const& Instance, TReturn(T::*Method)(TParam) const>
static delegate create()
{
return delegate(const_method_instance_stub<T, Instance, Method>);
return delegate(const_method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
/// Create from const instance method (Compile time).
/// New API
//*************************************************************************
template <typename T, TReturn(T::* Method)(TParam) const, T const& Instance>
static delegate create()
{
return delegate(const_method_instance_stub<T, Method, Instance>);
}

#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
Expand Down Expand Up @@ -350,7 +370,17 @@ namespace etl
template <typename T, T& Instance, TReturn(T::* Method)(TParam)>
void set()
{
assign(ETL_NULLPTR, method_instance_stub<T, Instance, Method>);
assign(ETL_NULLPTR, method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
/// Set from instance method (Compile time).
/// New API
//*************************************************************************
template <typename T, TReturn(T::* Method)(TParam), T& Instance>
void set()
{
assign(ETL_NULLPTR, method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
Expand All @@ -359,7 +389,17 @@ namespace etl
template <typename T, T const& Instance, TReturn(T::* Method)(TParam) const>
void set()
{
assign(ETL_NULLPTR, const_method_instance_stub<T, Instance, Method>);
assign(ETL_NULLPTR, const_method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
/// Set from const instance method (Compile time).
/// New API
//*************************************************************************
template <typename T, TReturn(T::* Method)(TParam) const, T const& Instance>
void set()
{
assign(ETL_NULLPTR, const_method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
Expand Down Expand Up @@ -571,7 +611,7 @@ namespace etl
//*************************************************************************
/// Stub call for a member function. Compile time instance.
//*************************************************************************
template <typename T, T& Instance, TReturn(T::*Method)(TParam)>
template <typename T, TReturn(T::*Method)(TParam), T& Instance>
static TReturn method_instance_stub(void*, TParam param)
{
return (Instance.*Method)(param);
Expand All @@ -580,7 +620,7 @@ namespace etl
//*************************************************************************
/// Stub call for a const member function. Compile time instance.
//*************************************************************************
template <typename T, const T& Instance, TReturn(T::*Method)(TParam) const>
template <typename T, TReturn(T::*Method)(TParam) const, const T& Instance>
static TReturn const_method_instance_stub(void*, TParam param)
{
return (Instance.*Method)(param);
Expand Down Expand Up @@ -734,7 +774,17 @@ namespace etl
template <typename T, T& Instance, TReturn(T::* Method)()>
static delegate create()
{
return delegate(method_instance_stub<T, Instance, Method>);
return delegate(method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
/// Create from instance method (Compile time).
/// New API
//*************************************************************************
template <typename T, TReturn(T::* Method)(), T& Instance>
static delegate create()
{
return delegate(method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
Expand All @@ -743,7 +793,17 @@ namespace etl
template <typename T, T const& Instance, TReturn(T::* Method)() const>
static delegate create()
{
return delegate(const_method_instance_stub<T, Instance, Method>);
return delegate(const_method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
/// Create from const instance method (Compile time).
/// New API
//*************************************************************************
template <typename T, TReturn(T::* Method)() const, T const& Instance>
static delegate create()
{
return delegate(const_method_instance_stub<T, Method, Instance>);
}

#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
Expand Down Expand Up @@ -811,7 +871,17 @@ namespace etl
template <typename T, T& Instance, TReturn(T::* Method)()>
void set()
{
assign(ETL_NULLPTR, method_instance_stub<T, Instance, Method>);
assign(ETL_NULLPTR, method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
/// Set from instance method (Compile time).
/// New API
//*************************************************************************
template <typename T, TReturn(T::* Method)(), T& Instance>
void set()
{
assign(ETL_NULLPTR, method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
Expand All @@ -820,7 +890,17 @@ namespace etl
template <typename T, T const& Instance, TReturn(T::* Method)() const>
void set()
{
assign(ETL_NULLPTR, const_method_instance_stub<T, Instance, Method>);
assign(ETL_NULLPTR, const_method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
/// Set from const instance method (Compile time).
/// New API
//*************************************************************************
template <typename T, TReturn(T::* Method)() const, T const& Instance>
void set()
{
assign(ETL_NULLPTR, const_method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
Expand Down Expand Up @@ -1032,7 +1112,7 @@ namespace etl
//*************************************************************************
/// Stub call for a member function. Compile time instance.
//*************************************************************************
template <typename T, T& Instance, TReturn(T::* Method)()>
template <typename T, TReturn(T::* Method)(), T& Instance>
static TReturn method_instance_stub(void*)
{
return (Instance.*Method)();
Expand All @@ -1041,7 +1121,7 @@ namespace etl
//*************************************************************************
/// Stub call for a const member function. Compile time instance.
//*************************************************************************
template <typename T, const T& Instance, TReturn(T::* Method)() const>
template <typename T, TReturn(T::* Method)() const, const T& Instance>
static TReturn const_method_instance_stub(void*)
{
return (Instance.*Method)();
Expand Down
56 changes: 49 additions & 7 deletions include/etl/private/delegate_cpp11.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,18 @@ namespace etl
ETL_NODISCARD
static ETL_CONSTEXPR14 delegate create()
{
return delegate(method_instance_stub<T, Instance, Method>);
return delegate(method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
/// Create from instance method (Compile time).
/// New API
//*************************************************************************
template <typename T, TReturn(T::* Method)(TParams...), T& Instance>
ETL_NODISCARD
static ETL_CONSTEXPR14 delegate create()
{
return delegate(method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
Expand All @@ -207,7 +218,18 @@ namespace etl
ETL_NODISCARD
static ETL_CONSTEXPR14 delegate create()
{
return delegate(const_method_instance_stub<T, Instance, Method>);
return delegate(const_method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
/// Create from const instance method (Compile time).
/// New API
//*************************************************************************
template <typename T, TReturn(T::* Method)(TParams...) const, T const& Instance>
ETL_NODISCARD
static ETL_CONSTEXPR14 delegate create()
{
return delegate(const_method_instance_stub<T, Method, Instance>);
}

#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
Expand All @@ -217,7 +239,7 @@ namespace etl
//*************************************************************************
template <typename T, T& Instance>
ETL_NODISCARD
static ETL_CONSTEXPR14 delegate create()
static ETL_CONSTEXPR14 delegate create()
{
return delegate(operator_instance_stub<T, Instance>);
}
Expand Down Expand Up @@ -274,7 +296,17 @@ namespace etl
template <typename T, T& Instance, TReturn(T::* Method)(TParams...)>
ETL_CONSTEXPR14 void set()
{
assign(ETL_NULLPTR, method_instance_stub<T, Instance, Method>);
assign(ETL_NULLPTR, method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
/// Set from instance method (Compile time).
/// New API
//*************************************************************************
template <typename T, TReturn(T::* Method)(TParams...), T& Instance>
ETL_CONSTEXPR14 void set()
{
assign(ETL_NULLPTR, method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
Expand All @@ -283,7 +315,17 @@ namespace etl
template <typename T, T const& Instance, TReturn(T::* Method)(TParams...) const>
ETL_CONSTEXPR14 void set()
{
assign(ETL_NULLPTR, const_method_instance_stub<T, Instance, Method>);
assign(ETL_NULLPTR, const_method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
/// Set from const instance method (Compile time).
/// New API
//*************************************************************************
template <typename T, TReturn(T::* Method)(TParams...) const, T const& Instance>
ETL_CONSTEXPR14 void set()
{
assign(ETL_NULLPTR, const_method_instance_stub<T, Method, Instance>);
}

//*************************************************************************
Expand Down Expand Up @@ -525,7 +567,7 @@ namespace etl
//*************************************************************************
/// Stub call for a member function. Compile time instance.
//*************************************************************************
template <typename T, T& Instance, TReturn(T::*Method)(TParams...)>
template <typename T, TReturn(T::*Method)(TParams...), T& Instance>
static ETL_CONSTEXPR14 TReturn method_instance_stub(void*, TParams... params)
{
return (Instance.*Method)(etl::forward<TParams>(params)...);
Expand All @@ -534,7 +576,7 @@ namespace etl
//*************************************************************************
/// Stub call for a const member function. Compile time instance.
//*************************************************************************
template <typename T, const T& Instance, TReturn(T::*Method)(TParams...) const>
template <typename T, TReturn(T::*Method)(TParams...) const, const T& Instance>
static ETL_CONSTEXPR14 TReturn const_method_instance_stub(void*, TParams... params)
{
return (Instance.*Method)(etl::forward<TParams>(params)...);
Expand Down
Loading

0 comments on commit af9b3de

Please sign in to comment.