diff options
Diffstat (limited to 'tutorial/05_loops.sfinae')
| -rw-r--r-- | tutorial/05_loops.sfinae | 47 |
1 files changed, 47 insertions, 0 deletions
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<V, ::sequence<...>> 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; |
