C++ – Implementing events and delegates, signals and slots mechanisms using the standard library

Use the C++ standard library to simply implement event triggering mechanism Event.h /* Author:StubbornHuang Data:2023.1.31 Email:[email protected] */ #ifndef _EVENT_H_ #define _EVENT_H_ #include <functional> #include <map> #include <type_traits> #ifndef EVENT_NO_THREAD_SAFETY #define EVENT_THREAD_SAFETY #endif // !EVENT_NO_THREAD_SAFETY #ifdef EVENT_THREAD_SAFETY #include <atomic> #include <mutex> #endif // EVENT_THREAD_SAFETY #ifdef EVENT_THREAD_SAFETY #define DELEGATE_ID_TYPE std::atomic_uint64_t #else #define DELEGATE_ID_TYPE std::uint64_t #endif // EVENT_THREAD_SAFETY […]

Asynchronous calls to delegates and methods

Overview Asynchronous calls are usually used to perform some time-consuming operations, while ensuring that the current main thread can continue to execute after executing the asynchronous call. During asynchronous execution, the system often creates a new thread, but it should be noted that when each asynchronous execution requires the creation of a thread, performance will […]

Jing: Why should delegates be introduced in C#

Introduction: For some friends who are new to C#, they may not have a deep understanding of some basic features in C#. However, this knowledge is also a question that interviewers often ask during interviews, so I think it is necessary to share with some friends who have not been in contact with C# for […]

[C#] Delegates, anonymous methods, Lambda expressions and events

【C#】Delegate, Anonymous Method, Lambda Expression and Event Delegation What is a delegation? Like a class, a delegate is a user-defined type and an abstraction of a method (function). In layman’s terms, a delegate is a representative of a method (function) of a custom type. Declaration delegation //<access modifier> delegate <function return type> <custom delegate name> […]

C# delegates and events, anonymous functions and lamabda expressions

Article directory (1) commission (2) Events (3) Anonymous function (4) lambda expression (5) Closure (1) Delegation The delegate is the container of the function method, which can be understood as the variable type of the function method, which is used to store the transfer function method The essence of delegation is a class, which is […]

Use Kotlin delegates to split more complex ViewModels

Requirement Background In an actual development scenario, the data of a page may be composed of data of multiple businesses. Implemented using the MVVM architecture, storing and processing multiple business data in the ViewModel, and notifying the View layer to refresh the UI. Traditional implementation For example, in the above example, the page consists of […]