From 2da2c56c72e7085bd9a52f848df90c6fc701de7f Mon Sep 17 00:00:00 2001 From: hachem Date: Sat, 19 Sep 2026 22:04:44 +0200 Subject: docs: add tutorial --- tutorial/05_loops.sfinae | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tutorial/05_loops.sfinae (limited to 'tutorial/05_loops.sfinae') diff --git a/tutorial/05_loops.sfinae b/tutorial/05_loops.sfinae new file mode 100644 index 0000000..d974f99 --- /dev/null +++ b/tutorial/05_loops.sfinae @@ -0,0 +1,47 @@ +// lesson 5: loops +// +// ::repeat> runs the sequence V times. that is the whole +// loop. there is no index, no condition, no break. + +::repeat< + ::difference<'D', 'A'>, + ::sequence< + ::emit< + ::tuple< + ::integral_constant<::char, ::difference<'h', '\0'>>, + ::integral_constant<::char, ::difference<'i', '\0'>> + > + >::commit + > +>::commit; + +// counting needs a variable, and changing a variable needs the undeclare dance, +// and the dance needs a second variable to hold the value while the first one +// is dead. this prints 1, 2, 3 + +::declare< + ::name<'i'>, + ::decltype(::difference<'B', 'A'>) +>::commit; + +::repeat< + ::difference<'D', 'A'>, + ::sequence< + ::emit<::decltype(::value_of<::name<'i'>>)>::commit, + ::declare< + ::name<'n', 'e', 'x', 't'>, + ::decltype( + ::sum< + ::value_of<::name<'i'>>, + ::difference<'B', 'A'> + > + ) + >::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; -- cgit v1.3