Live Cells C++
Reactive Programming for C++
Loading...
Searching...
No Matches
compute_cell.hpp
1/*
2 * live_cells_cpp
3 * Copyright (C) 2024 Alexander Gutev <alex.gutev@gmail.com>
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you
6 * may not use this file except in compliance with the License. You
7 * may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 */
17
18#ifndef LIVE_CELLS_COMPUTE_CELL_HPP
19#define LIVE_CELLS_COMPUTE_CELL_HPP
20
21#include <concepts>
22#include <type_traits>
23
24#include "dependent_cell.hpp"
25#include "make_cell.hpp"
26
27namespace live_cells {
28
43 template <std::invocable F, Cell... Ts>
44 class compute_cell_base : public dependent_cell<Ts...> {
45 public:
55 compute_cell_base(F compute, Ts... args) :
56 dependent_cell<Ts...>(args...),
57 compute(compute) {}
58
67 auto value() const {
68 return compute();
69 }
70
71 private:
73 const F compute;
74
75 };
76
85 template <std::invocable F, Cell... Ts>
87
100 auto make_compute_cell(std::invocable auto f, auto... args) {
101 return compute_cell<decltype(f), decltype(args)...>(f, args...);
102 }
103
118 auto make_compute_cell(key_ref key, std::invocable auto f, auto... args) {
119 return compute_cell<decltype(f), decltype(args)...>(key, f, args...);
120 }
121
122} // live_cells
123
124#endif /* LIVE_CELLS_COMPUTE_CELL_HPP */
A cell with a value that is a function of one or more argument cells.
Definition compute_cell.hpp:44
auto value() const
Get the value of the cell.
Definition compute_cell.hpp:67
compute_cell_base(F compute, Ts... args)
Create a cell with a value that is a function of the values of the cells args.
Definition compute_cell.hpp:55
Provides an interface for a cell with a value that is dependent on one or more argument cells.
Definition dependent_cell.hpp:44
Dynamically type key container.
Definition keys.hpp:76
Defines the interface for a key which uniquely identifies a cell.
Definition keys.hpp:33
Definition boolean.hpp:26
auto make_compute_cell(std::invocable auto f, auto... args)
Definition compute_cell.hpp:100
Defines a cell class using C such that the constraints defined by the concept Cell are satisifed.
Definition make_cell.hpp:60