hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/tutorial/03_variables.sfinae
blob: 6f200f10d137a07ac8760a0c936700813fb7ed3f (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
36
37
38
39
40
41
42
43
44
45
46
// lesson 3: variables
//
// a name is a list of characters. a variable holds a type, not a value, and the
// only type that carries a value is ::decltype(...). the ::conditional_t around
// it is not required. it is just what everyone does

::declare<
    ::name<'x'>,
    ::conditional_t<
        ::true_type::value,
        ::decltype(::difference<'F', 'A'>),
        ::void
    >
>::commit;

// reading it back is ::value_of<NAME>, which is a value, so ::decltype it again

::emit<::decltype(::value_of<::name<'x'>>)>::commit;

::declare<
    ::name<'y'>,
    ::decltype(
        ::sum<
            ::value_of<::name<'x'>>,
            ::difference<'B', 'A'>
        >
    )
>::commit;

::emit<::decltype(::value_of<::name<'y'>>)>::commit;

// there is no assignment. to change x, undeclare it and declare it again

::undeclare<::name<'x'>>::commit;

::declare<
    ::name<'x'>,
    ::decltype(
        ::product<
            ::value_of<::name<'y'>>,
            ::difference<'C', 'A'>
        >
    )
>::commit;

::emit<::decltype(::value_of<::name<'x'>>)>::commit;