hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/examples/enable_if.sfinae
blob: ff7dacc2df5ee3cdfc8436f55376fc132983eeff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// ::enable_if_t runs a ::sequence of statements when its condition holds
// the statements inside are separated by commas and each one is still committed

::enable_if_t<
    ::is_same<::remove_cv_t<::int32_t>, ::int32_t>::value,
    ::sequence<
        ::declare<::name<'x'>, ::decltype(::difference<'C', 'A'>)>::commit,
        ::emit<::decltype(::value_of<::name<'x'>>)>::commit
    >
>::commit;

// this one never runs, so nothing is printed and nothing is asserted
::enable_if_t<
    ::false_type::value,
    ::sequence<
        ::static_assert<::false_type::value>::commit,
        ::emit<::decltype(::difference<'Z', 'A'>)>::commit
    >
>::commit;

// an empty sequence is allowed, for when you have nothing to say
::enable_if_t<::true_type::value, ::sequence<>>::commit;