Live Cells C++
Reactive Programming for C++
Loading...
Searching...
No Matches
live_cells Namespace Reference

Namespaces

namespace  ops
 

Classes

class  argument_tracker
 
struct  bad_typed_cell_cast
 Exception thrown when attempting to cast a cell to a typed_cell with a value type that is incompatible with the cell's value type. More...
 
class  batch_update
 Defer changes to the values of mutable cells. More...
 
class  cell
 Dynamically typed Cell container. More...
 
class  cell_state
 Maintains the state of a stateful cell. More...
 
class  changes_only_cell_state
 Mixin that modifies a compute_cell_state subclass to only notify its observers if the new value of the cell is not equal (!=) to the previous value. More...
 
struct  changes_only_option
 Cell option specifying that the cell, to which it is applied, should only notify its observers when its new value is not equal (by ==) to its previous value. More...
 
class  compute_cell_base
 A cell with a value that is a function of one or more argument cells. More...
 
class  compute_cell_state
 Cell state for a cell which computes a value as a function of one or more argument cells. More...
 
class  constant_cell
 A cell which holds a constant value. More...
 
struct  constant_key
 Key identifying a constant_cell. More...
 
class  dependent_cell
 Provides an interface for a cell with a value that is dependent on one or more argument cells. More...
 
class  dynamic_compute_cell
 A computed cell which determines its argument cells at runtime. More...
 
class  dynamic_compute_cell_state
 Maintains the state of a dynamic_compute_cell. More...
 
class  dynamic_compute_changes_only_cell_state
 A dynamic_compute_cell_state that only notifies the observers of the cell if the new value of the cell is not equal to the previous value. More...
 
class  dynamic_compute_state
 Defines the computation function of the state of a dynamic_compute_cell. More...
 
class  dynamic_mutable_compute_cell
 A mutable computed cell with the argument cells determined dynamically. More...
 
class  dynamic_mutable_compute_cell_state
 Maintains the state of a dynamic_mutable_compute_cell. More...
 
class  dynamic_mutable_compute_changes_only_cell_state
 A dynamic_mutable_compute_cell_state that only notifies the observers of the cell if its value has actually changed. More...
 
class  key
 Defines the interface for a key which uniquely identifies a cell. More...
 
class  key_ref
 Dynamically type key container. More...
 
struct  make_cell
 Defines a cell class using C such that the constraints defined by the concept Cell are satisifed. More...
 
class  make_mutable_cell
 Same as make_cell but also provides a value setter value(Parent::value_type) so that the definition satisfies the MutableCell concept. More...
 
class  maybe
 Container holding a cell value or an exception that occurred while computing a value. More...
 
class  merged_observable
 Allows multiple cells to be observed at once. More...
 
class  merged_observable< T >
 
class  mutable_cell
 A stateful cell which can have its value set directly. More...
 
class  mutable_cell_state
 Maintains the state of a mutable_cell. More...
 
class  mutable_cell_view_base
 A stateless mutable computed cell that does not cache its own value. More...
 
class  mutable_compute_cell_state
 Maintains the state of a mutable computed cell. More...
 
class  observer
 Defines the interface for observing changes to the value of a Cell. More...
 
class  observer_cell_state
 Provides functionality for observing a cell from a cell_state. More...
 
class  peek_cell
 A Cell that reads the value of another Cell without notifying its observers when it changes. More...
 
struct  peek_cell_key
 Key identifying a peek_cell. More...
 
class  peek_cell_state
 Maintains the state of a peek_cell. More...
 
class  previous_value_cell
 A Cell that evaluates to the previous value of another Cell. More...
 
struct  previous_value_cell_key
 Key identifying a previous_value_cell. More...
 
class  previous_value_cell_state
 Maintains the state of a previous_value_cell. More...
 
class  state_manager
 Maintains the association between keys and cell states. More...
 
class  stateful_cell
 Base class for a cell with a state. More...
 
class  static_mutable_compute_cell
 A mutable computed cell with arguments determined at compile-time. More...
 
class  static_mutable_compute_cell_state
 Maintains the state for a static_mutable_compute_cell. More...
 
class  static_mutable_compute_changes_only_cell_state
 A static_mutable_compute_cell_state that only notifies the observers of the cell when the cell's value has actually changed. More...
 
struct  stop_compute_exception
 Exception indicating that the value of a cell should not be computed. More...
 
class  store_cell
 A Cell that caches the value of another Cell. More...
 
class  store_cell_compute_state
 Defines the computation function of a store_cell. More...
 
struct  store_cell_key
 Key identifying a store_cell. More...
 
class  store_cell_state
 Maintains the state of a store_cell. More...
 
class  store_changes_only_cell_state
 A store_cell_state that only notifies the observers of the cell if the new value of the cell is not equal to its previous value. More...
 
class  typed_cell
 Dynamically typed Cell container with a static value type. More...
 
struct  uninitialized_cell_error
 Exception indicating that the value of a cell was referenced before its initial value was computed. More...
 
class  unique_key
 A key of uniquely identified by a single instance. More...
 
class  value_key
 Base class for a key distinguished from other keys by one or more values. More...
 
class  value_key< T >
 Base class for a key distinguished from other keys by one value. More...
 
class  watcher
 Handle for a cell watch function. More...
 

Concepts

concept  Computable
 Defines a type that computes a value when the call operator operator() is invoked.
 
concept  CellOrValue
 Concept specifying that T is either a Cell or a value that can be converted to a constant_cell.
 
concept  Keyable
 Concept defining an object that can be identified by a key.
 
concept  Trackable
 Concept defining an observable object that can be tracked dynamically as a dependency.
 
concept  Cell
 Defines the cell protocol.
 
concept  TypedCell
 Concept that constrains Cell to cells holding a specific value type T.
 
concept  MutableCell
 Concept defining a Cell that can have its value set.
 
concept  TypedMutableCell
 Concept that constrains MutableCell to cells holding a specific value type T.
 

Typedefs

template<std::invocable F, Cell... Ts>
using compute_cell = make_cell<compute_cell_base<F,Ts...>>
 A computed cell with a static argument list.
 
template<typename C >
using cell_value_type = decltype(std::declval<C>().value())
 The return type of C::value().
 
template<std::invocable F, typename R , Cell... Ts>
using mutable_cell_view = make_mutable_cell<mutable_cell_view_base<F,R,Ts...>>
 A stateless mutable computed cell.
 

Functions

template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto operator&& (const A &a, const B &b)
 Creates a Cell that evaluates to the logical and of the values of cells a and b.
 
template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto operator|| (const A &a, const B &b)
 Create a cell that evaluates to the logical or of the values of cells a and b.
 
auto operator! (const Cell auto &cell)
 Create a cell that evaluates to the logical not of the value of a cell.
 
auto select (Cell auto condition, Cell auto if_true, Cell auto if_false)
 Create a cell which selects between the values of two cells based on the value of a condition cell.
 
auto select (Cell auto condition, Cell auto if_true)
 Create a cell which evaluates to the value of another cell only if a condition is true.
 
auto make_compute_cell (std::invocable auto f, auto... args)
 
auto make_compute_cell (key_ref key, std::invocable auto f, auto... args)
 
template<std::invocable F>
auto computed (F &&compute)
 Create a cell with a value that is a function of one or more argument cells.
 
template<std::invocable F>
auto computed (changes_only_option option, F &&compute)
 Create a cell with a value that is a function of one or more argument cells and only notifies its observers when its value has actually changed.
 
template<std::invocable F>
auto computed (key_ref key, F &&compute)
 Create a cell with a value that is a function of one or more argument cells.
 
template<std::invocable F>
auto computed (changes_only_option option, key_ref key, F &&compute)
 Create a cell with a value that is a function of one or more argument cells and only notifies its observers when its value has actually changed.
 
template<typename A , typename... As>
auto computed (A arg1, As... args)
 Create a cell with a value that is a function of the values of one or more argument cells.
 
template<typename A , typename... As>
auto computed (key_ref key, A arg1, As... args)
 Create a cell with a value that is a function of the values of one or more argument cells.
 
void none ()
 Stop the computation of the current computed cell's value.
 
template<typename T >
constant_cell< T > value (const T &value)
 
auto ensure_cell (const Cell auto &thing)
 Ensure that thing is a Cell.
 
template<typename T >
auto ensure_cell (const T &thing)
 Ensure that thing is a Cell.
 
template<typename T , typename U >
requires ( (Cell<T> && CellOrValue<U>) || (CellOrValue<T> && Cell<U>) )
auto operator== (const T &a, const U &b)
 Create a Cell that compares two cells for equality by ==.
 
template<typename T , typename U >
requires ( (Cell<T> && CellOrValue<U>) || (CellOrValue<T> && Cell<U>) )
auto operator!= (const T &a, const U &b)
 Create a Cell that compares two cells for inequality by !=.
 
auto on_error (const Cell auto &cell, const Cell auto &error_value)
 Create a Cell which handles all exceptions thrown while computing the value of a cell.
 
template<typename E >
auto on_error (const Cell auto &cell, const Cell auto &error_value)
 Create a Cell which handles exceptions of type E thrown while computing the value of a cell.
 
bool operator== (const key &k1, const key &k2)
 
bool operator!= (const key &k1, const key &k2)
 
bool operator== (const key_ref &k1, const key_ref &k2)
 
bool operator!= (const key_ref &k1, const key_ref &k2)
 
auto maybe_wrap (const std::invocable auto &f)
 Create a maybe holding the result of calling f.
 
template<typename A , typename B >
bool operator== (const maybe< A > &a, const maybe< B > &b)
 
template<typename T >
mutable_cell< T > variable (T value)
 Create a new mutable cell with an initial value.
 
template<typename T >
mutable_cell< T > variable (key_ref key, T value)
 Create a new mutable cell, identified by a key, with an initial value.
 
template<typename F >
void batch (F fn)
 Batch changes to the values of mutable cells.
 
