File tree Expand file tree Collapse file tree 2 files changed +20
-4
lines changed
provides/include/dumpster_v1 Expand file tree Collapse file tree 2 files changed +20
-4
lines changed Original file line number Diff line number Diff line change 44
55using namespace testing_v1 ;
66
7- auto finally_test = test([]() {
7+ auto finally_lambda_test = test([]() {
88 bool finalized = false ;
99 bool executed = false ;
1010
@@ -16,3 +16,18 @@ auto finally_test = test([]() {
1616 verify (finalized);
1717 verify (executed);
1818});
19+
20+ static bool s_finalized = false ;
21+ static void s_function () { s_finalized = true ; }
22+
23+ auto finally_function_test = test([]() {
24+ bool executed = false ;
25+
26+ {
27+ auto finalizer = dumpster_v1::finally (s_function);
28+ executed = true ;
29+ }
30+
31+ verify (s_finalized);
32+ verify (executed);
33+ });
Original file line number Diff line number Diff line change 77template <class Action > struct dumpster_v1 ::finally_t {
88 ~finally_t () { m_action (); }
99
10- finally_t (Action &&action) : m_action(std::move(action)) {}
11- finally_t (const Action &action) : m_action(action) {}
10+ template <class ForwardableAction >
11+ finally_t (ForwardableAction &&action)
12+ : m_action(std::forward<ForwardableAction>(action)) {}
1213
1314 finally_t (const finally_t &) = delete ;
1415 finally_t operator =(const finally_t &) = delete ;
1516
1617private:
17- Action m_action;
18+ std:: conditional_t <std::is_function_v< Action>, Action *, Action> m_action;
1819};
1920
2021template <class Action >
You can’t perform that action at this time.
0 commit comments