diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/countdown.sfinae | 23 |
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; |
