From 852ff838af56ef3668ff94c27b0140869dcb7359 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Wed, 14 Aug 2024 18:51:28 +0300 Subject: allow adding traits to pointers + Should be enough to fairly easily use pointers in standard containers. Note that this just uses the pointer value itself, and doesn't care about the underlying type at all. So for example a sorted vector of pointers is sorted by the address, not by some comparison function that the underlying type may have defined. For that you will need a wrapper struct or something. --- tests/ptr.ek | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/ptr.ek (limited to 'tests/ptr.ek') diff --git a/tests/ptr.ek b/tests/ptr.ek new file mode 100644 index 0000000..86f413c --- /dev/null +++ b/tests/ptr.ek @@ -0,0 +1,30 @@ +typedef bool {} + +typedef i27 { + cmp![]; + eq(i27 a, i27 b => bool) { + return a == b; + } +} + +typedef ptr { + cmp![]; + eq(ptr a, ptr b => bool) { + return a == b; + } +} + +typedef test[cmp T] {} + +define cmp[] { + eq(cmp, cmp => bool); +} + +main() +{ + const a = test![i27]{}; + 20.eq(20); + + const b = test![*i27]{}; + a&.eq(a&); +} -- cgit v1.3