Skip to content

Commit 2a86ef8

Browse files
committed
simplify scope exit in dynamic modint
1 parent 1a3e7ad commit 2a86ef8

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

cp-algo/math/modint.hpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,12 @@ namespace cp_algo::math {
8686

8787
// Wrapper for temp switching
8888
auto static with_mod(int64_t tmp, auto callback) {
89-
auto prev = mod();
89+
struct scoped {
90+
int prev = mod();
91+
~scoped() {switch_mod(prev);}
92+
} _;
9093
switch_mod(tmp);
91-
if constexpr(std::is_void_v<std::invoke_result_t<decltype(callback)>>) {
92-
callback();
93-
switch_mod(prev);
94-
} else {
95-
auto res = callback();
96-
switch_mod(prev);
97-
return res;
98-
}
94+
return callback();
9995
}
10096
private:
10197
static int64_t m;

0 commit comments

Comments
 (0)