aboutsummaryrefslogtreecommitdiff
path: root/example_vec/new/main.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2025-09-01 22:00:02 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2025-09-01 22:00:02 +0300
commite68480f2fc508ce73cad331ce4e8439e07d25702 (patch)
treebfa99b6f20402ba46230771a0d42172fc2169481 /example_vec/new/main.c
parent20ce6fa81cd9f55dca3212699d5949f8ebe7d95b (diff)
downloadngc-e68480f2fc508ce73cad331ce4e8439e07d25702.tar.gz
ngc-e68480f2fc508ce73cad331ce4e8439e07d25702.zip
use <> as expansion charactersHEADmaster
+ I kind of like the 'symmetry' of <> being 'self' and <param> being some parameter, but having to type lots of extra <*> is a bit annoying, and might also be an issue for C++. Still, enough functionality for a hashmap example
Diffstat (limited to 'example_vec/new/main.c')
-rw-r--r--example_vec/new/main.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/example_vec/new/main.c b/example_vec/new/main.c
index 4849cb3..a756281 100644
--- a/example_vec/new/main.c
+++ b/example_vec/new/main.c
@@ -1,12 +1,21 @@
#include <stdio.h>
+
+/* an empty trait matches anything, this would presumably be defined in a
+ * library somewhere and then included everywhere */
+typedef any {}
+
#include "vec.h"
#define foreach(name, i, s) \
for (name##_iter i = name##_begin(s); !name##_end(s, i); i = name##_next(i))
-typedef summable_vec[summable type]() = vec[type](){
- type <>_sum(struct <> *v) {
- type sum = 0;
+/* traits aren't really implemented fully yet but this would check for a
+ * function like <>_add(<> a, <> b) or something along those lines */
+typedef summable {}
+
+typedef summable_vec[summable type]() = vec[<type>](){
+ <type> <>_sum(struct <> *v) {
+ <type> sum = 0;
for (size_t i = 0; i < v->n; ++i) {
sum += v->buf[i];
}