hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/examples/conditions.sfinae
blob: e930480cd0b81c16fb21db2b25388b68a52a9739 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// a condition is not a condition until you say ::value

// ::conditional_t picks a type. picking ::void and emitting it prints nothing at all
::emit<
    ::conditional_t<
        ::less<::difference<'B', 'A'>, ::difference<'A', 'A'>>::value,
        ::decltype(::difference<'Z', 'A'>),
        ::void
    >
>::commit;

// ::conditional does the same for values. this prints 9
::emit<
    ::decltype(
        ::conditional<
            ::is_same<::remove_cv_t<::int32_t>, ::int32_t>::value,
            ::difference<'J', 'A'>,
            ::difference<'A', 'A'>
        >
    )
>::commit;

// two arrays are the same type when their extents agree. this prints 1
::emit<
    ::decltype(
        ::conditional<
            ::is_same<
                ::array<::byte, ::difference<'C', 'A'>>,
                ::array<::int32_t, ::sum<::difference<'B', 'A'>, ::difference<'B', 'A'>>>
            >::value,
            ::difference<'B', 'A'>,
            ::difference<'A', 'A'>
        >
    )
>::commit;