hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-19 15:51:57 +0200
committerhachem <im@hachem.wtf>2026-09-19 15:51:57 +0200
commitbe43ea893018090044cd411bc5b50787b99087b8 (patch)
tree379af1300ee53afa0a7029835257f254aaccfce2 /examples
parent6d8b0392bb0c0df82285eec1b0f692113e66eb1a (diff)
feat: add reapts and loops
Diffstat (limited to 'examples')
-rw-r--r--examples/countdown.sfinae23
1 files changed, 23 insertions, 0 deletions
diff --git a/examples/countdown.sfinae b/examples/countdown.sfinae
new file mode 100644
index 0000000..bd7c4a3
--- /dev/null
+++ b/examples/countdown.sfinae
@@ -0,0 +1,23 @@
+// count from 3 down to 1, then make sure we got to 0
+// ::repeat runs its sequence a number of times, and that is the whole loop
+
+::declare<::name<'i'>, ::decltype(::difference<'D', 'A'>)>::commit;
+
+::repeat<
+ ::value_of<::name<'i'>>,
+ ::sequence<
+ ::emit<::decltype(::value_of<::name<'i'>>)>::commit,
+ ::declare<
+ ::name<'n', 'e', 'x', 't'>,
+ ::decltype(::sum<::value_of<::name<'i'>>, ::difference<'A', 'B'>>)
+ >::commit,
+ ::undeclare<::name<'i'>>::commit,
+ ::declare<::name<'i'>, ::decltype(::value_of<::name<'n', 'e', 'x', 't'>>)>::commit,
+ ::undeclare<::name<'n', 'e', 'x', 't'>>::commit
+ >
+>::commit;
+
+::static_assert<::equal<::value_of<::name<'i'>>, ::difference<'A', 'A'>>::value>::commit;
+
+// a negative count runs nothing, which is the only sensible thing it could do
+::repeat<::difference<'A', 'D'>, ::sequence<::static_assert<::false_type::value>::commit>>::commit;