mirror of
https://gitlab.com/mfocko/Codeforces.git
synced 2024-12-21 18:41:22 +01:00
chore(cpp): reorder regions of helpers
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
3911ca609c
commit
e39ed7a5c0
1 changed files with 52 additions and 52 deletions
|
@ -22,6 +22,58 @@
|
|||
|
||||
#pragma region helpers
|
||||
|
||||
#pragma region debug
|
||||
void dbg_out() { std::cerr << std::endl; }
|
||||
template <typename Head, typename... Tail>
|
||||
void dbg_out(Head H, Tail... T) {
|
||||
std::cerr << ' ' << H;
|
||||
dbg_out(T...);
|
||||
}
|
||||
#ifdef LOCAL
|
||||
#define dbg(...) \
|
||||
std::cerr << '[' << __FILE__ << ':' << __LINE__ << "] (" << #__VA_ARGS__ \
|
||||
<< "):", \
|
||||
dbg_out(__VA_ARGS__)
|
||||
#else
|
||||
#define dbg(...)
|
||||
#endif
|
||||
#pragma endregion debug
|
||||
|
||||
#pragma region functional
|
||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html
|
||||
template <class Fun>
|
||||
class y_combinator_result {
|
||||
Fun fun_;
|
||||
|
||||
public:
|
||||
template <class T>
|
||||
explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)) {}
|
||||
template <class... Args>
|
||||
decltype(auto) operator()(Args &&...args) {
|
||||
return fun_(std::ref(*this), std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
template <class Fun>
|
||||
decltype(auto) y_combinator(Fun &&fun) {
|
||||
return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
|
||||
}
|
||||
#pragma endregion /* functional */
|
||||
|
||||
#pragma region input
|
||||
template <typename T>
|
||||
std::vector<T> load_vector(std::size_t size) {
|
||||
std::vector<T> result{};
|
||||
|
||||
for (auto i = 0u; i < size; ++i) {
|
||||
T x;
|
||||
std::cin >> x;
|
||||
result.push_back(std::move(x));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#pragma endregion /* input */
|
||||
|
||||
#pragma region math
|
||||
static constexpr std::int32_t MODULO = 1000000007;
|
||||
|
||||
|
@ -61,58 +113,6 @@ inline void no() { std::cout << "NO\n"; }
|
|||
inline void yesno(bool ans) { std::cout << (ans ? "YES" : "NO") << "\n"; }
|
||||
#pragma endregion /* output */
|
||||
|
||||
#pragma region debug
|
||||
void dbg_out() { std::cerr << std::endl; }
|
||||
template <typename Head, typename... Tail>
|
||||
void dbg_out(Head H, Tail... T) {
|
||||
std::cerr << ' ' << H;
|
||||
dbg_out(T...);
|
||||
}
|
||||
#ifdef LOCAL
|
||||
#define dbg(...) \
|
||||
std::cerr << '[' << __FILE__ << ':' << __LINE__ << "] (" << #__VA_ARGS__ \
|
||||
<< "):", \
|
||||
dbg_out(__VA_ARGS__)
|
||||
#else
|
||||
#define dbg(...)
|
||||
#endif
|
||||
#pragma endregion debug
|
||||
|
||||
#pragma region input
|
||||
template <typename T>
|
||||
std::vector<T> load_vector(std::size_t size) {
|
||||
std::vector<T> result{};
|
||||
|
||||
for (auto i = 0u; i < size; ++i) {
|
||||
T x;
|
||||
std::cin >> x;
|
||||
result.push_back(std::move(x));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
#pragma endregion /* input */
|
||||
|
||||
#pragma region functional
|
||||
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html
|
||||
template <class Fun>
|
||||
class y_combinator_result {
|
||||
Fun fun_;
|
||||
|
||||
public:
|
||||
template <class T>
|
||||
explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)) {}
|
||||
template <class... Args>
|
||||
decltype(auto) operator()(Args &&...args) {
|
||||
return fun_(std::ref(*this), std::forward<Args>(args)...);
|
||||
}
|
||||
};
|
||||
template <class Fun>
|
||||
decltype(auto) y_combinator(Fun &&fun) {
|
||||
return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
|
||||
}
|
||||
#pragma endregion /* functional */
|
||||
|
||||
#define LOOP(var, n) for (auto var = 0; var < n; ++var)
|
||||
|
||||
#pragma endregion /* helpers */
|
||||
|
|
Loading…
Reference in a new issue