From be43ea893018090044cd411bc5b50787b99087b8 Mon Sep 17 00:00:00 2001 From: hachem Date: Sat, 19 Sep 2026 15:51:57 +0200 Subject: feat: add reapts and loops --- examples/countdown.sfinae | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 examples/countdown.sfinae (limited to 'examples/countdown.sfinae') 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; -- cgit v1.3