diff options
author | Kai WU <kaiwu2004@gmail.com> | 2022-03-17 22:21:20 +0800 |
---|---|---|
committer | Kai WU <kaiwu2004@gmail.com> | 2022-03-17 22:21:20 +0800 |
commit | 29b341616a344ee89a776b3031353643b33afb58 (patch) | |
tree | 6ec84ab9bb2f66b8acb77333a4c3218d2befe5a0 /src | |
parent | 1914eb19f3ce24e59332df7950a83f2d00bf2531 (diff) | |
download | advent-of-code-29b341616a344ee89a776b3031353643b33afb58.tar.gz advent-of-code-29b341616a344ee89a776b3031353643b33afb58.zip |
cal parse
Diffstat (limited to 'src')
-rw-r--r-- | src/2015/day7/aoc.h | 15 | ||||
-rw-r--r-- | src/common.h | 7 |
2 files changed, 14 insertions, 8 deletions
diff --git a/src/2015/day7/aoc.h b/src/2015/day7/aoc.h index b03c3a8..e161166 100644 --- a/src/2015/day7/aoc.h +++ b/src/2015/day7/aoc.h @@ -66,6 +66,7 @@ struct cals { } result compute(line_view w) const noexcept { + // std::cout << "compute " << w << std::endl; uint16_t x = 0; if (is_value(w, &x)) { return {result::c_value, x}; @@ -75,33 +76,33 @@ struct cals { } } - std::function<result()> op_and(line_view x, line_view y) const noexcept { + std::function<result()> op_and(line_view& x, line_view& y) const noexcept { return [&x, &y, this]() -> result { return compute(x).op_and(compute(y)); }; } - std::function<result()> op_or(line_view x, line_view y) const noexcept { + std::function<result()> op_or(line_view& x, line_view& y) const noexcept { return [&x, &y, this]() -> result { return compute(x).op_or(compute(y)); }; } - std::function<result()> op_leftshift(line_view x, line_view y) const noexcept { + std::function<result()> op_leftshift(line_view& x, line_view& y) const noexcept { return [&x, &y, this]() -> result { return compute(x).op_leftshift(compute(y)); }; } - std::function<result()> op_rightshift(line_view x, line_view y) const noexcept { + std::function<result()> op_rightshift(line_view& x, line_view& y) const noexcept { return [&x, &y, this]() -> result { return compute(x).op_rightshift(compute(y)); }; } - std::function<result()> op_not(line_view x, line_view y) const noexcept { + std::function<result()> op_not(line_view& x, line_view& y) const noexcept { return [&x, this]() -> result { return compute(x).op_not(); }; } - std::function<result()> op_value(line_view x, line_view y) const noexcept { + std::function<result()> op_value(line_view& x, line_view& y) const noexcept { return [&x, this]() -> result { return compute(x); }; } std::function<result()> parse(line_view line, line_view* x, line_view* y, line_view* w) const noexcept { static struct _ { - std::function<result()> (cals::*op)(line_view, line_view) const noexcept; + std::function<result()> (cals::*op)(line_view&, line_view&) const noexcept; const char* label; } ops[] = { {&cals::op_and, "AND"}, diff --git a/src/common.h b/src/common.h index e9dd01c..7659322 100644 --- a/src/common.h +++ b/src/common.h @@ -27,9 +27,14 @@ struct line_view { size_t i = 0; size_t j = 0; while (i < length && j < lv.length) { - if (line[i++] < line[j++]) { + if (line[i] < lv.line[j]) { return true; } + if (line[i] > lv.line[j]) { + return false; + } + i++; + j++; } return j < lv.length; } |