48#ifndef ETL_DELEGATE_CPP11_INCLUDED
49#define ETL_DELEGATE_CPP11_INCLUDED
51#include "../platform.h"
52#include "../error_handler.h"
53#include "../exception.h"
54#include "../type_traits.h"
55#include "../function_traits.h"
56#include "../utility.h"
57#include "../optional.h"
58#include "../type_list.h"
65 class delegate_exception :
public exception
78 class delegate_uninitialised :
public delegate_exception
83 : delegate_exception(ETL_ERROR_TEXT(
"delegate:uninitialised", ETL_DELEGATE_FILE_ID
"A"),
file_name_,
line_number_)
105 template <
typename T>
112 template <
typename T>
151 ETL_CONSTEXPR14 delegate(
const TLambda& instance) ETL_NOEXCEPT
160 ETL_CONSTEXPR14 delegate(
TLambda&& instance) =
delete;
268#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
273 template <
typename T, T& Instance>
285 ETL_CONSTEXPR14
void set() ETL_NOEXCEPT
303 ETL_CONSTEXPR14
void set(
const TLambda& instance) ETL_NOEXCEPT
367 ETL_CONSTEXPR14
void clear() ETL_NOEXCEPT
379 ETL_STATIC_ASSERT((
sizeof...(
TCallArgs) ==
sizeof...(
TArgs)),
"Incorrect number of parameters passed to delegate");
396 ETL_STATIC_ASSERT((
sizeof...(
TCallArgs) ==
sizeof...(
TArgs)),
"Incorrect number of parameters passed to delegate");
419 ETL_STATIC_ASSERT((
sizeof...(
TCallArgs) ==
sizeof...(
TArgs)),
"Incorrect number of parameters passed to delegate");
439 ETL_STATIC_ASSERT((
sizeof...(
TCallArgs) ==
sizeof...(
TArgs)),
"Incorrect number of parameters passed to delegate");
459 ETL_STATIC_ASSERT((
sizeof...(
TCallArgs) ==
sizeof...(
TArgs)),
"Incorrect number of parameters passed to delegate");
503 return invocation ==
rhs.invocation;
511 return invocation !=
rhs.invocation;
520 return invocation.stub != ETL_NULLPTR;
539 template <
typename TCallableType,
typename =
void>
543 template <
typename TCallableType>
545 :
etl::bool_constant<etl::is_convertible<decltype(etl::declval<TCallableType&>()(etl::declval<TArgs>()...)), TReturn>::value>
548 template <
typename TCallableType,
typename =
void>
551 template <
typename TCallableType>
553 :
etl::bool_constant<etl::is_convertible<decltype(etl::declval<const TCallableType&>()(etl::declval<TArgs>()...)), TReturn>::value>
556 template <
typename TCallableType>
558 :
etl::bool_constant<is_invocable_with<TCallableType>::value || is_invocable_with_const<TCallableType>::value>
564 struct invocation_element
566 invocation_element() =
default;
569 ETL_CONSTEXPR14 invocation_element(
void* object_, stub_type stub_) ETL_NOEXCEPT
576 ETL_CONSTEXPR14
bool operator ==(
const invocation_element& rhs)
const ETL_NOEXCEPT
578 return (rhs.stub == stub) && (rhs.object == object);
582 ETL_CONSTEXPR14
bool operator !=(
const invocation_element& rhs)
const ETL_NOEXCEPT
584 return (rhs.stub != stub) || (rhs.object != object);
588 ETL_CONSTEXPR14
void clear() ETL_NOEXCEPT
590 object = ETL_NULLPTR;
595 void*
object = ETL_NULLPTR;
596 stub_type stub = ETL_NULLPTR;
602 ETL_CONSTEXPR14 delegate(
void*
object, stub_type stub) ETL_NOEXCEPT
603 : invocation(
object, stub)
610 ETL_CONSTEXPR14 delegate(stub_type stub) ETL_NOEXCEPT
611 : invocation(ETL_NULLPTR, stub)
618 ETL_CONSTEXPR14
void assign(
void*
object, stub_type stub) ETL_NOEXCEPT
620 invocation.object = object;
621 invocation.stub = stub;
630 T* p =
static_cast<T*
>(object);
640 T*
const p =
static_cast<T*
>(object);
662#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
666 template <
typename T, T& Instance>
685 template <
typename TLambda>
688 ETL_STATIC_ASSERT(is_compatible_callable<TLambda>::value,
"etl::delegate: bound lambda/functor is not compatible with the delegate signature");
697 template <
typename TLambda>
698 static ETL_CONSTEXPR14
TReturn const_lambda_stub(
void*
object,
TArgs...
arg)
700 ETL_STATIC_ASSERT(is_compatible_callable<TLambda>::value,
"etl::delegate: bound lambda/functor is not compatible with the delegate signature");
709 invocation_element invocation;
716 template <auto Function>
732 using function_type =
typename etl::function_traits<
decltype(&TLambda::operator())>::function_type;
740 template <
typename T, T& Instance>
752 template <
typename T, auto Method, T& Instance,
typename = etl::enable_if_t<!etl::function_traits<decltype(Method)>::is_const>>
764 template <
typename T, auto Method, const T& Instance,
typename = etl::enable_if_t<etl::function_traits<decltype(Method)>::is_const>>
776 template <
typename T, auto Method>
788 template <
typename T, auto Method>
static ETL_NODISCARD ETL_CONSTEXPR14 delegate create(const TLambda &instance) ETL_NOEXCEPT
Create from const Lambda or Functor.
Definition delegate_cpp11.h:187
ETL_CONSTEXPR14 void set(TLambda &instance) ETL_NOEXCEPT
Set from Lambda or Functor.
Definition delegate_cpp11.h:294
ETL_CONSTEXPR14 void clear() ETL_NOEXCEPT
Clear the delegate.
Definition delegate_cpp11.h:367
ETL_CONSTEXPR14 void set() ETL_NOEXCEPT
Set from function (Compile time).
Definition delegate_cpp11.h:285
static ETL_NODISCARD ETL_CONSTEXPR14 delegate create() ETL_NOEXCEPT
Definition delegate_cpp11.h:275
ETL_CONSTEXPR14 TReturn call_or(TCallArgs &&... args) const
Definition delegate_cpp11.h:457
static ETL_NODISCARD ETL_CONSTEXPR14 delegate create() ETL_NOEXCEPT
Create from function (Compile time).
Definition delegate_cpp11.h:167
ETL_CONSTEXPR14 etl::enable_if_t< etl::is_same< TRet, void >::value, bool > call_if(TCallArgs &&... args) const
Definition delegate_cpp11.h:394
static ETL_NODISCARD ETL_CONSTEXPR14 delegate create(TLambda &instance) ETL_NOEXCEPT
Create from Lambda or Functor.
Definition delegate_cpp11.h:177
ETL_CONSTEXPR14 return_type operator()(TCallArgs &&... args) const
Execute the delegate.
Definition delegate_cpp11.h:377
ETL_CONSTEXPR14 TReturn call_or(TAlternative &&alternative, TCallArgs &&... args) const
Definition delegate_cpp11.h:437
ETL_CONSTEXPR14 delegate() ETL_NOEXCEPT
Default constructor.
Definition delegate_cpp11.h:129
ETL_CONSTEXPR14 void set(const TLambda &instance) ETL_NOEXCEPT
Set from const Lambda or Functor.
Definition delegate_cpp11.h:303
ETL_CONSTEXPR14 etl::enable_if_t<!etl::is_same< TRet, void >::value, etl::optional< TReturn > > call_if(TCallArgs &&... args) const
Definition delegate_cpp11.h:417
ETL_NODISCARD ETL_CONSTEXPR14 bool is_valid() const ETL_NOEXCEPT
Returns true if the delegate is valid.
Definition delegate_cpp11.h:518
The exception thrown when the delegate is uninitialised.
Definition delegate_cpp03.h:162
Declaration.
Definition delegate_cpp03.h:191
Definition optional.h:1321
A templated set implementation that uses a fixed size buffer.
Definition set.h:2554
ETL_CONSTEXPR14 bool operator==(const etl::expected< TValue, TError > &lhs, const etl::expected< TValue2, TError2 > &rhs)
Equivalence operators.
Definition expected.h:962
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
ETL_CONSTEXPR exception(string_type reason_, string_type, numeric_type line_)
Constructor.
Definition exception.h:69
integral_constant
Definition type_traits_generator.h:895
is_same
Definition type_traits_generator.h:1104
bitset_ext
Definition absolute.h:39
T * create(Args &&... args)
Creates the object from a type. Variadic parameter constructor.
Definition variant_pool_generator.h:348
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1151
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1139
ETL_NODISCARD ETL_CONSTEXPR14 T round_half_even_unscaled(T value) ETL_NOEXCEPT
Definition scaled_rounding.h:315
Definition type_traits_generator.h:912
Definition delegate_cpp03.h:176
is_delegate
Definition delegate_cpp03.h:184