Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/P-p-H-d/mlib.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Pelissier <Patrick.Pelissier@gmail.com>2023-12-30 18:22:34 +0300
committerPatrick Pelissier <Patrick.Pelissier@gmail.com>2023-12-30 18:23:02 +0300
commit76ef061dec97bbf80c684f4494e7354b3730ef51 (patch)
tree34b506832867a2da847cfbfa25264b6c39a7154a
parentc98786a3b3b94348a034167e50a8bed6e88e9cff (diff)
Add basic example of generic interface
-rw-r--r--example/ex11-generic01.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/example/ex11-generic01.c b/example/ex11-generic01.c
new file mode 100644
index 0000000..36abfb1
--- /dev/null
+++ b/example/ex11-generic01.c
@@ -0,0 +1,25 @@
+#include "m-list.h"
+#include "m-generic.h"
+
+LIST_DEF(list_uint, unsigned int)
+// Register for M_LET & M_EACH
+#define M_OPL_list_uint_t() LIST_OPLIST(list_uint, M_BASIC_OPLIST)
+// Register for Generic:
+#define M_GENERIC_ORG_1() (USER)
+#define M_GENERIC_ORG_USER_COMP_1() (CORE)
+#define M_GENERIC_ORG_USER_COMP_CORE_OPLIST_1() M_OPL_list_uint_t()
+
+int main(void)
+{
+ M_LET(list, list_uint_t) {
+ // We can push in the list. It will call the registered method.
+ push(list, 42);
+ push(list, 17);
+ // We can iterate over the list
+ for each(item, list) {
+ M_PRINT("ITEM=", *item, "\n");
+ }
+ // We can print directly the list. It will use the registered method
+ M_PRINT("List = ", list, "\n");
+ }
+}