From 645a8026b6f6a89cda5a24d96cf3de39c3ab32e1 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Thu, 10 Jul 2025 19:44:04 +0300 Subject: initial commit --- example_vec/old/conts.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 example_vec/old/conts.h (limited to 'example_vec/old/conts.h') diff --git a/example_vec/old/conts.h b/example_vec/old/conts.h new file mode 100644 index 0000000..d175d30 --- /dev/null +++ b/example_vec/old/conts.h @@ -0,0 +1,22 @@ +#ifndef CONTS_H +#define CONTS_H + +#define CONTS_JOIN2(a, b) a##_##b +#define CONTS_JOIN(a, b) CONTS_JOIN2(a, b) + +#define CONTAINER_OF(ptr, type, member) \ + (type *)((char *)(ptr) - offsetof(type, member)) + +#if __STDC_VERSION__ >= 202311UL +# define CONTS_AUTO auto +#elif defined(__GNUC__) +# define CONTS_AUTO __auto_type +#else +# warning "iteration won't work with this compiler" +#endif + +#define foreach(name, i, s)\ + for (CONTS_AUTO i = CONTS_JOIN(name, begin)(s);\ + !CONTS_JOIN(name, end)(s, i);\ + i = CONTS_JOIN(name, next)(i)) +#endif /* CONTS_H */ -- cgit v1.2.3