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"
64 class delegate_exception :
public exception
77 class delegate_uninitialised :
public delegate_exception
82 : delegate_exception(ETL_ERROR_TEXT(
"delegate:uninitialised", ETL_DELEGATE_FILE_ID
"A"),
file_name_,
line_number_)
104 template <
typename T>
111 template <
typename T>
147 ETL_CONSTEXPR14 delegate(
const TLambda& instance) ETL_NOEXCEPT
156 ETL_CONSTEXPR14 delegate(
TLambda&& instance) =
delete;
264#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
269 template <
typename T, T& Instance>
281 ETL_CONSTEXPR14
void set() ETL_NOEXCEPT
299 ETL_CONSTEXPR14
void set(
const TLambda& instance) ETL_NOEXCEPT
363 ETL_CONSTEXPR14
void clear() ETL_NOEXCEPT
382 template <
typename TRet = TReturn>
402 template <
typename TRet = TReturn>
421 template <
typename TAlternative>
482 return invocation ==
rhs.invocation;
490 return invocation !=
rhs.invocation;
499 return invocation.stub != ETL_NULLPTR;
518 struct invocation_element
520 invocation_element() =
default;
523 ETL_CONSTEXPR14 invocation_element(
void* object_, stub_type stub_) ETL_NOEXCEPT
530 ETL_CONSTEXPR14
bool operator ==(
const invocation_element& rhs)
const ETL_NOEXCEPT
532 return (rhs.stub == stub) && (rhs.object == object);
536 ETL_CONSTEXPR14
bool operator !=(
const invocation_element& rhs)
const ETL_NOEXCEPT
538 return (rhs.stub != stub) || (rhs.object != object);
542 ETL_CONSTEXPR14
void clear() ETL_NOEXCEPT
544 object = ETL_NULLPTR;
549 void*
object = ETL_NULLPTR;
550 stub_type stub = ETL_NULLPTR;
556 ETL_CONSTEXPR14 delegate(
void*
object, stub_type stub) ETL_NOEXCEPT
557 : invocation(
object, stub)
564 ETL_CONSTEXPR14 delegate(stub_type stub) ETL_NOEXCEPT
565 : invocation(ETL_NULLPTR, stub)
572 ETL_CONSTEXPR14
void assign(
void*
object, stub_type stub) ETL_NOEXCEPT
574 invocation.object = object;
575 invocation.stub = stub;
584 T* p =
static_cast<T*
>(object);
594 T*
const p =
static_cast<T*
>(object);
616#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8))
620 template <
typename T, T& Instance>
639 template <
typename TLambda>
640 static ETL_CONSTEXPR14
TReturn lambda_stub(
void*
object,
TParams...
arg) ETL_NOEXCEPT
649 template <
typename TLambda>
650 static ETL_CONSTEXPR14
TReturn const_lambda_stub(
void*
object,
TParams...
arg) ETL_NOEXCEPT
659 invocation_element invocation;
666 template <auto Function>
682 using function_type =
typename etl::function_traits<
decltype(&TLambda::operator())>::function_type;
690 template <
typename T, T& Instance>
702 template <
typename T, auto Method, T& Instance,
typename = etl::enable_if_t<!etl::function_traits<decltype(Method)>::is_const>>
714 template <
typename T, auto Method, const T& Instance,
typename = etl::enable_if_t<etl::function_traits<decltype(Method)>::is_const>>
726 template <
typename T, auto Method>
738 template <
typename T, auto Method>
ETL_CONSTEXPR14 void set(const TLambda &instance) ETL_NOEXCEPT
Set from const Lambda or Functor.
Definition delegate_cpp11.h:299
ETL_CONSTEXPR14 void set(TLambda &instance) ETL_NOEXCEPT
Set from Lambda or Functor.
Definition delegate_cpp11.h:290
ETL_CONSTEXPR14 TReturn operator()(TParams... args) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
Execute the delegate.
Definition delegate_cpp11.h:371
ETL_CONSTEXPR14 TReturn call_or(TAlternative alternative, TParams... args) const ETL_NOEXCEPT
Definition delegate_cpp11.h:422
ETL_NODISCARD ETL_CONSTEXPR14 bool is_valid() const ETL_NOEXCEPT
Returns true if the delegate is valid.
Definition delegate_cpp11.h:497
static ETL_NODISCARD ETL_CONSTEXPR14 delegate create(const TLambda &instance) ETL_NOEXCEPT
Create from const Lambda or Functor.
Definition delegate_cpp11.h:183
static ETL_NODISCARD ETL_CONSTEXPR14 delegate create(TLambda &instance) ETL_NOEXCEPT
Create from Lambda or Functor.
Definition delegate_cpp11.h:173
ETL_CONSTEXPR14 etl::enable_if_t<!etl::is_same< TRet, void >::value, etl::optional< TReturn > > call_if(TParams... args) const ETL_NOEXCEPT
Definition delegate_cpp11.h:405
ETL_CONSTEXPR14 delegate() ETL_NOEXCEPT
Default constructor.
Definition delegate_cpp11.h:125
static ETL_NODISCARD ETL_CONSTEXPR14 delegate create() ETL_NOEXCEPT
Definition delegate_cpp11.h:271
static ETL_NODISCARD ETL_CONSTEXPR14 delegate create() ETL_NOEXCEPT
Create from function (Compile time).
Definition delegate_cpp11.h:163
ETL_CONSTEXPR14 void clear() ETL_NOEXCEPT
Clear the delegate.
Definition delegate_cpp11.h:363
ETL_CONSTEXPR14 etl::enable_if_t< etl::is_same< TRet, void >::value, bool > call_if(TParams... args) const ETL_NOEXCEPT
Definition delegate_cpp11.h:385
ETL_CONSTEXPR14 TReturn call_or(TParams... args) const ETL_NOEXCEPT
Definition delegate_cpp11.h:439
ETL_CONSTEXPR14 void set() ETL_NOEXCEPT
Set from function (Compile time).
Definition delegate_cpp11.h:281
The exception thrown when the delegate is uninitialised.
Definition delegate_cpp03.h:162
Declaration.
Definition delegate_cpp03.h:191
Definition optional.h:1227
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:974
#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
is_same
Definition type_traits_generator.h:1080
bitset_ext
Definition absolute.h:38
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:1109
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1097
ETL_NODISCARD ETL_CONSTEXPR14 T round_half_even_unscaled(T value) ETL_NOEXCEPT
Definition scaled_rounding.h:314
Definition type_traits_generator.h:888
Definition delegate_cpp03.h:176
is_delegate
Definition delegate_cpp03.h:184