-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtool.hpp
More file actions
38 lines (33 loc) · 1.16 KB
/
Copy pathtool.hpp
File metadata and controls
38 lines (33 loc) · 1.16 KB
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
29
30
31
32
33
34
35
36
37
38
#pragma once
#include "bit.hpp"
#include "types.hpp"
constexpr auto inf32 = std::numeric_limits<i32>::max() / 2;
constexpr auto inf64 = std::numeric_limits<i64>::max() / 2;
template <typename... Args>
bool cmax(auto &value, const Args &...args) {
if (const auto other = std::max({static_cast<std::common_type_t<Args...>>(args)...}); value < other) {
value = other;
return true;
}
return false;
}
template <typename... Args>
bool cmin(auto &value, const Args &...args) {
if (const auto other = std::min({static_cast<std::common_type_t<Args...>>(args)...}); value > other) {
value = other;
return true;
}
return false;
}
auto bisect_search(std::integral auto ok, std::integral auto ng, auto &&check) {
for (decltype(ok) x; std::abs(ok - ng) > 1; (std::forward<decltype(check)>(check)(x) ? ok : ng) = x) {
x = ok + (ng - ok) / 2;
}
return ok;
}
auto bisect_search(std::floating_point auto ok, std::floating_point auto ng, auto &&check, std::size_t loop = 30) {
for (decltype(ok) x; loop--; (std::forward<decltype(check)>(check)(x) ? ok : ng) = x) {
x = ok + (ng - ok) / 2;
}
return ok;
}