ラムダ式の再帰 (utility/make/fix_point.cpp)
- category: utility/make
-
View this file on GitHub
- Last commit date: 2020-01-21 16:32:25+09:00
Required by
- 最大流 (Dinitz 法) (Graph/dinitz.cpp)
- 強連結成分分解 (Graph/scc.cpp)
- 2-SAT (Graph/two_sat.cpp)
- 木 DP (algorithm/dp_on_tree.cpp)
- monotone minima (algorithm/monotone_minima.cpp)
- オンライン・オフライン変換 (algorithm/online_to_offline_optimization.cpp)
Verified with
- test/aoj_1595.test.cpp
- test/aoj_2178.test.cpp
- test/aoj_2313.test.cpp
- test/aoj_2580.test.cpp
- test/aoj_2748.test.cpp
- test/aoj_2976.test.cpp
- test/aoj_ALDS1_10_A.test.cpp
- test/yc_703_onoff.test.cpp
- test/yc_704_onoff.test.cpp
- test/yc_705_onoff.test.cpp
- test/yj_bipartitematching.test.cpp
- test/yj_persistent_unionfind_rollback.test.cpp
- test/yj_scc.test.cpp
- test/yj_two_sat.test.cpp
Code
/**
* @brief ラムダ式の再帰
* @author えびちゃん
*/
#ifndef H_make_fix_point
#define H_make_fix_point
#include <utility>
template <typename Fn>
class fix_point: Fn {
public:
explicit constexpr fix_point(Fn&& f) noexcept: Fn(std::forward<Fn>(f)) {}
template <typename... Args>
constexpr decltype(auto) operator ()(Args&&... args) const {
return Fn::operator ()(*this, std::forward<Args>(args)...);
}
};
template <typename Fn>
static inline constexpr decltype(auto) make_fix_point(Fn&& f) noexcept {
return fix_point<Fn>{std::forward<Fn>(f)};
}
#endif /* !defined(H_make_fix_point) */
#line 1 "utility/make/fix_point.cpp"
/**
* @brief ラムダ式の再帰
* @author えびちゃん
*/
#ifndef H_make_fix_point
#define H_make_fix_point
#include <utility>
template <typename Fn>
class fix_point: Fn {
public:
explicit constexpr fix_point(Fn&& f) noexcept: Fn(std::forward<Fn>(f)) {}
template <typename... Args>
constexpr decltype(auto) operator ()(Args&&... args) const {
return Fn::operator ()(*this, std::forward<Args>(args)...);
}
};
template <typename Fn>
static inline constexpr decltype(auto) make_fix_point(Fn&& f) noexcept {
return fix_point<Fn>{std::forward<Fn>(f)};
}
#endif /* !defined(H_make_fix_point) */