-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_tree.cc
More file actions
28 lines (20 loc) · 775 Bytes
/
test_tree.cc
File metadata and controls
28 lines (20 loc) · 775 Bytes
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
// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*-*/
// scratch: Fun things to do with constexpr
#include "tree.hh"
constexpr int plus(int x, int y) {
return x + y;
}
int main() {
constexpr auto one = scratch::make_leaf(1);
constexpr auto two = scratch::make_leaf(2);
constexpr auto three = scratch::make_leaf(3);
constexpr auto four = scratch::make_leaf(4);
constexpr auto five = scratch::make_leaf(5);
constexpr auto six = scratch::make_leaf(6);
constexpr auto t = (one ^ two) ^ ((three ^ four) ^ (five ^ six));
constexpr auto l = scratch::reduce_leaves(t, plus);
constexpr auto c = scratch::count_leaves<decltype(t), int>::value;
static_assert(l == 21, "Reduce failure.");
static_assert(c == 6, "Count failure.");
return 0;
}