mirror of
https://gitlab.com/mfocko/Codeforces.git
synced 2024-12-22 07:01:21 +01:00
chore(cpp): add Y-combinator
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
7c7377e138
commit
b8e79c09f6
1 changed files with 19 additions and 0 deletions
|
@ -93,6 +93,25 @@ std::vector<T> load_vector(std::size_t size) {
|
|||
}
|
||||
#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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue