16 class boxed : public std::shared_ptr<void> {
18 using fn = std::function<boxed(const boxed&)>;
19 using eff_fn = std::function<boxed(void)>;
22 using std::shared_ptr<void>::shared_ptr;
24 boxed(const int n) : std::shared_ptr<void>(std::make_shared<int>(n)) {
27 boxed(const double n) : std::shared_ptr<void>(std::make_shared<double>(n)) {
30 boxed(const bool b) : std::shared_ptr<void>(std::make_shared<bool>(b)) {
33 boxed(const char s[]) : std::shared_ptr<void>(std::make_shared<string>(s)) {
36 boxed(string&& s) : std::shared_ptr<void>(std::make_shared<string>(std::move(s))) {
39 boxed(const std::nullptr_t) : std::shared_ptr<void>() {
42 boxed(std::initializer_list<boxed> l) : std::shared_ptr<void>(std::make_shared<std::deque<boxed>>(l)) {
45 boxed(std::initializer_list<std::pair<const string, boxed>> m) : std::shared_ptr<void>(std::make_shared<std::map<string, boxed>>(m)) {
49 typename = typename std::enable_if<!std::is_same<boxed,T>::value>::type>
51 typename std::enable_if<std::is_assignable<std::function<boxed(boxed)>,T>::value>::type* = 0) : std::shared_ptr<void>(std::make_shared<fn>(f)) {
55 typename = typename std::enable_if<!std::is_same<boxed,T>::value>::type>
57 typename std::enable_if<std::is_assignable<std::function<boxed(void)>,T>::value>::type* = 0) : std::shared_ptr<void>(std::make_shared<eff_fn>(f)) {
61 typename = typename std::enable_if<!std::is_same<boxed,T>::value &&
62 std::is_convertible<T,fn>::value>::type>
63 auto operator=(const T& right) -> boxed& {
64 if (std::shared_ptr<void>::operator bool()) {
65 auto& f = *static_cast<fn*>(get());
73 auto operator()(const boxed& arg) const -> boxed {
74 auto& f = *static_cast<fn*>(get());
78 auto operator()() const -> boxed {
79 auto& f = *static_cast<eff_fn*>(get());
83 auto operator[](const char key[]) const -> boxed {
84 const auto& dict = *static_cast<const std::map<const string, boxed>*>(get());
90 template <typename T, typename... Args>
91 inline auto box(Args&&... args) -> boxed {
92 return std::make_shared<T>(std::forward<Args>(args)...);
96 inline auto unbox(const boxed& b) -> const T& {
97 const auto& unboxed = *static_cast<const T*>(b.get());
101 template <typename T>
102 inline auto peek(boxed& b) -> T& {
103 auto& unboxed = *static_cast<T*>(b.get());
107 template <typename T>
108 inline auto copy(const boxed& b) -> boxed {
109 return box<T>(unbox<T>(b));
112 using fn_t = std::function<boxed(const boxed&)>;
113 using dict_t = std::map<const string, boxed>;
114 using array_t = std::deque<boxed>;
116 using as_array = std::initializer_list<boxed>;
117 using as_dict = std::initializer_list<std::pair<const string, boxed>>;
119 constexpr auto undefined = nullptr;
121} // namespace purescript
123#define FOREIGN_EXPORTS(NS) namespace NS { using namespace purescript; auto _foreign_() -> dict_t&; static const auto& NS ## _foreign_init = []() { dict_t& foreign = _foreign_();
124#define END_FOREIGN_EXPORTS return foreign; }(); }
126#endif // purescript_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