GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 10 / 0 / 10
Functions: 100.0% 3 / 0 / 3
Branches: 100.0% 4 / 0 / 4

src/util/DeferredLogic.h
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #pragma once
4
5 #include <functional>
6 #include <utility>
7
8 namespace spice::compiler {
9
10 /**
11 * RAII helper that can run a lambda at the end of the scope
12 **/
13 struct DeferredLogic {
14 // Constructors
15 48887 explicit DeferredLogic(std::function<void()> deferredFunc, const bool triggerOnDestruct = true)
16 97774 : deferredFunc(std::move(deferredFunc)), triggerOnDestruct(triggerOnDestruct) {}
17
18 // Destructor
19 50994 ~DeferredLogic() {
20
4/4
✓ Branch 2 → 3 taken 46744 times.
✓ Branch 2 → 5 taken 4250 times.
✓ Branch 3 → 4 taken 23234 times.
✓ Branch 3 → 5 taken 23510 times.
50994 if (triggerOnDestruct && !alreadyExecuted)
21 23234 deferredFunc();
22 50994 }
23
24 // Public methods
25 25653 void execute() {
26 25653 deferredFunc();
27 25653 alreadyExecuted = true;
28 25653 }
29
30 private:
31 // Private members
32 std::function<void()> deferredFunc;
33 bool triggerOnDestruct;
34 bool alreadyExecuted = false;
35 };
36
37 } // namespace spice::compiler
38