Live Cells C++
Reactive Programming for C++
Loading...
Searching...
No Matches
maybe_cell.hpp
1#ifndef LIVE_CELLS_MAYBE_CELL_HPP
2#define LIVE_CELLS_MAYBE_CELL_HPP
3
4#include <concepts>
5
6#include "keys.hpp"
7#include "maybe.hpp"
8#include "types.hpp"
9#include "computed.hpp"
10#include "mutable_computed.hpp"
11
12namespace live_cells {
13
17 template<typename T>
19 using value_key<T>::value_key;
20 };
21
26 template<typename T>
28 using value_key<T>::value_key;
29 };
30
31
32
44 auto maybe_cell(const Cell auto &cell) {
46 return maybe_wrap(cell);
47 });
48 }
49
67 auto maybe_cell(const MutableCell auto &cell) {
69 return maybe_wrap(cell);
70 }, [=] (auto value) {
71 try {
72 cell = value.unwrap();
73 }
74 catch (...) {
75 // Prevent exception from propagating to caller
76 }
77 });
78 }
79
80 namespace ops {
85 struct maybe_operator {};
86
104
105 inline auto operator|(const Cell auto &cell, const maybe_operator &) {
106 return maybe_cell(cell);
107 }
108
109 inline auto operator|(const MutableCell auto &cell, const maybe_operator &) {
110 return maybe_cell(cell);
111 }
112 }
113} // live_cells
114
115#endif /* LIVE_CELLS_MAYBE_CELL_HPP */
Dynamically typed Cell container.
Definition observable.hpp:133
key_ref key() const
Get the key that uniquely identifies the underlying Cell.
Definition observable.hpp:182
A computed cell which determines its argument cells at runtime.
Definition dynamic_compute_cell.hpp:153
static key_ref create(Args... args)
Create a key_ref holding a key of type T.
Definition keys.hpp:87
Container holding a cell value or an exception that occurred while computing a value.
Definition maybe.hpp:17
Base class for a key distinguished from other keys by one or more values.
Definition keys.hpp:147
Defines the cell protocol.
Definition types.hpp:128
Concept defining a Cell that can have its value set.
Definition types.hpp:155
Definition boolean.hpp:26
constant_cell< T > value(const T &value)
Definition constant_cell.hpp:132
auto computed(F &&compute)
Create a cell with a value that is a function of one or more argument cells.
Definition computed.hpp:45
auto mutable_computed(F &&fn, R &&reverse)
Create a mutable computed cell with dynamically determined argument cells.
Definition mutable_computed.hpp:63
auto maybe_cell(const Cell auto &cell)
Create a cell that wraps the value of a cell in a maybe.
Definition maybe_cell.hpp:44
Key identifying cells created with maybe_cell.
Definition maybe_cell.hpp:18
Key identifying cells created with the mutable cell overload of maybe_cell.
Definition maybe_cell.hpp:27
Cell operator that creates a maybe cell as if by live_cells::maybe_cell.
Definition maybe_cell.hpp:85