template<typename T >
operator+= (const MutableCell auto &c, const T &value)
 Add value to the value of Cell c.
 
template<typename T >
operator-= (const MutableCell auto &c, const T &value)
 Subtract value from the value of Cell c.
 
template<typename T >
operator*= (const MutableCell auto &c, const T &value)
 Multiply the value of Cell c by value.
 
template<typename T >
operator/= (const MutableCell auto &c, const T &value)
 Divide the value of Cell c by value.
 
template<typename T >
operator%= (const MutableCell auto &c, const T &value)
 Compute the remainder of the value of Cell c divided by value, and assign it to c.
 
template<typename T >
operator<<= (const MutableCell auto &c, const T &value)
 Left shift the value of Cell c by value.
 
template<typename T >
operator>>= (const MutableCell auto &c, const T &value)
 Right shift the value of Cell c by value.
 
template<typename T >
operator&= (const MutableCell auto &c, const T &value)
 Compute the bitwise and of the value of Cell c and value, and assign it to c.
 
template<typename T >
operator^= (const MutableCell auto &c, const T &value)
 Compute the bitwise exclusive or of the value of Cell c and value, and assign it to c.
 
template<typename T >
operator|= (const MutableCell auto &c, const T &value)
 Compute the bitwise or of the value of Cell c and value, and assign it to c.
 
auto operator++ (const MutableCell auto &c)
 Increment the value of Cell c.
 
auto operator++ (const MutableCell auto &c, int)
 Increment the value of Cell c.
 
auto operator-- (const MutableCell auto &c)
 Decrement the value of Cell c.
 
auto operator-- (const MutableCell auto &c, int)
 Decrement the value of Cell c.
 
auto make_mutable_cell_view (std::invocable auto compute, auto reverse, auto... args)
 
auto make_mutable_cell_view (key_ref key, std::invocable auto compute, auto reverse, auto... args)
 
template<typename A1 , typename A2 , typename... As>
auto cell_view (key_ref key, A1 arg1, A2 arg2, As... args)
 
template<typename A1 , typename A2 , typename... As>
auto cell_view (A1 arg1, A2 arg2, As... args)
 
template<std::invocable F, typename R >
auto mutable_computed (F &&fn, R &&reverse)
 Create a mutable computed cell with dynamically determined argument cells.
 
template<std::invocable F, typename R >
auto mutable_computed (changes_only_option option, F &&fn, R &&reverse)
 Create a mutable computed cell with dynamically determined argument cells that only notifies its observers when its value has actually changed.
 
template<typename A1 , typename A2 , typename... As>
auto mutable_computed (A1 arg1, A2 arg2, As... args)
 Create a mutable computed cell.
 
template<typename A1 , typename A2 , typename... As>
auto mutable_computed (changes_only_option option, A1 arg1, A2 arg2, As... args)
 Create a mutable computed cell that only notifies its observers when its value has actually changed.
 
template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto operator+ (const A &a, const B &b)
 Create a Cell that computes the sum (using the + operator) of cells and .
 
template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto operator- (const A &a, const B &b)
 Create a Cell that computes the difference (using the - operator) of cells and .
 
auto operator- (const Cell auto &cell)
 Create a Cell that negates the value of another cell using the unary - operator.
 
