diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-08-14 18:51:28 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2024-08-14 18:51:28 +0300 |
| commit | 852ff838af56ef3668ff94c27b0140869dcb7359 (patch) | |
| tree | fbb51f25484832aeb4acc24ca0e9fb16a0831b7d /tests/ptr.ek | |
| parent | 085817c69d145400eac84e09704f48ede2bece68 (diff) | |
| download | ek-852ff838af56ef3668ff94c27b0140869dcb7359.tar.gz ek-852ff838af56ef3668ff94c27b0140869dcb7359.zip | |
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.
Diffstat (limited to 'tests/ptr.ek')
| -rw-r--r-- | tests/ptr.ek | 30 |
1 files changed, 30 insertions, 0 deletions
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&); +} |
