hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/examples/countdown.sfinae
blob: bd7c4a37eb3620f83ce106c71387d21d68483b31 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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;