template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto operator* (const A &a, const B &b)
 Create a Cell that computes the product (using the .
 
template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto operator/ (const A &a, const B &b)
 Create a Cell that computes the quotient (using the / operator) of cells and .
 
template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto operator% (const A &a, const B &b)
 Create a Cell that computes the remainder (using the % operator) of cell divided by .
 
template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto operator< (const A &a, const B &b)
 Create a Cell that is true if the value of cell is less than (by the < operator) the value of cell .
 
template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto operator<= (const A &a, const B &b)
 Create a Cell that is true if the value of cell is less than or equal to (by the <= operator) the value of cell .
 
template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto operator> (const A &a, const B &b)
 Create a Cell that is true if the value of cell is greater than (by the > operator) the value of cell .
 
template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto operator>= (const A &a, const B &b)
 Create a Cell that is true if the value of cell is greater than or equal to (by the >= operator) the value of cell .
 
template<typename C >
auto peek (const C &cell)
 Create a Cell that reads the value of cell but does not notify its observers when the value has changes.
 
template<Cell C>
auto previous (const C &cell)
 Create a Cell that evaluates to the previous value of cell.
 
template<std::invocable C, typename R , Cell... As>
auto make_mutable_compute_cell (C compute, R reverse, As... args)
 Create a static_mutable_compute_cell with compute function compute, reverse compute function reverse and arguments args.
 
template<std::invocable C, typename R , Cell... As>
auto make_mutable_compute_cell (changes_only_option option, C compute, R reverse, As... args)
 Create a static_mutable_compute_cell with compute function compute, reverse compute function reverse and arguments args, that only notifies its observers when its value has actually changed.
 
template<Cell C>
auto store (const C &arg)
 Create a Cell that caches the value of another Cell.
 
template<Cell C>
auto store (changes_only_option option, const C &arg)
 Create a Cell that caches the value of another Cell and only notifies its observers when its value has actually changed.
 
template<typename F >
std::shared_ptr< watcherwatch (F fn)
 Register a cell watch function.
 

Detailed Description

Namespace containing all functions and classes provided by the live cells library.

Typedef Documentation

◆ compute_cell

template<std::invocable F, Cell... Ts>
using live_cells::compute_cell = make_cell<compute_cell_base<F,Ts...>>

A computed cell with a static argument list.

This cell is stateless in that it does not cache its value, nor keeps track of its own observers. Instead, its value is computed whenever value() is called and observers added to this cell are added directly to the argument cells.

◆ mutable_cell_view

template<std::invocable F, typename R , Cell... Ts>
using live_cells::mutable_cell_view = make_mutable_cell<mutable_cell_view_base<F,R,Ts...>>

A stateless mutable computed cell.

This implements a mutable computed cell which does not cache its value. Instead its value is computed on demand and observers are added directly to the argument cells.

Note
This class satisfies the Cell and MutableCell concepts.

Function Documentation

◆ batch()

template<typename F >
void live_cells::batch ( F fn)

Batch changes to the values of mutable cells.

The function fn is called with zero arguments. When the value of a mutable cell is set within fn, the observers of the cell are only notified of the change after fn returns.

Parameters
fnA function of zero arguments

◆ cell_view()

template<typename A1 , typename A2 , typename... As>
auto live_cells::cell_view ( key_ref key,
A1 arg1,
A2 arg2,
As... args )

Create a stateless mutable computed cell.

This is like a mutable cell view but it does not store its own value nor does it track its own observers. As a result this cell has slightly different semantics from a mutable computed cell, in that its value is always recomputed when accessed even after it is set explicitly.

Parameters
keyThe key identifying the cell.
arg1First argument to compute value function.
arg2,argsRemaining compute value function arguments followed by compute value and reverse compute functions.

The compute value function is passed the values of the argument cells, in the same order as they are provided in the argument list.

The reverse compute function (last in the argument list) is passed the value that was assigned to the cell.

Returns
The cell.

◆ computed() [1/6]

template<typename A , typename... As>
auto live_cells::computed ( A arg1,
As... args )

Create a cell with a value that is a function of the values of one or more argument cells.

Parameters
arg1First argument to value computation function.
argsRemaining arguments followed by compute value function.
The compute value function is called to compute the value of the cell when necessary. The values of the argument cells are passed to the compute value function in the same order as they are provided in this function.
Returns
A computed cell

◆ computed() [2/6]

template<std::invocable F>
auto live_cells::computed ( changes_only_option option,
F && compute )

Create a cell with a value that is a function of one or more argument cells and only notifies its observers when its value has actually changed.

The argument cells, referenced within compute, are determined dynamically. For this to work, the values of the argument cells must be referenced using the function call operator and not the Cell::value() getter method.

Note
The difference between this and the other overloads, is that with this overload, the cell only notifies its observers when its new value is not equal to its previous value.
Parameters
optionChanges only cell option
computeCompute value function
Returns
A computed cell

◆ computed() [3/6]

template<std::invocable F>
auto live_cells::computed ( changes_only_option option,
key_ref key,
F && compute )

Create a cell with a value that is a function of one or more argument cells and only notifies its observers when its value has actually changed.

The argument cells, referenced within compute, are determined dynamically. For this to work, the values of the argument cells must be referenced using the function call operator and not the Cell::value() getter method.

Note
The difference between this and the other overloads, is that with this overload, the cell only notifies its observers when its new value is not equal to its previous value.
Parameters
optionChanges only cell option
keyKey identifying the cell
computeCompute value function
Returns
A computed cell

◆ computed() [4/6]

template<std::invocable F>
auto live_cells::computed ( F && compute)

Create a cell with a value that is a function of one or more argument cells.

The argument cells, referenced within compute, are determined dynamically. For this to work, the values of the argument cells must be referenced using the function call operator and not the Cell::value() getter method.

Parameters
computeCompute value function
Returns
A computed cell

◆ computed() [5/6]

template<typename A , typename... As>
auto live_cells::computed ( key_ref key,
A arg1,
As... args )

Create a cell with a value that is a function of the values of one or more argument cells.

Parameters
keyKey identifying the cell
arg1First argument to value computation function.
argsRemaining arguments followed by compute value function.
The compute value function is called to compute the value of the cell when necessary. The values of the argument cells are passed to the compute value function in the same order as they are provided in this function.
Returns
A computed cell

◆ computed() [6/6]

template<std::invocable F>
auto live_cells::computed ( key_ref key,
F && compute )

Create a cell with a value that is a function of one or more argument cells.

The argument cells, referenced within compute, are determined dynamically. For this to work, the values of the argument cells must be referenced using the function call operator and not the Cell::value() getter method.

Parameters
keyKey identifying the cell
computeCompute value function
Returns
A computed cell

◆ ensure_cell() [1/2]

auto live_cells::ensure_cell ( const Cell auto & thing)

Ensure that thing is a Cell.

If thing is not a cell it is converted to a constant_cell.

Note
This overload simply returns thing.
Parameters
thingA Cell or value
Returns
A Cell

◆ ensure_cell() [2/2]

template<typename T >
auto live_cells::ensure_cell ( const T & thing)

Ensure that thing is a Cell.

If thing is not a cell it is converted to a constant_cell.

Note
This overload returns a constant_cell holding the value thing.
Parameters
thingA Cell or value
Returns
A Cell

◆ make_compute_cell() [1/2]

auto live_cells::make_compute_cell ( key_ref key,
std::invocable auto f,
auto... args )

Create a stateless computed cell with a given compute value function and argument cells.

Parameters
keyKey identifying the cell.
fA function of no arguments, called to compute the value of the cell.
argsList of argument Cells on which the value of this cell depends.
Returns
The computed cell.

◆ make_compute_cell() [2/2]

auto live_cells::make_compute_cell ( std::invocable auto f,
auto... args )

Create a stateless computed cell with a given compute value function and argument cells.

Parameters
fA function of no arguments, called to compute the value of the cell.
argsList of argument Cells on which the value of this cell depends.
Returns
The computed cell.

◆ make_mutable_cell_view() [1/2]

auto live_cells::make_mutable_cell_view ( key_ref key,
std::invocable auto compute,
auto reverse,
auto... args )

Create a stateless computed cell with a given compute and reverse function function and argument cells

Parameters
keyKey identifying the cell.
fA function of no arguments, called to compute the value of the cell.
argsList of argument Cells on which the value of this cell depends.
Returns
The computed cell.

◆ make_mutable_cell_view() [2/2]

auto live_cells::make_mutable_cell_view ( std::invocable auto compute,
auto reverse,
auto... args )

Create a stateless mutable computed cell with a given compute and reverse function and argument cells.

Parameters
fA function of no arguments, called to compute the value of the cell.
argsList of argument Cells on which the value of this cell depends.
Returns
The computed cell.

◆ make_mutable_compute_cell() [1/2]

template<std::invocable C, typename R , Cell... As>
auto live_cells::make_mutable_compute_cell ( C compute,
R reverse,
As... args )

Create a static_mutable_compute_cell with compute function compute, reverse compute function reverse and arguments args.

Parameters
computeCompute value function.
reverseReverse compute function.
argsArgument cells
Returns
The cell

◆ make_mutable_compute_cell() [2/2]

template<std::invocable C, typename R , Cell... As>
auto live_cells::make_mutable_compute_cell ( changes_only_option option,
C compute,
R reverse,
As... args )

Create a static_mutable_compute_cell with compute function compute, reverse compute function reverse and arguments args, that only notifies its observers when its value has actually changed.

Note
The difference between this and the other overloads, is that with this overload, the cell only notifies its observers when its new value is not equal to its previous value.
Parameters
optionChanges only cell option
computeCompute value function.
reverseReverse compute function.
argsArgument cells
Returns
The cell

◆ maybe_wrap()

auto live_cells::maybe_wrap ( const std::invocable auto & f)

Create a maybe holding the result of calling f.

f is called with no arguments. If it returns normally, the resulting maybe holds the returned value. If f throws an exception the resulting maybe holds the thrown exception.

Parameters
Afunction of no arguments.
Returns
A maybe holding the result of calling f.

◆ mutable_computed() [1/4]

template<typename A1 , typename A2 , typename... As>
auto live_cells::mutable_computed ( A1 arg1,
A2 arg2,
As... args )

Create a mutable computed cell.

Ordinarily the value of the cell is the value computed by a function of the cells in args.

The returned cell is also a mutable cell, which means its value can be set explicitly. When the value of the cell is set explicitly, the reverse computation function is called. The reverse computation function, should set the values of the cells in args such that the compute value function returns the same value as the value that was assigned to the cell.

Parameters
arg1First argument to compute value function.
arg2,argsRemaining compute value function arguments followed by compute value and reverse compute functions.

The compute value function is passed the values of the argument cells, in the same order as they are provided in the argument list.

The reverse compute function (last in the argument list) is passed the value that was assigned to the cell.
Returns
The mutable computed cell.

◆ mutable_computed() [2/4]

template<typename A1 , typename A2 , typename... As>
auto live_cells::mutable_computed ( changes_only_option option,
A1 arg1,
A2 arg2,
As... args )

Create a mutable computed cell that only notifies its observers when its value has actually changed.

Ordinarily the value of the cell is the value computed by a function of the cells in args.

The returned cell is also a mutable cell, which means its value can be set explicitly. When the value of the cell is set explicitly, the reverse computation function is called. The reverse computation function, should set the values of the cells in args such that the compute value function returns the same value as the value that was assigned to the cell.

Note
The difference between this and the other overloads, is that with this overload, the cell only notifies its observers when its new value is not equal to its previous value.
Parameters
optionChanges only cell option
arg1First argument to compute value function.
arg2,argsRemaining compute value function arguments followed by compute value and reverse compute functions.

The compute value function is passed the values of the argument cells, in the same order as they are provided in the argument list.

The reverse compute function (last in the argument list) is passed the value that was assigned to the cell.
Returns
The mutable computed cell.

◆ mutable_computed() [3/4]

template<std::invocable F, typename R >
auto live_cells::mutable_computed ( changes_only_option option,
F && fn,
R && reverse )

Create a mutable computed cell with dynamically determined argument cells that only notifies its observers when its value has actually changed.

Ordinarily the value of the cell is the value computed by fn as a function of other cells.

The returned cell is also a mutable cell, which means its value can be set explicitly. When the value of the cell is set explicitly, the reverse computation function reverse is called. reverse should set the values of the cells referenced in fn such that fn returns the same value as the value that was assigned to the cell.

Attention
The values of Cell's should be referenced in fn using the function call operator, so that they are tracked as dependencies of the mutable computed cell, and not using the Cell::value() getter method.
Note
This differs from the other overload in that the argument cells are not specified explicitly, but are determined dynamically.
With this overload, the cell only notifies its observers when its new value is not equal to its previous value.
Parameters
optionChanges only cell option
fnCompute value function.
This function is called with no arguments.
reverseReverse computation function.
This function is passed the value that was assigned to the cell.
Returns
The mutable computed cell

◆ mutable_computed() [4/4]

template<std::invocable F, typename R >
auto live_cells::mutable_computed ( F && fn,
R && reverse )

Create a mutable computed cell with dynamically determined argument cells.

Ordinarily the value of the cell is the value computed by fn as a function of other cells.

The returned cell is also a mutable cell, which means its value can be set explicitly. When the value of the cell is set explicitly, the reverse computation function reverse is called. reverse should set the values of the cells referenced in fn such that fn returns the same value as the value that was assigned to the cell.

Attention
The values of Cell's should be referenced in fn using the function call operator, so that they are tracked as dependencies of the mutable computed cell, and not using the Cell::value() getter method.
Note
This differs from the other overload in that the argument cells are not specified explicitly, but are determined dynamically.
Parameters
fnCompute value function.
This function is called with no arguments.
reverseReverse computation function.
This function is passed the value that was assigned to the cell.
Returns
The mutable computed cell

◆ none()

void live_cells::none ( )
inline

Stop the computation of the current computed cell's value.

When this method is called within the value computation of a cell, the cell's value is not recomputed. Instead its current value is preserved.

◆ on_error() [1/2]

auto live_cells::on_error ( const Cell auto & cell,
const Cell auto & error_value )

Create a Cell which handles all exceptions thrown while computing the value of a cell.

If an exception is thrown during the computation of the value of cell, the cell evaluates to the value of the error_value cell.

Parameters
cellThe cell for which to handle exceptions
error_valueThe cell holding the value to use when an exception is thrown.
Returns
The new cell

◆ on_error() [2/2]

template<typename E >
auto live_cells::on_error ( const Cell auto & cell,
const Cell auto & error_value )

Create a Cell which handles exceptions of type E thrown while computing the value of a cell.

If an exception is thrown during the computation of the value of cell, the cell evaluates to the value of the error_value cell.

Note
Type E cannot be deduced so it should be specified explicitly.
Parameters
cellThe cell for which to handle exceptions
error_valueThe cell holding the value to use when an exception is thrown.
Returns
The new cell

◆ operator!()

auto live_cells::operator! ( const Cell auto & cell)

Create a cell that evaluates to the logical not of the value of a cell.

Parameters
cellThe Cell
Returns
A new Cell

◆ operator!=()

template<typename T , typename U >
requires ( (Cell<T> && CellOrValue<U>) || (CellOrValue<T> && Cell<U>) )
auto live_cells::operator!= ( const T & a,
const U & b )

Create a Cell that compares two cells for inequality by !=.

Parameters
aA Cell or value
bA Cell or value
Returns
A computed cell that evaluates the expression a != b.

◆ operator%()

template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto live_cells::operator% ( const A & a,
const B & b )

Create a Cell that computes the remainder (using the % operator) of cell divided by .

Parameters
aA Cell or value
bA Cell or value
Returns
A new Cell

◆ operator%=()

template<typename T >
T live_cells::operator%= ( const MutableCell auto & c,
const T & value )

Compute the remainder of the value of Cell c divided by value, and assign it to c.

Note
This is equivalent to c = c.value() % value
Parameters
cA Cell
valueThe divisor by which to divide the value of c
Returns
The new value of c.

◆ operator&&()

template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto live_cells::operator&& ( const A & a,
const B & b )

Creates a Cell that evaluates to the logical and of the values of cells a and b.

Note
This operator is short-circuiting which means that the value of cell b is only referenced if a is true.
Parameters
aA Cell or value
bA Cell or value
Returns
A new Cell

◆ operator&=()

template<typename T >
T live_cells::operator&= ( const MutableCell auto & c,
const T & value )

Compute the bitwise and of the value of Cell c and value, and assign it to c.

Note
This is equivalent to c = c.value() & value
Parameters
cA Cell
valueA value
Returns
The new value of c.

◆ operator*()

template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto live_cells::operator* ( const A & a,
const B & b )

Create a Cell that computes the product (using the .

  • operator) of cells and .
Parameters
aA Cell or value
bA Cell or value
Returns
A new Cell

◆ operator*=()

template<typename T >
T live_cells::operator*= ( const MutableCell auto & c,
const T & value )

Multiply the value of Cell c by value.

Note
This is equivalent to c = c.value() * value
Parameters
cA Cell
valueThe value by which to multiply the value of c
Returns
The new value of c.

◆ operator+()

template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto live_cells::operator+ ( const A & a,
const B & b )

Create a Cell that computes the sum (using the + operator) of cells and .

Parameters
aA Cell or value
bA Cell or value
Returns
A new Cell

◆ operator++() [1/2]

auto live_cells::operator++ ( const MutableCell auto & c)

Increment the value of Cell c.

Note
This is implemented in terms of the prefix ++ operator for the cell's value type.
Parameters
cA Cell
Returns
The new value of c.

◆ operator++() [2/2]

auto live_cells::operator++ ( const MutableCell auto & c,
int  )

Increment the value of Cell c.

Attention
This is also implemented in terms of the prefix ++ operator for the cell's value type.
Parameters
cA Cell
Returns
The value of c before it is incremented.

◆ operator+=()

template<typename T >
T live_cells::operator+= ( const MutableCell auto & c,
const T & value )

Add value to the value of Cell c.

Note
This is equivalent to c = c.value() + value
Parameters
cA Cell
valueThe value to add to the value of c
Returns
The new value of c.

◆ operator-() [1/2]

template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto live_cells::operator- ( const A & a,
const B & b )

Create a Cell that computes the difference (using the - operator) of cells and .

Parameters
aA Cell or value
bA Cell or value
Returns
A new Cell

◆ operator-() [2/2]

Create a Cell that negates the value of another cell using the unary - operator.

Parameters
cellThe Cell to negate.
Returns
A new Cell

◆ operator--() [1/2]

auto live_cells::operator-- ( const MutableCell auto & c)

Decrement the value of Cell c.

Note
This is implemented in terms of the prefix – operator for the cell's value type.
Parameters
cA Cell
Returns
The new value of c.

◆ operator--() [2/2]

auto live_cells::operator-- ( const MutableCell auto & c,
int  )

Decrement the value of Cell c.

Attention
This is also implemented in terms of the prefix – operator for the cell's value type.
Parameters
cA Cell
Returns
The value of c before it is decremented.

◆ operator-=()

template<typename T >
T live_cells::operator-= ( const MutableCell auto & c,
const T & value )

Subtract value from the value of Cell c.

Note
This is equivalent to c = c.value() - value
Parameters
cA Cell
valueThe value to subtract from the value of c
Returns
The new value of c.

◆ operator/()

template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto live_cells::operator/ ( const A & a,
const B & b )

Create a Cell that computes the quotient (using the / operator) of cells and .

Parameters
aA Cell or value
bA Cell or value
Returns
A new Cell

◆ operator/=()

template<typename T >
T live_cells::operator/= ( const MutableCell auto & c,
const T & value )

Divide the value of Cell c by value.

Note
This is equivalent to c = c.value() / value
Parameters
cA Cell
valueThe divisor by which to divide the value of c
Returns
The new value of c.

◆ operator<()

template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto live_cells::operator< ( const A & a,
const B & b )

Create a Cell that is true if the value of cell is less than (by the < operator) the value of cell .

Parameters
aA Cell or value
bA Cell or value
Returns
A new Cell

◆ operator<<=()

template<typename T >
T live_cells::operator<<= ( const MutableCell auto & c,
const T & value )

Left shift the value of Cell c by value.

Note
This is equivalent to c = c.value() << value
Parameters
cA Cell
valueNumber of times to left shift the value of c
Returns
The new value of c.

◆ operator<=()

template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto live_cells::operator<= ( const A & a,
const B & b )

Create a Cell that is true if the value of cell is less than or equal to (by the <= operator) the value of cell .

Parameters
aA Cell or value
bA Cell or value
Returns
A new Cell

◆ operator==()

template<typename T , typename U >
requires ( (Cell<T> && CellOrValue<U>) || (CellOrValue<T> && Cell<U>) )
auto live_cells::operator== ( const T & a,
const U & b )

Create a Cell that compares two cells for equality by ==.

Parameters
aA Cell or value
bA Cell or value
Returns
A computed cell which evaluates the expression a == b.

◆ operator>()

template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto live_cells::operator> ( const A & a,
const B & b )

Create a Cell that is true if the value of cell is greater than (by the > operator) the value of cell .

Parameters
aA Cell or value
bA Cell or value
Returns
A new Cell

◆ operator>=()

template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto live_cells::operator>= ( const A & a,
const B & b )

Create a Cell that is true if the value of cell is greater than or equal to (by the >= operator) the value of cell .

Parameters
aA Cell or value
bA Cell or value
Returns
A new Cell

◆ operator>>=()

template<typename T >
T live_cells::operator>>= ( const MutableCell auto & c,
const T & value )

Right shift the value of Cell c by value.

Note
This is equivalent to c = c.value() >> value
Parameters
cA Cell
valueNumber of times to right shift the value of c
Returns
The new value of c.

◆ operator^=()

template<typename T >
T live_cells::operator^= ( const MutableCell auto & c,
const T & value )

Compute the bitwise exclusive or of the value of Cell c and value, and assign it to c.

Note
This is equivalent to c = c.value() ^ value
Parameters
cA Cell
valueA value
Returns
The new value of c.

◆ operator|=()

template<typename T >
T live_cells::operator|= ( const MutableCell auto & c,
const T & value )

Compute the bitwise or of the value of Cell c and value, and assign it to c.

Note
This is equivalent to c = c.value() | value
Parameters
cA Cell
valueA value
Returns
The new value of c.

◆ operator||()

template<typename A , typename B >
requires ( (Cell<A> && CellOrValue<B>) || (CellOrValue<A> && Cell<B>) )
auto live_cells::operator|| ( const A & a,
const B & b )

Create a cell that evaluates to the logical or of the values of cells a and b.

Note
This operator is short-circuiting which means that the value of cell b is only referenced if a is false.
Parameters
aA Cell or value
bA Cell or value
Returns
A new Cell

◆ peek()

template<typename C >
auto live_cells::peek ( const C & cell)

Create a Cell that reads the value of cell but does not notify its observers when the value has changes.

Parameters
cellThe Cell of which to read the value.
Returns
The peek cell

◆ previous()

template<Cell C>
auto live_cells::previous ( const C & cell)

Create a Cell that evaluates to the previous value of cell.

Attention
The returned cell only starts tracking the previous value of cell when the first observer is added. The cell requires at least one observer to track the previous value of cell correctly.
Parameters
cellcell The argument cell.
Returns
A cell that evaluates to the previous value of cell.

◆ select() [1/2]

auto live_cells::select ( Cell auto condition,
Cell auto if_true )

Create a cell which evaluates to the value of another cell only if a condition is true.

If the value of the condition cell is true, the cell evaluates to the value of the if_true cell. Otherwise the cell preserves its current value as if by calling none().

Parameters
conditionCondition cell
if_trueCell selected when condition is true
Returns
The selection cell

◆ select() [2/2]

auto live_cells::select ( Cell auto condition,
Cell auto if_true,
Cell auto if_false )

Create a cell which selects between the values of two cells based on the value of a condition cell.

If the value of the condition cell is true, the cell evaluates to the value of the if_true cell. Otherwise the cell evaluates to the value of the if_false cell.

Parameters
conditionCondition cell used to select between if_true and if_false
if_trueCell selected when condition is true
if_falseCell selected when condition is false
Returns
The selection cell

◆ store() [1/2]

template<Cell C>
auto live_cells::store ( changes_only_option option,
const C & arg )

Create a Cell that caches the value of another Cell and only notifies its observers when its value has actually changed.

The returned cell reads the value of arg and caches it until it changes.

This cell guarantes that the value of arg is only recomputed when it when its dependencies change instead of being computed every time it is accessed, provided its value is only accessed through the returned cell.

Note
The difference between this and the other overloads, is that with this overload, the cell only notifies its observers when its new value is not equal to its previous value.
Parameters
optionChanges only cell option
argThe argument cell
Returns
A cell which has the same value as arg, but caches it in memory until it changes.

◆ store() [2/2]

template<Cell C>
auto live_cells::store ( const C & arg)

Create a Cell that caches the value of another Cell.

The returned cell reads the value of arg and caches it until it changes.

This cell guarantes that the value of arg is only recomputed when it when its dependencies change instead of being computed every time it is accessed, provided its value is only accessed through the returned cell.

Parameters
argThe argument cell
Returns
A cell which has the same value as arg, but caches it in memory until it changes.

◆ value()

template<typename T >
constant_cell< T > live_cells::value ( const T & value)

Create a cell that holds a constant value.

Parameters
valueThe constant value.
Returns
A cell

◆ variable() [1/2]

template<typename T >
mutable_cell< T > live_cells::variable ( key_ref key,
T value )

Create a new mutable cell, identified by a key, with an initial value.

Note
value is ignored if key already identifies a mutable cell.
Parameters
keyKey identifying cell
valueThe initial value
Returns
A mutable cell

◆ variable() [2/2]

template<typename T >
mutable_cell< T > live_cells::variable ( T value)

Create a new mutable cell with an initial value.

Parameters
valueThe initial value
Returns
A mutable cell

◆ watch()

template<typename F >
std::shared_ptr< watcher > live_cells::watch ( F fn)

Register a cell watch function.

The function fn is called whenever the values of the cells referenced within it change.

fn is always called once immediately before this function returns, to determine which cells it references.

Parameters
fnA function of no arguments.
Returns
A shared pointer to a watch handle.
The watch function is called for all changes to the values of the argument cells until the watch handle is destroyed, or its watcher::stop() method is called.