1///////////////////////////////////////////////////////////////////////////////
4// Copyright : (c) Andy Arvanitis 2019
7// Maintainer : Andy Arvanitis
8// Stability : experimental
11// Runtime types to support recursion
13///////////////////////////////////////////////////////////////////////////////
15#ifndef purescript_recursion_H
16#define purescript_recursion_H
22 namespace _template_ {
26 std::weak_ptr<void> wptr;
30 weak(T& b) : wptr(b.shared) {}
32 auto shared() const -> std::shared_ptr<void> {
36 return static_cast<std::shared_ptr<void>>(wptr);
44 std::shared_ptr<T> sptr;
45 std::shared_ptr<typename T::weak> wptr;
48 recur() : sptr(std::make_shared<T>())
49 , wptr(std::make_shared<typename T::weak>(*sptr)) {}
51 auto shared() const -> std::shared_ptr<void> {
55 auto operator()() const -> T {
59 auto operator()(const T& arg) const -> T {
64 auto operator=(U&& right) -> recur& {
65 *sptr = std::forward<U>(right);
71 std::shared_ptr<typename T::weak> wptr;
73 weak(const recur& r) : wptr(r.wptr) {}
75 auto shared() const -> std::shared_ptr<void> {
76 return wptr->shared();
79 auto operator()() const -> T {
80 return static_cast<T>(*wptr)();
83 auto operator()(const T& arg) const -> T {
84 return static_cast<T>(*wptr)(arg);
86 }; // class recur::weak
89 } // namespace _template_
90} // namespace purescript
92#endif // purescript_recursion_H
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list